4747#define _COMPONENT ACPI_UTILITIES
4848ACPI_MODULE_NAME ("utmath" )
4949
50- /*
51- * Optional support for 64-bit double-precision integer divide. This code
52- * is configurable and is implemented in order to support 32-bit kernel
53- * environments where a 64-bit double-precision math library is not available.
54- *
55- * Support for a more normal 64-bit divide/modulo (with check for a divide-
56- * by-zero) appears after this optional section of code.
57- */
58- #ifndef ACPI_USE_NATIVE_DIVIDE
5950/* Structures used only for 64-bit divide */
6051typedef struct uint64_struct {
6152 u32 lo ;
@@ -69,6 +60,217 @@ typedef union uint64_overlay {
6960
7061} uint64_overlay ;
7162
63+ /*
64+ * Optional support for 64-bit double-precision integer multiply and shift.
65+ * This code is configurable and is implemented in order to support 32-bit
66+ * kernel environments where a 64-bit double-precision math library is not
67+ * available.
68+ */
69+ #ifndef ACPI_USE_NATIVE_MATH64
70+
71+ /*******************************************************************************
72+ *
73+ * FUNCTION: acpi_ut_short_multiply
74+ *
75+ * PARAMETERS: multiplicand - 64-bit multiplicand
76+ * multiplier - 32-bit multiplier
77+ * out_product - Pointer to where the product is returned
78+ *
79+ * DESCRIPTION: Perform a short multiply.
80+ *
81+ ******************************************************************************/
82+
83+ acpi_status
84+ acpi_ut_short_multiply (u64 multiplicand , u32 multiplier , u64 * out_product )
85+ {
86+ union uint64_overlay multiplicand_ovl ;
87+ union uint64_overlay product ;
88+ u32 carry32 ;
89+
90+ ACPI_FUNCTION_TRACE (ut_short_multiply );
91+
92+ multiplicand_ovl .full = multiplicand ;
93+
94+ /*
95+ * The Product is 64 bits, the carry is always 32 bits,
96+ * and is generated by the second multiply.
97+ */
98+ ACPI_MUL_64_BY_32 (0 , multiplicand_ovl .part .hi , multiplier ,
99+ product .part .hi , carry32 );
100+
101+ ACPI_MUL_64_BY_32 (0 , multiplicand_ovl .part .lo , multiplier ,
102+ product .part .lo , carry32 );
103+
104+ product .part .hi += carry32 ;
105+
106+ /* Return only what was requested */
107+
108+ if (out_product ) {
109+ * out_product = product .full ;
110+ }
111+
112+ return_ACPI_STATUS (AE_OK );
113+ }
114+
115+ /*******************************************************************************
116+ *
117+ * FUNCTION: acpi_ut_short_shift_left
118+ *
119+ * PARAMETERS: operand - 64-bit shift operand
120+ * count - 32-bit shift count
121+ * out_result - Pointer to where the result is returned
122+ *
123+ * DESCRIPTION: Perform a short left shift.
124+ *
125+ ******************************************************************************/
126+
127+ acpi_status acpi_ut_short_shift_left (u64 operand , u32 count , u64 * out_result )
128+ {
129+ union uint64_overlay operand_ovl ;
130+
131+ ACPI_FUNCTION_TRACE (ut_short_shift_left );
132+
133+ operand_ovl .full = operand ;
134+
135+ if ((count & 63 ) >= 32 ) {
136+ operand_ovl .part .hi = operand_ovl .part .lo ;
137+ operand_ovl .part .lo ^= operand_ovl .part .lo ;
138+ count = (count & 63 ) - 32 ;
139+ }
140+ ACPI_SHIFT_LEFT_64_BY_32 (operand_ovl .part .hi ,
141+ operand_ovl .part .lo , count );
142+
143+ /* Return only what was requested */
144+
145+ if (out_result ) {
146+ * out_result = operand_ovl .full ;
147+ }
148+
149+ return_ACPI_STATUS (AE_OK );
150+ }
151+
152+ /*******************************************************************************
153+ *
154+ * FUNCTION: acpi_ut_short_shift_right
155+ *
156+ * PARAMETERS: operand - 64-bit shift operand
157+ * count - 32-bit shift count
158+ * out_result - Pointer to where the result is returned
159+ *
160+ * DESCRIPTION: Perform a short right shift.
161+ *
162+ ******************************************************************************/
163+
164+ acpi_status acpi_ut_short_shift_right (u64 operand , u32 count , u64 * out_result )
165+ {
166+ union uint64_overlay operand_ovl ;
167+
168+ ACPI_FUNCTION_TRACE (ut_short_shift_right );
169+
170+ operand_ovl .full = operand ;
171+
172+ if ((count & 63 ) >= 32 ) {
173+ operand_ovl .part .lo = operand_ovl .part .hi ;
174+ operand_ovl .part .hi ^= operand_ovl .part .hi ;
175+ count = (count & 63 ) - 32 ;
176+ }
177+ ACPI_SHIFT_RIGHT_64_BY_32 (operand_ovl .part .hi ,
178+ operand_ovl .part .lo , count );
179+
180+ /* Return only what was requested */
181+
182+ if (out_result ) {
183+ * out_result = operand_ovl .full ;
184+ }
185+
186+ return_ACPI_STATUS (AE_OK );
187+ }
188+ #else
189+
190+ /*******************************************************************************
191+ *
192+ * FUNCTION: acpi_ut_short_multiply
193+ *
194+ * PARAMETERS: See function headers above
195+ *
196+ * DESCRIPTION: Native version of the ut_short_multiply function.
197+ *
198+ ******************************************************************************/
199+
200+ acpi_status
201+ acpi_ut_short_multiply (u64 multiplicand , u32 multiplier , u64 * out_product )
202+ {
203+
204+ ACPI_FUNCTION_TRACE (ut_short_multiply );
205+
206+ /* Return only what was requested */
207+
208+ if (out_product ) {
209+ * out_product = multiplicand * multiplier ;
210+ }
211+
212+ return_ACPI_STATUS (AE_OK );
213+ }
214+
215+ /*******************************************************************************
216+ *
217+ * FUNCTION: acpi_ut_short_shift_left
218+ *
219+ * PARAMETERS: See function headers above
220+ *
221+ * DESCRIPTION: Native version of the ut_short_shift_left function.
222+ *
223+ ******************************************************************************/
224+
225+ acpi_status acpi_ut_short_shift_left (u64 operand , u32 count , u64 * out_result )
226+ {
227+
228+ ACPI_FUNCTION_TRACE (ut_short_shift_left );
229+
230+ /* Return only what was requested */
231+
232+ if (out_result ) {
233+ * out_result = operand << count ;
234+ }
235+
236+ return_ACPI_STATUS (AE_OK );
237+ }
238+
239+ /*******************************************************************************
240+ *
241+ * FUNCTION: acpi_ut_short_shift_right
242+ *
243+ * PARAMETERS: See function headers above
244+ *
245+ * DESCRIPTION: Native version of the ut_short_shift_right function.
246+ *
247+ ******************************************************************************/
248+
249+ acpi_status acpi_ut_short_shift_right (u64 operand , u32 count , u64 * out_result )
250+ {
251+
252+ ACPI_FUNCTION_TRACE (ut_short_shift_right );
253+
254+ /* Return only what was requested */
255+
256+ if (out_result ) {
257+ * out_result = operand >> count ;
258+ }
259+
260+ return_ACPI_STATUS (AE_OK );
261+ }
262+ #endif
263+
264+ /*
265+ * Optional support for 64-bit double-precision integer divide. This code
266+ * is configurable and is implemented in order to support 32-bit kernel
267+ * environments where a 64-bit double-precision math library is not available.
268+ *
269+ * Support for a more normal 64-bit divide/modulo (with check for a divide-
270+ * by-zero) appears after this optional section of code.
271+ */
272+ #ifndef ACPI_USE_NATIVE_DIVIDE
273+
72274/*******************************************************************************
73275 *
74276 * FUNCTION: acpi_ut_short_divide
@@ -258,6 +460,7 @@ acpi_ut_divide(u64 in_dividend,
258460}
259461
260462#else
463+
261464/*******************************************************************************
262465 *
263466 * FUNCTION: acpi_ut_short_divide, acpi_ut_divide
@@ -272,6 +475,7 @@ acpi_ut_divide(u64 in_dividend,
272475 * perform the divide.
273476 *
274477 ******************************************************************************/
478+
275479acpi_status
276480acpi_ut_short_divide (u64 in_dividend ,
277481 u32 divisor , u64 * out_quotient , u32 * out_remainder )
0 commit comments