1#/*++ 2# 3#Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> 4#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#include "EfiBind.h" 23#--------------------------------------------------------------------------- 24 .686: 25 #.MODEL flat,C 26 .code: 27 28#--------------------------------------------------------------------------- 29.globl ASM_PFX(GetPowerOfTwo) 30#UINT64 31#GetPowerOfTwo ( 32# IN UINT64 Input 33# ) 34#/*++ 35# 36#Routine Description: 37# 38# Calculates the largest integer that is both 39# a power of two and less than Input 40# 41#Arguments: 42# 43# Input - value to calculate power of two 44# 45#Returns: 46# 47# the largest integer that is both a power of 48# two and less than Input 49# 50#--*/ 51ASM_PFX(GetPowerOfTwo): 52 xorl %eax, %eax 53 movl %eax, %edx 54 movl 8(%esp), %ecx # dword ptr Input[4] 55 jecxz _F 56 bsrl %ecx, %ecx 57 btsl %ecx, %edx 58 jmp _Exit 59_F: 60 movl 4(%esp), %ecx # dword ptr Input[0] 61 jecxz _Exit 62 bsrl %ecx, %ecx 63 btsl %ecx, %eax 64_Exit: 65 66 ret 67#GetPowerOfTwo ENDP 68 69