blob: 4be1d097dc5e9f814d5d9ba34645dce0e5b8a0e6 [file] [log] [blame]
Stephen Hines990d2fc2014-07-23 10:40:48 -07001/*===---- 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#if defined(__cplusplus)
34extern "C" {
35#endif
36
Stephen Hinesee4ca282014-12-02 17:05:12 -080037/* 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)
43#endif
Stephen Hines990d2fc2014-07-23 10:40:48 -070044
Stephen Hinesee4ca282014-12-02 17:05:12 -080045/* 8.4 Hints */
46
47#if !defined(_MSC_VER)
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070048static __inline__ void __attribute__((__always_inline__, __nodebug__)) __wfi(void) {
Stephen Hinesee4ca282014-12-02 17:05:12 -080049 __builtin_arm_wfi();
50}
51
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070052static __inline__ void __attribute__((__always_inline__, __nodebug__)) __wfe(void) {
Stephen Hinesee4ca282014-12-02 17:05:12 -080053 __builtin_arm_wfe();
54}
55
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070056static __inline__ void __attribute__((__always_inline__, __nodebug__)) __sev(void) {
Stephen Hinesee4ca282014-12-02 17:05:12 -080057 __builtin_arm_sev();
58}
59
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070060static __inline__ void __attribute__((__always_inline__, __nodebug__)) __sevl(void) {
Stephen Hinesee4ca282014-12-02 17:05:12 -080061 __builtin_arm_sevl();
62}
63
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070064static __inline__ void __attribute__((__always_inline__, __nodebug__)) __yield(void) {
Stephen Hinesee4ca282014-12-02 17:05:12 -080065 __builtin_arm_yield();
66}
67#endif
68
69#if __ARM_32BIT_STATE
70#define __dbg(t) __builtin_arm_dbg(t)
71#endif
72
73/* 8.5 Swap */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -070074static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hinesee4ca282014-12-02 17:05:12 -080075 __swp(uint32_t x, volatile uint32_t *p) {
76 uint32_t v;
77 do v = __builtin_arm_ldrex(p); while (__builtin_arm_strex(x, p));
78 return v;
79}
80
81/* 8.6 Memory prefetch intrinsics */
82/* 8.6.1 Data prefetch */
83#define __pld(addr) __pldx(0, 0, 0, addr)
84
85#if __ARM_32BIT_STATE
86#define __pldx(access_kind, cache_level, retention_policy, addr) \
87 __builtin_arm_prefetch(addr, access_kind, 1)
88#else
89#define __pldx(access_kind, cache_level, retention_policy, addr) \
90 __builtin_arm_prefetch(addr, access_kind, cache_level, retention_policy, 1)
91#endif
92
93/* 8.6.2 Instruction prefetch */
94#define __pli(addr) __plix(0, 0, addr)
95
96#if __ARM_32BIT_STATE
97#define __plix(cache_level, retention_policy, addr) \
98 __builtin_arm_prefetch(addr, 0, 0)
99#else
100#define __plix(cache_level, retention_policy, addr) \
101 __builtin_arm_prefetch(addr, 0, cache_level, retention_policy, 0)
102#endif
103
104/* 8.7 NOP */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700105static __inline__ void __attribute__((__always_inline__, __nodebug__)) __nop(void) {
Stephen Hinesee4ca282014-12-02 17:05:12 -0800106 __builtin_arm_nop();
107}
108
109/* 9 DATA-PROCESSING INTRINSICS */
110/* 9.2 Miscellaneous data-processing intrinsics */
111/* ROR */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700112static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hinesee4ca282014-12-02 17:05:12 -0800113 __ror(uint32_t x, uint32_t y) {
114 y %= 32;
115 if (y == 0) return x;
116 return (x >> y) | (x << (32 - y));
117}
118
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700119static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
Stephen Hinesee4ca282014-12-02 17:05:12 -0800120 __rorll(uint64_t x, uint32_t y) {
121 y %= 64;
122 if (y == 0) return x;
123 return (x >> y) | (x << (64 - y));
124}
125
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700126static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
Stephen Hinesee4ca282014-12-02 17:05:12 -0800127 __rorl(unsigned long x, uint32_t y) {
128#if __SIZEOF_LONG__ == 4
129 return __ror(x, y);
130#else
131 return __rorll(x, y);
132#endif
133}
134
135
136/* CLZ */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700137static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700138 __clz(uint32_t t) {
139 return __builtin_clz(t);
140}
141
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700142static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700143 __clzl(unsigned long t) {
144 return __builtin_clzl(t);
145}
146
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700147static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700148 __clzll(uint64_t t) {
Stephen Hines990d2fc2014-07-23 10:40:48 -0700149 return __builtin_clzll(t);
Stephen Hines990d2fc2014-07-23 10:40:48 -0700150}
151
Stephen Hinesee4ca282014-12-02 17:05:12 -0800152/* REV */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700153static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700154 __rev(uint32_t t) {
155 return __builtin_bswap32(t);
156}
157
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700158static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700159 __revl(unsigned long t) {
160#if __SIZEOF_LONG__ == 4
161 return __builtin_bswap32(t);
162#else
163 return __builtin_bswap64(t);
164#endif
165}
166
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700167static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700168 __revll(uint64_t t) {
169 return __builtin_bswap64(t);
170}
171
Stephen Hinesee4ca282014-12-02 17:05:12 -0800172/* REV16 */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700173static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hinesee4ca282014-12-02 17:05:12 -0800174 __rev16(uint32_t t) {
175 return __ror(__rev(t), 16);
176}
177
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700178static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
Stephen Hinesee4ca282014-12-02 17:05:12 -0800179 __rev16ll(uint64_t t) {
Pirama Arumuga Nainar4e74a022016-03-17 18:03:02 -0700180 return (((uint64_t)__rev16(t >> 32)) << 32) | __rev16(t);
181}
182
183static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
184 __rev16l(unsigned long t) {
185#if __SIZEOF_LONG__ == 4
186 return __rev16(t);
187#else
188 return __rev16ll(t);
189#endif
Stephen Hinesee4ca282014-12-02 17:05:12 -0800190}
191
192/* REVSH */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700193static __inline__ int16_t __attribute__((__always_inline__, __nodebug__))
Stephen Hinesee4ca282014-12-02 17:05:12 -0800194 __revsh(int16_t t) {
195 return __builtin_bswap16(t);
196}
197
198/* RBIT */
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700199static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hinesee4ca282014-12-02 17:05:12 -0800200 __rbit(uint32_t t) {
201 return __builtin_arm_rbit(t);
202}
203
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700204static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
Stephen Hinesee4ca282014-12-02 17:05:12 -0800205 __rbitll(uint64_t t) {
206#if __ARM_32BIT_STATE
207 return (((uint64_t) __builtin_arm_rbit(t)) << 32) |
208 __builtin_arm_rbit(t >> 32);
209#else
210 return __builtin_arm_rbit64(t);
211#endif
212}
213
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700214static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
Stephen Hinesee4ca282014-12-02 17:05:12 -0800215 __rbitl(unsigned long t) {
216#if __SIZEOF_LONG__ == 4
217 return __rbit(t);
218#else
219 return __rbitll(t);
220#endif
221}
Stephen Hines990d2fc2014-07-23 10:40:48 -0700222
223/*
Stephen Hinesee4ca282014-12-02 17:05:12 -0800224 * 9.4 Saturating intrinsics
Stephen Hines990d2fc2014-07-23 10:40:48 -0700225 *
226 * FIXME: Change guard to their corrosponding __ARM_FEATURE flag when Q flag
227 * intrinsics are implemented and the flag is enabled.
228 */
Stephen Hinesee4ca282014-12-02 17:05:12 -0800229/* 9.4.1 Width-specified saturation intrinsics */
Stephen Hines990d2fc2014-07-23 10:40:48 -0700230#if __ARM_32BIT_STATE
231#define __ssat(x, y) __builtin_arm_ssat(x, y)
232#define __usat(x, y) __builtin_arm_usat(x, y)
Stephen Hinesee4ca282014-12-02 17:05:12 -0800233#endif
Stephen Hines990d2fc2014-07-23 10:40:48 -0700234
Stephen Hinesee4ca282014-12-02 17:05:12 -0800235/* 9.4.2 Saturating addition and subtraction intrinsics */
236#if __ARM_32BIT_STATE
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700237static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700238 __qadd(int32_t t, int32_t v) {
239 return __builtin_arm_qadd(t, v);
240}
241
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700242static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700243 __qsub(int32_t t, int32_t v) {
244 return __builtin_arm_qsub(t, v);
245}
246
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700247static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700248__qdbl(int32_t t) {
249 return __builtin_arm_qadd(t, t);
250}
251#endif
252
Stephen Hinesee4ca282014-12-02 17:05:12 -0800253/* 9.7 CRC32 intrinsics */
Stephen Hines990d2fc2014-07-23 10:40:48 -0700254#if __ARM_FEATURE_CRC32
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700255static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700256 __crc32b(uint32_t a, uint8_t b) {
257 return __builtin_arm_crc32b(a, b);
258}
259
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700260static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700261 __crc32h(uint32_t a, uint16_t b) {
262 return __builtin_arm_crc32h(a, b);
263}
264
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700265static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700266 __crc32w(uint32_t a, uint32_t b) {
267 return __builtin_arm_crc32w(a, b);
268}
269
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700270static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700271 __crc32d(uint32_t a, uint64_t b) {
272 return __builtin_arm_crc32d(a, b);
273}
274
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700275static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700276 __crc32cb(uint32_t a, uint8_t b) {
277 return __builtin_arm_crc32cb(a, b);
278}
279
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700280static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700281 __crc32ch(uint32_t a, uint16_t b) {
282 return __builtin_arm_crc32ch(a, b);
283}
284
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700285static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700286 __crc32cw(uint32_t a, uint32_t b) {
287 return __builtin_arm_crc32cw(a, b);
288}
289
Stephen Hinesb4d9c8b2015-03-30 16:04:04 -0700290static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
Stephen Hines990d2fc2014-07-23 10:40:48 -0700291 __crc32cd(uint32_t a, uint64_t b) {
292 return __builtin_arm_crc32cd(a, b);
293}
294#endif
295
Stephen Hines28c5e1e2015-08-13 18:18:46 -0700296/* 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)
303
Stephen Hines990d2fc2014-07-23 10:40:48 -0700304#if defined(__cplusplus)
305}
306#endif
307
308#endif /* __ARM_ACLE_H */