1 /*===---- arm_acle.h - ARM Non-Neon intrinsics -----------------------------===
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
21 *===-----------------------------------------------------------------------===
28 #error "ACLE intrinsics support not enabled."
33 #if defined(__cplusplus)
37 /* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
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)
47 #if !defined(_MSC_VER)
48 static __inline__ void __attribute__((__always_inline__, __nodebug__)) __wfi(void) {
52 static __inline__ void __attribute__((__always_inline__, __nodebug__)) __wfe(void) {
56 static __inline__ void __attribute__((__always_inline__, __nodebug__)) __sev(void) {
60 static __inline__ void __attribute__((__always_inline__, __nodebug__)) __sevl(void) {
64 static __inline__ void __attribute__((__always_inline__, __nodebug__)) __yield(void) {
65 __builtin_arm_yield();
70 #define __dbg(t) __builtin_arm_dbg(t)
74 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
75 __swp(uint32_t x, volatile uint32_t *p) {
77 do v = __builtin_arm_ldrex(p); while (__builtin_arm_strex(x, p));
81 /* 8.6 Memory prefetch intrinsics */
82 /* 8.6.1 Data prefetch */
83 #define __pld(addr) __pldx(0, 0, 0, addr)
86 #define __pldx(access_kind, cache_level, retention_policy, addr) \
87 __builtin_arm_prefetch(addr, access_kind, 1)
89 #define __pldx(access_kind, cache_level, retention_policy, addr) \
90 __builtin_arm_prefetch(addr, access_kind, cache_level, retention_policy, 1)
93 /* 8.6.2 Instruction prefetch */
94 #define __pli(addr) __plix(0, 0, addr)
97 #define __plix(cache_level, retention_policy, addr) \
98 __builtin_arm_prefetch(addr, 0, 0)
100 #define __plix(cache_level, retention_policy, addr) \
101 __builtin_arm_prefetch(addr, 0, cache_level, retention_policy, 0)
105 static __inline__ void __attribute__((__always_inline__, __nodebug__)) __nop(void) {
109 /* 9 DATA-PROCESSING INTRINSICS */
110 /* 9.2 Miscellaneous data-processing intrinsics */
112 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
113 __ror(uint32_t x, uint32_t y) {
115 if (y == 0) return x;
116 return (x >> y) | (x << (32 - y));
119 static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
120 __rorll(uint64_t x, uint32_t y) {
122 if (y == 0) return x;
123 return (x >> y) | (x << (64 - y));
126 static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
127 __rorl(unsigned long x, uint32_t y) {
128 #if __SIZEOF_LONG__ == 4
131 return __rorll(x, y);
137 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
139 return __builtin_clz(t);
142 static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
143 __clzl(unsigned long t) {
144 return __builtin_clzl(t);
147 static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
148 __clzll(uint64_t t) {
149 return __builtin_clzll(t);
153 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
155 return __builtin_bswap32(t);
158 static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
159 __revl(unsigned long t) {
160 #if __SIZEOF_LONG__ == 4
161 return __builtin_bswap32(t);
163 return __builtin_bswap64(t);
167 static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
168 __revll(uint64_t t) {
169 return __builtin_bswap64(t);
173 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
174 __rev16(uint32_t t) {
175 return __ror(__rev(t), 16);
178 static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
179 __rev16ll(uint64_t t) {
180 return (((uint64_t)__rev16(t >> 32)) << 32) | __rev16(t);
183 static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
184 __rev16l(unsigned long t) {
185 #if __SIZEOF_LONG__ == 4
193 static __inline__ int16_t __attribute__((__always_inline__, __nodebug__))
195 return __builtin_bswap16(t);
199 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
201 return __builtin_arm_rbit(t);
204 static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
205 __rbitll(uint64_t t) {
206 #if __ARM_32BIT_STATE
207 return (((uint64_t) __builtin_arm_rbit(t)) << 32) |
208 __builtin_arm_rbit(t >> 32);
210 return __builtin_arm_rbit64(t);
214 static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
215 __rbitl(unsigned long t) {
216 #if __SIZEOF_LONG__ == 4
224 * 9.4 Saturating intrinsics
226 * FIXME: Change guard to their corrosponding __ARM_FEATURE flag when Q flag
227 * intrinsics are implemented and the flag is enabled.
229 /* 9.4.1 Width-specified saturation intrinsics */
230 #if __ARM_32BIT_STATE
231 #define __ssat(x, y) __builtin_arm_ssat(x, y)
232 #define __usat(x, y) __builtin_arm_usat(x, y)
235 /* 9.4.2 Saturating addition and subtraction intrinsics */
236 #if __ARM_32BIT_STATE
237 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
238 __qadd(int32_t t, int32_t v) {
239 return __builtin_arm_qadd(t, v);
242 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
243 __qsub(int32_t t, int32_t v) {
244 return __builtin_arm_qsub(t, v);
247 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
249 return __builtin_arm_qadd(t, t);
253 /* 9.7 CRC32 intrinsics */
254 #if __ARM_FEATURE_CRC32
255 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
256 __crc32b(uint32_t a, uint8_t b) {
257 return __builtin_arm_crc32b(a, b);
260 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
261 __crc32h(uint32_t a, uint16_t b) {
262 return __builtin_arm_crc32h(a, b);
265 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
266 __crc32w(uint32_t a, uint32_t b) {
267 return __builtin_arm_crc32w(a, b);
270 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
271 __crc32d(uint32_t a, uint64_t b) {
272 return __builtin_arm_crc32d(a, b);
275 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
276 __crc32cb(uint32_t a, uint8_t b) {
277 return __builtin_arm_crc32cb(a, b);
280 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
281 __crc32ch(uint32_t a, uint16_t b) {
282 return __builtin_arm_crc32ch(a, b);
285 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
286 __crc32cw(uint32_t a, uint32_t b) {
287 return __builtin_arm_crc32cw(a, b);
290 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
291 __crc32cd(uint32_t a, uint64_t b) {
292 return __builtin_arm_crc32cd(a, b);
296 /* 10.1 Special register intrinsics */
297 #define __arm_rsr(sysreg) __builtin_arm_rsr(sysreg)
298 #define __arm_rsr64(sysreg) __builtin_arm_rsr64(sysreg)
299 #define __arm_rsrp(sysreg) __builtin_arm_rsrp(sysreg)
300 #define __arm_wsr(sysreg, v) __builtin_arm_wsr(sysreg, v)
301 #define __arm_wsr64(sysreg, v) __builtin_arm_wsr64(sysreg, v)
302 #define __arm_wsrp(sysreg, v) __builtin_arm_wsrp(sysreg, v)
304 #if defined(__cplusplus)
308 #endif /* __ARM_ACLE_H */