1*0a6a1f1dSLionel Sambuc /*===---- arm_acle.h - ARM Non-Neon intrinsics -----------------------------===
2*0a6a1f1dSLionel Sambuc *
3*0a6a1f1dSLionel Sambuc * Permission is hereby granted, free of charge, to any person obtaining a copy
4*0a6a1f1dSLionel Sambuc * of this software and associated documentation files (the "Software"), to deal
5*0a6a1f1dSLionel Sambuc * in the Software without restriction, including without limitation the rights
6*0a6a1f1dSLionel Sambuc * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*0a6a1f1dSLionel Sambuc * copies of the Software, and to permit persons to whom the Software is
8*0a6a1f1dSLionel Sambuc * furnished to do so, subject to the following conditions:
9*0a6a1f1dSLionel Sambuc *
10*0a6a1f1dSLionel Sambuc * The above copyright notice and this permission notice shall be included in
11*0a6a1f1dSLionel Sambuc * all copies or substantial portions of the Software.
12*0a6a1f1dSLionel Sambuc *
13*0a6a1f1dSLionel Sambuc * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14*0a6a1f1dSLionel Sambuc * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15*0a6a1f1dSLionel Sambuc * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16*0a6a1f1dSLionel Sambuc * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17*0a6a1f1dSLionel Sambuc * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18*0a6a1f1dSLionel Sambuc * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19*0a6a1f1dSLionel Sambuc * THE SOFTWARE.
20*0a6a1f1dSLionel Sambuc *
21*0a6a1f1dSLionel Sambuc *===-----------------------------------------------------------------------===
22*0a6a1f1dSLionel Sambuc */
23*0a6a1f1dSLionel Sambuc
24*0a6a1f1dSLionel Sambuc #ifndef __ARM_ACLE_H
25*0a6a1f1dSLionel Sambuc #define __ARM_ACLE_H
26*0a6a1f1dSLionel Sambuc
27*0a6a1f1dSLionel Sambuc #ifndef __ARM_ACLE
28*0a6a1f1dSLionel Sambuc #error "ACLE intrinsics support not enabled."
29*0a6a1f1dSLionel Sambuc #endif
30*0a6a1f1dSLionel Sambuc
31*0a6a1f1dSLionel Sambuc #include <stdint.h>
32*0a6a1f1dSLionel Sambuc
33*0a6a1f1dSLionel Sambuc #if defined(__cplusplus)
34*0a6a1f1dSLionel Sambuc extern "C" {
35*0a6a1f1dSLionel Sambuc #endif
36*0a6a1f1dSLionel Sambuc
37*0a6a1f1dSLionel Sambuc /* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
38*0a6a1f1dSLionel Sambuc /* 8.3 Memory barriers */
39*0a6a1f1dSLionel Sambuc #if !defined(_MSC_VER)
40*0a6a1f1dSLionel Sambuc #define __dmb(i) __builtin_arm_dmb(i)
41*0a6a1f1dSLionel Sambuc #define __dsb(i) __builtin_arm_dsb(i)
42*0a6a1f1dSLionel Sambuc #define __isb(i) __builtin_arm_isb(i)
43*0a6a1f1dSLionel Sambuc #endif
44*0a6a1f1dSLionel Sambuc
45*0a6a1f1dSLionel Sambuc /* 8.4 Hints */
46*0a6a1f1dSLionel Sambuc
47*0a6a1f1dSLionel Sambuc #if !defined(_MSC_VER)
__wfi(void)48*0a6a1f1dSLionel Sambuc static __inline__ void __attribute__((always_inline, nodebug)) __wfi(void) {
49*0a6a1f1dSLionel Sambuc __builtin_arm_wfi();
50*0a6a1f1dSLionel Sambuc }
51*0a6a1f1dSLionel Sambuc
__wfe(void)52*0a6a1f1dSLionel Sambuc static __inline__ void __attribute__((always_inline, nodebug)) __wfe(void) {
53*0a6a1f1dSLionel Sambuc __builtin_arm_wfe();
54*0a6a1f1dSLionel Sambuc }
55*0a6a1f1dSLionel Sambuc
__sev(void)56*0a6a1f1dSLionel Sambuc static __inline__ void __attribute__((always_inline, nodebug)) __sev(void) {
57*0a6a1f1dSLionel Sambuc __builtin_arm_sev();
58*0a6a1f1dSLionel Sambuc }
59*0a6a1f1dSLionel Sambuc
__sevl(void)60*0a6a1f1dSLionel Sambuc static __inline__ void __attribute__((always_inline, nodebug)) __sevl(void) {
61*0a6a1f1dSLionel Sambuc __builtin_arm_sevl();
62*0a6a1f1dSLionel Sambuc }
63*0a6a1f1dSLionel Sambuc
__yield(void)64*0a6a1f1dSLionel Sambuc static __inline__ void __attribute__((always_inline, nodebug)) __yield(void) {
65*0a6a1f1dSLionel Sambuc __builtin_arm_yield();
66*0a6a1f1dSLionel Sambuc }
67*0a6a1f1dSLionel Sambuc #endif
68*0a6a1f1dSLionel Sambuc
69*0a6a1f1dSLionel Sambuc #if __ARM_32BIT_STATE
70*0a6a1f1dSLionel Sambuc #define __dbg(t) __builtin_arm_dbg(t)
71*0a6a1f1dSLionel Sambuc #endif
72*0a6a1f1dSLionel Sambuc
73*0a6a1f1dSLionel Sambuc /* 8.5 Swap */
74*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__swp(uint32_t x,volatile uint32_t * p)75*0a6a1f1dSLionel Sambuc __swp(uint32_t x, volatile uint32_t *p) {
76*0a6a1f1dSLionel Sambuc uint32_t v;
77*0a6a1f1dSLionel Sambuc do v = __builtin_arm_ldrex(p); while (__builtin_arm_strex(x, p));
78*0a6a1f1dSLionel Sambuc return v;
79*0a6a1f1dSLionel Sambuc }
80*0a6a1f1dSLionel Sambuc
81*0a6a1f1dSLionel Sambuc /* 8.6 Memory prefetch intrinsics */
82*0a6a1f1dSLionel Sambuc /* 8.6.1 Data prefetch */
83*0a6a1f1dSLionel Sambuc #define __pld(addr) __pldx(0, 0, 0, addr)
84*0a6a1f1dSLionel Sambuc
85*0a6a1f1dSLionel Sambuc #if __ARM_32BIT_STATE
86*0a6a1f1dSLionel Sambuc #define __pldx(access_kind, cache_level, retention_policy, addr) \
87*0a6a1f1dSLionel Sambuc __builtin_arm_prefetch(addr, access_kind, 1)
88*0a6a1f1dSLionel Sambuc #else
89*0a6a1f1dSLionel Sambuc #define __pldx(access_kind, cache_level, retention_policy, addr) \
90*0a6a1f1dSLionel Sambuc __builtin_arm_prefetch(addr, access_kind, cache_level, retention_policy, 1)
91*0a6a1f1dSLionel Sambuc #endif
92*0a6a1f1dSLionel Sambuc
93*0a6a1f1dSLionel Sambuc /* 8.6.2 Instruction prefetch */
94*0a6a1f1dSLionel Sambuc #define __pli(addr) __plix(0, 0, addr)
95*0a6a1f1dSLionel Sambuc
96*0a6a1f1dSLionel Sambuc #if __ARM_32BIT_STATE
97*0a6a1f1dSLionel Sambuc #define __plix(cache_level, retention_policy, addr) \
98*0a6a1f1dSLionel Sambuc __builtin_arm_prefetch(addr, 0, 0)
99*0a6a1f1dSLionel Sambuc #else
100*0a6a1f1dSLionel Sambuc #define __plix(cache_level, retention_policy, addr) \
101*0a6a1f1dSLionel Sambuc __builtin_arm_prefetch(addr, 0, cache_level, retention_policy, 0)
102*0a6a1f1dSLionel Sambuc #endif
103*0a6a1f1dSLionel Sambuc
104*0a6a1f1dSLionel Sambuc /* 8.7 NOP */
__nop(void)105*0a6a1f1dSLionel Sambuc static __inline__ void __attribute__((always_inline, nodebug)) __nop(void) {
106*0a6a1f1dSLionel Sambuc __builtin_arm_nop();
107*0a6a1f1dSLionel Sambuc }
108*0a6a1f1dSLionel Sambuc
109*0a6a1f1dSLionel Sambuc /* 9 DATA-PROCESSING INTRINSICS */
110*0a6a1f1dSLionel Sambuc /* 9.2 Miscellaneous data-processing intrinsics */
111*0a6a1f1dSLionel Sambuc /* ROR */
112*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__ror(uint32_t x,uint32_t y)113*0a6a1f1dSLionel Sambuc __ror(uint32_t x, uint32_t y) {
114*0a6a1f1dSLionel Sambuc y %= 32;
115*0a6a1f1dSLionel Sambuc if (y == 0) return x;
116*0a6a1f1dSLionel Sambuc return (x >> y) | (x << (32 - y));
117*0a6a1f1dSLionel Sambuc }
118*0a6a1f1dSLionel Sambuc
119*0a6a1f1dSLionel Sambuc static __inline__ uint64_t __attribute__((always_inline, nodebug))
__rorll(uint64_t x,uint32_t y)120*0a6a1f1dSLionel Sambuc __rorll(uint64_t x, uint32_t y) {
121*0a6a1f1dSLionel Sambuc y %= 64;
122*0a6a1f1dSLionel Sambuc if (y == 0) return x;
123*0a6a1f1dSLionel Sambuc return (x >> y) | (x << (64 - y));
124*0a6a1f1dSLionel Sambuc }
125*0a6a1f1dSLionel Sambuc
126*0a6a1f1dSLionel Sambuc static __inline__ unsigned long __attribute__((always_inline, nodebug))
__rorl(unsigned long x,uint32_t y)127*0a6a1f1dSLionel Sambuc __rorl(unsigned long x, uint32_t y) {
128*0a6a1f1dSLionel Sambuc #if __SIZEOF_LONG__ == 4
129*0a6a1f1dSLionel Sambuc return __ror(x, y);
130*0a6a1f1dSLionel Sambuc #else
131*0a6a1f1dSLionel Sambuc return __rorll(x, y);
132*0a6a1f1dSLionel Sambuc #endif
133*0a6a1f1dSLionel Sambuc }
134*0a6a1f1dSLionel Sambuc
135*0a6a1f1dSLionel Sambuc
136*0a6a1f1dSLionel Sambuc /* CLZ */
137*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__clz(uint32_t t)138*0a6a1f1dSLionel Sambuc __clz(uint32_t t) {
139*0a6a1f1dSLionel Sambuc return __builtin_clz(t);
140*0a6a1f1dSLionel Sambuc }
141*0a6a1f1dSLionel Sambuc
142*0a6a1f1dSLionel Sambuc static __inline__ unsigned long __attribute__((always_inline, nodebug))
__clzl(unsigned long t)143*0a6a1f1dSLionel Sambuc __clzl(unsigned long t) {
144*0a6a1f1dSLionel Sambuc return __builtin_clzl(t);
145*0a6a1f1dSLionel Sambuc }
146*0a6a1f1dSLionel Sambuc
147*0a6a1f1dSLionel Sambuc static __inline__ uint64_t __attribute__((always_inline, nodebug))
__clzll(uint64_t t)148*0a6a1f1dSLionel Sambuc __clzll(uint64_t t) {
149*0a6a1f1dSLionel Sambuc return __builtin_clzll(t);
150*0a6a1f1dSLionel Sambuc }
151*0a6a1f1dSLionel Sambuc
152*0a6a1f1dSLionel Sambuc /* REV */
153*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__rev(uint32_t t)154*0a6a1f1dSLionel Sambuc __rev(uint32_t t) {
155*0a6a1f1dSLionel Sambuc return __builtin_bswap32(t);
156*0a6a1f1dSLionel Sambuc }
157*0a6a1f1dSLionel Sambuc
158*0a6a1f1dSLionel Sambuc static __inline__ unsigned long __attribute__((always_inline, nodebug))
__revl(unsigned long t)159*0a6a1f1dSLionel Sambuc __revl(unsigned long t) {
160*0a6a1f1dSLionel Sambuc #if __SIZEOF_LONG__ == 4
161*0a6a1f1dSLionel Sambuc return __builtin_bswap32(t);
162*0a6a1f1dSLionel Sambuc #else
163*0a6a1f1dSLionel Sambuc return __builtin_bswap64(t);
164*0a6a1f1dSLionel Sambuc #endif
165*0a6a1f1dSLionel Sambuc }
166*0a6a1f1dSLionel Sambuc
167*0a6a1f1dSLionel Sambuc static __inline__ uint64_t __attribute__((always_inline, nodebug))
__revll(uint64_t t)168*0a6a1f1dSLionel Sambuc __revll(uint64_t t) {
169*0a6a1f1dSLionel Sambuc return __builtin_bswap64(t);
170*0a6a1f1dSLionel Sambuc }
171*0a6a1f1dSLionel Sambuc
172*0a6a1f1dSLionel Sambuc /* REV16 */
173*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__rev16(uint32_t t)174*0a6a1f1dSLionel Sambuc __rev16(uint32_t t) {
175*0a6a1f1dSLionel Sambuc return __ror(__rev(t), 16);
176*0a6a1f1dSLionel Sambuc }
177*0a6a1f1dSLionel Sambuc
178*0a6a1f1dSLionel Sambuc static __inline__ unsigned long __attribute__((always_inline, nodebug))
__rev16l(unsigned long t)179*0a6a1f1dSLionel Sambuc __rev16l(unsigned long t) {
180*0a6a1f1dSLionel Sambuc return __rorl(__revl(t), sizeof(long) / 2);
181*0a6a1f1dSLionel Sambuc }
182*0a6a1f1dSLionel Sambuc
183*0a6a1f1dSLionel Sambuc static __inline__ uint64_t __attribute__((always_inline, nodebug))
__rev16ll(uint64_t t)184*0a6a1f1dSLionel Sambuc __rev16ll(uint64_t t) {
185*0a6a1f1dSLionel Sambuc return __rorll(__revll(t), 32);
186*0a6a1f1dSLionel Sambuc }
187*0a6a1f1dSLionel Sambuc
188*0a6a1f1dSLionel Sambuc /* REVSH */
189*0a6a1f1dSLionel Sambuc static __inline__ int16_t __attribute__((always_inline, nodebug))
__revsh(int16_t t)190*0a6a1f1dSLionel Sambuc __revsh(int16_t t) {
191*0a6a1f1dSLionel Sambuc return __builtin_bswap16(t);
192*0a6a1f1dSLionel Sambuc }
193*0a6a1f1dSLionel Sambuc
194*0a6a1f1dSLionel Sambuc /* RBIT */
195*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__rbit(uint32_t t)196*0a6a1f1dSLionel Sambuc __rbit(uint32_t t) {
197*0a6a1f1dSLionel Sambuc return __builtin_arm_rbit(t);
198*0a6a1f1dSLionel Sambuc }
199*0a6a1f1dSLionel Sambuc
200*0a6a1f1dSLionel Sambuc static __inline__ uint64_t __attribute__((always_inline, nodebug))
__rbitll(uint64_t t)201*0a6a1f1dSLionel Sambuc __rbitll(uint64_t t) {
202*0a6a1f1dSLionel Sambuc #if __ARM_32BIT_STATE
203*0a6a1f1dSLionel Sambuc return (((uint64_t) __builtin_arm_rbit(t)) << 32) |
204*0a6a1f1dSLionel Sambuc __builtin_arm_rbit(t >> 32);
205*0a6a1f1dSLionel Sambuc #else
206*0a6a1f1dSLionel Sambuc return __builtin_arm_rbit64(t);
207*0a6a1f1dSLionel Sambuc #endif
208*0a6a1f1dSLionel Sambuc }
209*0a6a1f1dSLionel Sambuc
210*0a6a1f1dSLionel Sambuc static __inline__ unsigned long __attribute__((always_inline, nodebug))
__rbitl(unsigned long t)211*0a6a1f1dSLionel Sambuc __rbitl(unsigned long t) {
212*0a6a1f1dSLionel Sambuc #if __SIZEOF_LONG__ == 4
213*0a6a1f1dSLionel Sambuc return __rbit(t);
214*0a6a1f1dSLionel Sambuc #else
215*0a6a1f1dSLionel Sambuc return __rbitll(t);
216*0a6a1f1dSLionel Sambuc #endif
217*0a6a1f1dSLionel Sambuc }
218*0a6a1f1dSLionel Sambuc
219*0a6a1f1dSLionel Sambuc /*
220*0a6a1f1dSLionel Sambuc * 9.4 Saturating intrinsics
221*0a6a1f1dSLionel Sambuc *
222*0a6a1f1dSLionel Sambuc * FIXME: Change guard to their corrosponding __ARM_FEATURE flag when Q flag
223*0a6a1f1dSLionel Sambuc * intrinsics are implemented and the flag is enabled.
224*0a6a1f1dSLionel Sambuc */
225*0a6a1f1dSLionel Sambuc /* 9.4.1 Width-specified saturation intrinsics */
226*0a6a1f1dSLionel Sambuc #if __ARM_32BIT_STATE
227*0a6a1f1dSLionel Sambuc #define __ssat(x, y) __builtin_arm_ssat(x, y)
228*0a6a1f1dSLionel Sambuc #define __usat(x, y) __builtin_arm_usat(x, y)
229*0a6a1f1dSLionel Sambuc #endif
230*0a6a1f1dSLionel Sambuc
231*0a6a1f1dSLionel Sambuc /* 9.4.2 Saturating addition and subtraction intrinsics */
232*0a6a1f1dSLionel Sambuc #if __ARM_32BIT_STATE
233*0a6a1f1dSLionel Sambuc static __inline__ int32_t __attribute__((always_inline, nodebug))
__qadd(int32_t t,int32_t v)234*0a6a1f1dSLionel Sambuc __qadd(int32_t t, int32_t v) {
235*0a6a1f1dSLionel Sambuc return __builtin_arm_qadd(t, v);
236*0a6a1f1dSLionel Sambuc }
237*0a6a1f1dSLionel Sambuc
238*0a6a1f1dSLionel Sambuc static __inline__ int32_t __attribute__((always_inline, nodebug))
__qsub(int32_t t,int32_t v)239*0a6a1f1dSLionel Sambuc __qsub(int32_t t, int32_t v) {
240*0a6a1f1dSLionel Sambuc return __builtin_arm_qsub(t, v);
241*0a6a1f1dSLionel Sambuc }
242*0a6a1f1dSLionel Sambuc
243*0a6a1f1dSLionel Sambuc static __inline__ int32_t __attribute__((always_inline, nodebug))
__qdbl(int32_t t)244*0a6a1f1dSLionel Sambuc __qdbl(int32_t t) {
245*0a6a1f1dSLionel Sambuc return __builtin_arm_qadd(t, t);
246*0a6a1f1dSLionel Sambuc }
247*0a6a1f1dSLionel Sambuc #endif
248*0a6a1f1dSLionel Sambuc
249*0a6a1f1dSLionel Sambuc /* 9.7 CRC32 intrinsics */
250*0a6a1f1dSLionel Sambuc #if __ARM_FEATURE_CRC32
251*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__crc32b(uint32_t a,uint8_t b)252*0a6a1f1dSLionel Sambuc __crc32b(uint32_t a, uint8_t b) {
253*0a6a1f1dSLionel Sambuc return __builtin_arm_crc32b(a, b);
254*0a6a1f1dSLionel Sambuc }
255*0a6a1f1dSLionel Sambuc
256*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__crc32h(uint32_t a,uint16_t b)257*0a6a1f1dSLionel Sambuc __crc32h(uint32_t a, uint16_t b) {
258*0a6a1f1dSLionel Sambuc return __builtin_arm_crc32h(a, b);
259*0a6a1f1dSLionel Sambuc }
260*0a6a1f1dSLionel Sambuc
261*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__crc32w(uint32_t a,uint32_t b)262*0a6a1f1dSLionel Sambuc __crc32w(uint32_t a, uint32_t b) {
263*0a6a1f1dSLionel Sambuc return __builtin_arm_crc32w(a, b);
264*0a6a1f1dSLionel Sambuc }
265*0a6a1f1dSLionel Sambuc
266*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__crc32d(uint32_t a,uint64_t b)267*0a6a1f1dSLionel Sambuc __crc32d(uint32_t a, uint64_t b) {
268*0a6a1f1dSLionel Sambuc return __builtin_arm_crc32d(a, b);
269*0a6a1f1dSLionel Sambuc }
270*0a6a1f1dSLionel Sambuc
271*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__crc32cb(uint32_t a,uint8_t b)272*0a6a1f1dSLionel Sambuc __crc32cb(uint32_t a, uint8_t b) {
273*0a6a1f1dSLionel Sambuc return __builtin_arm_crc32cb(a, b);
274*0a6a1f1dSLionel Sambuc }
275*0a6a1f1dSLionel Sambuc
276*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__crc32ch(uint32_t a,uint16_t b)277*0a6a1f1dSLionel Sambuc __crc32ch(uint32_t a, uint16_t b) {
278*0a6a1f1dSLionel Sambuc return __builtin_arm_crc32ch(a, b);
279*0a6a1f1dSLionel Sambuc }
280*0a6a1f1dSLionel Sambuc
281*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__crc32cw(uint32_t a,uint32_t b)282*0a6a1f1dSLionel Sambuc __crc32cw(uint32_t a, uint32_t b) {
283*0a6a1f1dSLionel Sambuc return __builtin_arm_crc32cw(a, b);
284*0a6a1f1dSLionel Sambuc }
285*0a6a1f1dSLionel Sambuc
286*0a6a1f1dSLionel Sambuc static __inline__ uint32_t __attribute__((always_inline, nodebug))
__crc32cd(uint32_t a,uint64_t b)287*0a6a1f1dSLionel Sambuc __crc32cd(uint32_t a, uint64_t b) {
288*0a6a1f1dSLionel Sambuc return __builtin_arm_crc32cd(a, b);
289*0a6a1f1dSLionel Sambuc }
290*0a6a1f1dSLionel Sambuc #endif
291*0a6a1f1dSLionel Sambuc
292*0a6a1f1dSLionel Sambuc #if defined(__cplusplus)
293*0a6a1f1dSLionel Sambuc }
294*0a6a1f1dSLionel Sambuc #endif
295*0a6a1f1dSLionel Sambuc
296*0a6a1f1dSLionel Sambuc #endif /* __ARM_ACLE_H */
297