OSDN Git Service

dfad7d308b13efb56743b441111cb067cba7f7e9
[pf3gnuchains/gcc-fork.git] / gcc / config / dfp-bit.h
1 /* Header file for dfp-bit.c.
2    Copyright (C) 2005, 2006 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file.  (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
18 executable.)
19
20 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with GCC; see the file COPYING.  If not, write to the Free
27 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
28 02110-1301, USA.  */
29
30 #ifndef _DFPBIT_H
31 #define _DFPBIT_H
32
33 #include "tconfig.h"
34 #include "coretypes.h"
35 #include "tm.h"
36
37 #ifndef LIBGCC2_WORDS_BIG_ENDIAN
38 #define LIBGCC2_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
39 #endif
40
41 #ifndef LIBGCC2_FLOAT_WORDS_BIG_ENDIAN
42 #define LIBGCC2_FLOAT_WORDS_BIG_ENDIAN LIBGCC2_WORDS_BIG_ENDIAN
43 #endif
44
45 #ifndef LIBGCC2_LONG_DOUBLE_TYPE_SIZE
46 #define LIBGCC2_LONG_DOUBLE_TYPE_SIZE LONG_DOUBLE_TYPE_SIZE
47 #endif
48
49 #ifndef LIBGCC2_HAS_XF_MODE
50 #define LIBGCC2_HAS_XF_MODE \
51   (BITS_PER_UNIT == 8 && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
52 #endif
53
54 /* Depending on WIDTH, define a number of macros:
55
56    DFP_C_TYPE: type of the arguments to the libgcc functions;
57         (eg _Decimal32)
58
59    IEEE_TYPE: the corresponding (encoded) IEEE754R type;
60         (eg decimal32)
61    
62    TO_INTERNAL: the name of the decNumber function to convert an
63    encoded value into the decNumber internal representation;
64
65    TO_ENCODED: the name of the decNumber function to convert an
66    internally represented decNumber into the encoded
67    representation.
68
69    FROM_STRING: the name of the decNumber function to read an
70    encoded value from a string.
71
72    TO_STRING: the name of the decNumber function to write an
73    encoded value to a string.  */
74
75 #if WIDTH == 32
76 #define DFP_C_TYPE      _Decimal32
77 #define IEEE_TYPE       decimal32
78 #define HOST_TO_IEEE    __host_to_ieee_32
79 #define IEEE_TO_HOST    __ieee_to_host_32
80 #define TO_INTERNAL     __decimal32ToNumber
81 #define TO_ENCODED      __decimal32FromNumber
82 #define FROM_STRING     __decimal32FromString
83 #define TO_STRING       __decimal32ToString
84 #elif WIDTH == 64
85 #define DFP_C_TYPE      _Decimal64
86 #define IEEE_TYPE       decimal64
87 #define HOST_TO_IEEE    __host_to_ieee_64
88 #define IEEE_TO_HOST    __ieee_to_host_64
89 #define TO_INTERNAL     __decimal64ToNumber
90 #define TO_ENCODED      __decimal64FromNumber
91 #define FROM_STRING     __decimal64FromString
92 #define TO_STRING       __decimal64ToString
93 #elif WIDTH == 128
94 #define DFP_C_TYPE      _Decimal128
95 #define IEEE_TYPE       decimal128
96 #define HOST_TO_IEEE    __host_to_ieee_128
97 #define IEEE_TO_HOST    __ieee_to_host_128
98 #define TO_INTERNAL     __decimal128ToNumber
99 #define TO_ENCODED      __decimal128FromNumber
100 #define FROM_STRING     __decimal128FromString
101 #define TO_STRING       __decimal128ToString
102 #else
103 #error invalid decimal float word width
104 #endif
105
106 /* We define __DEC_EVAL_METHOD__ to 2, saying that we evaluate all
107    operations and constants to the range and precision of the _Decimal128
108    type.  Make it so.  */
109 #if WIDTH == 32
110 #define CONTEXT_INIT DEC_INIT_DECIMAL32
111 #elif WIDTH == 64
112 #define CONTEXT_INIT DEC_INIT_DECIMAL64
113 #elif WIDTH == 128
114 #define CONTEXT_INIT DEC_INIT_DECIMAL128
115 #endif
116
117 /* Define CONTEXT_ROUND to obtain the current decNumber rounding mode.  */
118 extern enum rounding    __decGetRound (void);
119 #define CONTEXT_ROUND   __decGetRound ()
120
121 /* Conversions between different decimal float types use WIDTH_TO to
122    determine additional macros to define.  */
123
124 #if defined (L_dd_to_sd) || defined (L_td_to_sd)
125 #define WIDTH_TO 32
126 #elif defined (L_sd_to_dd) || defined (L_td_to_dd)
127 #define WIDTH_TO 64
128 #elif defined (L_sd_to_td) || defined (L_dd_to_td)
129 #define WIDTH_TO 128
130 #endif
131
132 /* If WIDTH_TO is defined, define additional macros:
133
134    DFP_C_TYPE_TO: type of the result of dfp to dfp conversion.
135
136    IEEE_TYPE_TO: the corresponding (encoded) IEEE754R type.
137
138    TO_ENCODED_TO: the name of the decNumber function to convert an
139    internally represented decNumber into the encoded representation
140    for the destination.  */
141
142 #if WIDTH_TO == 32
143 #define DFP_C_TYPE_TO   _Decimal32
144 #define IEEE_TYPE_TO    decimal32
145 #define TO_ENCODED_TO   __decimal32FromNumber
146 #define IEEE_TO_HOST_TO __ieee_to_host_32
147 #elif WIDTH_TO == 64
148 #define DFP_C_TYPE_TO   _Decimal64
149 #define IEEE_TYPE_TO    decimal64
150 #define TO_ENCODED_TO   __decimal64FromNumber
151 #define IEEE_TO_HOST_TO __ieee_to_host_64
152 #elif WIDTH_TO == 128
153 #define DFP_C_TYPE_TO   _Decimal128
154 #define IEEE_TYPE_TO    decimal128
155 #define TO_ENCODED_TO   __decimal128FromNumber
156 #define IEEE_TO_HOST_TO __ieee_to_host_128
157 #endif
158
159 /* Conversions between decimal float types and integral types use INT_KIND
160    to determine the data type and C functions to use.  */
161
162 #if defined (L_sd_to_si) || defined (L_dd_to_si) || defined (L_td_to_si)  \
163    || defined (L_si_to_sd) || defined (L_si_to_dd) || defined (L_si_to_td)
164 #define INT_KIND 1
165 #elif defined (L_sd_to_di) || defined (L_dd_to_di) || defined (L_td_to_di) \
166    || defined (L_di_to_sd) || defined (L_di_to_dd) || defined (L_di_to_td)
167 #define INT_KIND 2
168 #elif defined (L_sd_to_usi) || defined (L_dd_to_usi) || defined (L_td_to_usi) \
169    || defined (L_usi_to_sd) || defined (L_usi_to_dd) || defined (L_usi_to_td)
170 #define INT_KIND 3
171 #elif defined (L_sd_to_udi) || defined (L_dd_to_udi) || defined (L_td_to_udi) \
172    || defined (L_udi_to_sd) || defined (L_udi_to_dd) || defined (L_udi_to_td)
173 #define INT_KIND 4
174 #endif
175
176 /*  If INT_KIND is defined, define additional macros:
177
178     INT_TYPE: The integer data type.
179
180     INT_FMT: The format string for writing the integer to a string.
181
182     CAST_FOR_FMT: Cast variable of INT_KIND to C type for sprintf.
183     This works for ILP32 and LP64, won't for other type size systems.
184
185     STR_TO_INT: The function to read the integer from a string.  */
186
187 #if INT_KIND == 1
188 #define INT_TYPE SItype
189 #define INT_FMT "%d"
190 #define CAST_FOR_FMT(A) (int)A
191 #define STR_TO_INT strtol
192 #elif INT_KIND == 2
193 #define INT_TYPE DItype
194 #define INT_FMT "%lld"
195 #define CAST_FOR_FMT(A) (long long)A
196 #define STR_TO_INT strtoll
197 #elif INT_KIND == 3
198 #define INT_TYPE USItype
199 #define INT_FMT "%u"
200 #define CAST_FOR_FMT(A) (unsigned int)A
201 #define STR_TO_INT strtoul
202 #elif INT_KIND == 4
203 #define INT_TYPE UDItype
204 #define INT_FMT "%llu"
205 #define CAST_FOR_FMT(A) (unsigned long long)A
206 #define STR_TO_INT strtoull
207 #endif
208
209 /* Conversions between decimal float types and binary float types use
210    BFP_KIND to determine the data type and C functions to use.  */
211
212 #if defined (L_sd_to_sf) || defined (L_dd_to_sf) || defined (L_td_to_sf) \
213  || defined (L_sf_to_sd) || defined (L_sf_to_dd) || defined (L_sf_to_td)
214 #define BFP_KIND 1
215 #elif defined (L_sd_to_df) || defined (L_dd_to_df ) || defined (L_td_to_df) \
216  ||   defined (L_df_to_sd) || defined (L_df_to_dd) || defined (L_df_to_td)
217 #define BFP_KIND 2
218 #elif defined (L_sd_to_xf) || defined (L_dd_to_xf ) || defined (L_td_to_xf) \
219  ||   defined (L_xf_to_sd) || defined (L_xf_to_dd) || defined (L_xf_to_td)
220 #define BFP_KIND 3
221 #endif
222
223 /*  If BFP_KIND is defined, define additional macros:
224
225     BFP_TYPE: The binary floating point data type.
226
227     BFP_FMT: The format string for writing the value to a string.
228
229     STR_TO_BFP: The function to read the value from a string.  */
230
231 #if BFP_KIND == 1
232 /* strtof is declared in <stdlib.h> only for C99.  */
233 extern float strtof (const char *, char **);
234 #define BFP_TYPE SFtype
235 #define BFP_FMT "%e"
236 #define STR_TO_BFP strtof
237
238 #elif BFP_KIND == 2
239 #define BFP_TYPE DFtype
240 #define BFP_FMT "%e"
241 #define STR_TO_BFP strtod
242
243 #elif BFP_KIND == 3
244 #if LIBGCC2_HAS_XF_MODE
245 /* These aren't used if XF mode is not supported.  */
246 #define BFP_TYPE XFtype
247 #define BFP_FMT "%e"
248 #define BFP_VIA_TYPE double
249 #define STR_TO_BFP strtod
250 #endif
251
252 #endif /* BFP_KIND */
253
254 #if WIDTH == 128 || WIDTH_TO == 128
255 #include "decimal128.h"
256 #endif
257 #if WIDTH == 64 || WIDTH_TO == 64
258 #include "decimal64.h"
259 #endif
260 #if WIDTH == 32 || WIDTH_TO == 32
261 #include "decimal32.h"
262 #endif
263 #include "decNumber.h"
264
265 /* Names of arithmetic functions.  */
266
267 #if WIDTH == 32
268 #define DFP_ADD         __addsd3
269 #define DFP_SUB         __subsd3
270 #define DFP_MULTIPLY    __mulsd3
271 #define DFP_DIVIDE      __divsd3
272 #define DFP_EQ          __eqsd2
273 #define DFP_NE          __nesd2
274 #define DFP_LT          __ltsd2
275 #define DFP_GT          __gtsd2
276 #define DFP_LE          __lesd2
277 #define DFP_GE          __gesd2
278 #define DFP_UNORD       __unordsd2
279 #elif WIDTH == 64
280 #define DFP_ADD         __adddd3
281 #define DFP_SUB         __subdd3
282 #define DFP_MULTIPLY    __muldd3
283 #define DFP_DIVIDE      __divdd3
284 #define DFP_EQ          __eqdd2
285 #define DFP_NE          __nedd2
286 #define DFP_LT          __ltdd2
287 #define DFP_GT          __gtdd2
288 #define DFP_LE          __ledd2
289 #define DFP_GE          __gedd2
290 #define DFP_UNORD       __unorddd2
291 #elif WIDTH == 128
292 #define DFP_ADD         __addtd3
293 #define DFP_SUB         __subtd3
294 #define DFP_MULTIPLY    __multd3
295 #define DFP_DIVIDE      __divtd3
296 #define DFP_EQ          __eqtd2
297 #define DFP_NE          __netd2
298 #define DFP_LT          __lttd2
299 #define DFP_GT          __gttd2
300 #define DFP_LE          __letd2
301 #define DFP_GE          __getd2
302 #define DFP_UNORD       __unordtd2
303 #endif
304
305 /* Names of functions to convert between different decimal float types.  */
306
307 #if WIDTH == 32
308 #if WIDTH_TO == 64
309 #define DFP_TO_DFP      __extendsddd2
310 #elif WIDTH_TO == 128
311 #define DFP_TO_DFP      __extendsdtd2
312 #endif
313 #elif WIDTH == 64       
314 #if WIDTH_TO == 32
315 #define DFP_TO_DFP      __truncddsd2
316 #elif WIDTH_TO == 128
317 #define DFP_TO_DFP      __extendddtd2
318 #endif
319 #elif WIDTH == 128
320 #if WIDTH_TO == 32
321 #define DFP_TO_DFP      __trunctdsd2
322 #elif WIDTH_TO == 64
323 #define DFP_TO_DFP      __trunctddd2
324 #endif
325 #endif
326
327 /* Names of functions to convert between decimal float and integers.  */
328
329 #if WIDTH == 32
330 #if INT_KIND == 1
331 #define INT_TO_DFP      __floatsisd
332 #define DFP_TO_INT      __fixsdsi
333 #elif INT_KIND == 2
334 #define INT_TO_DFP      __floatdisd
335 #define DFP_TO_INT      __fixsddi
336 #elif INT_KIND == 3
337 #define INT_TO_DFP      __floatunssisd
338 #define DFP_TO_INT      __fixunssdsi
339 #elif INT_KIND == 4
340 #define INT_TO_DFP      __floatunsdisd
341 #define DFP_TO_INT      __fixunssddi
342 #endif
343 #elif WIDTH == 64
344 #if INT_KIND == 1
345 #define INT_TO_DFP      __floatsidd
346 #define DFP_TO_INT      __fixddsi
347 #elif INT_KIND == 2
348 #define INT_TO_DFP      __floatdidd
349 #define DFP_TO_INT      __fixdddi
350 #elif INT_KIND == 3
351 #define INT_TO_DFP      __floatunssidd
352 #define DFP_TO_INT      __fixunsddsi
353 #elif INT_KIND == 4
354 #define INT_TO_DFP      __floatunsdidd
355 #define DFP_TO_INT      __fixunsdddi
356 #endif
357 #elif WIDTH == 128
358 #if INT_KIND == 1
359 #define INT_TO_DFP      __floatsitd
360 #define DFP_TO_INT      __fixtdsi
361 #elif INT_KIND == 2
362 #define INT_TO_DFP      __floatditd
363 #define DFP_TO_INT      __fixtddi
364 #elif INT_KIND == 3
365 #define INT_TO_DFP      __floatunssitd
366 #define DFP_TO_INT      __fixunstdsi
367 #elif INT_KIND == 4
368 #define INT_TO_DFP      __floatunsditd
369 #define DFP_TO_INT      __fixunstddi
370 #endif
371 #endif
372
373 /* Names of functions to convert between decimal float and binary float.  */
374
375 #if WIDTH == 32
376 #if BFP_KIND == 1
377 #define BFP_TO_DFP      __extendsfsd
378 #define DFP_TO_BFP      __truncsdsf
379 #elif BFP_KIND == 2
380 #define BFP_TO_DFP      __truncdfsd
381 #define DFP_TO_BFP      __extendsddf
382 #elif BFP_KIND == 3
383 #define BFP_TO_DFP      __truncxfsd
384 #define DFP_TO_BFP      __extendsdxf
385 #endif /* BFP_KIND */
386
387 #elif WIDTH == 64
388 #if BFP_KIND == 1
389 #define BFP_TO_DFP      __extendsfdd
390 #define DFP_TO_BFP      __truncddsf
391 #elif BFP_KIND == 2
392 #define BFP_TO_DFP      __extenddfdd
393 #define DFP_TO_BFP      __truncdddf
394 #elif BFP_KIND == 3
395 #define BFP_TO_DFP      __truncxfdd
396 #define DFP_TO_BFP      __extendddxf
397 #endif /* BFP_KIND */
398
399 #elif WIDTH == 128
400 #if BFP_KIND == 1
401 #define BFP_TO_DFP      __extendsftd
402 #define DFP_TO_BFP      __trunctdsf
403 #elif BFP_KIND == 2
404 #define BFP_TO_DFP      __extenddftd
405 #define DFP_TO_BFP      __trunctddf
406 #elif BFP_KIND == 3
407 #define BFP_TO_DFP      __extendxftd
408 #define DFP_TO_BFP      __trunctdxf
409 #endif /* BFP_KIND */
410
411 #endif /* WIDTH */
412
413 /* Some handy typedefs.  */
414
415 typedef float SFtype __attribute__ ((mode (SF)));
416 typedef float DFtype __attribute__ ((mode (DF)));
417 #if LIBGCC2_HAS_XF_MODE
418 typedef float XFtype __attribute__ ((mode (XF)));
419 #endif /* LIBGCC2_HAS_XF_MODE */
420
421 typedef int SItype __attribute__ ((mode (SI)));
422 typedef int DItype __attribute__ ((mode (DI)));
423 typedef unsigned int USItype __attribute__ ((mode (SI)));
424 typedef unsigned int UDItype __attribute__ ((mode (DI)));
425
426 /* The type of the result of a decimal float comparison.  This must
427    match `word_mode' in GCC for the target.  */
428
429 typedef int CMPtype __attribute__ ((mode (word)));
430
431 /* Prototypes.  */
432
433 #if defined (L_mul_sd) || defined (L_mul_dd) || defined (L_mul_td)
434 extern DFP_C_TYPE DFP_MULTIPLY (DFP_C_TYPE, DFP_C_TYPE);
435 #endif
436
437 #if defined (L_div_sd) || defined (L_div_dd) || defined (L_div_td)
438 extern DFP_C_TYPE DFP_DIVIDE (DFP_C_TYPE, DFP_C_TYPE);
439 #endif
440
441 #if defined (L_addsub_sd) || defined (L_addsub_dd) || defined (L_addsub_td)
442 extern DFP_C_TYPE DFP_ADD (DFP_C_TYPE, DFP_C_TYPE);
443 extern DFP_C_TYPE DFP_SUB (DFP_C_TYPE, DFP_C_TYPE);
444 #endif
445
446 #if defined (L_eq_sd) || defined (L_eq_dd) || defined (L_eq_td)
447 extern CMPtype DFP_EQ (DFP_C_TYPE, DFP_C_TYPE);
448 #endif
449
450 #if defined (L_ne_sd) || defined (L_ne_dd) || defined (L_ne_td)
451 extern CMPtype DFP_NE (DFP_C_TYPE, DFP_C_TYPE);
452 #endif
453
454 #if defined (L_lt_sd) || defined (L_lt_dd) || defined (L_lt_td)
455 extern CMPtype DFP_LT (DFP_C_TYPE, DFP_C_TYPE);
456 #endif
457
458 #if defined (L_gt_sd) || defined (L_gt_dd) || defined (L_gt_td)
459 extern CMPtype DFP_GT (DFP_C_TYPE, DFP_C_TYPE);
460 #endif
461
462 #if defined (L_le_sd) || defined (L_le_dd) || defined (L_le_td)
463 extern CMPtype DFP_LE (DFP_C_TYPE, DFP_C_TYPE);
464 #endif
465
466 #if defined (L_ge_sd) || defined (L_ge_dd) || defined (L_ge_td)
467 extern CMPtype DFP_GE (DFP_C_TYPE, DFP_C_TYPE);
468 #endif
469
470 #if defined (L_unord_sd) || defined (L_unord_dd) || defined (L_unord_td)
471 extern CMPtype DFP_UNORD (DFP_C_TYPE, DFP_C_TYPE);
472 #endif
473
474 #if defined (L_sd_to_dd) || defined (L_sd_to_td) || defined (L_dd_to_sd) \
475  || defined (L_dd_to_td) || defined (L_td_to_sd) || defined (L_td_to_dd)
476 extern DFP_C_TYPE_TO DFP_TO_DFP (DFP_C_TYPE);
477 #endif
478
479 #if defined (L_sd_to_si) || defined (L_dd_to_si) || defined (L_td_to_si) \
480  || defined (L_sd_to_di) || defined (L_dd_to_di) || defined (L_td_to_di) \
481  || defined (L_sd_to_usi) || defined (L_dd_to_usi) || defined (L_td_to_usi) \
482  || defined (L_sd_to_udi) || defined (L_dd_to_udi) || defined (L_td_to_udi)
483 extern INT_TYPE DFP_TO_INT (DFP_C_TYPE);
484 #endif
485
486 #if defined (L_si_to_sd) || defined (L_si_to_dd) || defined (L_si_to_td) \
487  || defined (L_di_to_sd) || defined (L_di_to_dd) || defined (L_di_to_td) \
488  || defined (L_usi_to_sd) || defined (L_usi_to_dd) || defined (L_usi_to_td) \
489  || defined (L_udi_to_sd) || defined (L_udi_to_dd) || defined (L_udi_to_td)
490 extern DFP_C_TYPE INT_TO_DFP (INT_TYPE);
491 #endif
492
493 #if defined (L_sd_to_sf) || defined (L_dd_to_sf) || defined (L_td_to_sf) \
494  || defined (L_sd_to_df) || defined (L_dd_to_df) || defined (L_td_to_df) \
495  || ((defined (L_sd_to_xf) || defined (L_dd_to_xf) || defined (L_td_to_xf)) \
496      && LIBGCC2_HAS_XF_MODE)
497 extern BFP_TYPE DFP_TO_BFP (DFP_C_TYPE);
498 #endif
499
500 #if defined (L_sf_to_sd) || defined (L_sf_to_dd) || defined (L_sf_to_td) \
501  || defined (L_df_to_sd) || defined (L_df_to_dd) || defined (L_df_to_td) \
502  || ((defined (L_xf_to_sd) || defined (L_xf_to_dd) || defined (L_xf_to_td)) \
503      && LIBGCC2_HAS_XF_MODE)
504 extern DFP_C_TYPE BFP_TO_DFP (BFP_TYPE);
505 #endif
506
507 #endif /* _DFPBIT_H */