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