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 | |
| 33 | /* Miscellaneous data-processing intrinsics */ |
| 34 | |
| 35 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 36 | __clz(uint32_t t) { |
| 37 | return __builtin_clz(t); |
| 38 | } |
| 39 | |
| 40 | static __inline__ unsigned long __attribute__((always_inline, nodebug)) |
| 41 | __clzl(unsigned long t) { |
| 42 | return __builtin_clzl(t); |
| 43 | } |
| 44 | |
| 45 | static __inline__ uint64_t __attribute__((always_inline, nodebug)) |
| 46 | __clzll(uint64_t t) { |
| 47 | #if __SIZEOF_LONG_LONG__ == 8 |
| 48 | return __builtin_clzll(t); |
| 49 | #else |
| 50 | return __builtin_clzl(t); |
| 51 | #endif |
| 52 | } |
| 53 | |
| 54 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 55 | __rev(uint32_t t) { |
| 56 | return __builtin_bswap32(t); |
| 57 | } |
| 58 | |
| 59 | static __inline__ unsigned long __attribute__((always_inline, nodebug)) |
| 60 | __revl(unsigned long t) { |
| 61 | #if __SIZEOF_LONG__ == 4 |
| 62 | return __builtin_bswap32(t); |
| 63 | #else |
| 64 | return __builtin_bswap64(t); |
| 65 | #endif |
| 66 | } |
| 67 | |
| 68 | static __inline__ uint64_t __attribute__((always_inline, nodebug)) |
| 69 | __revll(uint64_t t) { |
| 70 | return __builtin_bswap64(t); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | /* |
| 75 | * Saturating intrinsics |
| 76 | * |
| 77 | * FIXME: Change guard to their corrosponding __ARM_FEATURE flag when Q flag |
| 78 | * intrinsics are implemented and the flag is enabled. |
| 79 | */ |
| 80 | #if __ARM_32BIT_STATE |
| 81 | #define __ssat(x, y) __builtin_arm_ssat(x, y) |
| 82 | #define __usat(x, y) __builtin_arm_usat(x, y) |
| 83 | |
| 84 | static __inline__ int32_t __attribute__((always_inline, nodebug)) |
| 85 | __qadd(int32_t t, int32_t v) { |
| 86 | return __builtin_arm_qadd(t, v); |
| 87 | } |
| 88 | |
| 89 | static __inline__ int32_t __attribute__((always_inline, nodebug)) |
| 90 | __qsub(int32_t t, int32_t v) { |
| 91 | return __builtin_arm_qsub(t, v); |
| 92 | } |
Renato Golin | 47843ef | 2014-07-03 10:14:52 +0000 | [diff] [blame^] | 93 | |
| 94 | static __inline__ int32_t __attribute__((always_inline, nodebug)) |
| 95 | __qdbl(int32_t t) { |
| 96 | return __builtin_arm_qadd(t, t); |
| 97 | } |
Yi Kong | a44c4d7 | 2014-06-27 21:25:42 +0000 | [diff] [blame] | 98 | #endif |
| 99 | |
| 100 | /* CRC32 intrinsics */ |
| 101 | #if __ARM_FEATURE_CRC32 |
| 102 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 103 | __crc32b(uint32_t a, uint8_t b) { |
| 104 | return __builtin_arm_crc32b(a, b); |
| 105 | } |
| 106 | |
| 107 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 108 | __crc32h(uint32_t a, uint16_t b) { |
| 109 | return __builtin_arm_crc32h(a, b); |
| 110 | } |
| 111 | |
| 112 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 113 | __crc32w(uint32_t a, uint32_t b) { |
| 114 | return __builtin_arm_crc32w(a, b); |
| 115 | } |
| 116 | |
| 117 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 118 | __crc32d(uint32_t a, uint64_t b) { |
| 119 | return __builtin_arm_crc32d(a, b); |
| 120 | } |
| 121 | |
| 122 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 123 | __crc32cb(uint32_t a, uint8_t b) { |
| 124 | return __builtin_arm_crc32cb(a, b); |
| 125 | } |
| 126 | |
| 127 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 128 | __crc32ch(uint32_t a, uint16_t b) { |
| 129 | return __builtin_arm_crc32ch(a, b); |
| 130 | } |
| 131 | |
| 132 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 133 | __crc32cw(uint32_t a, uint32_t b) { |
| 134 | return __builtin_arm_crc32cw(a, b); |
| 135 | } |
| 136 | |
| 137 | static __inline__ uint32_t __attribute__((always_inline, nodebug)) |
| 138 | __crc32cd(uint32_t a, uint64_t b) { |
| 139 | return __builtin_arm_crc32cd(a, b); |
| 140 | } |
| 141 | #endif |
| 142 | |
| 143 | #endif /* __ARM_ACLE_H */ |