OSDN Git Service

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