Daniel Dunbar | 4467b65 | 2009-10-27 17:48:46 +0000 | [diff] [blame] | 1 | /* ===-- int_lib.h - configuration header for compiler-rt -----------------=== |
Edward O'Callaghan | 0e4ad9c | 2009-08-05 01:47:29 +0000 | [diff] [blame] | 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
Howard Hinnant | 9ad441f | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | * This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | * Source Licenses. See LICENSE.TXT for details. |
Edward O'Callaghan | 0e4ad9c | 2009-08-05 01:47:29 +0000 | [diff] [blame] | 7 | * |
| 8 | * ===----------------------------------------------------------------------=== |
| 9 | * |
Daniel Dunbar | 4467b65 | 2009-10-27 17:48:46 +0000 | [diff] [blame] | 10 | * This file is a configuration header for compiler-rt. |
Edward O'Callaghan | 0e4ad9c | 2009-08-05 01:47:29 +0000 | [diff] [blame] | 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> |
Nick Kledzik | c31717b | 2011-01-07 19:09:06 +0000 | [diff] [blame^] | 23 | #include <stdint.h> |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 24 | #include "endianness.h" |
Edward O'Callaghan | df479b6 | 2009-08-04 03:30:10 +0000 | [diff] [blame] | 25 | #include <math.h> |
| 26 | |
Daniel Dunbar | d3d2263 | 2010-03-31 17:00:48 +0000 | [diff] [blame] | 27 | /* If compiling for kernel use, call panic() instead of abort(). */ |
| 28 | #ifdef KERNEL_USE |
| 29 | extern void panic (const char *, ...); |
| 30 | #define compilerrt_abort() \ |
| 31 | panic("%s:%d: abort in %s", __FILE__, __LINE__, __FUNCTION__) |
| 32 | #else |
Daniel Dunbar | 48f46ac | 2010-03-31 17:00:45 +0000 | [diff] [blame] | 33 | #define compilerrt_abort() abort() |
Daniel Dunbar | d3d2263 | 2010-03-31 17:00:48 +0000 | [diff] [blame] | 34 | #endif |
Daniel Dunbar | 48f46ac | 2010-03-31 17:00:45 +0000 | [diff] [blame] | 35 | |
Edward O'Callaghan | df479b6 | 2009-08-04 03:30:10 +0000 | [diff] [blame] | 36 | #if !defined(INFINITY) && defined(HUGE_VAL) |
| 37 | #define INFINITY HUGE_VAL |
Edward O'Callaghan | 0898ee9 | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 38 | #endif /* INFINITY */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 39 | |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 40 | typedef int si_int; |
| 41 | typedef unsigned su_int; |
| 42 | |
| 43 | typedef long long di_int; |
| 44 | typedef unsigned long long du_int; |
| 45 | |
| 46 | typedef union |
| 47 | { |
| 48 | di_int all; |
| 49 | struct |
| 50 | { |
| 51 | #if _YUGA_LITTLE_ENDIAN |
| 52 | su_int low; |
| 53 | si_int high; |
| 54 | #else |
| 55 | si_int high; |
| 56 | su_int low; |
Edward O'Callaghan | 0898ee9 | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 57 | #endif /* _YUGA_LITTLE_ENDIAN */ |
Edward O'Callaghan | 8bf1e09 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 58 | }s; |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 59 | } dwords; |
| 60 | |
| 61 | typedef union |
| 62 | { |
| 63 | du_int all; |
| 64 | struct |
| 65 | { |
| 66 | #if _YUGA_LITTLE_ENDIAN |
| 67 | su_int low; |
| 68 | su_int high; |
| 69 | #else |
| 70 | su_int high; |
| 71 | su_int low; |
Edward O'Callaghan | 0898ee9 | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 72 | #endif /* _YUGA_LITTLE_ENDIAN */ |
Edward O'Callaghan | 8bf1e09 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 73 | }s; |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 74 | } udwords; |
| 75 | |
| 76 | #if __x86_64 |
| 77 | |
| 78 | typedef int ti_int __attribute__ ((mode (TI))); |
| 79 | typedef unsigned tu_int __attribute__ ((mode (TI))); |
| 80 | |
| 81 | typedef union |
| 82 | { |
| 83 | ti_int all; |
| 84 | struct |
| 85 | { |
| 86 | #if _YUGA_LITTLE_ENDIAN |
| 87 | du_int low; |
| 88 | di_int high; |
| 89 | #else |
| 90 | di_int high; |
| 91 | du_int low; |
Edward O'Callaghan | 0898ee9 | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 92 | #endif /* _YUGA_LITTLE_ENDIAN */ |
Edward O'Callaghan | 8bf1e09 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 93 | }s; |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 94 | } twords; |
| 95 | |
| 96 | typedef union |
| 97 | { |
| 98 | tu_int all; |
| 99 | struct |
| 100 | { |
| 101 | #if _YUGA_LITTLE_ENDIAN |
| 102 | du_int low; |
| 103 | du_int high; |
| 104 | #else |
| 105 | du_int high; |
| 106 | du_int low; |
Edward O'Callaghan | 0898ee9 | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 107 | #endif /* _YUGA_LITTLE_ENDIAN */ |
Edward O'Callaghan | 8bf1e09 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 108 | }s; |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 109 | } utwords; |
| 110 | |
Daniel Dunbar | 4467b65 | 2009-10-27 17:48:46 +0000 | [diff] [blame] | 111 | static inline ti_int make_ti(di_int h, di_int l) { |
| 112 | twords r; |
| 113 | r.s.high = h; |
| 114 | r.s.low = l; |
| 115 | return r.all; |
| 116 | } |
| 117 | |
| 118 | static inline tu_int make_tu(du_int h, du_int l) { |
| 119 | utwords r; |
| 120 | r.s.high = h; |
| 121 | r.s.low = l; |
| 122 | return r.all; |
| 123 | } |
| 124 | |
Edward O'Callaghan | 0898ee9 | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 125 | #endif /* __x86_64 */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 126 | |
| 127 | typedef union |
| 128 | { |
| 129 | su_int u; |
| 130 | float f; |
| 131 | } float_bits; |
| 132 | |
| 133 | typedef union |
| 134 | { |
| 135 | udwords u; |
| 136 | double f; |
| 137 | } double_bits; |
| 138 | |
| 139 | typedef struct |
| 140 | { |
| 141 | #if _YUGA_LITTLE_ENDIAN |
| 142 | udwords low; |
| 143 | udwords high; |
| 144 | #else |
| 145 | udwords high; |
| 146 | udwords low; |
Edward O'Callaghan | 0898ee9 | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 147 | #endif /* _YUGA_LITTLE_ENDIAN */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 148 | } uqwords; |
| 149 | |
| 150 | typedef union |
| 151 | { |
| 152 | uqwords u; |
| 153 | long double f; |
| 154 | } long_double_bits; |
| 155 | |
Edward O'Callaghan | 0898ee9 | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 156 | #endif /* INT_LIB_H */ |