op-8.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* Software floating-point emulation.
  2. Basic eight-word fraction declaration and manipulation.
  3. Copyright (C) 1997-2017 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, see
  26. <http://www.gnu.org/licenses/>. */
  27. #ifndef SOFT_FP_OP_8_H
  28. #define SOFT_FP_OP_8_H 1
  29. /* We need just a few things from here for op-4, if we ever need some
  30. other macros, they can be added. */
  31. #define _FP_FRAC_DECL_8(X) _FP_W_TYPE X##_f[8]
  32. #define _FP_FRAC_HIGH_8(X) (X##_f[7])
  33. #define _FP_FRAC_LOW_8(X) (X##_f[0])
  34. #define _FP_FRAC_WORD_8(X, w) (X##_f[w])
  35. #define _FP_FRAC_SLL_8(X, N) \
  36. do \
  37. { \
  38. _FP_I_TYPE _FP_FRAC_SLL_8_up, _FP_FRAC_SLL_8_down; \
  39. _FP_I_TYPE _FP_FRAC_SLL_8_skip, _FP_FRAC_SLL_8_i; \
  40. _FP_FRAC_SLL_8_skip = (N) / _FP_W_TYPE_SIZE; \
  41. _FP_FRAC_SLL_8_up = (N) % _FP_W_TYPE_SIZE; \
  42. _FP_FRAC_SLL_8_down = _FP_W_TYPE_SIZE - _FP_FRAC_SLL_8_up; \
  43. if (!_FP_FRAC_SLL_8_up) \
  44. for (_FP_FRAC_SLL_8_i = 7; \
  45. _FP_FRAC_SLL_8_i >= _FP_FRAC_SLL_8_skip; \
  46. --_FP_FRAC_SLL_8_i) \
  47. X##_f[_FP_FRAC_SLL_8_i] \
  48. = X##_f[_FP_FRAC_SLL_8_i-_FP_FRAC_SLL_8_skip]; \
  49. else \
  50. { \
  51. for (_FP_FRAC_SLL_8_i = 7; \
  52. _FP_FRAC_SLL_8_i > _FP_FRAC_SLL_8_skip; \
  53. --_FP_FRAC_SLL_8_i) \
  54. X##_f[_FP_FRAC_SLL_8_i] \
  55. = ((X##_f[_FP_FRAC_SLL_8_i-_FP_FRAC_SLL_8_skip] \
  56. << _FP_FRAC_SLL_8_up) \
  57. | (X##_f[_FP_FRAC_SLL_8_i-_FP_FRAC_SLL_8_skip-1] \
  58. >> _FP_FRAC_SLL_8_down)); \
  59. X##_f[_FP_FRAC_SLL_8_i--] = X##_f[0] << _FP_FRAC_SLL_8_up; \
  60. } \
  61. for (; _FP_FRAC_SLL_8_i >= 0; --_FP_FRAC_SLL_8_i) \
  62. X##_f[_FP_FRAC_SLL_8_i] = 0; \
  63. } \
  64. while (0)
  65. #define _FP_FRAC_SRL_8(X, N) \
  66. do \
  67. { \
  68. _FP_I_TYPE _FP_FRAC_SRL_8_up, _FP_FRAC_SRL_8_down; \
  69. _FP_I_TYPE _FP_FRAC_SRL_8_skip, _FP_FRAC_SRL_8_i; \
  70. _FP_FRAC_SRL_8_skip = (N) / _FP_W_TYPE_SIZE; \
  71. _FP_FRAC_SRL_8_down = (N) % _FP_W_TYPE_SIZE; \
  72. _FP_FRAC_SRL_8_up = _FP_W_TYPE_SIZE - _FP_FRAC_SRL_8_down; \
  73. if (!_FP_FRAC_SRL_8_down) \
  74. for (_FP_FRAC_SRL_8_i = 0; \
  75. _FP_FRAC_SRL_8_i <= 7-_FP_FRAC_SRL_8_skip; \
  76. ++_FP_FRAC_SRL_8_i) \
  77. X##_f[_FP_FRAC_SRL_8_i] \
  78. = X##_f[_FP_FRAC_SRL_8_i+_FP_FRAC_SRL_8_skip]; \
  79. else \
  80. { \
  81. for (_FP_FRAC_SRL_8_i = 0; \
  82. _FP_FRAC_SRL_8_i < 7-_FP_FRAC_SRL_8_skip; \
  83. ++_FP_FRAC_SRL_8_i) \
  84. X##_f[_FP_FRAC_SRL_8_i] \
  85. = ((X##_f[_FP_FRAC_SRL_8_i+_FP_FRAC_SRL_8_skip] \
  86. >> _FP_FRAC_SRL_8_down) \
  87. | (X##_f[_FP_FRAC_SRL_8_i+_FP_FRAC_SRL_8_skip+1] \
  88. << _FP_FRAC_SRL_8_up)); \
  89. X##_f[_FP_FRAC_SRL_8_i++] = X##_f[7] >> _FP_FRAC_SRL_8_down; \
  90. } \
  91. for (; _FP_FRAC_SRL_8_i < 8; ++_FP_FRAC_SRL_8_i) \
  92. X##_f[_FP_FRAC_SRL_8_i] = 0; \
  93. } \
  94. while (0)
  95. /* Right shift with sticky-lsb.
  96. What this actually means is that we do a standard right-shift,
  97. but that if any of the bits that fall off the right hand side
  98. were one then we always set the LSbit. */
  99. #define _FP_FRAC_SRS_8(X, N, size) \
  100. do \
  101. { \
  102. _FP_I_TYPE _FP_FRAC_SRS_8_up, _FP_FRAC_SRS_8_down; \
  103. _FP_I_TYPE _FP_FRAC_SRS_8_skip, _FP_FRAC_SRS_8_i; \
  104. _FP_W_TYPE _FP_FRAC_SRS_8_s; \
  105. _FP_FRAC_SRS_8_skip = (N) / _FP_W_TYPE_SIZE; \
  106. _FP_FRAC_SRS_8_down = (N) % _FP_W_TYPE_SIZE; \
  107. _FP_FRAC_SRS_8_up = _FP_W_TYPE_SIZE - _FP_FRAC_SRS_8_down; \
  108. for (_FP_FRAC_SRS_8_s = _FP_FRAC_SRS_8_i = 0; \
  109. _FP_FRAC_SRS_8_i < _FP_FRAC_SRS_8_skip; \
  110. ++_FP_FRAC_SRS_8_i) \
  111. _FP_FRAC_SRS_8_s |= X##_f[_FP_FRAC_SRS_8_i]; \
  112. if (!_FP_FRAC_SRS_8_down) \
  113. for (_FP_FRAC_SRS_8_i = 0; \
  114. _FP_FRAC_SRS_8_i <= 7-_FP_FRAC_SRS_8_skip; \
  115. ++_FP_FRAC_SRS_8_i) \
  116. X##_f[_FP_FRAC_SRS_8_i] \
  117. = X##_f[_FP_FRAC_SRS_8_i+_FP_FRAC_SRS_8_skip]; \
  118. else \
  119. { \
  120. _FP_FRAC_SRS_8_s \
  121. |= X##_f[_FP_FRAC_SRS_8_i] << _FP_FRAC_SRS_8_up; \
  122. for (_FP_FRAC_SRS_8_i = 0; \
  123. _FP_FRAC_SRS_8_i < 7-_FP_FRAC_SRS_8_skip; \
  124. ++_FP_FRAC_SRS_8_i) \
  125. X##_f[_FP_FRAC_SRS_8_i] \
  126. = ((X##_f[_FP_FRAC_SRS_8_i+_FP_FRAC_SRS_8_skip] \
  127. >> _FP_FRAC_SRS_8_down) \
  128. | (X##_f[_FP_FRAC_SRS_8_i+_FP_FRAC_SRS_8_skip+1] \
  129. << _FP_FRAC_SRS_8_up)); \
  130. X##_f[_FP_FRAC_SRS_8_i++] = X##_f[7] >> _FP_FRAC_SRS_8_down; \
  131. } \
  132. for (; _FP_FRAC_SRS_8_i < 8; ++_FP_FRAC_SRS_8_i) \
  133. X##_f[_FP_FRAC_SRS_8_i] = 0; \
  134. /* Don't fix the LSB until the very end when we're sure f[0] is \
  135. stable. */ \
  136. X##_f[0] |= (_FP_FRAC_SRS_8_s != 0); \
  137. } \
  138. while (0)
  139. #endif /* !SOFT_FP_OP_8_H */