1169695Skan/* Temporary library support for decimal floating point.
2169695Skan   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
3169695Skan
4169695Skan   This file is part of GCC.
5169695Skan
6169695Skan   GCC is free software; you can redistribute it and/or modify it
7169695Skan   under the terms of the GNU General Public License as published by
8169695Skan   the Free Software Foundation; either version 2, or (at your option)
9169695Skan   any later version.
10169695Skan
11169695Skan   In addition to the permissions in the GNU General Public License,
12169695Skan   the Free Software Foundation gives you unlimited permission to link
13169695Skan   the compiled version of this file into combinations with other
14169695Skan   programs, and to distribute those combinations without any
15169695Skan   restriction coming from the use of this file.  (The General Public
16169695Skan   License restrictions do apply in other respects; for example, they
17169695Skan   cover modification of the file, and distribution when not linked
18169695Skan   into a combine executable.)
19169695Skan
20169695Skan   GCC is distributed in the hope that it will be useful, but WITHOUT
21169695Skan   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22169695Skan   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
23169695Skan   License for more details.
24169695Skan
25169695Skan   You should have received a copy of the GNU General Public License
26169695Skan   along with GCC; see the file COPYING.  If not, write to the Free
27169695Skan   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
28169695Skan   02110-1301, USA.  */
29169695Skan
30169695Skan#include "config.h"
31169695Skan#include "decContext.h"
32169695Skan#include "decimal128.h"
33169695Skan#include "decimal64.h"
34169695Skan#include "decimal32.h"
35169695Skan
36169695Skanvoid __host_to_ieee_32 (_Decimal32, decimal32 *);
37169695Skanvoid __host_to_ieee_64 (_Decimal64, decimal64 *);
38169695Skanvoid __host_to_ieee_128 (_Decimal128, decimal128 *);
39169695Skan
40169695Skanextern int isinfd32 (_Decimal32);
41169695Skanextern int isinfd64 (_Decimal64);
42169695Skanextern int isinfd128 (_Decimal128);
43169695Skanextern void __dfp_enable_traps (void);
44169695Skanextern void __dfp_raise (int exception __attribute__ ((unused)));
45169695Skan
46169695Skanint
47169695Skanisinfd32 (_Decimal32 arg)
48169695Skan{
49169695Skan  decNumber dn;
50169695Skan  decimal32 d32;
51169695Skan
52169695Skan  __host_to_ieee_32 (arg, &d32);
53169695Skan  decimal32ToNumber (&d32, &dn);
54169695Skan  return (decNumberIsInfinite (&dn));
55169695Skan}
56169695Skan
57169695Skanint
58169695Skanisinfd64 (_Decimal64 arg)
59169695Skan{
60169695Skan  decNumber dn;
61169695Skan  decimal64 d64;
62169695Skan
63169695Skan  __host_to_ieee_64 (arg, &d64);
64169695Skan  decimal64ToNumber (&d64, &dn);
65169695Skan  return (decNumberIsInfinite (&dn));
66169695Skan}
67169695Skan
68169695Skanint
69169695Skanisinfd128 (_Decimal128 arg)
70169695Skan{
71169695Skan  decNumber dn;
72169695Skan  decimal128 d128;
73169695Skan
74169695Skan  __host_to_ieee_128 (arg, &d128);
75169695Skan  decimal128ToNumber (&d128, &dn);
76169695Skan  return (decNumberIsInfinite (&dn));
77169695Skan}
78169695Skan
79169695Skanint __dfp_traps;
80169695Skan
81169695Skanvoid
82169695Skan__dfp_enable_traps (void)
83169695Skan{
84169695Skan  __dfp_traps = 1;
85169695Skan}
86169695Skan
87169695Skanvoid
88169695Skan__dfp_raise (int exception __attribute__ ((unused)))
89169695Skan{
90169695Skan  raise (SIGFPE);
91169695Skan}
92169695Skan
93169695Skanuint32_t
94169695Skan__dec_byte_swap (uint32_t in)
95169695Skan{
96169695Skan  uint32_t out = 0;
97169695Skan  unsigned char *p = (unsigned char *) &out;
98169695Skan  union {
99169695Skan    uint32_t i;
100169695Skan    unsigned char b[4];
101169695Skan  } u;
102169695Skan
103169695Skan  u.i = in;
104169695Skan  p[0] = u.b[3];
105169695Skan  p[1] = u.b[2];
106169695Skan  p[2] = u.b[1];
107169695Skan  p[3] = u.b[0];
108169695Skan
109169695Skan  return out;
110169695Skan}
111