]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/HighBitSet32.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseLib / HighBitSet32.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 #include "BaseLibInternals.h"
10
11 /**
12 Returns the bit position of the highest bit set in a 32-bit value. Equivalent
13 to log2(x).
14
15 This function computes the bit position of the highest bit set in the 32-bit
16 value specified by Operand. If Operand is zero, then -1 is returned.
17 Otherwise, a value between 0 and 31 is returned.
18
19 @param Operand The 32-bit operand to evaluate.
20
21 @retval 0..31 Position of the highest bit set in Operand if found.
22 @retval -1 Operand is zero.
23
24 **/
25 INTN
26 EFIAPI
27 HighBitSet32 (
28 IN UINT32 Operand
29 )
30 {
31 INTN BitIndex;
32
33 if (Operand == 0) {
34 return -1;
35 }
36
37 for (BitIndex = 31; (INT32)Operand > 0; BitIndex--, Operand <<= 1) {
38 }
39
40 return BitIndex;
41 }