]>
Commit | Line | Data |
---|---|---|
b341712e | 1 | #/*++\r |
2 | #\r | |
4ea9375a HT |
3 | #Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r |
4 | #This program and the accompanying materials \r | |
b341712e | 5 | #are licensed and made available under the terms and conditions of the BSD License \r |
6 | #which accompanies this distribution. The full text of the license may be found at \r | |
7 | #http://opensource.org/licenses/bsd-license.php \r | |
8 | # \r | |
9 | #THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | #WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | #\r | |
12 | #Module Name:\r | |
13 | #\r | |
14 | # Log2.c\r | |
15 | #\r | |
16 | #Abstract:\r | |
17 | #\r | |
18 | # 64-bit integer logarithm function for IA-32\r | |
19 | #\r | |
20 | #--*/\r | |
21 | #\r | |
22 | #---------------------------------------------------------------------------\r | |
23 | #include "EfiBind.h" //For ASM_PFX\r | |
24 | #---------------------------------------------------------------------------\r | |
25 | \r | |
26 | .globl ASM_PFX(Log2)\r | |
27 | \r | |
28 | #UINT8\r | |
29 | #Log2 (\r | |
30 | # IN UINT64 Operand\r | |
31 | # )\r | |
32 | #/*++\r | |
33 | #\r | |
34 | #Routine Description:\r | |
35 | # \r | |
36 | # Calculates and floors logarithms based on 2\r | |
37 | #\r | |
38 | #Arguments:\r | |
39 | #\r | |
40 | # Operand - value to calculate logarithm\r | |
41 | # \r | |
42 | #Returns:\r | |
43 | #\r | |
44 | # The largest integer that is less than or equal\r | |
45 | # to the logarithm of Operand based on 2 \r | |
46 | #\r | |
47 | #--*/\r | |
48 | ASM_PFX(Log2):\r | |
49 | movl $64, %ecx\r | |
50 | \r | |
51 | cmpl $0, 4(%esp) # (UINT32 *(&Operand))\r | |
52 | jne _Log2_Wend\r | |
53 | cmpl $0, 8(%esp) # (UINT32 *(&Operand)) + 1\r | |
54 | jne _Log2_Wend\r | |
55 | movb $0xFF, %cl\r | |
56 | jmp _Log2_Done\r | |
57 | \r | |
58 | _Log2_Wend: \r | |
59 | decl %ecx\r | |
60 | cmpl $32, %ecx\r | |
61 | jae _Log2_Higher\r | |
62 | btl %ecx, 4(%esp) # (UINT32 *(&Operand))\r | |
63 | jmp _Log2_Bit\r | |
64 | \r | |
65 | _Log2_Higher: \r | |
66 | movl %ecx, %eax\r | |
67 | subl $32, %eax\r | |
68 | btl %eax, 8(%esp) # (UINT32 *(&Operand)) + 1\r | |
69 | \r | |
70 | _Log2_Bit: \r | |
71 | jc _Log2_Done\r | |
72 | jmp _Log2_Wend\r | |
73 | \r | |
74 | _Log2_Done: \r | |
75 | movb %cl, %al\r | |
76 | \r | |
77 | ret\r | |
78 | \r |