]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/Ia32/GetPowerOfTwo.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EfiCommonLib / Ia32 / GetPowerOfTwo.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 GetPowerOfTwo.c
15
16 Abstract:
17
18 Calculates the largest integer that is both
19 a power of two and less than Input
20
21 --*/
22
23 #include "Tiano.h"
24
25 UINT64
26 GetPowerOfTwo (
27 IN UINT64 Input
28 )
29 /*++
30
31 Routine Description:
32
33 Calculates the largest integer that is both
34 a power of two and less than Input
35
36 Arguments:
37
38 Input - value to calculate power of two
39
40 Returns:
41
42 the largest integer that is both a power of
43 two and less than Input
44
45 --*/
46 {
47 __asm {
48 xor eax, eax
49 mov edx, eax
50 mov ecx, dword ptr Input[4]
51 jecxz _F
52 bsr ecx, ecx
53 bts edx, ecx
54 jmp _Exit
55 _F:
56 mov ecx, dword ptr Input[0]
57 jecxz _Exit
58 bsr ecx, ecx
59 bts eax, ecx
60 _Exit:
61 }
62 }