]>
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 | GetPowerOfTwo.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Calculates the largest integer that is both \r | |
19 | a power of two and less than Input\r | |
20 | \r | |
21 | --*/\r | |
22 | \r | |
23 | #include "Tiano.h"\r | |
24 | \r | |
25 | UINT64\r | |
26 | GetPowerOfTwo (\r | |
27 | IN UINT64 Input\r | |
28 | )\r | |
29 | /*++\r | |
30 | \r | |
31 | Routine Description:\r | |
32 | \r | |
33 | Calculates the largest integer that is both \r | |
34 | a power of two and less than Input\r | |
35 | \r | |
36 | Arguments:\r | |
37 | \r | |
38 | Input - value to calculate power of two\r | |
39 | \r | |
40 | Returns:\r | |
41 | \r | |
42 | the largest integer that is both a power of \r | |
43 | two and less than Input\r | |
44 | \r | |
45 | --*/\r | |
46 | {\r | |
47 | __asm {\r | |
48 | xor eax, eax\r | |
49 | mov edx, eax\r | |
50 | mov ecx, dword ptr Input[4]\r | |
51 | jecxz _F\r | |
52 | bsr ecx, ecx\r | |
53 | bts edx, ecx\r | |
54 | jmp _Exit\r | |
55 | _F:\r | |
56 | mov ecx, dword ptr Input[0]\r | |
57 | jecxz _Exit\r | |
58 | bsr ecx, ecx\r | |
59 | bts eax, ecx\r | |
60 | _Exit:\r | |
61 | }\r | |
62 | }\r |