math.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef __GNUC__
  14. #pragma RUNTIME_CODE(LShiftU64)
  15. #pragma RUNTIME_CODE(RShiftU64)
  16. #pragma RUNTIME_CODE(MultU64x32)
  17. #pragma RUNTIME_CODE(DivU64x32)
  18. #endif
  19. #endif
  20. //
  21. //
  22. //
  23. UINT64
  24. LShiftU64 (
  25. IN UINT64 Operand,
  26. IN UINTN Count
  27. )
  28. // Left shift 64bit by 32bit and get a 64bit result
  29. {
  30. return Operand << Count;
  31. }
  32. UINT64
  33. RShiftU64 (
  34. IN UINT64 Operand,
  35. IN UINTN Count
  36. )
  37. // Right shift 64bit by 32bit and get a 64bit result
  38. {
  39. return Operand >> Count;
  40. }
  41. UINT64
  42. MultU64x32 (
  43. IN UINT64 Multiplicand,
  44. IN UINTN Multiplier
  45. )
  46. // Multiple 64bit by 32bit and get a 64bit result
  47. {
  48. return Multiplicand * Multiplier;
  49. }
  50. UINT64
  51. DivU64x32 (
  52. IN UINT64 Dividend,
  53. IN UINTN Divisor,
  54. OUT UINTN *Remainder OPTIONAL
  55. )
  56. // divide 64bit by 32bit and get a 64bit result
  57. // N.B. only works for 31bit divisors!!
  58. {
  59. ASSERT (Divisor != 0);
  60. if (Remainder) {
  61. *Remainder = Dividend % Divisor;
  62. }
  63. return Dividend / Divisor;
  64. }