Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +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 | |
| 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 | |
| 23 | #ifdef __LITTLE_ENDIAN__ |
| 24 | #if __LITTLE_ENDIAN__ |
| 25 | #define _YUGA_LITTLE_ENDIAN 1 |
| 26 | #define _YUGA_BIG_ENDIAN 0 |
| 27 | #endif |
| 28 | #endif |
| 29 | |
| 30 | #ifdef __BIG_ENDIAN__ |
| 31 | #if __BIG_ENDIAN__ |
| 32 | #define _YUGA_LITTLE_ENDIAN 0 |
| 33 | #define _YUGA_BIG_ENDIAN 1 |
| 34 | #endif |
| 35 | #endif |
| 36 | |
| 37 | #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN) |
| 38 | #error unable to determine endian |
| 39 | #endif |
| 40 | |
| 41 | typedef int si_int; |
| 42 | typedef unsigned su_int; |
| 43 | |
| 44 | typedef long long di_int; |
| 45 | typedef unsigned long long du_int; |
| 46 | |
| 47 | typedef union |
| 48 | { |
| 49 | di_int all; |
| 50 | struct |
| 51 | { |
| 52 | #if _YUGA_LITTLE_ENDIAN |
| 53 | su_int low; |
| 54 | si_int high; |
| 55 | #else |
| 56 | si_int high; |
| 57 | su_int low; |
| 58 | #endif |
| 59 | }; |
| 60 | } dwords; |
| 61 | |
| 62 | typedef union |
| 63 | { |
| 64 | du_int all; |
| 65 | struct |
| 66 | { |
| 67 | #if _YUGA_LITTLE_ENDIAN |
| 68 | su_int low; |
| 69 | su_int high; |
| 70 | #else |
| 71 | su_int high; |
| 72 | su_int low; |
| 73 | #endif |
| 74 | }; |
| 75 | } udwords; |
| 76 | |
| 77 | #if __x86_64 |
| 78 | |
| 79 | typedef int ti_int __attribute__ ((mode (TI))); |
| 80 | typedef unsigned tu_int __attribute__ ((mode (TI))); |
| 81 | |
| 82 | typedef union |
| 83 | { |
| 84 | ti_int all; |
| 85 | struct |
| 86 | { |
| 87 | #if _YUGA_LITTLE_ENDIAN |
| 88 | du_int low; |
| 89 | di_int high; |
| 90 | #else |
| 91 | di_int high; |
| 92 | du_int low; |
| 93 | #endif |
| 94 | }; |
| 95 | } twords; |
| 96 | |
| 97 | typedef union |
| 98 | { |
| 99 | tu_int all; |
| 100 | struct |
| 101 | { |
| 102 | #if _YUGA_LITTLE_ENDIAN |
| 103 | du_int low; |
| 104 | du_int high; |
| 105 | #else |
| 106 | du_int high; |
| 107 | du_int low; |
| 108 | #endif |
| 109 | }; |
| 110 | } utwords; |
| 111 | |
| 112 | #endif |
| 113 | |
| 114 | typedef union |
| 115 | { |
| 116 | su_int u; |
| 117 | float f; |
| 118 | } float_bits; |
| 119 | |
| 120 | typedef union |
| 121 | { |
| 122 | udwords u; |
| 123 | double f; |
| 124 | } double_bits; |
| 125 | |
| 126 | typedef struct |
| 127 | { |
| 128 | #if _YUGA_LITTLE_ENDIAN |
| 129 | udwords low; |
| 130 | udwords high; |
| 131 | #else |
| 132 | udwords high; |
| 133 | udwords low; |
| 134 | #endif |
| 135 | } uqwords; |
| 136 | |
| 137 | typedef union |
| 138 | { |
| 139 | uqwords u; |
| 140 | long double f; |
| 141 | } long_double_bits; |
| 142 | |
| 143 | #endif |