]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/Math.c
3 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
4 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 worker functions.
33 This routine allows a 64 bit value to be left shifted by 32 bits and
34 returns the shifted value.
35 Count is valid up 63. (Only Bits 0-5 is valid for Count)
39 Operand - Value to be shifted
40 Count - Number of times to shift left.
44 Value shifted left identified by the Count.
48 return Operand
<< Count
;
53 IN UINT64 Multiplicand
,
60 This routine allows a 64 bit value to be multiplied with a 32 bit
61 value returns 64bit result.
62 No checking if the result is greater than 64bits
66 Multiplicand - multiplicand
67 Multiplier - multiplier
71 Multiplicand * Multiplier
75 return Multiplicand
* Multiplier
;
102 This routine allows a 64 bit value to be right shifted by 32 bits and returns the
104 Count is valid up 63. (Only Bits 0-5 is valid for Count)
108 Operand - Value to be shifted
109 Count - Number of times to shift right.
113 Value shifted right identified by the Count.
117 return Operand
>> Count
;
124 OUT UINTN
*Remainder OPTIONAL
130 This routine allows a 64 bit value to be divided with a 32 bit value returns
131 64bit result and the Remainder.
137 Remainder - buffer for remainder
142 Remainder = Dividend mod Divisor
146 if (Remainder
!= NULL
) {
147 *Remainder
= Dividend
% Divisor
;
150 return Dividend
/ Divisor
;
161 This function computes rounded down log2 of the Operand. This is an equivalent
162 of the position of the highest bit set in the Operand treated as a mask.
163 E.g., Log2 (0x0001) == 0, Log2 (0x0002) == 1, Log2 (0x0003) == 1, Log2 (0x0005) == 2
164 Log2 (0x4000) == 14, Log2 (0x8000) == 15, Log2 (0xC000) == 15, Log2 (0xFFFF) == 15, etc.
167 Operand - value of which the Log2 is to be computed.
170 Rounded down log2 of the Operand or 0xFF if zero passed in.
181 while (Operand
!= 0) {
185 return (UINT8
)(Bitpos
- 1);
197 Calculates the largest integer that is both
198 a power of two and less than Input
202 Operand - value to calculate power of two
206 the largest integer that is both a power of
207 two and less than Input
218 while (Operand
!= 0) {
225 while (Bitpos
!= 0) {