Edward O'Callaghan | 0e4ad9c | 2009-08-05 01:47:29 +0000 | [diff] [blame^] | 1 | /* ===-- 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 Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 15 | |
| 16 | #ifndef INT_LIB_H |
| 17 | #define INT_LIB_H |
| 18 | |
Edward O'Callaghan | 0e4ad9c | 2009-08-05 01:47:29 +0000 | [diff] [blame^] | 19 | /* Assumption: signed integral is 2's complement */ |
| 20 | /* Assumption: right shift of signed negative is arithmetic shift */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 21 | |
| 22 | #include <limits.h> |
Edward O'Callaghan | df479b6 | 2009-08-04 03:30:10 +0000 | [diff] [blame] | 23 | #include <math.h> |
| 24 | |
| 25 | #if !defined(INFINITY) && defined(HUGE_VAL) |
| 26 | #define INFINITY HUGE_VAL |
| 27 | #endif |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 28 | |
Edward O'Callaghan | 0e4ad9c | 2009-08-05 01:47:29 +0000 | [diff] [blame^] | 29 | /* TODO: Improve this to minimal pre-processor hackish'ness. */ |
Edward O'Callaghan | 6c307f0 | 2009-08-03 05:59:48 +0000 | [diff] [blame] | 30 | #if defined (__SVR4) && defined (__sun) |
Edward O'Callaghan | 0e4ad9c | 2009-08-05 01:47:29 +0000 | [diff] [blame^] | 31 | /* config.h build via CMake. */ |
| 32 | /* #include <config.h> */ |
Edward O'Callaghan | 6c307f0 | 2009-08-03 05:59:48 +0000 | [diff] [blame] | 33 | |
Edward O'Callaghan | 0e4ad9c | 2009-08-05 01:47:29 +0000 | [diff] [blame^] | 34 | /* Solaris header for endian and byte swap */ |
| 35 | /* #if defined HAVE_SYS_BYTEORDER_H */ |
Edward O'Callaghan | 6c307f0 | 2009-08-03 05:59:48 +0000 | [diff] [blame] | 36 | #include <sys/byteorder.h> |
| 37 | |
Edward O'Callaghan | 0e4ad9c | 2009-08-05 01:47:29 +0000 | [diff] [blame^] | 38 | /* Solaris defines endian by setting _LITTLE_ENDIAN or _BIG_ENDIAN */ |
Edward O'Callaghan | 6c307f0 | 2009-08-03 05:59:48 +0000 | [diff] [blame] | 39 | #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'Callaghan | 0e4ad9c | 2009-08-05 01:47:29 +0000 | [diff] [blame^] | 55 | #endif /* End of Solaris ifdef. */ |
Edward O'Callaghan | 6c307f0 | 2009-08-03 05:59:48 +0000 | [diff] [blame] | 56 | |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 57 | #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 | |
| 75 | typedef int si_int; |
| 76 | typedef unsigned su_int; |
| 77 | |
| 78 | typedef long long di_int; |
| 79 | typedef unsigned long long du_int; |
| 80 | |
| 81 | typedef 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 | |
| 96 | typedef 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 | |
| 113 | typedef int ti_int __attribute__ ((mode (TI))); |
| 114 | typedef unsigned tu_int __attribute__ ((mode (TI))); |
| 115 | |
| 116 | typedef 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 | |
| 131 | typedef 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 | |
| 148 | typedef union |
| 149 | { |
| 150 | su_int u; |
| 151 | float f; |
| 152 | } float_bits; |
| 153 | |
| 154 | typedef union |
| 155 | { |
| 156 | udwords u; |
| 157 | double f; |
| 158 | } double_bits; |
| 159 | |
| 160 | typedef 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 | |
| 171 | typedef union |
| 172 | { |
| 173 | uqwords u; |
| 174 | long double f; |
| 175 | } long_double_bits; |
| 176 | |
| 177 | #endif |