• 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 #include "Tiano.h"
23 
24 UINT8
Log2(IN UINT64 Operand)25 Log2 (
26   IN UINT64   Operand
27   )
28 /*++
29 
30 Routine Description:
31 
32   Calculates and floors logarithms based on 2
33 
34 Arguments:
35 
36   Operand - value to calculate logarithm
37 
38 Returns:
39 
40   The largest integer that is less than or equal
41   to the logarithm of Operand based on 2
42 
43 --*/
44 {
45   __asm {
46   mov    ecx, 64
47 
48   cmp    dword ptr Operand[0], 0
49   jne    _Log2_Wend
50   cmp    dword ptr Operand[4], 0
51   jne    _Log2_Wend
52   mov    cl, 0FFH
53   jmp    _Log2_Done
54 
55 _Log2_Wend:
56   dec    ecx
57   cmp    ecx, 32
58   jae    _Log2_Higher
59   bt     dword ptr Operand[0], ecx
60   jmp    _Log2_Bit
61 
62 _Log2_Higher:
63   mov    eax, ecx
64   sub    eax, 32
65   bt     dword ptr Operand[4], eax
66 
67 _Log2_Bit:
68   jc     _Log2_Done
69   jmp    _Log2_Wend
70 
71 _Log2_Done:
72   mov    al, cl
73   }
74 }
75