]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseLib/LowBitSet64.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseLib / LowBitSet64.c
CommitLineData
e1f414b6 1/** @file\r
2 Math worker functions.\r
3\r
bb817c56 4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
9344f092 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
e1f414b6 6\r
7**/\r
8\r
e1f414b6 9#include "BaseLibInternals.h"\r
10\r
11/**\r
12 Returns the bit position of the lowest bit set in a 64-bit value.\r
13\r
14 This function computes the bit position of the lowest bit set in the 64-bit\r
15 value specified by Operand. If Operand is zero, then -1 is returned.\r
16 Otherwise, a value between 0 and 63 is returned.\r
17\r
18 @param Operand The 64-bit operand to evaluate.\r
19\r
9aa049d9 20 @retval 0..63 The lowest bit set in Operand was found.\r
127010dd 21 @retval -1 Operand is zero.\r
9aa049d9 22\r
e1f414b6 23\r
24**/\r
25INTN\r
26EFIAPI\r
27LowBitSet64 (\r
2f88bd3a 28 IN UINT64 Operand\r
e1f414b6 29 )\r
30{\r
2f88bd3a 31 INTN BitIndex;\r
e1f414b6 32\r
33 if (Operand == 0) {\r
34 return -1;\r
35 }\r
36\r
37 for (BitIndex = 0;\r
38 (Operand & 1) == 0;\r
2f88bd3a
MK
39 BitIndex++, Operand = RShiftU64 (Operand, 1))\r
40 {\r
41 }\r
42\r
e1f414b6 43 return BitIndex;\r
44}\r