blob: 6ef7b8e3f37aab81a7372dbd3809c2cbfa4f5606 [file] [log] [blame]
Edward O'Callaghan0e4ad9c2009-08-05 01:47:29 +00001/* ===-- int_lib.h - configuration header for libgcc replacement -----------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
5 * This file is distributed under the University of Illinois Open Source
6 * License. See LICENSE.TXT for details.
7 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file is a configuration header for libgcc replacement.
11 * 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'Callaghandf479b62009-08-04 03:30:10 +000023#include <math.h>
24
25#if !defined(INFINITY) && defined(HUGE_VAL)
26#define INFINITY HUGE_VAL
27#endif
Daniel Dunbarb3a69012009-06-26 16:47:03 +000028
Edward O'Callaghan0e4ad9c2009-08-05 01:47:29 +000029/* TODO: Improve this to minimal pre-processor hackish'ness. */
Edward O'Callaghan6c307f02009-08-03 05:59:48 +000030#if defined (__SVR4) && defined (__sun)
Edward O'Callaghan0e4ad9c2009-08-05 01:47:29 +000031/* config.h build via CMake. */
32/* #include <config.h> */
Edward O'Callaghan6c307f02009-08-03 05:59:48 +000033
Edward O'Callaghan0e4ad9c2009-08-05 01:47:29 +000034/* Solaris header for endian and byte swap */
35/* #if defined HAVE_SYS_BYTEORDER_H */
Edward O'Callaghan6c307f02009-08-03 05:59:48 +000036#include <sys/byteorder.h>
37
Edward O'Callaghan0e4ad9c2009-08-05 01:47:29 +000038/* Solaris defines endian by setting _LITTLE_ENDIAN or _BIG_ENDIAN */
Edward O'Callaghan6c307f02009-08-03 05:59:48 +000039#ifdef _BIG_ENDIAN
40# define IS_BIG_ENDIAN
41#endif
42#ifdef _LITTLE_ENDIAN
43# define IS_LITTLE_ENDIAN
44#endif
45
46#ifdef IS_BIG_ENDIAN
47#define __BIG_ENDIAN__ 1
48#define __LITTLE_ENDIAN__ 0
49#endif
50#ifdef IS_LITTLE_ENDIAN
51#define __BIG_ENDIAN__ 0
52#define __LITTLE_ENDIAN__ 1
53#endif
54
Edward O'Callaghan0e4ad9c2009-08-05 01:47:29 +000055#endif /* End of Solaris ifdef. */
Edward O'Callaghan6c307f02009-08-03 05:59:48 +000056
Daniel Dunbarb3a69012009-06-26 16:47:03 +000057#ifdef __LITTLE_ENDIAN__
58#if __LITTLE_ENDIAN__
59#define _YUGA_LITTLE_ENDIAN 1
60#define _YUGA_BIG_ENDIAN 0
61#endif
62#endif
63
64#ifdef __BIG_ENDIAN__
65#if __BIG_ENDIAN__
66#define _YUGA_LITTLE_ENDIAN 0
67#define _YUGA_BIG_ENDIAN 1
68#endif
69#endif
70
71#if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
72#error unable to determine endian
73#endif
74
75typedef int si_int;
76typedef unsigned su_int;
77
78typedef long long di_int;
79typedef unsigned long long du_int;
80
81typedef union
82{
83 di_int all;
84 struct
85 {
86#if _YUGA_LITTLE_ENDIAN
87 su_int low;
88 si_int high;
89#else
90 si_int high;
91 su_int low;
92#endif
93 };
94} dwords;
95
96typedef union
97{
98 du_int all;
99 struct
100 {
101#if _YUGA_LITTLE_ENDIAN
102 su_int low;
103 su_int high;
104#else
105 su_int high;
106 su_int low;
107#endif
108 };
109} udwords;
110
111#if __x86_64
112
113typedef int ti_int __attribute__ ((mode (TI)));
114typedef unsigned tu_int __attribute__ ((mode (TI)));
115
116typedef union
117{
118 ti_int all;
119 struct
120 {
121#if _YUGA_LITTLE_ENDIAN
122 du_int low;
123 di_int high;
124#else
125 di_int high;
126 du_int low;
127#endif
128 };
129} twords;
130
131typedef union
132{
133 tu_int all;
134 struct
135 {
136#if _YUGA_LITTLE_ENDIAN
137 du_int low;
138 du_int high;
139#else
140 du_int high;
141 du_int low;
142#endif
143 };
144} utwords;
145
146#endif
147
148typedef union
149{
150 su_int u;
151 float f;
152} float_bits;
153
154typedef union
155{
156 udwords u;
157 double f;
158} double_bits;
159
160typedef struct
161{
162#if _YUGA_LITTLE_ENDIAN
163 udwords low;
164 udwords high;
165#else
166 udwords high;
167 udwords low;
168#endif
169} uqwords;
170
171typedef union
172{
173 uqwords u;
174 long double f;
175} long_double_bits;
176
177#endif