math.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * crt0-efi-aarch64.S - PE/COFF header for Aarch64 EFI applications
  3. *
  4. * Copright (C) 2014 Linaro Ltd.
  5. * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. */
  12. #include "lib.h"
  13. UINT64
  14. LShiftU64 (
  15. IN UINT64 Operand,
  16. IN UINTN Count
  17. )
  18. // Left shift 64bit by 32bit and get a 64bit result
  19. {
  20. return Operand << Count;
  21. }
  22. UINT64
  23. RShiftU64 (
  24. IN UINT64 Operand,
  25. IN UINTN Count
  26. )
  27. // Right shift 64bit by 32bit and get a 64bit result
  28. {
  29. return Operand >> Count;
  30. }
  31. UINT64
  32. MultU64x32 (
  33. IN UINT64 Multiplicand,
  34. IN UINTN Multiplier
  35. )
  36. // Multiple 64bit by 32bit and get a 64bit result
  37. {
  38. return Multiplicand * Multiplier;
  39. }
  40. UINT64
  41. DivU64x32 (
  42. IN UINT64 Dividend,
  43. IN UINTN Divisor,
  44. OUT UINTN *Remainder OPTIONAL
  45. )
  46. // divide 64bit by 32bit and get a 64bit result
  47. // N.B. only works for 31bit divisors!!
  48. {
  49. if (Remainder)
  50. *Remainder = Dividend % Divisor;
  51. return Dividend / Divisor;
  52. }