sfp-util.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * These are copied from glibc/stdlib/longlong.h
  4. */
  5. #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  6. do { \
  7. UWtype __x; \
  8. __x = (al) + (bl); \
  9. (sh) = (ah) + (bh) + (__x < (al)); \
  10. (sl) = __x; \
  11. } while (0)
  12. #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  13. do { \
  14. UWtype __x; \
  15. __x = (al) - (bl); \
  16. (sh) = (ah) - (bh) - (__x > (al)); \
  17. (sl) = __x; \
  18. } while (0)
  19. #define umul_ppmm(w1, w0, u, v) \
  20. __asm__ ("dmulu.l %2,%3\n\tsts macl,%1\n\tsts mach,%0" \
  21. : "=r" ((u32)(w1)), "=r" ((u32)(w0)) \
  22. : "r" ((u32)(u)), "r" ((u32)(v)) \
  23. : "macl", "mach")
  24. #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
  25. #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
  26. #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
  27. #define udiv_qrnnd(q, r, n1, n0, d) \
  28. do { \
  29. UWtype __d1, __d0, __q1, __q0; \
  30. UWtype __r1, __r0, __m; \
  31. __d1 = __ll_highpart (d); \
  32. __d0 = __ll_lowpart (d); \
  33. \
  34. __r1 = (n1) % __d1; \
  35. __q1 = (n1) / __d1; \
  36. __m = (UWtype) __q1 * __d0; \
  37. __r1 = __r1 * __ll_B | __ll_highpart (n0); \
  38. if (__r1 < __m) \
  39. { \
  40. __q1--, __r1 += (d); \
  41. if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
  42. if (__r1 < __m) \
  43. __q1--, __r1 += (d); \
  44. } \
  45. __r1 -= __m; \
  46. \
  47. __r0 = __r1 % __d1; \
  48. __q0 = __r1 / __d1; \
  49. __m = (UWtype) __q0 * __d0; \
  50. __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
  51. if (__r0 < __m) \
  52. { \
  53. __q0--, __r0 += (d); \
  54. if (__r0 >= (d)) \
  55. if (__r0 < __m) \
  56. __q0--, __r0 += (d); \
  57. } \
  58. __r0 -= __m; \
  59. \
  60. (q) = (UWtype) __q1 * __ll_B | __q0; \
  61. (r) = __r0; \
  62. } while (0)
  63. #define abort() return 0
  64. #define __BYTE_ORDER __LITTLE_ENDIAN