• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#  Log2.c
15#
16#Abstract:
17#
18#  64-bit integer logarithm function for IA-32
19#
20#--*/
21#
22#---------------------------------------------------------------------------
23#include "EfiBind.h" //For ASM_PFX
24#---------------------------------------------------------------------------
25
26.globl ASM_PFX(Log2)
27
28#UINT8
29#Log2 (
30#  IN UINT64   Operand
31#  )
32#/*++
33#
34#Routine Description:
35#
36#  Calculates and floors logarithms based on 2
37#
38#Arguments:
39#
40#  Operand - value to calculate logarithm
41#
42#Returns:
43#
44#  The largest integer that is less than or equal
45#  to the logarithm of Operand based on 2
46#
47#--*/
48ASM_PFX(Log2):
49  movl   $64, %ecx
50
51  cmpl   $0, 4(%esp)             # (UINT32 *(&Operand))
52  jne    _Log2_Wend
53  cmpl   $0, 8(%esp)             # (UINT32 *(&Operand)) + 1
54  jne    _Log2_Wend
55  movb   $0xFF, %cl
56  jmp    _Log2_Done
57
58_Log2_Wend:
59  decl   %ecx
60  cmpl   $32, %ecx
61  jae    _Log2_Higher
62  btl    %ecx, 4(%esp)  # (UINT32 *(&Operand))
63  jmp    _Log2_Bit
64
65_Log2_Higher:
66  movl   %ecx, %eax
67  subl   $32, %eax
68  btl    %eax, 8(%esp)  # (UINT32 *(&Operand)) + 1
69
70_Log2_Bit:
71  jc     _Log2_Done
72  jmp    _Log2_Wend
73
74_Log2_Done:
75  movb   %cl, %al
76
77  ret
78
79