miasm
Reverse engineering framework
int_types.h
Go to the documentation of this file.
1 //===-- int_lib.h - configuration header for compiler-rt -----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is not part of the interface of this library.
10 //
11 // This file defines various standard types, most importantly a number of unions
12 // used to access parts of larger types.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef INT_TYPES_H
17 #define INT_TYPES_H
18 
19 #include "int_endianness.h"
20 
21 // si_int is defined in Linux sysroot's asm-generic/siginfo.h
22 #ifdef si_int
23 #undef si_int
24 #endif
25 typedef int si_int;
26 typedef unsigned su_int;
27 
28 typedef long long di_int;
29 typedef unsigned long long du_int;
30 
31 typedef union {
33  struct {
34 #if _YUGA_LITTLE_ENDIAN
35  su_int low;
36  si_int high;
37 #else
40 #endif // _YUGA_LITTLE_ENDIAN
41  } s;
42 } dwords;
43 
44 typedef union {
46  struct {
47 #if _YUGA_LITTLE_ENDIAN
48  su_int low;
49  su_int high;
50 #else
53 #endif // _YUGA_LITTLE_ENDIAN
54  } s;
55 } udwords;
56 
57 #if defined(__LP64__) || defined(__wasm__) || defined(__mips64) || \
58  defined(__riscv) || defined(_WIN64)
59 #define CRT_HAS_128BIT
60 #endif
61 
62 // MSVC doesn't have a working 128bit integer type. Users should really compile
63 // compiler-rt with clang, but if they happen to be doing a standalone build for
64 // asan or something else, disable the 128 bit parts so things sort of work.
65 #if defined(_MSC_VER) && !defined(__clang__)
66 #undef CRT_HAS_128BIT
67 #endif
68 
69 #ifdef CRT_HAS_128BIT
70 typedef int ti_int __attribute__((mode(TI)));
71 typedef unsigned tu_int __attribute__((mode(TI)));
72 
73 typedef union {
74  ti_int all;
75  struct {
76 #if _YUGA_LITTLE_ENDIAN
77  du_int low;
78  di_int high;
79 #else
80  di_int high;
81  du_int low;
82 #endif // _YUGA_LITTLE_ENDIAN
83  } s;
84 } twords;
85 
86 typedef union {
87  tu_int all;
88  struct {
89 #if _YUGA_LITTLE_ENDIAN
90  du_int low;
91  du_int high;
92 #else
93  du_int high;
94  du_int low;
95 #endif // _YUGA_LITTLE_ENDIAN
96  } s;
97 } utwords;
98 
99 static __inline ti_int make_ti(di_int h, di_int l) {
100  twords r;
101  r.s.high = h;
102  r.s.low = l;
103  return r.all;
104 }
105 
106 static __inline tu_int make_tu(du_int h, du_int l) {
107  utwords r;
108  r.s.high = h;
109  r.s.low = l;
110  return r.all;
111 }
112 
113 #endif // CRT_HAS_128BIT
114 
115 typedef union {
117  float f;
118 } float_bits;
119 
120 typedef union {
122  double f;
123 } double_bits;
124 
125 typedef struct {
126 #if _YUGA_LITTLE_ENDIAN
127  udwords low;
128  udwords high;
129 #else
132 #endif // _YUGA_LITTLE_ENDIAN
133 } uqwords;
134 
135 // Check if the target supports 80 bit extended precision long doubles.
136 // Notably, on x86 Windows, MSVC only provides a 64-bit long double, but GCC
137 // still makes it 80 bits. Clang will match whatever compiler it is trying to
138 // be compatible with.
139 #if ((defined(__i386__) || defined(__x86_64__)) && !defined(_MSC_VER)) || \
140  defined(__m68k__) || defined(__ia64__)
141 #define HAS_80_BIT_LONG_DOUBLE 1
142 #else
143 #define HAS_80_BIT_LONG_DOUBLE 0
144 #endif
145 
146 typedef union {
148  long double f;
150 
151 #if __STDC_VERSION__ >= 199901L
152 typedef float _Complex Fcomplex;
153 typedef double _Complex Dcomplex;
154 typedef long double _Complex Lcomplex;
155 
156 #define COMPLEX_REAL(x) __real__(x)
157 #define COMPLEX_IMAGINARY(x) __imag__(x)
158 #else
159 typedef struct {
160  float real, imaginary;
161 } Fcomplex;
162 
163 typedef struct {
164  double real, imaginary;
165 } Dcomplex;
166 
167 typedef struct {
168  long double real, imaginary;
169 } Lcomplex;
170 
171 #define COMPLEX_REAL(x) (x).real
172 #define COMPLEX_IMAGINARY(x) (x).imaginary
173 #endif
174 #endif // INT_TYPES_H
long_double_bits
Definition: int_types.h:146
Fcomplex
Definition: int_types.h:159
single_instr.l
l
Definition: single_instr.py:7
Dcomplex
Definition: int_types.h:163
du_int
unsigned long long du_int
Definition: int_types.h:29
Dcomplex::real
double real
Definition: int_types.h:164
long_double_bits::u
uqwords u
Definition: int_types.h:147
si_int
int si_int
Definition: int_types.h:25
double_bits
Definition: int_types.h:120
modint.h
h
Definition: modint.py:69
long_double_bits::f
long double f
Definition: int_types.h:148
float_bits::u
su_int u
Definition: int_types.h:116
float_bits
Definition: int_types.h:115
dwords::low
su_int low
Definition: int_types.h:39
uqwords::high
udwords high
Definition: int_types.h:130
di_int
long long di_int
Definition: int_types.h:28
float_bits::f
float f
Definition: int_types.h:117
Lcomplex
Definition: int_types.h:167
int_endianness.h
dwords
Definition: int_types.h:31
uqwords::low
udwords low
Definition: int_types.h:131
Fcomplex::real
float real
Definition: int_types.h:160
double_bits::f
double f
Definition: int_types.h:122
udwords
Definition: int_types.h:44
Lcomplex::real
long double real
Definition: int_types.h:168
uqwords
Definition: int_types.h:125
simplification_tools.s
s
Definition: simplification_tools.py:18
data_flow.r
r
Definition: data_flow.py:18
double_bits::u
udwords u
Definition: int_types.h:121
su_int
unsigned su_int
Definition: int_types.h:26
udwords::all
du_int all
Definition: int_types.h:45
udwords::low
su_int low
Definition: int_types.h:52
dwords::all
di_int all
Definition: int_types.h:32
udwords::high
su_int high
Definition: int_types.h:51
dwords::high
si_int high
Definition: int_types.h:38