Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 1 | /*===---- arm_acle.h - ARM Non-Neon intrinsics -----------------------------=== |
| 2 | * |
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | * of this software and associated documentation files (the "Software"), to deal |
| 5 | * in the Software without restriction, including without limitation the rights |
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | * copies of the Software, and to permit persons to whom the Software is |
| 8 | * furnished to do so, subject to the following conditions: |
| 9 | * |
| 10 | * The above copyright notice and this permission notice shall be included in |
| 11 | * all copies or substantial portions of the Software. |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 | * THE SOFTWARE. |
| 20 | * |
| 21 | *===-----------------------------------------------------------------------=== |
| 22 | */ |
| 23 | |
| 24 | #ifndef __ARM_ACLE_H |
| 25 | #define __ARM_ACLE_H |
| 26 | |
| 27 | #ifndef __ARM_ACLE |
| 28 | #error "ACLE intrinsics support not enabled." |
| 29 | #endif |
| 30 | |
| 31 | #include <stdint.h> |
| 32 | |
Saleem Abdulrasool | 60df061 | 2014-07-08 05:46:00 +0000 | [diff] [blame] | 33 | #if defined(__cplusplus) |
| 34 | extern "C" { |
| 35 | #endif |
Yi Kong | 28d7b02 | 2014-07-17 12:45:17 +0000 | [diff] [blame] | 36 | |
Yi Kong | 472e521 | 2014-07-14 15:32:29 +0000 | [diff] [blame] | 37 | /* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */ |
Yi Kong | 28d7b02 | 2014-07-17 12:45:17 +0000 | [diff] [blame] | 38 | /* 8.3 Memory barriers */ |
| 39 | #if !defined(_MSC_VER) |
| 40 | #define __dmb(i) __builtin_arm_dmb(i) |
| 41 | #define __dsb(i) __builtin_arm_dsb(i) |
| 42 | #define __isb(i) __builtin_arm_isb(i) |
| 43 | #endif |
| 44 | |
Yi Kong | 472e521 | 2014-07-14 15:32:29 +0000 | [diff] [blame] | 45 | /* 8.4 Hints */ |
Saleem Abdulrasool | 07257fe | 2014-07-12 23:27:26 +0000 | [diff] [blame] | 46 | |
| 47 | #if !defined(_MSC_VER) |
| 48 | static __inline__ void __attribute__((always_inline, nodebug)) __wfi(void) { |
| 49 | __builtin_arm_wfi(); |
| 50 | } |
| 51 | |
| 52 | static __inline__ void __attribute__((always_inline, nodebug)) __wfe(void) { |
| 53 | __builtin_arm_wfe(); |
| 54 | } |
| 55 | |
| 56 | static __inline__ void __attribute__((always_inline, nodebug)) __sev(void) { |
| 57 | __builtin_arm_sev(); |
| 58 | } |
| 59 | |
| 60 | static __inline__ void __attribute__((always_inline, nodebug)) __sevl(void) { |
| 61 | __builtin_arm_sevl(); |
| 62 | } |
| 63 | |
| 64 | static __inline__ void __attribute__((always_inline, nodebug)) __yield(void) { |
| 65 | __builtin_arm_yield(); |
| 66 | } |
| 67 | #endif |
| 68 | |
Yi Kong | 0705e00 | 2014-08-26 09:50:54 +0000 | [diff] [blame^] | 69 | /* 8.5 Swap */ |
| 70 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 71 | __swp(uint32_t x, volatile uint32_t *p) { |
| 72 | uint32_t v; |
| 73 | do v = __builtin_arm_ldrex(p); while (__builtin_arm_strex(x, p)); |
| 74 | return v; |
| 75 | } |
| 76 | |
Yi Kong | 45a0931 | 2014-08-13 23:20:15 +0000 | [diff] [blame] | 77 | /* 8.6 Memory prefetch intrinsics */ |
| 78 | /* 8.6.1 Data prefetch */ |
| 79 | #define __pld(addr) __pldx(0, 0, 0, addr) |
| 80 | |
| 81 | #if __ARM_32BIT_STATE |
| 82 | #define __pldx(access_kind, cache_level, retention_policy, addr) \ |
| 83 | __builtin_arm_prefetch(addr, access_kind, 1) |
| 84 | #else |
| 85 | #define __pldx(access_kind, cache_level, retention_policy, addr) \ |
| 86 | __builtin_arm_prefetch(addr, access_kind, cache_level, retention_policy, 1) |
| 87 | #endif |
| 88 | |
| 89 | /* 8.6.2 Instruction prefetch */ |
| 90 | #define __pli(addr) __plix(0, 0, addr) |
| 91 | |
| 92 | #if __ARM_32BIT_STATE |
| 93 | #define __plix(cache_level, retention_policy, addr) \ |
| 94 | __builtin_arm_prefetch(addr, 0, 0) |
| 95 | #else |
| 96 | #define __plix(cache_level, retention_policy, addr) \ |
| 97 | __builtin_arm_prefetch(addr, 0, cache_level, retention_policy, 0) |
| 98 | #endif |
| 99 | |
Yi Kong | 472e521 | 2014-07-14 15:32:29 +0000 | [diff] [blame] | 100 | /* 8.7 NOP */ |
| 101 | static __inline__ void __attribute__((always_inline, nodebug)) __nop(void) { |
| 102 | __builtin_arm_nop(); |
| 103 | } |
| 104 | |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 105 | /* 9 DATA-PROCESSING INTRINSICS */ |
| 106 | /* 9.2 Miscellaneous data-processing intrinsics */ |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 107 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 108 | __clz(uint32_t t) { |
| 109 | return __builtin_clz(t); |
| 110 | } |
| 111 | |
| 112 | static __inline__ unsigned long __attribute__((always_inline, nodebug)) |
| 113 | __clzl(unsigned long t) { |
| 114 | return __builtin_clzl(t); |
| 115 | } |
| 116 | |
| 117 | static __inline__ uint64_t __attribute__((always_inline, nodebug)) |
| 118 | __clzll(uint64_t t) { |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 119 | return __builtin_clzll(t); |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 123 | __rev(uint32_t t) { |
| 124 | return __builtin_bswap32(t); |
| 125 | } |
| 126 | |
| 127 | static __inline__ unsigned long __attribute__((always_inline, nodebug)) |
| 128 | __revl(unsigned long t) { |
| 129 | #if __SIZEOF_LONG__ == 4 |
| 130 | return __builtin_bswap32(t); |
| 131 | #else |
| 132 | return __builtin_bswap64(t); |
| 133 | #endif |
| 134 | } |
| 135 | |
| 136 | static __inline__ uint64_t __attribute__((always_inline, nodebug)) |
| 137 | __revll(uint64_t t) { |
| 138 | return __builtin_bswap64(t); |
| 139 | } |
| 140 | |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 141 | /* |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 142 | * 9.4 Saturating intrinsics |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 143 | * |
| 144 | * FIXME: Change guard to their corrosponding __ARM_FEATURE flag when Q flag |
| 145 | * intrinsics are implemented and the flag is enabled. |
| 146 | */ |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 147 | /* 9.4.1 Width-specified saturation intrinsics */ |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 148 | #if __ARM_32BIT_STATE |
| 149 | #define __ssat(x, y) __builtin_arm_ssat(x, y) |
| 150 | #define __usat(x, y) __builtin_arm_usat(x, y) |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 151 | #endif |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 152 | |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 153 | /* 9.4.2 Saturating addition and subtraction intrinsics */ |
| 154 | #if __ARM_32BIT_STATE |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 155 | static __inline__ int32_t __attribute__((always_inline, nodebug)) |
| 156 | __qadd(int32_t t, int32_t v) { |
| 157 | return __builtin_arm_qadd(t, v); |
| 158 | } |
| 159 | |
| 160 | static __inline__ int32_t __attribute__((always_inline, nodebug)) |
| 161 | __qsub(int32_t t, int32_t v) { |
| 162 | return __builtin_arm_qsub(t, v); |
| 163 | } |
Renato Golin | 47843ef | 2014-07-03 10:14:52 +0000 | [diff] [blame] | 164 | |
| 165 | static __inline__ int32_t __attribute__((always_inline, nodebug)) |
| 166 | __qdbl(int32_t t) { |
| 167 | return __builtin_arm_qadd(t, t); |
| 168 | } |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 169 | #endif |
| 170 | |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 171 | /* 9.7 CRC32 intrinsics */ |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 172 | #if __ARM_FEATURE_CRC32 |
| 173 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 174 | __crc32b(uint32_t a, uint8_t b) { |
| 175 | return __builtin_arm_crc32b(a, b); |
| 176 | } |
| 177 | |
| 178 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 179 | __crc32h(uint32_t a, uint16_t b) { |
| 180 | return __builtin_arm_crc32h(a, b); |
| 181 | } |
| 182 | |
| 183 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 184 | __crc32w(uint32_t a, uint32_t b) { |
| 185 | return __builtin_arm_crc32w(a, b); |
| 186 | } |
| 187 | |
| 188 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 189 | __crc32d(uint32_t a, uint64_t b) { |
| 190 | return __builtin_arm_crc32d(a, b); |
| 191 | } |
| 192 | |
| 193 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 194 | __crc32cb(uint32_t a, uint8_t b) { |
| 195 | return __builtin_arm_crc32cb(a, b); |
| 196 | } |
| 197 | |
| 198 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 199 | __crc32ch(uint32_t a, uint16_t b) { |
| 200 | return __builtin_arm_crc32ch(a, b); |
| 201 | } |
| 202 | |
| 203 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 204 | __crc32cw(uint32_t a, uint32_t b) { |
| 205 | return __builtin_arm_crc32cw(a, b); |
| 206 | } |
| 207 | |
| 208 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 209 | __crc32cd(uint32_t a, uint64_t b) { |
| 210 | return __builtin_arm_crc32cd(a, b); |
| 211 | } |
| 212 | #endif |
| 213 | |
Saleem Abdulrasool | 60df061 | 2014-07-08 05:46:00 +0000 | [diff] [blame] | 214 | #if defined(__cplusplus) |
| 215 | } |
| 216 | #endif |
| 217 | |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 218 | #endif /* __ARM_ACLE_H */ |