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 |
| 36 | |
Saleem Abdulrasool | 07257fe | 2014-07-12 23:27:26 +0000 | [diff] [blame^] | 37 | /* 8.4 - Hints */ |
| 38 | |
| 39 | #if !defined(_MSC_VER) |
| 40 | static __inline__ void __attribute__((always_inline, nodebug)) __wfi(void) { |
| 41 | __builtin_arm_wfi(); |
| 42 | } |
| 43 | |
| 44 | static __inline__ void __attribute__((always_inline, nodebug)) __wfe(void) { |
| 45 | __builtin_arm_wfe(); |
| 46 | } |
| 47 | |
| 48 | static __inline__ void __attribute__((always_inline, nodebug)) __sev(void) { |
| 49 | __builtin_arm_sev(); |
| 50 | } |
| 51 | |
| 52 | static __inline__ void __attribute__((always_inline, nodebug)) __sevl(void) { |
| 53 | __builtin_arm_sevl(); |
| 54 | } |
| 55 | |
| 56 | static __inline__ void __attribute__((always_inline, nodebug)) __yield(void) { |
| 57 | __builtin_arm_yield(); |
| 58 | } |
| 59 | #endif |
| 60 | |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 61 | /* 9 DATA-PROCESSING INTRINSICS */ |
| 62 | /* 9.2 Miscellaneous data-processing intrinsics */ |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 63 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 64 | __clz(uint32_t t) { |
| 65 | return __builtin_clz(t); |
| 66 | } |
| 67 | |
| 68 | static __inline__ unsigned long __attribute__((always_inline, nodebug)) |
| 69 | __clzl(unsigned long t) { |
| 70 | return __builtin_clzl(t); |
| 71 | } |
| 72 | |
| 73 | static __inline__ uint64_t __attribute__((always_inline, nodebug)) |
| 74 | __clzll(uint64_t t) { |
| 75 | #if __SIZEOF_LONG_LONG__ == 8 |
| 76 | return __builtin_clzll(t); |
| 77 | #else |
| 78 | return __builtin_clzl(t); |
| 79 | #endif |
| 80 | } |
| 81 | |
| 82 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 83 | __rev(uint32_t t) { |
| 84 | return __builtin_bswap32(t); |
| 85 | } |
| 86 | |
| 87 | static __inline__ unsigned long __attribute__((always_inline, nodebug)) |
| 88 | __revl(unsigned long t) { |
| 89 | #if __SIZEOF_LONG__ == 4 |
| 90 | return __builtin_bswap32(t); |
| 91 | #else |
| 92 | return __builtin_bswap64(t); |
| 93 | #endif |
| 94 | } |
| 95 | |
| 96 | static __inline__ uint64_t __attribute__((always_inline, nodebug)) |
| 97 | __revll(uint64_t t) { |
| 98 | return __builtin_bswap64(t); |
| 99 | } |
| 100 | |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 101 | /* |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 102 | * 9.4 Saturating intrinsics |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 103 | * |
| 104 | * FIXME: Change guard to their corrosponding __ARM_FEATURE flag when Q flag |
| 105 | * intrinsics are implemented and the flag is enabled. |
| 106 | */ |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 107 | /* 9.4.1 Width-specified saturation intrinsics */ |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 108 | #if __ARM_32BIT_STATE |
| 109 | #define __ssat(x, y) __builtin_arm_ssat(x, y) |
| 110 | #define __usat(x, y) __builtin_arm_usat(x, y) |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 111 | #endif |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 112 | |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 113 | /* 9.4.2 Saturating addition and subtraction intrinsics */ |
| 114 | #if __ARM_32BIT_STATE |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 115 | static __inline__ int32_t __attribute__((always_inline, nodebug)) |
| 116 | __qadd(int32_t t, int32_t v) { |
| 117 | return __builtin_arm_qadd(t, v); |
| 118 | } |
| 119 | |
| 120 | static __inline__ int32_t __attribute__((always_inline, nodebug)) |
| 121 | __qsub(int32_t t, int32_t v) { |
| 122 | return __builtin_arm_qsub(t, v); |
| 123 | } |
Renato Golin | 47843ef | 2014-07-03 10:14:52 +0000 | [diff] [blame] | 124 | |
| 125 | static __inline__ int32_t __attribute__((always_inline, nodebug)) |
| 126 | __qdbl(int32_t t) { |
| 127 | return __builtin_arm_qadd(t, t); |
| 128 | } |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 129 | #endif |
| 130 | |
Yi Kong | 4e00ce7 | 2014-07-12 22:48:13 +0000 | [diff] [blame] | 131 | /* 9.7 CRC32 intrinsics */ |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 132 | #if __ARM_FEATURE_CRC32 |
| 133 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 134 | __crc32b(uint32_t a, uint8_t b) { |
| 135 | return __builtin_arm_crc32b(a, b); |
| 136 | } |
| 137 | |
| 138 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 139 | __crc32h(uint32_t a, uint16_t b) { |
| 140 | return __builtin_arm_crc32h(a, b); |
| 141 | } |
| 142 | |
| 143 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 144 | __crc32w(uint32_t a, uint32_t b) { |
| 145 | return __builtin_arm_crc32w(a, b); |
| 146 | } |
| 147 | |
| 148 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 149 | __crc32d(uint32_t a, uint64_t b) { |
| 150 | return __builtin_arm_crc32d(a, b); |
| 151 | } |
| 152 | |
| 153 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 154 | __crc32cb(uint32_t a, uint8_t b) { |
| 155 | return __builtin_arm_crc32cb(a, b); |
| 156 | } |
| 157 | |
| 158 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 159 | __crc32ch(uint32_t a, uint16_t b) { |
| 160 | return __builtin_arm_crc32ch(a, b); |
| 161 | } |
| 162 | |
| 163 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 164 | __crc32cw(uint32_t a, uint32_t b) { |
| 165 | return __builtin_arm_crc32cw(a, b); |
| 166 | } |
| 167 | |
| 168 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 169 | __crc32cd(uint32_t a, uint64_t b) { |
| 170 | return __builtin_arm_crc32cd(a, b); |
| 171 | } |
| 172 | #endif |
| 173 | |
Saleem Abdulrasool | 60df061 | 2014-07-08 05:46:00 +0000 | [diff] [blame] | 174 | #if defined(__cplusplus) |
| 175 | } |
| 176 | #endif |
| 177 | |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 178 | #endif /* __ARM_ACLE_H */ |