blob: 3690d2ebef734cc3f212c2d0d3e2f48c566523b4 [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +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
15#ifndef INT_LIB_H
16#define INT_LIB_H
17
18// Assumption: signed integral is 2's complement
19// Assumption: right shift of signed negative is arithmetic shift
20
21#include <limits.h>
Edward O'Callaghandf479b62009-08-04 03:30:10 +000022#include <math.h>
23
24#if !defined(INFINITY) && defined(HUGE_VAL)
25#define INFINITY HUGE_VAL
26#endif
Daniel Dunbarb3a69012009-06-26 16:47:03 +000027
Edward O'Callaghan6c307f02009-08-03 05:59:48 +000028// TODO: Improve this to minimal pre-processor hackish'ness.
29#if defined (__SVR4) && defined (__sun)
30// config.h build via CMake.
31//#include <config.h>
32
33// Solaris header for endian and byte swap
34//#if defined HAVE_SYS_BYTEORDER_H
35#include <sys/byteorder.h>
36
37// Solaris defines endian by setting _LITTLE_ENDIAN or _BIG_ENDIAN
38#ifdef _BIG_ENDIAN
39# define IS_BIG_ENDIAN
40#endif
41#ifdef _LITTLE_ENDIAN
42# define IS_LITTLE_ENDIAN
43#endif
44
45#ifdef IS_BIG_ENDIAN
46#define __BIG_ENDIAN__ 1
47#define __LITTLE_ENDIAN__ 0
48#endif
49#ifdef IS_LITTLE_ENDIAN
50#define __BIG_ENDIAN__ 0
51#define __LITTLE_ENDIAN__ 1
52#endif
53
54#endif //End of Solaris ifdef.
55
Daniel Dunbarb3a69012009-06-26 16:47:03 +000056#ifdef __LITTLE_ENDIAN__
57#if __LITTLE_ENDIAN__
58#define _YUGA_LITTLE_ENDIAN 1
59#define _YUGA_BIG_ENDIAN 0
60#endif
61#endif
62
63#ifdef __BIG_ENDIAN__
64#if __BIG_ENDIAN__
65#define _YUGA_LITTLE_ENDIAN 0
66#define _YUGA_BIG_ENDIAN 1
67#endif
68#endif
69
70#if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
71#error unable to determine endian
72#endif
73
74typedef int si_int;
75typedef unsigned su_int;
76
77typedef long long di_int;
78typedef unsigned long long du_int;
79
80typedef union
81{
82 di_int all;
83 struct
84 {
85#if _YUGA_LITTLE_ENDIAN
86 su_int low;
87 si_int high;
88#else
89 si_int high;
90 su_int low;
91#endif
92 };
93} dwords;
94
95typedef union
96{
97 du_int all;
98 struct
99 {
100#if _YUGA_LITTLE_ENDIAN
101 su_int low;
102 su_int high;
103#else
104 su_int high;
105 su_int low;
106#endif
107 };
108} udwords;
109
110#if __x86_64
111
112typedef int ti_int __attribute__ ((mode (TI)));
113typedef unsigned tu_int __attribute__ ((mode (TI)));
114
115typedef union
116{
117 ti_int all;
118 struct
119 {
120#if _YUGA_LITTLE_ENDIAN
121 du_int low;
122 di_int high;
123#else
124 di_int high;
125 du_int low;
126#endif
127 };
128} twords;
129
130typedef union
131{
132 tu_int all;
133 struct
134 {
135#if _YUGA_LITTLE_ENDIAN
136 du_int low;
137 du_int high;
138#else
139 du_int high;
140 du_int low;
141#endif
142 };
143} utwords;
144
145#endif
146
147typedef union
148{
149 su_int u;
150 float f;
151} float_bits;
152
153typedef union
154{
155 udwords u;
156 double f;
157} double_bits;
158
159typedef struct
160{
161#if _YUGA_LITTLE_ENDIAN
162 udwords low;
163 udwords high;
164#else
165 udwords high;
166 udwords low;
167#endif
168} uqwords;
169
170typedef union
171{
172 uqwords u;
173 long double f;
174} long_double_bits;
175
176#endif