MathRShiftU64.c 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. /*
  9. * Shifts a 64-bit unsigned value right by a certain number of bits.
  10. */
  11. __declspec(naked) void __cdecl _aullshr (void)
  12. {
  13. _asm {
  14. ;
  15. ; Checking: Only handle 64bit shifting or more
  16. ;
  17. cmp cl, 64
  18. jae _Exit
  19. ;
  20. ; Handle shifting between 0 and 31 bits
  21. ;
  22. cmp cl, 32
  23. jae More32
  24. shrd eax, edx, cl
  25. shr edx, cl
  26. ret
  27. ;
  28. ; Handle shifting of 32-63 bits
  29. ;
  30. More32:
  31. mov eax, edx
  32. xor edx, edx
  33. and cl, 31
  34. shr eax, cl
  35. ret
  36. ;
  37. ; Invalid number (less then 32bits), return 0
  38. ;
  39. _Exit:
  40. xor eax, eax
  41. xor edx, edx
  42. ret
  43. }
  44. }