dfp-bit.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /* Header file for dfp-bit.c.
  2. Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #ifndef _DFPBIT_H
  20. #define _DFPBIT_H
  21. #include <float.h>
  22. #include <fenv.h>
  23. #include <decRound.h>
  24. #include <decExcept.h>
  25. #include "tconfig.h"
  26. #include "coretypes.h"
  27. #include "tm.h"
  28. #include "libgcc_tm.h"
  29. /* We need to know the size of long double that the C library supports.
  30. Don't use LIBGCC2_HAS_XF_MODE or LIBGCC2_HAS_TF_MODE here because
  31. some targets set both of those. */
  32. #ifndef __LIBGCC_XF_MANT_DIG__
  33. #define __LIBGCC_XF_MANT_DIG__ 0
  34. #endif
  35. #define LONG_DOUBLE_HAS_XF_MODE \
  36. (__LDBL_MANT_DIG__ == __LIBGCC_XF_MANT_DIG__)
  37. #ifndef __LIBGCC_TF_MANT_DIG__
  38. #define __LIBGCC_TF_MANT_DIG__ 0
  39. #endif
  40. #define LONG_DOUBLE_HAS_TF_MODE \
  41. (__LDBL_MANT_DIG__ == __LIBGCC_TF_MANT_DIG__)
  42. /* Depending on WIDTH, define a number of macros:
  43. DFP_C_TYPE: type of the arguments to the libgcc functions;
  44. (eg _Decimal32)
  45. IEEE_TYPE: the corresponding (encoded) IEEE754 type;
  46. (eg decimal32)
  47. TO_INTERNAL: the name of the decNumber function to convert an
  48. encoded value into the decNumber internal representation;
  49. TO_ENCODED: the name of the decNumber function to convert an
  50. internally represented decNumber into the encoded
  51. representation.
  52. FROM_STRING: the name of the decNumber function to read an
  53. encoded value from a string.
  54. TO_STRING: the name of the decNumber function to write an
  55. encoded value to a string. */
  56. #if WIDTH == 32
  57. #define DFP_C_TYPE _Decimal32
  58. #define IEEE_TYPE decimal32
  59. #define HOST_TO_IEEE __host_to_ieee_32
  60. #define IEEE_TO_HOST __ieee_to_host_32
  61. #define TO_INTERNAL __decimal32ToNumber
  62. #define TO_ENCODED __decimal32FromNumber
  63. #define FROM_STRING __decimal32FromString
  64. #define TO_STRING __decimal32ToString
  65. #elif WIDTH == 64
  66. #define DFP_C_TYPE _Decimal64
  67. #define IEEE_TYPE decimal64
  68. #define HOST_TO_IEEE __host_to_ieee_64
  69. #define IEEE_TO_HOST __ieee_to_host_64
  70. #define TO_INTERNAL __decimal64ToNumber
  71. #define TO_ENCODED __decimal64FromNumber
  72. #define FROM_STRING __decimal64FromString
  73. #define TO_STRING __decimal64ToString
  74. #elif WIDTH == 128
  75. #define DFP_C_TYPE _Decimal128
  76. #define IEEE_TYPE decimal128
  77. #define HOST_TO_IEEE __host_to_ieee_128
  78. #define IEEE_TO_HOST __ieee_to_host_128
  79. #define TO_INTERNAL __decimal128ToNumber
  80. #define TO_ENCODED __decimal128FromNumber
  81. #define FROM_STRING __decimal128FromString
  82. #define TO_STRING __decimal128ToString
  83. #else
  84. #error invalid decimal float word width
  85. #endif
  86. /* We define __DEC_EVAL_METHOD__ to 2, saying that we evaluate all
  87. operations and constants to the range and precision of the _Decimal128
  88. type. Make it so. */
  89. #if WIDTH == 32
  90. #define CONTEXT_INIT DEC_INIT_DECIMAL32
  91. #elif WIDTH == 64
  92. #define CONTEXT_INIT DEC_INIT_DECIMAL64
  93. #elif WIDTH == 128
  94. #define CONTEXT_INIT DEC_INIT_DECIMAL128
  95. #endif
  96. #ifndef DFP_INIT_ROUNDMODE
  97. #define DFP_INIT_ROUNDMODE(A) A = DEC_ROUND_HALF_EVEN
  98. #endif
  99. #ifdef DFP_EXCEPTIONS_ENABLED
  100. /* Return IEEE exception flags based on decNumber status flags. */
  101. #define DFP_IEEE_FLAGS(DEC_FLAGS) __extension__ \
  102. ({int _fe_flags = 0; \
  103. if ((dec_flags & DEC_IEEE_854_Division_by_zero) != 0) \
  104. _fe_flags |= FE_DIVBYZERO; \
  105. if ((dec_flags & DEC_IEEE_854_Inexact) != 0) \
  106. _fe_flags |= FE_INEXACT; \
  107. if ((dec_flags & DEC_IEEE_854_Invalid_operation) != 0) \
  108. _fe_flags |= FE_INVALID; \
  109. if ((dec_flags & DEC_IEEE_854_Overflow) != 0) \
  110. _fe_flags |= FE_OVERFLOW; \
  111. if ((dec_flags & DEC_IEEE_854_Underflow) != 0) \
  112. _fe_flags |= FE_UNDERFLOW; \
  113. _fe_flags; })
  114. #else
  115. #define DFP_EXCEPTIONS_ENABLED 0
  116. #define DFP_IEEE_FLAGS(A) 0
  117. #define DFP_HANDLE_EXCEPTIONS(A) do {} while (0)
  118. #endif
  119. /* Conversions between different decimal float types use WIDTH_TO to
  120. determine additional macros to define. */
  121. #if defined (L_dd_to_sd) || defined (L_td_to_sd)
  122. #define WIDTH_TO 32
  123. #elif defined (L_sd_to_dd) || defined (L_td_to_dd)
  124. #define WIDTH_TO 64
  125. #elif defined (L_sd_to_td) || defined (L_dd_to_td)
  126. #define WIDTH_TO 128
  127. #endif
  128. /* If WIDTH_TO is defined, define additional macros:
  129. DFP_C_TYPE_TO: type of the result of dfp to dfp conversion.
  130. IEEE_TYPE_TO: the corresponding (encoded) IEEE754 type.
  131. TO_ENCODED_TO: the name of the decNumber function to convert an
  132. internally represented decNumber into the encoded representation
  133. for the destination. */
  134. #if WIDTH_TO == 32
  135. #define DFP_C_TYPE_TO _Decimal32
  136. #define IEEE_TYPE_TO decimal32
  137. #define TO_ENCODED_TO __decimal32FromNumber
  138. #define IEEE_TO_HOST_TO __ieee_to_host_32
  139. #elif WIDTH_TO == 64
  140. #define DFP_C_TYPE_TO _Decimal64
  141. #define IEEE_TYPE_TO decimal64
  142. #define TO_ENCODED_TO __decimal64FromNumber
  143. #define IEEE_TO_HOST_TO __ieee_to_host_64
  144. #elif WIDTH_TO == 128
  145. #define DFP_C_TYPE_TO _Decimal128
  146. #define IEEE_TYPE_TO decimal128
  147. #define TO_ENCODED_TO __decimal128FromNumber
  148. #define IEEE_TO_HOST_TO __ieee_to_host_128
  149. #endif
  150. /* Conversions between decimal float types and integral types use INT_KIND
  151. to determine the data type and C functions to use. */
  152. #if defined (L_sd_to_si) || defined (L_dd_to_si) || defined (L_td_to_si) \
  153. || defined (L_si_to_sd) || defined (L_si_to_dd) || defined (L_si_to_td)
  154. #define INT_KIND 1
  155. #elif defined (L_sd_to_di) || defined (L_dd_to_di) || defined (L_td_to_di) \
  156. || defined (L_di_to_sd) || defined (L_di_to_dd) || defined (L_di_to_td)
  157. #define INT_KIND 2
  158. #elif defined (L_sd_to_usi) || defined (L_dd_to_usi) || defined (L_td_to_usi) \
  159. || defined (L_usi_to_sd) || defined (L_usi_to_dd) || defined (L_usi_to_td)
  160. #define INT_KIND 3
  161. #elif defined (L_sd_to_udi) || defined (L_dd_to_udi) || defined (L_td_to_udi) \
  162. || defined (L_udi_to_sd) || defined (L_udi_to_dd) || defined (L_udi_to_td)
  163. #define INT_KIND 4
  164. #endif
  165. /* If INT_KIND is defined, define additional macros:
  166. INT_TYPE: The integer data type.
  167. INT_FMT: The format string for writing the integer to a string.
  168. CAST_FOR_FMT: Cast variable of INT_KIND to C type for sprintf.
  169. This works for ILP32 and LP64, won't for other type size systems.
  170. STR_TO_INT: The function to read the integer from a string. */
  171. #if INT_KIND == 1
  172. #define INT_TYPE SItype
  173. #define INT_FMT "%d"
  174. #define CAST_FOR_FMT(A) (int)A
  175. #define STR_TO_INT strtol
  176. #elif INT_KIND == 2
  177. #define INT_TYPE DItype
  178. #define INT_FMT "%lld"
  179. #define CAST_FOR_FMT(A) (long long)A
  180. #define STR_TO_INT strtoll
  181. #elif INT_KIND == 3
  182. #define INT_TYPE USItype
  183. #define INT_FMT "%u"
  184. #define CAST_FOR_FMT(A) (unsigned int)A
  185. #define STR_TO_INT strtoul
  186. #elif INT_KIND == 4
  187. #define INT_TYPE UDItype
  188. #define INT_FMT "%llu"
  189. #define CAST_FOR_FMT(A) (unsigned long long)A
  190. #define STR_TO_INT strtoull
  191. #endif
  192. /* Conversions between decimal float types and binary float types use
  193. BFP_KIND to determine the data type and C functions to use. */
  194. #if defined (L_sd_to_sf) || defined (L_dd_to_sf) || defined (L_td_to_sf) \
  195. || defined (L_sf_to_sd) || defined (L_sf_to_dd) || defined (L_sf_to_td)
  196. #define BFP_KIND 1
  197. #elif defined (L_sd_to_df) || defined (L_dd_to_df ) || defined (L_td_to_df) \
  198. || defined (L_df_to_sd) || defined (L_df_to_dd) || defined (L_df_to_td)
  199. #define BFP_KIND 2
  200. #elif defined (L_sd_to_xf) || defined (L_dd_to_xf ) || defined (L_td_to_xf) \
  201. || defined (L_xf_to_sd) || defined (L_xf_to_dd) || defined (L_xf_to_td)
  202. #define BFP_KIND 3
  203. #elif defined (L_sd_to_tf) || defined (L_dd_to_tf) || defined (L_td_to_tf) \
  204. || defined (L_tf_to_sd) || defined (L_tf_to_dd) || defined (L_tf_to_td)
  205. #define BFP_KIND 4
  206. #elif defined (L_sd_to_kf) || defined (L_dd_to_kf) || defined (L_td_to_kf) \
  207. || defined (L_kf_to_sd) || defined (L_kf_to_dd) || defined (L_kf_to_td)
  208. #define BFP_KIND 5
  209. #endif
  210. /* If BFP_KIND is defined, define additional macros:
  211. BFP_TYPE: The binary floating point data type.
  212. BFP_FMT: The format string for writing the value to a string.
  213. The number of decimal digits printed is
  214. ceil (nbits / log2 (10.) + 1)
  215. as described in David Matula's CACM 19(3) 716-723 June 1968 paper.
  216. BFP_VIA_TYPE: Type to which to cast a variable of BPF_TYPE for a
  217. call to sprintf.
  218. STR_TO_BFP: The function to read the value from a string. */
  219. #if BFP_KIND == 1
  220. #define BFP_TYPE SFtype
  221. #define BFP_FMT "%.9e"
  222. #define BFP_VIA_TYPE double
  223. #define STR_TO_BFP strtof
  224. #elif BFP_KIND == 2
  225. #define BFP_TYPE DFtype
  226. #define BFP_FMT "%.17e"
  227. #define BFP_VIA_TYPE double
  228. #define STR_TO_BFP strtod
  229. #elif BFP_KIND == 3
  230. #if LONG_DOUBLE_HAS_XF_MODE
  231. #define BFP_TYPE XFtype
  232. #define BFP_FMT "%.21Le"
  233. #define BFP_VIA_TYPE long double
  234. #define STR_TO_BFP strtold
  235. #endif /* LONG_DOUBLE_HAS_XF_MODE */
  236. #elif BFP_KIND == 4
  237. #if LONG_DOUBLE_HAS_TF_MODE
  238. #define BFP_TYPE TFtype
  239. #if LDBL_MANT_DIG == 106
  240. #define BFP_FMT "%.33Le"
  241. #elif LDBL_MANT_DIG == 113
  242. #define BFP_FMT "%.36Le"
  243. #else
  244. #error "unknown long double size, cannot define BFP_FMT"
  245. #endif /* LDBL_MANT_DIG */
  246. #define STR_TO_BFP strtold
  247. #define BFP_VIA_TYPE long double
  248. #endif /* LONG_DOUBLE_HAS_TF_MODE */
  249. #elif BFP_KIND == 5
  250. #define BFP_TYPE _Float128
  251. #define BFP_FMT "%.36Le"
  252. #define BFP_VIA_TYPE _Float128
  253. #define STR_TO_BFP __strtoieee128
  254. extern _Float128 __strtoieee128 (const char *, char **);
  255. #endif /* BFP_KIND */
  256. #if WIDTH == 128 || WIDTH_TO == 128
  257. #include "decimal128.h"
  258. #include "decQuad.h"
  259. #endif
  260. #if WIDTH == 64 || WIDTH_TO == 64
  261. #include "decimal64.h"
  262. #include "decDouble.h"
  263. #endif
  264. #if WIDTH == 32 || WIDTH_TO == 32
  265. #include "decimal32.h"
  266. #include "decSingle.h"
  267. #endif
  268. #include "decNumber.h"
  269. /* Names of arithmetic functions. */
  270. #if ENABLE_DECIMAL_BID_FORMAT
  271. #define DPD_BID_NAME(DPD,BID) BID
  272. #else
  273. #define DPD_BID_NAME(DPD,BID) DPD
  274. #endif
  275. #if WIDTH == 32
  276. #define DFP_ADD DPD_BID_NAME(__dpd_addsd3,__bid_addsd3)
  277. #define DFP_SUB DPD_BID_NAME(__dpd_subsd3,__bid_subsd3)
  278. #define DFP_MULTIPLY DPD_BID_NAME(__dpd_mulsd3,__bid_mulsd3)
  279. #define DFP_DIVIDE DPD_BID_NAME(__dpd_divsd3,__bid_divsd3)
  280. #define DFP_EQ DPD_BID_NAME(__dpd_eqsd2,__bid_eqsd2)
  281. #define DFP_NE DPD_BID_NAME(__dpd_nesd2,__bid_nesd2)
  282. #define DFP_LT DPD_BID_NAME(__dpd_ltsd2,__bid_ltsd2)
  283. #define DFP_GT DPD_BID_NAME(__dpd_gtsd2,__bid_gtsd2)
  284. #define DFP_LE DPD_BID_NAME(__dpd_lesd2,__bid_lesd2)
  285. #define DFP_GE DPD_BID_NAME(__dpd_gesd2,__bid_gesd2)
  286. #define DFP_UNORD DPD_BID_NAME(__dpd_unordsd2,__bid_unordsd2)
  287. #elif WIDTH == 64
  288. #define DFP_ADD DPD_BID_NAME(__dpd_adddd3,__bid_adddd3)
  289. #define DFP_SUB DPD_BID_NAME(__dpd_subdd3,__bid_subdd3)
  290. #define DFP_MULTIPLY DPD_BID_NAME(__dpd_muldd3,__bid_muldd3)
  291. #define DFP_DIVIDE DPD_BID_NAME(__dpd_divdd3,__bid_divdd3)
  292. #define DFP_EQ DPD_BID_NAME(__dpd_eqdd2,__bid_eqdd2)
  293. #define DFP_NE DPD_BID_NAME(__dpd_nedd2,__bid_nedd2)
  294. #define DFP_LT DPD_BID_NAME(__dpd_ltdd2,__bid_ltdd2)
  295. #define DFP_GT DPD_BID_NAME(__dpd_gtdd2,__bid_gtdd2)
  296. #define DFP_LE DPD_BID_NAME(__dpd_ledd2,__bid_ledd2)
  297. #define DFP_GE DPD_BID_NAME(__dpd_gedd2,__bid_gedd2)
  298. #define DFP_UNORD DPD_BID_NAME(__dpd_unorddd2,__bid_unorddd2)
  299. #elif WIDTH == 128
  300. #define DFP_ADD DPD_BID_NAME(__dpd_addtd3,__bid_addtd3)
  301. #define DFP_SUB DPD_BID_NAME(__dpd_subtd3,__bid_subtd3)
  302. #define DFP_MULTIPLY DPD_BID_NAME(__dpd_multd3,__bid_multd3)
  303. #define DFP_DIVIDE DPD_BID_NAME(__dpd_divtd3,__bid_divtd3)
  304. #define DFP_EQ DPD_BID_NAME(__dpd_eqtd2,__bid_eqtd2)
  305. #define DFP_NE DPD_BID_NAME(__dpd_netd2,__bid_netd2)
  306. #define DFP_LT DPD_BID_NAME(__dpd_lttd2,__bid_lttd2)
  307. #define DFP_GT DPD_BID_NAME(__dpd_gttd2,__bid_gttd2)
  308. #define DFP_LE DPD_BID_NAME(__dpd_letd2,__bid_letd2)
  309. #define DFP_GE DPD_BID_NAME(__dpd_getd2,__bid_getd2)
  310. #define DFP_UNORD DPD_BID_NAME(__dpd_unordtd2,__bid_unordtd2)
  311. #endif
  312. /* Names of decNumber functions for DPD arithmetic. */
  313. #if WIDTH == 32
  314. #define decFloat decDouble
  315. #define DFP_BINARY_OP d32_binary_op
  316. #define DFP_COMPARE_OP d32_compare_op
  317. #define DEC_FLOAT_ADD decDoubleAdd
  318. #define DEC_FLOAT_SUBTRACT decDoubleSubtract
  319. #define DEC_FLOAT_MULTIPLY decDoubleMultiply
  320. #define DEC_FLOAT_DIVIDE decDoubleDivide
  321. #define DEC_FLOAT_COMPARE decDoubleCompare
  322. #define DEC_FLOAT_IS_ZERO decDoubleIsZero
  323. #define DEC_FLOAT_IS_NAN decDoubleIsNaN
  324. #define DEC_FLOAT_IS_SIGNED decDoubleIsSigned
  325. #elif WIDTH == 64
  326. #define DFP_BINARY_OP dnn_binary_op
  327. #define DFP_COMPARE_OP dnn_compare_op
  328. #define decFloat decDouble
  329. #define DEC_FLOAT_ADD decDoubleAdd
  330. #define DEC_FLOAT_SUBTRACT decDoubleSubtract
  331. #define DEC_FLOAT_MULTIPLY decDoubleMultiply
  332. #define DEC_FLOAT_DIVIDE decDoubleDivide
  333. #define DEC_FLOAT_COMPARE decDoubleCompare
  334. #define DEC_FLOAT_IS_ZERO decDoubleIsZero
  335. #define DEC_FLOAT_IS_NAN decDoubleIsNaN
  336. #define DEC_FLOAT_IS_SIGNED decDoubleIsSigned
  337. #elif WIDTH == 128
  338. #define DFP_BINARY_OP dnn_binary_op
  339. #define DFP_COMPARE_OP dnn_compare_op
  340. #define decFloat decQuad
  341. #define DEC_FLOAT_ADD decQuadAdd
  342. #define DEC_FLOAT_SUBTRACT decQuadSubtract
  343. #define DEC_FLOAT_MULTIPLY decQuadMultiply
  344. #define DEC_FLOAT_DIVIDE decQuadDivide
  345. #define DEC_FLOAT_COMPARE decQuadCompare
  346. #define DEC_FLOAT_IS_ZERO decQuadIsZero
  347. #define DEC_FLOAT_IS_NAN decQuadIsNaN
  348. #define DEC_FLOAT_IS_SIGNED decQuadIsSigned
  349. #endif
  350. /* Names of functions to convert between different decimal float types. */
  351. #if WIDTH == 32
  352. #if WIDTH_TO == 64
  353. #define DFP_TO_DFP DPD_BID_NAME(__dpd_extendsddd2,__bid_extendsddd2)
  354. #elif WIDTH_TO == 128
  355. #define DFP_TO_DFP DPD_BID_NAME(__dpd_extendsdtd2,__bid_extendsdtd2)
  356. #endif
  357. #elif WIDTH == 64
  358. #if WIDTH_TO == 32
  359. #define DFP_TO_DFP DPD_BID_NAME(__dpd_truncddsd2,__bid_truncddsd2)
  360. #elif WIDTH_TO == 128
  361. #define DFP_TO_DFP DPD_BID_NAME(__dpd_extendddtd2,__bid_extendddtd2)
  362. #endif
  363. #elif WIDTH == 128
  364. #if WIDTH_TO == 32
  365. #define DFP_TO_DFP DPD_BID_NAME(__dpd_trunctdsd2,__bid_trunctdsd2)
  366. #elif WIDTH_TO == 64
  367. #define DFP_TO_DFP DPD_BID_NAME(__dpd_trunctddd2,__bid_trunctddd2)
  368. #endif
  369. #endif
  370. /* Names of functions to convert between decimal float and integers. */
  371. #if WIDTH == 32
  372. #if INT_KIND == 1
  373. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatsisd,__bid_floatsisd)
  374. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixsdsi,__bid_fixsdsi)
  375. #define DEC_FLOAT_FROM_INT decDoubleFromInt32
  376. #define DEC_FLOAT_TO_INT decDoubleToInt32
  377. #elif INT_KIND == 2
  378. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatdisd,__bid_floatdisd)
  379. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixsddi,__bid_fixsddi)
  380. #elif INT_KIND == 3
  381. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatunssisd,__bid_floatunssisd)
  382. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixunssdsi,__bid_fixunssdsi)
  383. #define DEC_FLOAT_FROM_INT decDoubleFromUInt32
  384. #define DEC_FLOAT_TO_INT decDoubleToUInt32
  385. #elif INT_KIND == 4
  386. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatunsdisd,__bid_floatunsdisd)
  387. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixunssddi,__bid_fixunssddi)
  388. #endif
  389. #elif WIDTH == 64
  390. #define decFloat decDouble
  391. #if INT_KIND == 1
  392. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatsidd,__bid_floatsidd)
  393. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixddsi,__bid_fixddsi)
  394. #define DEC_FLOAT_FROM_INT decDoubleFromInt32
  395. #define DEC_FLOAT_TO_INT decDoubleToInt32
  396. #elif INT_KIND == 2
  397. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatdidd,__bid_floatdidd)
  398. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixdddi,__bid_fixdddi)
  399. #elif INT_KIND == 3
  400. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatunssidd,__bid_floatunssidd)
  401. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixunsddsi,__bid_fixunsddsi)
  402. #define DEC_FLOAT_FROM_INT decDoubleFromUInt32
  403. #define DEC_FLOAT_TO_INT decDoubleToUInt32
  404. #elif INT_KIND == 4
  405. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatunsdidd,__bid_floatunsdidd)
  406. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixunsdddi,__bid_fixunsdddi)
  407. #endif
  408. #elif WIDTH == 128
  409. #define decFloat decQuad
  410. #if INT_KIND == 1
  411. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatsitd,__bid_floatsitd)
  412. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixtdsi,__bid_fixtdsi)
  413. #define DEC_FLOAT_FROM_INT decQuadFromInt32
  414. #define DEC_FLOAT_TO_INT decQuadToInt32
  415. #elif INT_KIND == 2
  416. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatditd,__bid_floatditd)
  417. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixtddi,__bid_fixtddi)
  418. #elif INT_KIND == 3
  419. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatunssitd,__bid_floatunssitd)
  420. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixunstdsi,__bid_fixunstdsi)
  421. #define DEC_FLOAT_FROM_INT decQuadFromUInt32
  422. #define DEC_FLOAT_TO_INT decQuadToUInt32
  423. #elif INT_KIND == 4
  424. #define INT_TO_DFP DPD_BID_NAME(__dpd_floatunsditd,__bid_floatunsditd)
  425. #define DFP_TO_INT DPD_BID_NAME(__dpd_fixunstddi,__bid_fixunstddi)
  426. #endif
  427. #endif
  428. /* Names of functions to convert between decimal float and binary float. */
  429. #if WIDTH == 32
  430. #if BFP_KIND == 1
  431. #define BFP_TO_DFP DPD_BID_NAME(__dpd_extendsfsd,__bid_extendsfsd)
  432. #define DFP_TO_BFP DPD_BID_NAME(__dpd_truncsdsf,__bid_truncsdsf)
  433. #elif BFP_KIND == 2
  434. #define BFP_TO_DFP DPD_BID_NAME(__dpd_truncdfsd,__bid_truncdfsd)
  435. #define DFP_TO_BFP DPD_BID_NAME(__dpd_extendsddf,__bid_extendsddf)
  436. #elif BFP_KIND == 3
  437. #define BFP_TO_DFP DPD_BID_NAME(__dpd_truncxfsd,__bid_truncxfsd)
  438. #define DFP_TO_BFP DPD_BID_NAME(__dpd_extendsdxf,__bid_extendsdxf)
  439. #elif BFP_KIND == 4
  440. #define BFP_TO_DFP DPD_BID_NAME(__dpd_trunctfsd,__bid_trunctfsd)
  441. #define DFP_TO_BFP DPD_BID_NAME(__dpd_extendsdtf,__bid_extendsdtf)
  442. #elif BFP_KIND == 5
  443. #define BFP_TO_DFP DPD_BID_NAME(__dpd_trunckfsd,__bid_trunckfsd)
  444. #define DFP_TO_BFP DPD_BID_NAME(__dpd_extendsdkf,__bid_extendsdkf)
  445. #endif /* BFP_KIND */
  446. #elif WIDTH == 64
  447. #if BFP_KIND == 1
  448. #define BFP_TO_DFP DPD_BID_NAME(__dpd_extendsfdd,__bid_extendsfdd)
  449. #define DFP_TO_BFP DPD_BID_NAME(__dpd_truncddsf,__bid_truncddsf)
  450. #elif BFP_KIND == 2
  451. #define BFP_TO_DFP DPD_BID_NAME(__dpd_extenddfdd,__bid_extenddfdd)
  452. #define DFP_TO_BFP DPD_BID_NAME(__dpd_truncdddf,__bid_truncdddf)
  453. #elif BFP_KIND == 3
  454. #define BFP_TO_DFP DPD_BID_NAME(__dpd_truncxfdd,__bid_truncxfdd)
  455. #define DFP_TO_BFP DPD_BID_NAME(__dpd_extendddxf,__bid_extendddxf)
  456. #elif BFP_KIND == 4
  457. #define BFP_TO_DFP DPD_BID_NAME(__dpd_trunctfdd,__bid_trunctfdd)
  458. #define DFP_TO_BFP DPD_BID_NAME(__dpd_extendddtf,__bid_extendddtf)
  459. #elif BFP_KIND == 5
  460. #define BFP_TO_DFP DPD_BID_NAME(__dpd_trunckfdd,__bid_trunckfdd)
  461. #define DFP_TO_BFP DPD_BID_NAME(__dpd_extendddkf,__bid_extendddkf)
  462. #endif /* BFP_KIND */
  463. #elif WIDTH == 128
  464. #if BFP_KIND == 1
  465. #define BFP_TO_DFP DPD_BID_NAME(__dpd_extendsftd,__bid_extendsftd)
  466. #define DFP_TO_BFP DPD_BID_NAME(__dpd_trunctdsf,__bid_trunctdsf)
  467. #elif BFP_KIND == 2
  468. #define BFP_TO_DFP DPD_BID_NAME(__dpd_extenddftd,__bid_extenddftd)
  469. #define DFP_TO_BFP DPD_BID_NAME(__dpd_trunctddf,__bid_trunctddf)
  470. #elif BFP_KIND == 3
  471. #define BFP_TO_DFP DPD_BID_NAME(__dpd_extendxftd,__bid_extendxftd)
  472. #define DFP_TO_BFP DPD_BID_NAME(__dpd_trunctdxf,__bid_trunctdxf)
  473. #elif BFP_KIND == 4
  474. #define BFP_TO_DFP DPD_BID_NAME(__dpd_extendtftd,__bid_extendtftd)
  475. #define DFP_TO_BFP DPD_BID_NAME(__dpd_trunctdtf,__bid_trunctdtf)
  476. #elif BFP_KIND == 5
  477. #define BFP_TO_DFP DPD_BID_NAME(__dpd_extendkftd,__bid_extendkftd)
  478. #define DFP_TO_BFP DPD_BID_NAME(__dpd_trunctdkf,__bid_trunctdkf)
  479. #endif /* BFP_KIND */
  480. #endif /* WIDTH */
  481. /* Some handy typedefs. */
  482. typedef float SFtype __attribute__ ((mode (SF)));
  483. typedef float DFtype __attribute__ ((mode (DF)));
  484. #if LONG_DOUBLE_HAS_XF_MODE
  485. typedef float XFtype __attribute__ ((mode (XF)));
  486. #endif /* LONG_DOUBLE_HAS_XF_MODE */
  487. #if LONG_DOUBLE_HAS_TF_MODE
  488. typedef float TFtype __attribute__ ((mode (TF)));
  489. #endif /* LONG_DOUBLE_HAS_TF_MODE */
  490. typedef int SItype __attribute__ ((mode (SI)));
  491. typedef int DItype __attribute__ ((mode (DI)));
  492. typedef unsigned int USItype __attribute__ ((mode (SI)));
  493. typedef unsigned int UDItype __attribute__ ((mode (DI)));
  494. /* The type of the result of a decimal float comparison. This must
  495. match `__libgcc_cmp_return__' in GCC for the target. */
  496. typedef int CMPtype __attribute__ ((mode (__libgcc_cmp_return__)));
  497. /* Prototypes. */
  498. #if defined (L_mul_sd) || defined (L_mul_dd) || defined (L_mul_td)
  499. extern DFP_C_TYPE DFP_MULTIPLY (DFP_C_TYPE, DFP_C_TYPE);
  500. #endif
  501. #if defined (L_div_sd) || defined (L_div_dd) || defined (L_div_td)
  502. extern DFP_C_TYPE DFP_DIVIDE (DFP_C_TYPE, DFP_C_TYPE);
  503. #endif
  504. #if defined (L_addsub_sd) || defined (L_addsub_dd) || defined (L_addsub_td)
  505. extern DFP_C_TYPE DFP_ADD (DFP_C_TYPE, DFP_C_TYPE);
  506. extern DFP_C_TYPE DFP_SUB (DFP_C_TYPE, DFP_C_TYPE);
  507. #endif
  508. #if defined (L_eq_sd) || defined (L_eq_dd) || defined (L_eq_td)
  509. extern CMPtype DFP_EQ (DFP_C_TYPE, DFP_C_TYPE);
  510. #endif
  511. #if defined (L_ne_sd) || defined (L_ne_dd) || defined (L_ne_td)
  512. extern CMPtype DFP_NE (DFP_C_TYPE, DFP_C_TYPE);
  513. #endif
  514. #if defined (L_lt_sd) || defined (L_lt_dd) || defined (L_lt_td)
  515. extern CMPtype DFP_LT (DFP_C_TYPE, DFP_C_TYPE);
  516. #endif
  517. #if defined (L_gt_sd) || defined (L_gt_dd) || defined (L_gt_td)
  518. extern CMPtype DFP_GT (DFP_C_TYPE, DFP_C_TYPE);
  519. #endif
  520. #if defined (L_le_sd) || defined (L_le_dd) || defined (L_le_td)
  521. extern CMPtype DFP_LE (DFP_C_TYPE, DFP_C_TYPE);
  522. #endif
  523. #if defined (L_ge_sd) || defined (L_ge_dd) || defined (L_ge_td)
  524. extern CMPtype DFP_GE (DFP_C_TYPE, DFP_C_TYPE);
  525. #endif
  526. #if defined (L_unord_sd) || defined (L_unord_dd) || defined (L_unord_td)
  527. extern CMPtype DFP_UNORD (DFP_C_TYPE, DFP_C_TYPE);
  528. #endif
  529. #if defined (L_sd_to_dd) || defined (L_sd_to_td) || defined (L_dd_to_sd) \
  530. || defined (L_dd_to_td) || defined (L_td_to_sd) || defined (L_td_to_dd)
  531. extern DFP_C_TYPE_TO DFP_TO_DFP (DFP_C_TYPE);
  532. #endif
  533. #if defined (L_sd_to_si) || defined (L_dd_to_si) || defined (L_td_to_si) \
  534. || defined (L_sd_to_di) || defined (L_dd_to_di) || defined (L_td_to_di) \
  535. || defined (L_sd_to_usi) || defined (L_dd_to_usi) || defined (L_td_to_usi) \
  536. || defined (L_sd_to_udi) || defined (L_dd_to_udi) || defined (L_td_to_udi)
  537. extern INT_TYPE DFP_TO_INT (DFP_C_TYPE);
  538. #endif
  539. #if defined (L_si_to_sd) || defined (L_si_to_dd) || defined (L_si_to_td) \
  540. || defined (L_di_to_sd) || defined (L_di_to_dd) || defined (L_di_to_td) \
  541. || defined (L_usi_to_sd) || defined (L_usi_to_dd) || defined (L_usi_to_td) \
  542. || defined (L_udi_to_sd) || defined (L_udi_to_dd) || defined (L_udi_to_td)
  543. extern DFP_C_TYPE INT_TO_DFP (INT_TYPE);
  544. #endif
  545. #if defined (L_sd_to_sf) || defined (L_dd_to_sf) || defined (L_td_to_sf) \
  546. || defined (L_sd_to_df) || defined (L_dd_to_df) || defined (L_td_to_df) \
  547. || defined (L_sd_to_kf) || defined (L_dd_to_kf) || defined (L_td_to_kf) \
  548. || ((defined (L_sd_to_xf) || defined (L_dd_to_xf) || defined (L_td_to_xf)) \
  549. && LONG_DOUBLE_HAS_XF_MODE) \
  550. || ((defined (L_sd_to_tf) || defined (L_dd_to_tf) || defined (L_td_to_tf)) \
  551. && LONG_DOUBLE_HAS_TF_MODE)
  552. extern BFP_TYPE DFP_TO_BFP (DFP_C_TYPE);
  553. #endif
  554. #if defined (L_sf_to_sd) || defined (L_sf_to_dd) || defined (L_sf_to_td) \
  555. || defined (L_df_to_sd) || defined (L_df_to_dd) || defined (L_df_to_td) \
  556. || ((defined (L_xf_to_sd) || defined (L_xf_to_dd) || defined (L_xf_to_td)) \
  557. && LONG_DOUBLE_HAS_XF_MODE) \
  558. || ((defined (L_tf_to_sd) || defined (L_tf_to_dd) || defined (L_tf_to_td)) \
  559. && LONG_DOUBLE_HAS_TF_MODE)
  560. extern DFP_C_TYPE BFP_TO_DFP (BFP_TYPE);
  561. #define BFP_SPRINTF sprintf
  562. #elif defined (L_kf_to_sd) || defined (L_kf_to_dd) || defined (L_kf_to_td)
  563. extern DFP_C_TYPE BFP_TO_DFP (BFP_TYPE);
  564. extern int __sprintfieee128 (char *restrict, const char *restrict, ...);
  565. #define BFP_SPRINTF __sprintfieee128
  566. #endif
  567. #endif /* _DFPBIT_H */