]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/Math.c
ba00c8bb3d3f467923c902cb2ce2abe4bc95baac
3 Copyright (c) 2004, 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 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
;
87 This routine allows a 64 bit value to be right shifted by 32 bits and returns the
89 Count is valid up 63. (Only Bits 0-5 is valid for Count)
93 Operand - Value to be shifted
94 Count - Number of times to shift right.
98 Value shifted right identified by the Count.
102 return Operand
>> Count
;
109 OUT UINTN
*Remainder OPTIONAL
115 This routine allows a 64 bit value to be divided with a 32 bit value returns
116 64bit result and the Remainder.
122 Remainder - buffer for remainder
127 Remainder = Dividend mod Divisor
131 if (Remainder
!= NULL
) {
132 *Remainder
= Dividend
% Divisor
;
135 return Dividend
/ Divisor
;
146 This function computes rounded down log2 of the Operand. This is an equivalent
147 of the position of the highest bit set in the Operand treated as a mask.
148 E.g., Log2 (0x0001) == 0, Log2 (0x0002) == 1, Log2 (0x0003) == 1, Log2 (0x0005) == 2
149 Log2 (0x4000) == 14, Log2 (0x8000) == 15, Log2 (0xC000) == 15, Log2 (0xFFFF) == 15, etc.
152 Operand - value of which the Log2 is to be computed.
155 Rounded down log2 of the Operand or 0xFF if zero passed in.
166 while (Operand
!= 0) {
170 return (UINT8
)(Bitpos
- 1);
182 Calculates the largest integer that is both
183 a power of two and less than Input
187 Operand - value to calculate power of two
191 the largest integer that is both a power of
192 two and less than Input
203 while (Operand
!= 0) {
210 while (Bitpos
!= 0) {