1 /** @file
2   64-bit Math Worker Function.
3   The 32-bit versions of C compiler generate calls to library routines
4   to handle 64-bit math. These functions use non-standard calling conventions.
5 
6 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution.  The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11 
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 
17 
18 /*
19  * Shifts a 64-bit unsigned value right by a certain number of bits.
20  */
_aullshr(void)21 __declspec(naked) void __cdecl _aullshr (void)
22 {
23   _asm {
24     ;
25     ; Checking: Only handle 64bit shifting or more
26     ;
27     cmp     cl, 64
28     jae     _Exit
29 
30     ;
31     ; Handle shifting between 0 and 31 bits
32     ;
33     cmp     cl, 32
34     jae     More32
35     shrd    eax, edx, cl
36     shr     edx, cl
37     ret
38 
39     ;
40     ; Handle shifting of 32-63 bits
41     ;
42 More32:
43     mov     eax, edx
44     xor     edx, edx
45     and     cl, 31
46     shr     eax, cl
47     ret
48 
49     ;
50     ; Invalid number (less then 32bits), return 0
51     ;
52 _Exit:
53     xor     eax, eax
54     xor     edx, edx
55     ret
56   }
57 }
58