math.c 859 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: BSD-2-Clause-Patent
  2. /*
  3. * This code is based on EDK II MdePkg/Library/BaseLib/Math64.c
  4. * Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
  5. */
  6. #include "lib.h"
  7. /**
  8. * LShiftU64() - left shift
  9. */
  10. UINT64
  11. LShiftU64 (
  12. IN UINT64 Operand,
  13. IN UINTN Count
  14. )
  15. {
  16. return Operand << Count;
  17. }
  18. /**
  19. * RShiftU64() - right shift
  20. */
  21. UINT64
  22. RShiftU64 (
  23. IN UINT64 Operand,
  24. IN UINTN Count
  25. )
  26. {
  27. return Operand >> Count;
  28. }
  29. /**
  30. * MultU64x32() - multiply
  31. */
  32. UINT64
  33. MultU64x32 (
  34. IN UINT64 Multiplicand,
  35. IN UINTN Multiplier
  36. )
  37. {
  38. return Multiplicand * Multiplier;
  39. }
  40. /**
  41. * DivU64x32() - divide
  42. */
  43. UINT64
  44. DivU64x32 (
  45. IN UINT64 Dividend,
  46. IN UINTN Divisor,
  47. OUT UINTN *Remainder OPTIONAL
  48. )
  49. {
  50. ASSERT(Divisor != 0);
  51. if (Remainder) {
  52. *Remainder = Dividend % Divisor;
  53. }
  54. return Dividend / Divisor;
  55. }