]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/HighBitSet64.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseLib / HighBitSet64.c
1 /** @file
2 Math worker functions.
3
4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9
10
11
12 #include "BaseLibInternals.h"
13
14 /**
15 Returns the bit position of the highest bit set in a 64-bit value. Equivalent
16 to log2(x).
17
18 This function computes the bit position of the highest bit set in the 64-bit
19 value specified by Operand. If Operand is zero, then -1 is returned.
20 Otherwise, a value between 0 and 63 is returned.
21
22 @param Operand The 64-bit operand to evaluate.
23
24 @retval 0..63 Position of the highest bit set in Operand if found.
25 @retval -1 Operand is zero.
26
27 **/
28 INTN
29 EFIAPI
30 HighBitSet64 (
31 IN UINT64 Operand
32 )
33 {
34 if (Operand == (UINT32)Operand) {
35 //
36 // Operand is just a 32-bit integer
37 //
38 return HighBitSet32 ((UINT32)Operand);
39 }
40
41 //
42 // Operand is really a 64-bit integer
43 //
44 if (sizeof (UINTN) == sizeof (UINT32)) {
45 return HighBitSet32 (((UINT32*)&Operand)[1]) + 32;
46 } else {
47 return HighBitSet32 ((UINT32)RShiftU64 (Operand, 32)) + 32;
48 }
49 }