float128-hw.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* Automatic switching between software and hardware IEEE 128-bit
  2. floating-point emulation for PowerPC.
  3. Copyright (C) 2016-2022 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. Contributed by Michael Meissner (meissner@linux.vnet.ibm.com)
  6. Code is based on the main soft-fp library written by:
  7. Richard Henderson (rth@cygnus.com) and
  8. Jakub Jelinek (jj@ultra.linux.cz).
  9. The GNU C Library is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU Lesser General Public
  11. License as published by the Free Software Foundation; either
  12. version 2.1 of the License, or (at your option) any later version.
  13. In addition to the permissions in the GNU Lesser General Public
  14. License, the Free Software Foundation gives you unlimited
  15. permission to link the compiled version of this file into
  16. combinations with other programs, and to distribute those
  17. combinations without any restriction coming from the use of this
  18. file. (The Lesser General Public License restrictions do apply in
  19. other respects; for example, they cover modification of the file,
  20. and distribution when not linked into a combine executable.)
  21. The GNU C Library is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. Lesser General Public License for more details.
  25. You should have received a copy of the GNU Lesser General Public
  26. License along with the GNU C Library; if not, see
  27. <http://www.gnu.org/licenses/>. */
  28. #include <soft-fp.h>
  29. #include <quad-float128.h>
  30. #ifndef __FLOAT128_HARDWARE__
  31. #error "This module must be compiled with IEEE 128-bit hardware support"
  32. #endif
  33. TFtype
  34. __addkf3_hw (TFtype a, TFtype b)
  35. {
  36. return a + b;
  37. }
  38. TFtype
  39. __subkf3_hw (TFtype a, TFtype b)
  40. {
  41. return a - b;
  42. }
  43. TFtype
  44. __mulkf3_hw (TFtype a, TFtype b)
  45. {
  46. return a * b;
  47. }
  48. TFtype
  49. __divkf3_hw (TFtype a, TFtype b)
  50. {
  51. return a / b;
  52. }
  53. TFtype
  54. __negkf2_hw (TFtype a)
  55. {
  56. return -a;
  57. }
  58. TFtype
  59. __floatsikf_hw (SItype_ppc a)
  60. {
  61. return (TFtype) a;
  62. }
  63. TFtype
  64. __floatunsikf_hw (USItype_ppc a)
  65. {
  66. return (TFtype) a;
  67. }
  68. TFtype
  69. __floatdikf_hw (DItype_ppc a)
  70. {
  71. return (TFtype) a;
  72. }
  73. TFtype
  74. __floatundikf_hw (UDItype_ppc a)
  75. {
  76. return (TFtype) a;
  77. }
  78. SItype_ppc
  79. __fixkfsi_hw (TFtype a)
  80. {
  81. return (SItype_ppc) a;
  82. }
  83. USItype_ppc
  84. __fixunskfsi_hw (TFtype a)
  85. {
  86. return (USItype_ppc) a;
  87. }
  88. DItype_ppc
  89. __fixkfdi_hw (TFtype a)
  90. {
  91. return (DItype_ppc) a;
  92. }
  93. UDItype_ppc
  94. __fixunskfdi_hw (TFtype a)
  95. {
  96. return (UDItype_ppc) a;
  97. }
  98. TFtype
  99. __extendsfkf2_hw (float a)
  100. {
  101. return (TFtype) a;
  102. }
  103. TFtype
  104. __extenddfkf2_hw (double a)
  105. {
  106. return (TFtype) a;
  107. }
  108. float
  109. __trunckfsf2_hw (TFtype a)
  110. {
  111. return (float) a;
  112. }
  113. double
  114. __trunckfdf2_hw (TFtype a)
  115. {
  116. return (double) a;
  117. }
  118. /* __eqkf2 returns 0 if equal, or 1 if not equal or NaN. */
  119. CMPtype
  120. __eqkf2_hw (TFtype a, TFtype b)
  121. {
  122. return (a != b);
  123. }
  124. /* __gekf2 returns -1 if a < b, 0 if a == b, +1 if a > b, or -2 if NaN. */
  125. CMPtype
  126. __gekf2_hw (TFtype a, TFtype b)
  127. {
  128. if (a < b)
  129. return -1;
  130. else if (__builtin_isunordered (a, b))
  131. return -2;
  132. else if (a == b)
  133. return 0;
  134. return 1;
  135. }
  136. /* __lekf2 returns -1 if a < b, 0 if a == b, +1 if a > b, or +2 if NaN. */
  137. CMPtype
  138. __lekf2_hw (TFtype a, TFtype b)
  139. {
  140. if (a < b)
  141. return -1;
  142. else if (__builtin_isunordered (a, b))
  143. return 2;
  144. else if (a == b)
  145. return 0;
  146. return 1;
  147. }
  148. /* __unordkf2 returns 1 if NaN or 0 otherwise. */
  149. CMPtype
  150. __unordkf2_hw (TFtype a, TFtype b)
  151. {
  152. return (__builtin_isunordered (a, b)) ? 1 : 0;
  153. }
  154. /* Convert __float128 to __ibm128. */
  155. IBM128_TYPE
  156. __extendkftf2_hw (TFtype value)
  157. {
  158. IBM128_TYPE ret;
  159. CVT_FLOAT128_TO_IBM128 (ret, value);
  160. return ret;
  161. }
  162. /* Convert __ibm128 to __float128. */
  163. TFtype
  164. __trunctfkf2_hw (IBM128_TYPE value)
  165. {
  166. TFtype ret;
  167. CVT_IBM128_TO_FLOAT128 (ret, value);
  168. return ret;
  169. }