op-8.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Software floating-point emulation.
  2. Basic eight-word fraction declaration and manipulation.
  3. Copyright (C) 1997,1998,1999 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 Library General Public License as
  10. published by the Free Software Foundation; either version 2 of the
  11. License, or (at your option) any later version.
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Library General Public License for more details.
  16. You should have received a copy of the GNU Library General Public
  17. License along with the GNU C Library; see the file COPYING.LIB. If
  18. not, write to the Free Software Foundation, Inc.,
  19. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  20. #ifndef __MATH_EMU_OP_8_H__
  21. #define __MATH_EMU_OP_8_H__
  22. /* We need just a few things from here for op-4, if we ever need some
  23. other macros, they can be added. */
  24. #define _FP_FRAC_DECL_8(X) _FP_W_TYPE X##_f[8]
  25. #define _FP_FRAC_HIGH_8(X) (X##_f[7])
  26. #define _FP_FRAC_LOW_8(X) (X##_f[0])
  27. #define _FP_FRAC_WORD_8(X,w) (X##_f[w])
  28. #define _FP_FRAC_SLL_8(X,N) \
  29. do { \
  30. _FP_I_TYPE _up, _down, _skip, _i; \
  31. _skip = (N) / _FP_W_TYPE_SIZE; \
  32. _up = (N) % _FP_W_TYPE_SIZE; \
  33. _down = _FP_W_TYPE_SIZE - _up; \
  34. if (!_up) \
  35. for (_i = 7; _i >= _skip; --_i) \
  36. X##_f[_i] = X##_f[_i-_skip]; \
  37. else \
  38. { \
  39. for (_i = 7; _i > _skip; --_i) \
  40. X##_f[_i] = X##_f[_i-_skip] << _up \
  41. | X##_f[_i-_skip-1] >> _down; \
  42. X##_f[_i--] = X##_f[0] << _up; \
  43. } \
  44. for (; _i >= 0; --_i) \
  45. X##_f[_i] = 0; \
  46. } while (0)
  47. #define _FP_FRAC_SRL_8(X,N) \
  48. do { \
  49. _FP_I_TYPE _up, _down, _skip, _i; \
  50. _skip = (N) / _FP_W_TYPE_SIZE; \
  51. _down = (N) % _FP_W_TYPE_SIZE; \
  52. _up = _FP_W_TYPE_SIZE - _down; \
  53. if (!_down) \
  54. for (_i = 0; _i <= 7-_skip; ++_i) \
  55. X##_f[_i] = X##_f[_i+_skip]; \
  56. else \
  57. { \
  58. for (_i = 0; _i < 7-_skip; ++_i) \
  59. X##_f[_i] = X##_f[_i+_skip] >> _down \
  60. | X##_f[_i+_skip+1] << _up; \
  61. X##_f[_i++] = X##_f[7] >> _down; \
  62. } \
  63. for (; _i < 8; ++_i) \
  64. X##_f[_i] = 0; \
  65. } while (0)
  66. /* Right shift with sticky-lsb.
  67. * What this actually means is that we do a standard right-shift,
  68. * but that if any of the bits that fall off the right hand side
  69. * were one then we always set the LSbit.
  70. */
  71. #define _FP_FRAC_SRS_8(X,N,size) \
  72. do { \
  73. _FP_I_TYPE _up, _down, _skip, _i; \
  74. _FP_W_TYPE _s; \
  75. _skip = (N) / _FP_W_TYPE_SIZE; \
  76. _down = (N) % _FP_W_TYPE_SIZE; \
  77. _up = _FP_W_TYPE_SIZE - _down; \
  78. for (_s = _i = 0; _i < _skip; ++_i) \
  79. _s |= X##_f[_i]; \
  80. _s |= X##_f[_i] << _up; \
  81. /* s is now != 0 if we want to set the LSbit */ \
  82. if (!_down) \
  83. for (_i = 0; _i <= 7-_skip; ++_i) \
  84. X##_f[_i] = X##_f[_i+_skip]; \
  85. else \
  86. { \
  87. for (_i = 0; _i < 7-_skip; ++_i) \
  88. X##_f[_i] = X##_f[_i+_skip] >> _down \
  89. | X##_f[_i+_skip+1] << _up; \
  90. X##_f[_i++] = X##_f[7] >> _down; \
  91. } \
  92. for (; _i < 8; ++_i) \
  93. X##_f[_i] = 0; \
  94. /* don't fix the LSB until the very end when we're sure f[0] is stable */ \
  95. X##_f[0] |= (_s != 0); \
  96. } while (0)
  97. #endif