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