*** empty log message ***
[libfirm] / ir / tv / ieee754.h
1 /* IEEE754 fp format.
2    Copyright (C) 1995, 1996 Christian von Roques */
3
4 /* This file was derived from the GNU C Library's ieee754.h which
5    carried the following copyright notice:
6
7 Copyright (C) 1992 Free Software Foundation, Inc.
8
9 The GNU C Library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
13
14 The GNU C Library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public
20 License along with the GNU C Library; see the file COPYING.LIB.  If
21 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
22 Cambridge, MA 02139, USA.  */
23
24 /* @@@ This is completely non-portable!  ISO/IEC DIS 9899, section
25    3.5.2.1: An implementation may allocate any addressable storage
26    unit large enough to hold a bit-field.  If enough space remains, a
27    bit-field that immediately follows another bit-field in a structure
28    shall be packed into adjacent bits of the same unit.  If
29    insufficient space remains, whether a bit-field that does not fit
30    is put into the next unit or overlaps adjacent units is
31    implementation-defined.  The order of allocation of bit-fields
32    within a unit (high-order to low-order or low-order to high-order)
33    is implementation-defined.  */
34
35 /* Floating point definitions in ieee standard number 754
36    only used in target values (/libfirm/ir/tv/tv.c). */
37 #ifndef _IEEE754_H
38 #define _IEEE754_H
39
40 #ifdef HAVE_CONFIG_H
41 # include <config.h>
42 #endif
43
44
45 union ieee754_double
46   {
47     double d;
48
49     /* This is the IEEE 754 double-precision format.  */
50     struct
51       {
52 #ifdef WORDS_BIGENDIAN
53         unsigned int negative:1;
54         unsigned int exponent:11;
55         unsigned int mantissa0:20;
56         unsigned int mantissa1:32;
57 #else
58         unsigned int mantissa1:32;
59         unsigned int mantissa0:20;
60         unsigned int exponent:11;
61         unsigned int negative:1;
62 #endif
63       } ieee;
64     struct
65       {
66 #ifdef WORDS_BIGENDIAN
67         unsigned int negative:1;
68         unsigned int exponent:11;
69         unsigned int quiet_nan:1;
70         unsigned int mantissa0:19;
71         unsigned int mantissa1:32;
72 #else
73         unsigned int mantissa1:32;
74         unsigned int mantissa0:19;
75         unsigned int quiet_nan:1;
76         unsigned int exponent:11;
77         unsigned int negative:1;
78 #endif
79       } ieee_nan;
80   };
81
82 /* bias added to exponent of ieee754_double */
83 #define _IEEE754_DOUBLE_BIAS 0x3ff
84
85
86 union ieee754_float
87   {
88     float f;
89
90     /* This is the ieee754 single-precision format.  */
91     struct
92       {
93 #ifdef WORDS_BIGENDIAN
94         unsigned int negative:1;
95         unsigned int exponent:8;
96         unsigned int mantissa:23;
97 #else
98         unsigned int mantissa:23;
99         unsigned int exponent:8;
100         unsigned int negative:1;
101 #endif
102       } ieee;
103     /* This is for extracting information about NaNs.  */
104     struct
105       {
106 #ifdef WORDS_BIGENDIAN
107         unsigned int negative:1;
108         unsigned int exponent:8;
109         unsigned int quiet_nan:1;
110         unsigned int mantissa:22;
111 #else
112         unsigned int mantissa:22;
113         unsigned int quiet_nan:1;
114         unsigned int exponent:8;
115         unsigned int negative:1;
116 #endif
117       } ieee_nan;
118   };
119
120 /* bias added to exponent of ieee_float */
121 #define _IEEE754_FLOAT_BIAS 0x7f
122
123 #endif  /* _IEEE754_H */