float128-ifunc.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. #include <string.h>
  31. #include <stdlib.h>
  32. #include <ctype.h>
  33. #ifndef FLOAT128_HW_INSNS
  34. #error "float128-ifunc.c needs access to ISA 3.0 instructions and ifunc"
  35. #endif
  36. #ifdef __FLOAT128_HARDWARE__
  37. #error "This module must not be compiled with IEEE 128-bit hardware support"
  38. #endif
  39. #define SW_OR_HW(SW, HW) (__builtin_cpu_supports ("ieee128") ? HW : SW)
  40. #ifdef FLOAT128_HW_INSNS_ISA3_1
  41. #define SW_OR_HW_ISA3_1(SW, HW) (__builtin_cpu_supports ("arch_3_1") ? HW : SW)
  42. #endif
  43. /* Resolvers. */
  44. static __typeof__ (__addkf3_sw) *
  45. __addkf3_resolve (void)
  46. {
  47. return SW_OR_HW (__addkf3_sw, __addkf3_hw);
  48. }
  49. static __typeof__ (__subkf3_sw) *
  50. __subkf3_resolve (void)
  51. {
  52. return SW_OR_HW (__subkf3_sw, __subkf3_hw);
  53. }
  54. static __typeof__ (__mulkf3_sw) *
  55. __mulkf3_resolve (void)
  56. {
  57. return SW_OR_HW (__mulkf3_sw, __mulkf3_hw);
  58. }
  59. static __typeof__ (__divkf3_sw) *
  60. __divkf3_resolve (void)
  61. {
  62. return SW_OR_HW (__divkf3_sw, __divkf3_hw);
  63. }
  64. static __typeof__ (__negkf2_sw) *
  65. __negkf2_resolve (void)
  66. {
  67. return SW_OR_HW (__negkf2_sw, __negkf2_hw);
  68. }
  69. static __typeof__ (__powikf2_sw) *
  70. __powikf2_resolve (void)
  71. {
  72. return SW_OR_HW (__powikf2_sw, __powikf2_hw);
  73. }
  74. static __typeof__ (__floatsikf_sw) *
  75. __floatsikf_resolve (void)
  76. {
  77. return SW_OR_HW (__floatsikf_sw, __floatsikf_hw);
  78. }
  79. static __typeof__ (__floatdikf_sw) *
  80. __floatdikf_resolve (void)
  81. {
  82. return SW_OR_HW (__floatdikf_sw, __floatdikf_hw);
  83. }
  84. #ifdef FLOAT128_HW_INSNS_ISA3_1
  85. static __typeof__ (__floattikf_sw) *
  86. __floattikf_resolve (void)
  87. {
  88. return SW_OR_HW_ISA3_1 (__floattikf_sw, __floattikf_hw);
  89. }
  90. static __typeof__ (__floatuntikf_sw) *
  91. __floatuntikf_resolve (void)
  92. {
  93. return SW_OR_HW_ISA3_1 (__floatuntikf_sw, __floatuntikf_hw);
  94. }
  95. #endif
  96. static __typeof__ (__floatunsikf_sw) *
  97. __floatunsikf_resolve (void)
  98. {
  99. return SW_OR_HW (__floatunsikf_sw, __floatunsikf_hw);
  100. }
  101. static __typeof__ (__floatundikf_sw) *
  102. __floatundikf_resolve (void)
  103. {
  104. return SW_OR_HW (__floatundikf_sw, __floatundikf_hw);
  105. }
  106. #ifdef FLOAT128_HW_INSNS_ISA3_1
  107. static __typeof__ (__fixkfti_sw) *
  108. __fixkfti_resolve (void)
  109. {
  110. return SW_OR_HW_ISA3_1 (__fixkfti_sw, __fixkfti_hw);
  111. }
  112. static __typeof__ (__fixunskfti_sw) *
  113. __fixunskfti_resolve (void)
  114. {
  115. return SW_OR_HW_ISA3_1 (__fixunskfti_sw, __fixunskfti_hw);
  116. }
  117. #endif
  118. static __typeof__ (__fixkfsi_sw) *
  119. __fixkfsi_resolve (void)
  120. {
  121. return SW_OR_HW (__fixkfsi_sw, __fixkfsi_hw);
  122. }
  123. static __typeof__ (__fixkfdi_sw) *
  124. __fixkfdi_resolve (void)
  125. {
  126. return SW_OR_HW (__fixkfdi_sw, __fixkfdi_hw);
  127. }
  128. static __typeof__ (__fixunskfsi_sw) *
  129. __fixunskfsi_resolve (void)
  130. {
  131. return SW_OR_HW (__fixunskfsi_sw, __fixunskfsi_hw);
  132. }
  133. static __typeof__ (__fixunskfdi_sw) *
  134. __fixunskfdi_resolve (void)
  135. {
  136. return SW_OR_HW (__fixunskfdi_sw, __fixunskfdi_hw);
  137. }
  138. static __typeof__ (__extendsfkf2_sw) *
  139. __extendsfkf2_resolve (void)
  140. {
  141. return SW_OR_HW (__extendsfkf2_sw, __extendsfkf2_hw);
  142. }
  143. static __typeof__ (__extenddfkf2_sw) *
  144. __extenddfkf2_resolve (void)
  145. {
  146. return SW_OR_HW (__extenddfkf2_sw, __extenddfkf2_hw);
  147. }
  148. static __typeof__ (__trunckfsf2_sw) *
  149. __trunckfsf2_resolve (void)
  150. {
  151. return SW_OR_HW (__trunckfsf2_sw, __trunckfsf2_hw);
  152. }
  153. static __typeof__ (__trunckfdf2_sw) *
  154. __trunckfdf2_resolve (void)
  155. {
  156. return (void *) SW_OR_HW (__trunckfdf2_sw, __trunckfdf2_hw);
  157. }
  158. static __typeof__ (__extendkftf2_sw) *
  159. __extendkftf2_resolve (void)
  160. {
  161. return SW_OR_HW (__extendkftf2_sw, __extendkftf2_hw);
  162. }
  163. static __typeof__ (__trunctfkf2_sw) *
  164. __trunctfkf2_resolve (void)
  165. {
  166. return SW_OR_HW (__trunctfkf2_sw, __trunctfkf2_hw);
  167. }
  168. static __typeof__ (__mulkc3_sw) *
  169. __mulkc3_resolve (void)
  170. {
  171. return SW_OR_HW (__mulkc3_sw, __mulkc3_hw);
  172. }
  173. static __typeof__ (__divkc3_sw) *
  174. __divkc3_resolve (void)
  175. {
  176. return SW_OR_HW (__divkc3_sw, __divkc3_hw);
  177. }
  178. static __typeof__ (__eqkf2_sw) *
  179. __eqkf2_resolve (void)
  180. {
  181. return SW_OR_HW (__eqkf2_sw, __eqkf2_hw);
  182. }
  183. static __typeof__ (__gekf2_sw) *
  184. __gekf2_resolve (void)
  185. {
  186. return SW_OR_HW (__gekf2_sw, __gekf2_hw);
  187. }
  188. static __typeof__ (__lekf2_sw) *
  189. __lekf2_resolve (void)
  190. {
  191. return SW_OR_HW (__lekf2_sw, __lekf2_hw);
  192. }
  193. static __typeof__ (__unordkf2_sw) *
  194. __unordkf2_resolve (void)
  195. {
  196. return SW_OR_HW (__unordkf2_sw, __unordkf2_hw);
  197. }
  198. /* Resolve __nekf2, __gtkf2, __ltkf2 like __eqkf2, __gekf2, and __lekf2, since
  199. the functions return the same values. */
  200. static __typeof__ (__eqkf2_sw) *
  201. __nekf2_resolve (void)
  202. {
  203. return SW_OR_HW (__eqkf2_sw, __eqkf2_hw);
  204. }
  205. static __typeof__ (__eqkf2_sw) *
  206. __gtkf2_resolve (void)
  207. {
  208. return SW_OR_HW (__gekf2_sw, __gekf2_hw);
  209. }
  210. static __typeof__ (__eqkf2_sw) *
  211. __ltkf2_resolve (void)
  212. {
  213. return SW_OR_HW (__lekf2_sw, __lekf2_hw);
  214. }
  215. /* Ifunc definitions. */
  216. TFtype __addkf3 (TFtype, TFtype)
  217. __attribute__ ((__ifunc__ ("__addkf3_resolve")));
  218. TFtype __subkf3 (TFtype, TFtype)
  219. __attribute__ ((__ifunc__ ("__subkf3_resolve")));
  220. TFtype __mulkf3 (TFtype, TFtype)
  221. __attribute__ ((__ifunc__ ("__mulkf3_resolve")));
  222. TFtype __divkf3 (TFtype, TFtype)
  223. __attribute__ ((__ifunc__ ("__divkf3_resolve")));
  224. TFtype __negkf2 (TFtype)
  225. __attribute__ ((__ifunc__ ("__negkf2_resolve")));
  226. TFtype __powikf2 (TFtype, SItype_ppc)
  227. __attribute__ ((__ifunc__ ("__powikf2_resolve")));
  228. CMPtype __eqkf2 (TFtype, TFtype)
  229. __attribute__ ((__ifunc__ ("__eqkf2_resolve")));
  230. CMPtype __nekf2 (TFtype, TFtype)
  231. __attribute__ ((__ifunc__ ("__nekf2_resolve")));
  232. CMPtype __gekf2 (TFtype, TFtype)
  233. __attribute__ ((__ifunc__ ("__gekf2_resolve")));
  234. CMPtype __gtkf2 (TFtype, TFtype)
  235. __attribute__ ((__ifunc__ ("__gtkf2_resolve")));
  236. CMPtype __lekf2 (TFtype, TFtype)
  237. __attribute__ ((__ifunc__ ("__lekf2_resolve")));
  238. CMPtype __ltkf2 (TFtype, TFtype)
  239. __attribute__ ((__ifunc__ ("__ltkf2_resolve")));
  240. CMPtype __unordkf2 (TFtype, TFtype)
  241. __attribute__ ((__ifunc__ ("__unordkf2_resolve")));
  242. TFtype __extendsfkf2 (float)
  243. __attribute__ ((__ifunc__ ("__extendsfkf2_resolve")));
  244. TFtype __extenddfkf2 (double)
  245. __attribute__ ((__ifunc__ ("__extenddfkf2_resolve")));
  246. float __trunckfsf2 (TFtype)
  247. __attribute__ ((__ifunc__ ("__trunckfsf2_resolve")));
  248. double __trunckfdf2 (TFtype)
  249. __attribute__ ((__ifunc__ ("__trunckfdf2_resolve")));
  250. SItype_ppc __fixkfsi (TFtype)
  251. __attribute__ ((__ifunc__ ("__fixkfsi_resolve")));
  252. DItype_ppc __fixkfdi (TFtype)
  253. __attribute__ ((__ifunc__ ("__fixkfdi_resolve")));
  254. USItype_ppc __fixunskfsi (TFtype)
  255. __attribute__ ((__ifunc__ ("__fixunskfsi_resolve")));
  256. UDItype_ppc __fixunskfdi (TFtype)
  257. __attribute__ ((__ifunc__ ("__fixunskfdi_resolve")));
  258. TFtype __floatsikf (SItype_ppc)
  259. __attribute__ ((__ifunc__ ("__floatsikf_resolve")));
  260. TFtype __floatdikf (DItype_ppc)
  261. __attribute__ ((__ifunc__ ("__floatdikf_resolve")));
  262. #ifdef FLOAT128_HW_INSNS_ISA3_1
  263. TFtype __floattikf (TItype_ppc)
  264. __attribute__ ((__ifunc__ ("__floattikf_resolve")));
  265. TFtype __floatuntikf (UTItype_ppc)
  266. __attribute__ ((__ifunc__ ("__floatuntikf_resolve")));
  267. TItype_ppc __fixkfti (TFtype)
  268. __attribute__ ((__ifunc__ ("__fixkfti_resolve")));
  269. UTItype_ppc __fixunskfti (TFtype)
  270. __attribute__ ((__ifunc__ ("__fixunskfti_resolve")));
  271. #endif
  272. TFtype __floatunsikf (USItype_ppc)
  273. __attribute__ ((__ifunc__ ("__floatunsikf_resolve")));
  274. TFtype __floatundikf (UDItype_ppc)
  275. __attribute__ ((__ifunc__ ("__floatundikf_resolve")));
  276. IBM128_TYPE __extendkftf2 (TFtype)
  277. __attribute__ ((__ifunc__ ("__extendkftf2_resolve")));
  278. TFtype __trunctfkf2 (IBM128_TYPE)
  279. __attribute__ ((__ifunc__ ("__trunctfkf2_resolve")));
  280. TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype)
  281. __attribute__ ((__ifunc__ ("__mulkc3_resolve")));
  282. TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype)
  283. __attribute__ ((__ifunc__ ("__divkc3_resolve")));