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