EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/Ia32/GetPowerOfTwo.c

Go to the documentation of this file.
00001 /*++
00002 
00003 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
00004 This program and the accompanying materials                          
00005 are licensed and made available under the terms and conditions of the BSD License         
00006 which accompanies this distribution.  The full text of the license may be found at        
00007 http://opensource.org/licenses/bsd-license.php                                            
00008                                                                                           
00009 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
00010 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
00011 
00012 Module Name:
00013 
00014   GetPowerOfTwo.c
00015 
00016 Abstract:
00017 
00018   Calculates the largest integer that is both 
00019   a power of two and less than Input
00020 
00021 --*/
00022 
00023 #include "Tiano.h"
00024 
00025 UINT64
00026 GetPowerOfTwo (
00027   IN UINT64   Input
00028   )
00029 /*++
00030 
00031 Routine Description:
00032 
00033   Calculates the largest integer that is both 
00034   a power of two and less than Input
00035 
00036 Arguments:
00037 
00038   Input  - value to calculate power of two
00039 
00040 Returns:
00041 
00042   the largest integer that is both  a power of 
00043   two and less than Input
00044 
00045 --*/
00046 {
00047   __asm {
00048     xor     eax, eax
00049     mov     edx, eax
00050     mov     ecx, dword ptr Input[4]
00051     jecxz   _F
00052     bsr     ecx, ecx
00053     bts     edx, ecx
00054     jmp     _Exit
00055 _F:
00056     mov     ecx, dword ptr Input[0]
00057     jecxz   _Exit
00058     bsr     ecx, ecx
00059     bts     eax, ecx
00060 _Exit:
00061   }
00062 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines