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