blob: f07975627921f954dce5699ee9e1058f78f86f58 [file] [log] [blame]
Daniel Dunbar4467b652009-10-27 17:48:46 +00001/* ===-- int_lib.h - configuration header for compiler-rt -----------------===
Edward O'Callaghan0e4ad9c2009-08-05 01:47:29 +00002 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan0e4ad9c2009-08-05 01:47:29 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
Daniel Dunbar4467b652009-10-27 17:48:46 +000010 * This file is a configuration header for compiler-rt.
Edward O'Callaghan0e4ad9c2009-08-05 01:47:29 +000011 * This file is not part of the interface of this library.
12 *
13 * ===----------------------------------------------------------------------===
14 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000015
16#ifndef INT_LIB_H
17#define INT_LIB_H
18
Edward O'Callaghan0e4ad9c2009-08-05 01:47:29 +000019/* Assumption: signed integral is 2's complement */
20/* Assumption: right shift of signed negative is arithmetic shift */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000021
22#include <limits.h>
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +000023#include "endianness.h"
Edward O'Callaghandf479b62009-08-04 03:30:10 +000024#include <math.h>
25
Daniel Dunbard3d22632010-03-31 17:00:48 +000026/* If compiling for kernel use, call panic() instead of abort(). */
27#ifdef KERNEL_USE
28extern void panic (const char *, ...);
29#define compilerrt_abort() \
30 panic("%s:%d: abort in %s", __FILE__, __LINE__, __FUNCTION__)
31#else
Daniel Dunbar48f46ac2010-03-31 17:00:45 +000032#define compilerrt_abort() abort()
Daniel Dunbard3d22632010-03-31 17:00:48 +000033#endif
Daniel Dunbar48f46ac2010-03-31 17:00:45 +000034
Edward O'Callaghandf479b62009-08-04 03:30:10 +000035#if !defined(INFINITY) && defined(HUGE_VAL)
36#define INFINITY HUGE_VAL
Edward O'Callaghan0898ee92009-08-05 19:57:20 +000037#endif /* INFINITY */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000038
Daniel Dunbarb3a69012009-06-26 16:47:03 +000039typedef int si_int;
40typedef unsigned su_int;
41
42typedef long long di_int;
43typedef unsigned long long du_int;
44
45typedef union
46{
47 di_int all;
48 struct
49 {
50#if _YUGA_LITTLE_ENDIAN
51 su_int low;
52 si_int high;
53#else
54 si_int high;
55 su_int low;
Edward O'Callaghan0898ee92009-08-05 19:57:20 +000056#endif /* _YUGA_LITTLE_ENDIAN */
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000057 }s;
Daniel Dunbarb3a69012009-06-26 16:47:03 +000058} dwords;
59
60typedef union
61{
62 du_int all;
63 struct
64 {
65#if _YUGA_LITTLE_ENDIAN
66 su_int low;
67 su_int high;
68#else
69 su_int high;
70 su_int low;
Edward O'Callaghan0898ee92009-08-05 19:57:20 +000071#endif /* _YUGA_LITTLE_ENDIAN */
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000072 }s;
Daniel Dunbarb3a69012009-06-26 16:47:03 +000073} udwords;
74
75#if __x86_64
76
77typedef int ti_int __attribute__ ((mode (TI)));
78typedef unsigned tu_int __attribute__ ((mode (TI)));
79
80typedef union
81{
82 ti_int all;
83 struct
84 {
85#if _YUGA_LITTLE_ENDIAN
86 du_int low;
87 di_int high;
88#else
89 di_int high;
90 du_int low;
Edward O'Callaghan0898ee92009-08-05 19:57:20 +000091#endif /* _YUGA_LITTLE_ENDIAN */
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000092 }s;
Daniel Dunbarb3a69012009-06-26 16:47:03 +000093} twords;
94
95typedef union
96{
97 tu_int all;
98 struct
99 {
100#if _YUGA_LITTLE_ENDIAN
101 du_int low;
102 du_int high;
103#else
104 du_int high;
105 du_int low;
Edward O'Callaghan0898ee92009-08-05 19:57:20 +0000106#endif /* _YUGA_LITTLE_ENDIAN */
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +0000107 }s;
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000108} utwords;
109
Daniel Dunbar4467b652009-10-27 17:48:46 +0000110static inline ti_int make_ti(di_int h, di_int l) {
111 twords r;
112 r.s.high = h;
113 r.s.low = l;
114 return r.all;
115}
116
117static inline tu_int make_tu(du_int h, du_int l) {
118 utwords r;
119 r.s.high = h;
120 r.s.low = l;
121 return r.all;
122}
123
Edward O'Callaghan0898ee92009-08-05 19:57:20 +0000124#endif /* __x86_64 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000125
126typedef union
127{
128 su_int u;
129 float f;
130} float_bits;
131
132typedef union
133{
134 udwords u;
135 double f;
136} double_bits;
137
138typedef struct
139{
140#if _YUGA_LITTLE_ENDIAN
141 udwords low;
142 udwords high;
143#else
144 udwords high;
145 udwords low;
Edward O'Callaghan0898ee92009-08-05 19:57:20 +0000146#endif /* _YUGA_LITTLE_ENDIAN */
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000147} uqwords;
148
149typedef union
150{
151 uqwords u;
152 long double f;
153} long_double_bits;
154
Edward O'Callaghan0898ee92009-08-05 19:57:20 +0000155#endif /* INT_LIB_H */