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