Daniel Dunbar | 2476873 | 2009-10-27 17:48:46 +0000 | [diff] [blame] | 1 | /* ===-- int_lib.h - configuration header for compiler-rt -----------------=== |
Edward O'Callaghan | df72046 | 2009-08-05 01:47:29 +0000 | [diff] [blame] | 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 | * |
Daniel Dunbar | 2476873 | 2009-10-27 17:48:46 +0000 | [diff] [blame] | 10 | * This file is a configuration header for compiler-rt. |
Edward O'Callaghan | df72046 | 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 | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 15 | |
| 16 | #ifndef INT_LIB_H |
| 17 | #define INT_LIB_H |
| 18 | |
Edward O'Callaghan | df72046 | 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 | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 21 | |
| 22 | #include <limits.h> |
Edward O'Callaghan | dabf71f | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 23 | #include "endianness.h" |
Edward O'Callaghan | 30009e7 | 2009-08-04 03:30:10 +0000 | [diff] [blame] | 24 | #include <math.h> |
| 25 | |
Daniel Dunbar | f287008 | 2010-03-31 17:00:45 +0000 | [diff] [blame^] | 26 | #define compilerrt_abort() abort() |
| 27 | |
Edward O'Callaghan | 30009e7 | 2009-08-04 03:30:10 +0000 | [diff] [blame] | 28 | #if !defined(INFINITY) && defined(HUGE_VAL) |
| 29 | #define INFINITY HUGE_VAL |
Edward O'Callaghan | 7a6cb5f | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 30 | #endif /* INFINITY */ |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 31 | |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 32 | typedef int si_int; |
| 33 | typedef unsigned su_int; |
| 34 | |
| 35 | typedef long long di_int; |
| 36 | typedef unsigned long long du_int; |
| 37 | |
| 38 | typedef union |
| 39 | { |
| 40 | di_int all; |
| 41 | struct |
| 42 | { |
| 43 | #if _YUGA_LITTLE_ENDIAN |
| 44 | su_int low; |
| 45 | si_int high; |
| 46 | #else |
| 47 | si_int high; |
| 48 | su_int low; |
Edward O'Callaghan | 7a6cb5f | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 49 | #endif /* _YUGA_LITTLE_ENDIAN */ |
Edward O'Callaghan | ccf4813 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 50 | }s; |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 51 | } dwords; |
| 52 | |
| 53 | typedef union |
| 54 | { |
| 55 | du_int all; |
| 56 | struct |
| 57 | { |
| 58 | #if _YUGA_LITTLE_ENDIAN |
| 59 | su_int low; |
| 60 | su_int high; |
| 61 | #else |
| 62 | su_int high; |
| 63 | su_int low; |
Edward O'Callaghan | 7a6cb5f | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 64 | #endif /* _YUGA_LITTLE_ENDIAN */ |
Edward O'Callaghan | ccf4813 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 65 | }s; |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 66 | } udwords; |
| 67 | |
| 68 | #if __x86_64 |
| 69 | |
| 70 | typedef int ti_int __attribute__ ((mode (TI))); |
| 71 | typedef unsigned tu_int __attribute__ ((mode (TI))); |
| 72 | |
| 73 | typedef union |
| 74 | { |
| 75 | ti_int all; |
| 76 | struct |
| 77 | { |
| 78 | #if _YUGA_LITTLE_ENDIAN |
| 79 | du_int low; |
| 80 | di_int high; |
| 81 | #else |
| 82 | di_int high; |
| 83 | du_int low; |
Edward O'Callaghan | 7a6cb5f | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 84 | #endif /* _YUGA_LITTLE_ENDIAN */ |
Edward O'Callaghan | ccf4813 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 85 | }s; |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 86 | } twords; |
| 87 | |
| 88 | typedef union |
| 89 | { |
| 90 | tu_int all; |
| 91 | struct |
| 92 | { |
| 93 | #if _YUGA_LITTLE_ENDIAN |
| 94 | du_int low; |
| 95 | du_int high; |
| 96 | #else |
| 97 | du_int high; |
| 98 | du_int low; |
Edward O'Callaghan | 7a6cb5f | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 99 | #endif /* _YUGA_LITTLE_ENDIAN */ |
Edward O'Callaghan | ccf4813 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 100 | }s; |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 101 | } utwords; |
| 102 | |
Daniel Dunbar | 2476873 | 2009-10-27 17:48:46 +0000 | [diff] [blame] | 103 | static inline ti_int make_ti(di_int h, di_int l) { |
| 104 | twords r; |
| 105 | r.s.high = h; |
| 106 | r.s.low = l; |
| 107 | return r.all; |
| 108 | } |
| 109 | |
| 110 | static inline tu_int make_tu(du_int h, du_int l) { |
| 111 | utwords r; |
| 112 | r.s.high = h; |
| 113 | r.s.low = l; |
| 114 | return r.all; |
| 115 | } |
| 116 | |
Edward O'Callaghan | 7a6cb5f | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 117 | #endif /* __x86_64 */ |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 118 | |
| 119 | typedef union |
| 120 | { |
| 121 | su_int u; |
| 122 | float f; |
| 123 | } float_bits; |
| 124 | |
| 125 | typedef union |
| 126 | { |
| 127 | udwords u; |
| 128 | double f; |
| 129 | } double_bits; |
| 130 | |
| 131 | typedef struct |
| 132 | { |
| 133 | #if _YUGA_LITTLE_ENDIAN |
| 134 | udwords low; |
| 135 | udwords high; |
| 136 | #else |
| 137 | udwords high; |
| 138 | udwords low; |
Edward O'Callaghan | 7a6cb5f | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 139 | #endif /* _YUGA_LITTLE_ENDIAN */ |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 140 | } uqwords; |
| 141 | |
| 142 | typedef union |
| 143 | { |
| 144 | uqwords u; |
| 145 | long double f; |
| 146 | } long_double_bits; |
| 147 | |
Edward O'Callaghan | 7a6cb5f | 2009-08-05 19:57:20 +0000 | [diff] [blame] | 148 | #endif /* INT_LIB_H */ |