op-8.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Software floating-point emulation.
  2. Basic eight-word fraction declaration and manipulation.
  3. Copyright (C) 1997,1998,1999,2006 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Richard Henderson (rth@cygnus.com),
  6. Jakub Jelinek (jj@ultra.linux.cz) and
  7. Peter Maydell (pmaydell@chiark.greenend.org.uk).
  8. The GNU C Library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12. In addition to the permissions in the GNU Lesser General Public
  13. License, the Free Software Foundation gives you unlimited
  14. permission to link the compiled version of this file into
  15. combinations with other programs, and to distribute those
  16. combinations without any restriction coming from the use of this
  17. file. (The Lesser General Public License restrictions do apply in
  18. other respects; for example, they cover modification of the file,
  19. and distribution when not linked into a combine executable.)
  20. The GNU C Library is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. Lesser General Public License for more details.
  24. You should have received a copy of the GNU Lesser General Public
  25. License along with the GNU C Library; if not, write to the Free
  26. Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  27. MA 02110-1301, USA. */
  28. /* We need just a few things from here for op-4, if we ever need some
  29. other macros, they can be added. */
  30. #define _FP_FRAC_DECL_8(X) _FP_W_TYPE X##_f[8]
  31. #define _FP_FRAC_HIGH_8(X) (X##_f[7])
  32. #define _FP_FRAC_LOW_8(X) (X##_f[0])
  33. #define _FP_FRAC_WORD_8(X,w) (X##_f[w])
  34. #define _FP_FRAC_SLL_8(X,N) \
  35. do { \
  36. _FP_I_TYPE _up, _down, _skip, _i; \
  37. _skip = (N) / _FP_W_TYPE_SIZE; \
  38. _up = (N) % _FP_W_TYPE_SIZE; \
  39. _down = _FP_W_TYPE_SIZE - _up; \
  40. if (!_up) \
  41. for (_i = 7; _i >= _skip; --_i) \
  42. X##_f[_i] = X##_f[_i-_skip]; \
  43. else \
  44. { \
  45. for (_i = 7; _i > _skip; --_i) \
  46. X##_f[_i] = X##_f[_i-_skip] << _up \
  47. | X##_f[_i-_skip-1] >> _down; \
  48. X##_f[_i--] = X##_f[0] << _up; \
  49. } \
  50. for (; _i >= 0; --_i) \
  51. X##_f[_i] = 0; \
  52. } while (0)
  53. #define _FP_FRAC_SRL_8(X,N) \
  54. do { \
  55. _FP_I_TYPE _up, _down, _skip, _i; \
  56. _skip = (N) / _FP_W_TYPE_SIZE; \
  57. _down = (N) % _FP_W_TYPE_SIZE; \
  58. _up = _FP_W_TYPE_SIZE - _down; \
  59. if (!_down) \
  60. for (_i = 0; _i <= 7-_skip; ++_i) \
  61. X##_f[_i] = X##_f[_i+_skip]; \
  62. else \
  63. { \
  64. for (_i = 0; _i < 7-_skip; ++_i) \
  65. X##_f[_i] = X##_f[_i+_skip] >> _down \
  66. | X##_f[_i+_skip+1] << _up; \
  67. X##_f[_i++] = X##_f[7] >> _down; \
  68. } \
  69. for (; _i < 8; ++_i) \
  70. X##_f[_i] = 0; \
  71. } while (0)
  72. /* Right shift with sticky-lsb.
  73. * What this actually means is that we do a standard right-shift,
  74. * but that if any of the bits that fall off the right hand side
  75. * were one then we always set the LSbit.
  76. */
  77. #define _FP_FRAC_SRS_8(X,N,size) \
  78. do { \
  79. _FP_I_TYPE _up, _down, _skip, _i; \
  80. _FP_W_TYPE _s; \
  81. _skip = (N) / _FP_W_TYPE_SIZE; \
  82. _down = (N) % _FP_W_TYPE_SIZE; \
  83. _up = _FP_W_TYPE_SIZE - _down; \
  84. for (_s = _i = 0; _i < _skip; ++_i) \
  85. _s |= X##_f[_i]; \
  86. if (!_down) \
  87. for (_i = 0; _i <= 7-_skip; ++_i) \
  88. X##_f[_i] = X##_f[_i+_skip]; \
  89. else \
  90. { \
  91. _s |= X##_f[_i] << _up; \
  92. for (_i = 0; _i < 7-_skip; ++_i) \
  93. X##_f[_i] = X##_f[_i+_skip] >> _down \
  94. | X##_f[_i+_skip+1] << _up; \
  95. X##_f[_i++] = X##_f[7] >> _down; \
  96. } \
  97. for (; _i < 8; ++_i) \
  98. X##_f[_i] = 0; \
  99. /* don't fix the LSB until the very end when we're sure f[0] is stable */ \
  100. X##_f[0] |= (_s != 0); \
  101. } while (0)