3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Math routines for IPF.
31 Left-shift a 64 bit value.
35 Operand - 64-bit value to shift
48 return Operand
<< Count
;
60 Right-shift a 64 bit value.
64 Operand - 64-bit value to shift
77 return Operand
>> Count
;
89 Right-shift a 64 bit signed value.
93 Operand - 64-bit value to shift
104 if (Operand
& (0x01 << 63)) {
111 return Operand
>> Count
;
116 // The compiler generates true assembly for these, so we don't need them.
127 Right shift a 32-bit value
131 Operand - value to shift
140 return Operand
>> (Count
& 0x1f);
153 Multiply two signed 32-bit numbers.
157 Value1 - first value to multiply
158 Value2 - value to multiply Value1 by
159 ResultHigh - overflow
167 The 64-bit result is the concatenation of *ResultHigh and the return value
169 The product fits in 32 bits if
170 (*ResultHigh == 0x00000000 AND *ResultLow_bit31 == 0)
172 (*ResultHigh == 0xffffffff AND *ResultLow_bit31 == 1)
179 Res64
= (INT64
) Value1
* (INT64
) Value2
;
180 *ResultHigh
= (Res64
>> 32) & 0xffffffff;
181 Result
= Res64
& 0xffffffff;
195 Multiply two unsigned 32-bit values.
199 Value1 - first number
200 Value2 - number to multiply by Value1
201 ResultHigh - overflow
209 The 64-bit result is the concatenation of *ResultHigh and the return value.
210 The product fits in 32 bits if *ResultHigh == 0x00000000
217 Res64
= (INT64
) Value1
* (INT64
) Value2
;
218 *ResultHigh
= (Res64
>> 32) & 0xffffffff;
219 Result
= Res64
& 0xffffffff;
231 // signed 32-bit by signed 32-bit divide; the 32-bit remainder is
232 // in *Remainder and the quotient is the return value; *error = 1 if the
233 // divisor is 0, and it is 1 otherwise
243 *Remainder
= 0x80000000;
245 Result
= Value1
/ Value2
;
246 *Remainder
= Value1
- Result
* Value2
;
260 // unsigned 32-bit by unsigned 32-bit divide; the 32-bit remainder is
261 // in *Remainder and the quotient is the return value; *error = 1 if the
262 // divisor is 0, and it is 1 otherwise
272 *Remainder
= 0x80000000;
274 Result
= Value1
/ Value2
;
275 *Remainder
= Value1
- Result
* Value2
;
294 Divide two 64-bit signed values.
300 Remainder - remainder of Value1/Value2
301 Error - to flag errors (divide-by-0)
309 The 64-bit remainder is in *Remainder and the quotient is the return value.
310 *Error = 1 if the divisor is 0, and it is 1 otherwise
320 Result
= 0x8000000000000000;
321 *Remainder
= 0x8000000000000000;
323 Result
= Value1
/ Value2
;
324 *Remainder
= Value1
- Result
* Value2
;
341 Divide two 64-bit unsigned values.
347 Remainder - remainder of Value1/Value2
348 Error - to flag errors (divide-by-0)
356 The 64-bit remainder is in *Remainder and the quotient is the return value.
357 *Error = 1 if the divisor is 0, and it is 1 otherwise
367 Result
= 0x8000000000000000;
368 *Remainder
= 0x8000000000000000;
370 Result
= Value1
/ Value2
;
371 *Remainder
= Value1
- Result
* Value2
;