utmath.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer /*******************************************************************************
2 1.1.1.2.2.2 bouyer *
3 1.1.1.2.2.2 bouyer * Module Name: utmath - Integer math support routines
4 1.1.1.2.2.2 bouyer *
5 1.1.1.2.2.2 bouyer ******************************************************************************/
6 1.1.1.2.2.2 bouyer
7 1.1.1.2.2.2 bouyer /*
8 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.2.2.2 bouyer * All rights reserved.
10 1.1.1.2.2.2 bouyer *
11 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.1.2.2.2 bouyer * are met:
14 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2.2.2 bouyer * without modification.
17 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.1.1.2.2.2 bouyer * binary redistribution.
22 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
25 1.1.1.2.2.2 bouyer *
26 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2.2.2 bouyer * Software Foundation.
29 1.1.1.2.2.2 bouyer *
30 1.1.1.2.2.2 bouyer * NO WARRANTY
31 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2.2.2 bouyer */
43 1.1.1.2.2.2 bouyer
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer #define __UTMATH_C__
46 1.1.1.2.2.2 bouyer
47 1.1.1.2.2.2 bouyer #include "acpi.h"
48 1.1.1.2.2.2 bouyer #include "accommon.h"
49 1.1.1.2.2.2 bouyer
50 1.1.1.2.2.2 bouyer
51 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_UTILITIES
52 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("utmath")
53 1.1.1.2.2.2 bouyer
54 1.1.1.2.2.2 bouyer /*
55 1.1.1.2.2.2 bouyer * Optional support for 64-bit double-precision integer divide. This code
56 1.1.1.2.2.2 bouyer * is configurable and is implemented in order to support 32-bit kernel
57 1.1.1.2.2.2 bouyer * environments where a 64-bit double-precision math library is not available.
58 1.1.1.2.2.2 bouyer *
59 1.1.1.2.2.2 bouyer * Support for a more normal 64-bit divide/modulo (with check for a divide-
60 1.1.1.2.2.2 bouyer * by-zero) appears after this optional section of code.
61 1.1.1.2.2.2 bouyer */
62 1.1.1.2.2.2 bouyer #ifndef ACPI_USE_NATIVE_DIVIDE
63 1.1.1.2.2.2 bouyer
64 1.1.1.2.2.2 bouyer /* Structures used only for 64-bit divide */
65 1.1.1.2.2.2 bouyer
66 1.1.1.2.2.2 bouyer typedef struct uint64_struct
67 1.1.1.2.2.2 bouyer {
68 1.1.1.2.2.2 bouyer UINT32 Lo;
69 1.1.1.2.2.2 bouyer UINT32 Hi;
70 1.1.1.2.2.2 bouyer
71 1.1.1.2.2.2 bouyer } UINT64_STRUCT;
72 1.1.1.2.2.2 bouyer
73 1.1.1.2.2.2 bouyer typedef union uint64_overlay
74 1.1.1.2.2.2 bouyer {
75 1.1.1.2.2.2 bouyer UINT64 Full;
76 1.1.1.2.2.2 bouyer UINT64_STRUCT Part;
77 1.1.1.2.2.2 bouyer
78 1.1.1.2.2.2 bouyer } UINT64_OVERLAY;
79 1.1.1.2.2.2 bouyer
80 1.1.1.2.2.2 bouyer
81 1.1.1.2.2.2 bouyer /*******************************************************************************
82 1.1.1.2.2.2 bouyer *
83 1.1.1.2.2.2 bouyer * FUNCTION: AcpiUtShortDivide
84 1.1.1.2.2.2 bouyer *
85 1.1.1.2.2.2 bouyer * PARAMETERS: Dividend - 64-bit dividend
86 1.1.1.2.2.2 bouyer * Divisor - 32-bit divisor
87 1.1.1.2.2.2 bouyer * OutQuotient - Pointer to where the quotient is returned
88 1.1.1.2.2.2 bouyer * OutRemainder - Pointer to where the remainder is returned
89 1.1.1.2.2.2 bouyer *
90 1.1.1.2.2.2 bouyer * RETURN: Status (Checks for divide-by-zero)
91 1.1.1.2.2.2 bouyer *
92 1.1.1.2.2.2 bouyer * DESCRIPTION: Perform a short (maximum 64 bits divided by 32 bits)
93 1.1.1.2.2.2 bouyer * divide and modulo. The result is a 64-bit quotient and a
94 1.1.1.2.2.2 bouyer * 32-bit remainder.
95 1.1.1.2.2.2 bouyer *
96 1.1.1.2.2.2 bouyer ******************************************************************************/
97 1.1.1.2.2.2 bouyer
98 1.1.1.2.2.2 bouyer ACPI_STATUS
99 1.1.1.2.2.2 bouyer AcpiUtShortDivide (
100 1.1.1.2.2.2 bouyer UINT64 Dividend,
101 1.1.1.2.2.2 bouyer UINT32 Divisor,
102 1.1.1.2.2.2 bouyer UINT64 *OutQuotient,
103 1.1.1.2.2.2 bouyer UINT32 *OutRemainder)
104 1.1.1.2.2.2 bouyer {
105 1.1.1.2.2.2 bouyer UINT64_OVERLAY DividendOvl;
106 1.1.1.2.2.2 bouyer UINT64_OVERLAY Quotient;
107 1.1.1.2.2.2 bouyer UINT32 Remainder32;
108 1.1.1.2.2.2 bouyer
109 1.1.1.2.2.2 bouyer
110 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (UtShortDivide);
111 1.1.1.2.2.2 bouyer
112 1.1.1.2.2.2 bouyer
113 1.1.1.2.2.2 bouyer /* Always check for a zero divisor */
114 1.1.1.2.2.2 bouyer
115 1.1.1.2.2.2 bouyer if (Divisor == 0)
116 1.1.1.2.2.2 bouyer {
117 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "Divide by zero"));
118 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
119 1.1.1.2.2.2 bouyer }
120 1.1.1.2.2.2 bouyer
121 1.1.1.2.2.2 bouyer DividendOvl.Full = Dividend;
122 1.1.1.2.2.2 bouyer
123 1.1.1.2.2.2 bouyer /*
124 1.1.1.2.2.2 bouyer * The quotient is 64 bits, the remainder is always 32 bits,
125 1.1.1.2.2.2 bouyer * and is generated by the second divide.
126 1.1.1.2.2.2 bouyer */
127 1.1.1.2.2.2 bouyer ACPI_DIV_64_BY_32 (0, DividendOvl.Part.Hi, Divisor,
128 1.1.1.2.2.2 bouyer Quotient.Part.Hi, Remainder32);
129 1.1.1.2.2.2 bouyer ACPI_DIV_64_BY_32 (Remainder32, DividendOvl.Part.Lo, Divisor,
130 1.1.1.2.2.2 bouyer Quotient.Part.Lo, Remainder32);
131 1.1.1.2.2.2 bouyer
132 1.1.1.2.2.2 bouyer /* Return only what was requested */
133 1.1.1.2.2.2 bouyer
134 1.1.1.2.2.2 bouyer if (OutQuotient)
135 1.1.1.2.2.2 bouyer {
136 1.1.1.2.2.2 bouyer *OutQuotient = Quotient.Full;
137 1.1.1.2.2.2 bouyer }
138 1.1.1.2.2.2 bouyer if (OutRemainder)
139 1.1.1.2.2.2 bouyer {
140 1.1.1.2.2.2 bouyer *OutRemainder = Remainder32;
141 1.1.1.2.2.2 bouyer }
142 1.1.1.2.2.2 bouyer
143 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
144 1.1.1.2.2.2 bouyer }
145 1.1.1.2.2.2 bouyer
146 1.1.1.2.2.2 bouyer
147 1.1.1.2.2.2 bouyer /*******************************************************************************
148 1.1.1.2.2.2 bouyer *
149 1.1.1.2.2.2 bouyer * FUNCTION: AcpiUtDivide
150 1.1.1.2.2.2 bouyer *
151 1.1.1.2.2.2 bouyer * PARAMETERS: InDividend - Dividend
152 1.1.1.2.2.2 bouyer * InDivisor - Divisor
153 1.1.1.2.2.2 bouyer * OutQuotient - Pointer to where the quotient is returned
154 1.1.1.2.2.2 bouyer * OutRemainder - Pointer to where the remainder is returned
155 1.1.1.2.2.2 bouyer *
156 1.1.1.2.2.2 bouyer * RETURN: Status (Checks for divide-by-zero)
157 1.1.1.2.2.2 bouyer *
158 1.1.1.2.2.2 bouyer * DESCRIPTION: Perform a divide and modulo.
159 1.1.1.2.2.2 bouyer *
160 1.1.1.2.2.2 bouyer ******************************************************************************/
161 1.1.1.2.2.2 bouyer
162 1.1.1.2.2.2 bouyer ACPI_STATUS
163 1.1.1.2.2.2 bouyer AcpiUtDivide (
164 1.1.1.2.2.2 bouyer UINT64 InDividend,
165 1.1.1.2.2.2 bouyer UINT64 InDivisor,
166 1.1.1.2.2.2 bouyer UINT64 *OutQuotient,
167 1.1.1.2.2.2 bouyer UINT64 *OutRemainder)
168 1.1.1.2.2.2 bouyer {
169 1.1.1.2.2.2 bouyer UINT64_OVERLAY Dividend;
170 1.1.1.2.2.2 bouyer UINT64_OVERLAY Divisor;
171 1.1.1.2.2.2 bouyer UINT64_OVERLAY Quotient;
172 1.1.1.2.2.2 bouyer UINT64_OVERLAY Remainder;
173 1.1.1.2.2.2 bouyer UINT64_OVERLAY NormalizedDividend;
174 1.1.1.2.2.2 bouyer UINT64_OVERLAY NormalizedDivisor;
175 1.1.1.2.2.2 bouyer UINT32 Partial1;
176 1.1.1.2.2.2 bouyer UINT64_OVERLAY Partial2;
177 1.1.1.2.2.2 bouyer UINT64_OVERLAY Partial3;
178 1.1.1.2.2.2 bouyer
179 1.1.1.2.2.2 bouyer
180 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (UtDivide);
181 1.1.1.2.2.2 bouyer
182 1.1.1.2.2.2 bouyer
183 1.1.1.2.2.2 bouyer /* Always check for a zero divisor */
184 1.1.1.2.2.2 bouyer
185 1.1.1.2.2.2 bouyer if (InDivisor == 0)
186 1.1.1.2.2.2 bouyer {
187 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "Divide by zero"));
188 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
189 1.1.1.2.2.2 bouyer }
190 1.1.1.2.2.2 bouyer
191 1.1.1.2.2.2 bouyer Divisor.Full = InDivisor;
192 1.1.1.2.2.2 bouyer Dividend.Full = InDividend;
193 1.1.1.2.2.2 bouyer if (Divisor.Part.Hi == 0)
194 1.1.1.2.2.2 bouyer {
195 1.1.1.2.2.2 bouyer /*
196 1.1.1.2.2.2 bouyer * 1) Simplest case is where the divisor is 32 bits, we can
197 1.1.1.2.2.2 bouyer * just do two divides
198 1.1.1.2.2.2 bouyer */
199 1.1.1.2.2.2 bouyer Remainder.Part.Hi = 0;
200 1.1.1.2.2.2 bouyer
201 1.1.1.2.2.2 bouyer /*
202 1.1.1.2.2.2 bouyer * The quotient is 64 bits, the remainder is always 32 bits,
203 1.1.1.2.2.2 bouyer * and is generated by the second divide.
204 1.1.1.2.2.2 bouyer */
205 1.1.1.2.2.2 bouyer ACPI_DIV_64_BY_32 (0, Dividend.Part.Hi, Divisor.Part.Lo,
206 1.1.1.2.2.2 bouyer Quotient.Part.Hi, Partial1);
207 1.1.1.2.2.2 bouyer ACPI_DIV_64_BY_32 (Partial1, Dividend.Part.Lo, Divisor.Part.Lo,
208 1.1.1.2.2.2 bouyer Quotient.Part.Lo, Remainder.Part.Lo);
209 1.1.1.2.2.2 bouyer }
210 1.1.1.2.2.2 bouyer
211 1.1.1.2.2.2 bouyer else
212 1.1.1.2.2.2 bouyer {
213 1.1.1.2.2.2 bouyer /*
214 1.1.1.2.2.2 bouyer * 2) The general case where the divisor is a full 64 bits
215 1.1.1.2.2.2 bouyer * is more difficult
216 1.1.1.2.2.2 bouyer */
217 1.1.1.2.2.2 bouyer Quotient.Part.Hi = 0;
218 1.1.1.2.2.2 bouyer NormalizedDividend = Dividend;
219 1.1.1.2.2.2 bouyer NormalizedDivisor = Divisor;
220 1.1.1.2.2.2 bouyer
221 1.1.1.2.2.2 bouyer /* Normalize the operands (shift until the divisor is < 32 bits) */
222 1.1.1.2.2.2 bouyer
223 1.1.1.2.2.2 bouyer do
224 1.1.1.2.2.2 bouyer {
225 1.1.1.2.2.2 bouyer ACPI_SHIFT_RIGHT_64 (NormalizedDivisor.Part.Hi,
226 1.1.1.2.2.2 bouyer NormalizedDivisor.Part.Lo);
227 1.1.1.2.2.2 bouyer ACPI_SHIFT_RIGHT_64 (NormalizedDividend.Part.Hi,
228 1.1.1.2.2.2 bouyer NormalizedDividend.Part.Lo);
229 1.1.1.2.2.2 bouyer
230 1.1.1.2.2.2 bouyer } while (NormalizedDivisor.Part.Hi != 0);
231 1.1.1.2.2.2 bouyer
232 1.1.1.2.2.2 bouyer /* Partial divide */
233 1.1.1.2.2.2 bouyer
234 1.1.1.2.2.2 bouyer ACPI_DIV_64_BY_32 (NormalizedDividend.Part.Hi,
235 1.1.1.2.2.2 bouyer NormalizedDividend.Part.Lo,
236 1.1.1.2.2.2 bouyer NormalizedDivisor.Part.Lo,
237 1.1.1.2.2.2 bouyer Quotient.Part.Lo, Partial1);
238 1.1.1.2.2.2 bouyer
239 1.1.1.2.2.2 bouyer /*
240 1.1.1.2.2.2 bouyer * The quotient is always 32 bits, and simply requires adjustment.
241 1.1.1.2.2.2 bouyer * The 64-bit remainder must be generated.
242 1.1.1.2.2.2 bouyer */
243 1.1.1.2.2.2 bouyer Partial1 = Quotient.Part.Lo * Divisor.Part.Hi;
244 1.1.1.2.2.2 bouyer Partial2.Full = (UINT64) Quotient.Part.Lo * Divisor.Part.Lo;
245 1.1.1.2.2.2 bouyer Partial3.Full = (UINT64) Partial2.Part.Hi + Partial1;
246 1.1.1.2.2.2 bouyer
247 1.1.1.2.2.2 bouyer Remainder.Part.Hi = Partial3.Part.Lo;
248 1.1.1.2.2.2 bouyer Remainder.Part.Lo = Partial2.Part.Lo;
249 1.1.1.2.2.2 bouyer
250 1.1.1.2.2.2 bouyer if (Partial3.Part.Hi == 0)
251 1.1.1.2.2.2 bouyer {
252 1.1.1.2.2.2 bouyer if (Partial3.Part.Lo >= Dividend.Part.Hi)
253 1.1.1.2.2.2 bouyer {
254 1.1.1.2.2.2 bouyer if (Partial3.Part.Lo == Dividend.Part.Hi)
255 1.1.1.2.2.2 bouyer {
256 1.1.1.2.2.2 bouyer if (Partial2.Part.Lo > Dividend.Part.Lo)
257 1.1.1.2.2.2 bouyer {
258 1.1.1.2.2.2 bouyer Quotient.Part.Lo--;
259 1.1.1.2.2.2 bouyer Remainder.Full -= Divisor.Full;
260 1.1.1.2.2.2 bouyer }
261 1.1.1.2.2.2 bouyer }
262 1.1.1.2.2.2 bouyer else
263 1.1.1.2.2.2 bouyer {
264 1.1.1.2.2.2 bouyer Quotient.Part.Lo--;
265 1.1.1.2.2.2 bouyer Remainder.Full -= Divisor.Full;
266 1.1.1.2.2.2 bouyer }
267 1.1.1.2.2.2 bouyer }
268 1.1.1.2.2.2 bouyer
269 1.1.1.2.2.2 bouyer Remainder.Full = Remainder.Full - Dividend.Full;
270 1.1.1.2.2.2 bouyer Remainder.Part.Hi = (UINT32) -((INT32) Remainder.Part.Hi);
271 1.1.1.2.2.2 bouyer Remainder.Part.Lo = (UINT32) -((INT32) Remainder.Part.Lo);
272 1.1.1.2.2.2 bouyer
273 1.1.1.2.2.2 bouyer if (Remainder.Part.Lo)
274 1.1.1.2.2.2 bouyer {
275 1.1.1.2.2.2 bouyer Remainder.Part.Hi--;
276 1.1.1.2.2.2 bouyer }
277 1.1.1.2.2.2 bouyer }
278 1.1.1.2.2.2 bouyer }
279 1.1.1.2.2.2 bouyer
280 1.1.1.2.2.2 bouyer /* Return only what was requested */
281 1.1.1.2.2.2 bouyer
282 1.1.1.2.2.2 bouyer if (OutQuotient)
283 1.1.1.2.2.2 bouyer {
284 1.1.1.2.2.2 bouyer *OutQuotient = Quotient.Full;
285 1.1.1.2.2.2 bouyer }
286 1.1.1.2.2.2 bouyer if (OutRemainder)
287 1.1.1.2.2.2 bouyer {
288 1.1.1.2.2.2 bouyer *OutRemainder = Remainder.Full;
289 1.1.1.2.2.2 bouyer }
290 1.1.1.2.2.2 bouyer
291 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
292 1.1.1.2.2.2 bouyer }
293 1.1.1.2.2.2 bouyer
294 1.1.1.2.2.2 bouyer #else
295 1.1.1.2.2.2 bouyer
296 1.1.1.2.2.2 bouyer /*******************************************************************************
297 1.1.1.2.2.2 bouyer *
298 1.1.1.2.2.2 bouyer * FUNCTION: AcpiUtShortDivide, AcpiUtDivide
299 1.1.1.2.2.2 bouyer *
300 1.1.1.2.2.2 bouyer * PARAMETERS: See function headers above
301 1.1.1.2.2.2 bouyer *
302 1.1.1.2.2.2 bouyer * DESCRIPTION: Native versions of the UtDivide functions. Use these if either
303 1.1.1.2.2.2 bouyer * 1) The target is a 64-bit platform and therefore 64-bit
304 1.1.1.2.2.2 bouyer * integer math is supported directly by the machine.
305 1.1.1.2.2.2 bouyer * 2) The target is a 32-bit or 16-bit platform, and the
306 1.1.1.2.2.2 bouyer * double-precision integer math library is available to
307 1.1.1.2.2.2 bouyer * perform the divide.
308 1.1.1.2.2.2 bouyer *
309 1.1.1.2.2.2 bouyer ******************************************************************************/
310 1.1.1.2.2.2 bouyer
311 1.1.1.2.2.2 bouyer ACPI_STATUS
312 1.1.1.2.2.2 bouyer AcpiUtShortDivide (
313 1.1.1.2.2.2 bouyer UINT64 InDividend,
314 1.1.1.2.2.2 bouyer UINT32 Divisor,
315 1.1.1.2.2.2 bouyer UINT64 *OutQuotient,
316 1.1.1.2.2.2 bouyer UINT32 *OutRemainder)
317 1.1.1.2.2.2 bouyer {
318 1.1.1.2.2.2 bouyer
319 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (UtShortDivide);
320 1.1.1.2.2.2 bouyer
321 1.1.1.2.2.2 bouyer
322 1.1.1.2.2.2 bouyer /* Always check for a zero divisor */
323 1.1.1.2.2.2 bouyer
324 1.1.1.2.2.2 bouyer if (Divisor == 0)
325 1.1.1.2.2.2 bouyer {
326 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "Divide by zero"));
327 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
328 1.1.1.2.2.2 bouyer }
329 1.1.1.2.2.2 bouyer
330 1.1.1.2.2.2 bouyer /* Return only what was requested */
331 1.1.1.2.2.2 bouyer
332 1.1.1.2.2.2 bouyer if (OutQuotient)
333 1.1.1.2.2.2 bouyer {
334 1.1.1.2.2.2 bouyer *OutQuotient = InDividend / Divisor;
335 1.1.1.2.2.2 bouyer }
336 1.1.1.2.2.2 bouyer if (OutRemainder)
337 1.1.1.2.2.2 bouyer {
338 1.1.1.2.2.2 bouyer *OutRemainder = (UINT32) (InDividend % Divisor);
339 1.1.1.2.2.2 bouyer }
340 1.1.1.2.2.2 bouyer
341 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
342 1.1.1.2.2.2 bouyer }
343 1.1.1.2.2.2 bouyer
344 1.1.1.2.2.2 bouyer ACPI_STATUS
345 1.1.1.2.2.2 bouyer AcpiUtDivide (
346 1.1.1.2.2.2 bouyer UINT64 InDividend,
347 1.1.1.2.2.2 bouyer UINT64 InDivisor,
348 1.1.1.2.2.2 bouyer UINT64 *OutQuotient,
349 1.1.1.2.2.2 bouyer UINT64 *OutRemainder)
350 1.1.1.2.2.2 bouyer {
351 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (UtDivide);
352 1.1.1.2.2.2 bouyer
353 1.1.1.2.2.2 bouyer
354 1.1.1.2.2.2 bouyer /* Always check for a zero divisor */
355 1.1.1.2.2.2 bouyer
356 1.1.1.2.2.2 bouyer if (InDivisor == 0)
357 1.1.1.2.2.2 bouyer {
358 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "Divide by zero"));
359 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_DIVIDE_BY_ZERO);
360 1.1.1.2.2.2 bouyer }
361 1.1.1.2.2.2 bouyer
362 1.1.1.2.2.2 bouyer
363 1.1.1.2.2.2 bouyer /* Return only what was requested */
364 1.1.1.2.2.2 bouyer
365 1.1.1.2.2.2 bouyer if (OutQuotient)
366 1.1.1.2.2.2 bouyer {
367 1.1.1.2.2.2 bouyer *OutQuotient = InDividend / InDivisor;
368 1.1.1.2.2.2 bouyer }
369 1.1.1.2.2.2 bouyer if (OutRemainder)
370 1.1.1.2.2.2 bouyer {
371 1.1.1.2.2.2 bouyer *OutRemainder = InDividend % InDivisor;
372 1.1.1.2.2.2 bouyer }
373 1.1.1.2.2.2 bouyer
374 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
375 1.1.1.2.2.2 bouyer }
376 1.1.1.2.2.2 bouyer
377 1.1.1.2.2.2 bouyer #endif
378 1.1.1.2.2.2 bouyer
379 1.1.1.2.2.2 bouyer
380