blob: e1fd6b73dc7fcd81d9bbc1e4e8009da1239d70aa [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>
Nick Kledzikc31717b2011-01-07 19:09:06 +000023#include <stdint.h>
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +000024#include "endianness.h"
Edward O'Callaghandf479b62009-08-04 03:30:10 +000025#include <math.h>
26
Daniel Dunbard3d22632010-03-31 17:00:48 +000027/* If compiling for kernel use, call panic() instead of abort(). */
28#ifdef KERNEL_USE
29extern void panic (const char *, ...);
30#define compilerrt_abort() \
31 panic("%s:%d: abort in %s", __FILE__, __LINE__, __FUNCTION__)
32#else
Daniel Dunbar48f46ac2010-03-31 17:00:45 +000033#define compilerrt_abort() abort()
Daniel Dunbard3d22632010-03-31 17:00:48 +000034#endif
Daniel Dunbar48f46ac2010-03-31 17:00:45 +000035
Edward O'Callaghandf479b62009-08-04 03:30:10 +000036#if !defined(INFINITY) && defined(HUGE_VAL)
37#define INFINITY HUGE_VAL
Edward O'Callaghan0898ee92009-08-05 19:57:20 +000038#endif /* INFINITY */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000039
Daniel Dunbarb3a69012009-06-26 16:47:03 +000040typedef int si_int;
41typedef unsigned su_int;
42
43typedef long long di_int;
44typedef unsigned long long du_int;
45
46typedef union
47{
48 di_int all;
49 struct
50 {
51#if _YUGA_LITTLE_ENDIAN
52 su_int low;
53 si_int high;
54#else
55 si_int high;
56 su_int low;
Edward O'Callaghan0898ee92009-08-05 19:57:20 +000057#endif /* _YUGA_LITTLE_ENDIAN */
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000058 }s;
Daniel Dunbarb3a69012009-06-26 16:47:03 +000059} dwords;
60
61typedef union
62{
63 du_int all;
64 struct
65 {
66#if _YUGA_LITTLE_ENDIAN
67 su_int low;
68 su_int high;
69#else
70 su_int high;
71 su_int low;
Edward O'Callaghan0898ee92009-08-05 19:57:20 +000072#endif /* _YUGA_LITTLE_ENDIAN */
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000073 }s;
Daniel Dunbarb3a69012009-06-26 16:47:03 +000074} udwords;
75
76#if __x86_64
77
78typedef int ti_int __attribute__ ((mode (TI)));
79typedef unsigned tu_int __attribute__ ((mode (TI)));
80
81typedef union
82{
83 ti_int all;
84 struct
85 {
86#if _YUGA_LITTLE_ENDIAN
87 du_int low;
88 di_int high;
89#else
90 di_int high;
91 du_int low;
Edward O'Callaghan0898ee92009-08-05 19:57:20 +000092#endif /* _YUGA_LITTLE_ENDIAN */
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000093 }s;
Daniel Dunbarb3a69012009-06-26 16:47:03 +000094} twords;
95
96typedef union
97{
98 tu_int all;
99 struct
100 {
101#if _YUGA_LITTLE_ENDIAN
102 du_int low;
103 du_int high;
104#else
105 du_int high;
106 du_int low;
Edward O'Callaghan0898ee92009-08-05 19:57:20 +0000107#endif /* _YUGA_LITTLE_ENDIAN */
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +0000108 }s;
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000109} utwords;
110
Daniel Dunbar4467b652009-10-27 17:48:46 +0000111static inline ti_int make_ti(di_int h, di_int l) {
112 twords r;
113 r.s.high = h;
114 r.s.low = l;
115 return r.all;
116}
117
118static inline tu_int make_tu(du_int h, du_int l) {
119 utwords r;
120 r.s.high = h;
121 r.s.low = l;
122 return r.all;
123}
124
Edward O'Callaghan0898ee92009-08-05 19:57:20 +0000125#endif /* __x86_64 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000126
127typedef union
128{
129 su_int u;
130 float f;
131} float_bits;
132
133typedef union
134{
135 udwords u;
136 double f;
137} double_bits;
138
139typedef struct
140{
141#if _YUGA_LITTLE_ENDIAN
142 udwords low;
143 udwords high;
144#else
145 udwords high;
146 udwords low;
Edward O'Callaghan0898ee92009-08-05 19:57:20 +0000147#endif /* _YUGA_LITTLE_ENDIAN */
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000148} uqwords;
149
150typedef union
151{
152 uqwords u;
153 long double f;
154} long_double_bits;
155
Edward O'Callaghan0898ee92009-08-05 19:57:20 +0000156#endif /* INT_LIB_H */