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