1 /* ===-- int_lib.h - configuration header for compiler-rt  -----------------===
2  *
3  *                     The LLVM Compiler Infrastructure
4  *
5  * This file is dual licensed under the MIT and the University of Illinois Open
6  * Source Licenses. See LICENSE.TXT for details.
7  *
8  * ===----------------------------------------------------------------------===
9  *
10  * This file is not part of the interface of this library.
11  *
12  * This file defines various standard types, most importantly a number of unions
13  * used to access parts of larger types.
14  *
15  * ===----------------------------------------------------------------------===
16  */
17 
18 #ifndef INT_TYPES_H
19 #define INT_TYPES_H
20 
21 #include "int_endianness.h"
22 
23 /* si_int is defined in Linux sysroot's asm-generic/siginfo.h */
24 #ifdef si_int
25 #undef si_int
26 #endif
27 typedef      int si_int;
28 typedef unsigned su_int;
29 
30 typedef          long long di_int;
31 typedef unsigned long long du_int;
32 
33 typedef union
34 {
35     di_int all;
36     struct
37     {
38 #if _YUGA_LITTLE_ENDIAN
39         su_int low;
40         si_int high;
41 #else
42         si_int high;
43         su_int low;
44 #endif /* _YUGA_LITTLE_ENDIAN */
45     }s;
46 } dwords;
47 
48 typedef union
49 {
50     du_int all;
51     struct
52     {
53 #if _YUGA_LITTLE_ENDIAN
54         su_int low;
55         su_int high;
56 #else
57         su_int high;
58         su_int low;
59 #endif /* _YUGA_LITTLE_ENDIAN */
60     }s;
61 } udwords;
62 
63 /* MIPS64 issue: PR 20098 */
64 #if defined(__LP64__) && !(defined(__mips__) && defined(__clang__))
65 #define CRT_HAS_128BIT
66 #endif
67 
68 #ifdef CRT_HAS_128BIT
69 typedef int      ti_int __attribute__ ((mode (TI)));
70 typedef unsigned tu_int __attribute__ ((mode (TI)));
71 
72 typedef union
73 {
74     ti_int all;
75     struct
76     {
77 #if _YUGA_LITTLE_ENDIAN
78         du_int low;
79         di_int high;
80 #else
81         di_int high;
82         du_int low;
83 #endif /* _YUGA_LITTLE_ENDIAN */
84     }s;
85 } twords;
86 
87 typedef union
88 {
89     tu_int all;
90     struct
91     {
92 #if _YUGA_LITTLE_ENDIAN
93         du_int low;
94         du_int high;
95 #else
96         du_int high;
97         du_int low;
98 #endif /* _YUGA_LITTLE_ENDIAN */
99     }s;
100 } utwords;
101 
make_ti(di_int h,di_int l)102 static __inline ti_int make_ti(di_int h, di_int l) {
103     twords r;
104     r.s.high = h;
105     r.s.low = l;
106     return r.all;
107 }
108 
make_tu(du_int h,du_int l)109 static __inline tu_int make_tu(du_int h, du_int l) {
110     utwords r;
111     r.s.high = h;
112     r.s.low = l;
113     return r.all;
114 }
115 
116 #endif /* CRT_HAS_128BIT */
117 
118 typedef union
119 {
120     su_int u;
121     float f;
122 } float_bits;
123 
124 typedef union
125 {
126     udwords u;
127     double  f;
128 } double_bits;
129 
130 typedef struct
131 {
132 #if _YUGA_LITTLE_ENDIAN
133     udwords low;
134     udwords high;
135 #else
136     udwords high;
137     udwords low;
138 #endif /* _YUGA_LITTLE_ENDIAN */
139 } uqwords;
140 
141 typedef union
142 {
143     uqwords     u;
144     long double f;
145 } long_double_bits;
146 
147 #if __STDC_VERSION__ >= 199901L
148 typedef float _Complex Fcomplex;
149 typedef double _Complex Dcomplex;
150 typedef long double _Complex Lcomplex;
151 
152 #define COMPLEX_REAL(x) __real__(x)
153 #define COMPLEX_IMAGINARY(x) __imag__(x)
154 #else
155 typedef struct { float real, imaginary; } Fcomplex;
156 
157 typedef struct { double real, imaginary; } Dcomplex;
158 
159 typedef struct { long double real, imaginary; } Lcomplex;
160 
161 #define COMPLEX_REAL(x) (x).real
162 #define COMPLEX_IMAGINARY(x) (x).imaginary
163 #endif
164 #endif /* INT_TYPES_H */
165 
166