Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.2 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. math.c
  5. Abstract:
  6. Revision History
  7. --*/
  8. #include "lib.h"
  9. /*
  10. * Declare runtime functions
  11. */
  12. #ifdef RUNTIME_CODE
  13. #pragma RUNTIME_CODE(LShiftU64)
  14. #pragma RUNTIME_CODE(RShiftU64)
  15. #pragma RUNTIME_CODE(MultU64x32)
  16. #pragma RUNTIME_CODE(DivU64x32)
  17. #endif
  18. /*
  19. *
  20. */
  21. UINT64
  22. LShiftU64 (
  23. IN UINT64 Operand,
  24. IN UINTN Count
  25. )
  26. /* Left shift 64bit by 32bit and get a 64bit result */
  27. {
  28. return Operand << Count;
  29. }
  30. UINT64
  31. RShiftU64 (
  32. IN UINT64 Operand,
  33. IN UINTN Count
  34. )
  35. /* Right shift 64bit by 32bit and get a 64bit result */
  36. {
  37. return Operand >> Count;
  38. }
  39. UINT64
  40. MultU64x32 (
  41. IN UINT64 Multiplicand,
  42. IN UINTN Multiplier
  43. )
  44. /* Multiple 64bit by 32bit and get a 64bit result */
  45. {
  46. return Multiplicand * Multiplier;
  47. }
  48. UINT64
  49. DivU64x32 (
  50. IN UINT64 Dividend,
  51. IN UINTN Divisor,
  52. OUT UINTN *Remainder OPTIONAL
  53. )
  54. /* divide 64bit by 32bit and get a 64bit result
  55. * N.B. only works for 31bit divisors!! */
  56. {
  57. ASSERT (Divisor != 0);
  58. if (Remainder) {
  59. *Remainder = Dividend % Divisor;
  60. }
  61. return Dividend / Divisor;
  62. }