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