blob: a0fd6894ab9692f442abbb4bdd12d1d41bbdb0ff [file] [log] [blame]
Yi Konga44c4d72014-06-27 21:25:42 +00001/*===---- 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 Abdulrasool60df0612014-07-08 05:46:00 +000033#if defined(__cplusplus)
34extern "C" {
35#endif
Yi Kong28d7b022014-07-17 12:45:17 +000036
Yi Kong472e5212014-07-14 15:32:29 +000037/* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
Yi Kong28d7b022014-07-17 12:45:17 +000038/* 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
44
Yi Kong472e5212014-07-14 15:32:29 +000045/* 8.4 Hints */
Saleem Abdulrasool07257fe2014-07-12 23:27:26 +000046
47#if !defined(_MSC_VER)
48static __inline__ void __attribute__((always_inline, nodebug)) __wfi(void) {
49 __builtin_arm_wfi();
50}
51
52static __inline__ void __attribute__((always_inline, nodebug)) __wfe(void) {
53 __builtin_arm_wfe();
54}
55
56static __inline__ void __attribute__((always_inline, nodebug)) __sev(void) {
57 __builtin_arm_sev();
58}
59
60static __inline__ void __attribute__((always_inline, nodebug)) __sevl(void) {
61 __builtin_arm_sevl();
62}
63
64static __inline__ void __attribute__((always_inline, nodebug)) __yield(void) {
65 __builtin_arm_yield();
66}
67#endif
68
Yi Kong472e5212014-07-14 15:32:29 +000069/* 8.7 NOP */
70static __inline__ void __attribute__((always_inline, nodebug)) __nop(void) {
71 __builtin_arm_nop();
72}
73
Yi Kong4e00ce72014-07-12 22:48:13 +000074/* 9 DATA-PROCESSING INTRINSICS */
75/* 9.2 Miscellaneous data-processing intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +000076static __inline__ uint32_t __attribute__((always_inline, nodebug))
77 __clz(uint32_t t) {
78 return __builtin_clz(t);
79}
80
81static __inline__ unsigned long __attribute__((always_inline, nodebug))
82 __clzl(unsigned long t) {
83 return __builtin_clzl(t);
84}
85
86static __inline__ uint64_t __attribute__((always_inline, nodebug))
87 __clzll(uint64_t t) {
88#if __SIZEOF_LONG_LONG__ == 8
89 return __builtin_clzll(t);
90#else
91 return __builtin_clzl(t);
92#endif
93}
94
95static __inline__ uint32_t __attribute__((always_inline, nodebug))
96 __rev(uint32_t t) {
97 return __builtin_bswap32(t);
98}
99
100static __inline__ unsigned long __attribute__((always_inline, nodebug))
101 __revl(unsigned long t) {
102#if __SIZEOF_LONG__ == 4
103 return __builtin_bswap32(t);
104#else
105 return __builtin_bswap64(t);
106#endif
107}
108
109static __inline__ uint64_t __attribute__((always_inline, nodebug))
110 __revll(uint64_t t) {
111 return __builtin_bswap64(t);
112}
113
Yi Konga44c4d72014-06-27 21:25:42 +0000114/*
Yi Kong4e00ce72014-07-12 22:48:13 +0000115 * 9.4 Saturating intrinsics
Yi Konga44c4d72014-06-27 21:25:42 +0000116 *
117 * FIXME: Change guard to their corrosponding __ARM_FEATURE flag when Q flag
118 * intrinsics are implemented and the flag is enabled.
119 */
Yi Kong4e00ce72014-07-12 22:48:13 +0000120/* 9.4.1 Width-specified saturation intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +0000121#if __ARM_32BIT_STATE
122#define __ssat(x, y) __builtin_arm_ssat(x, y)
123#define __usat(x, y) __builtin_arm_usat(x, y)
Yi Kong4e00ce72014-07-12 22:48:13 +0000124#endif
Yi Konga44c4d72014-06-27 21:25:42 +0000125
Yi Kong4e00ce72014-07-12 22:48:13 +0000126/* 9.4.2 Saturating addition and subtraction intrinsics */
127#if __ARM_32BIT_STATE
Yi Konga44c4d72014-06-27 21:25:42 +0000128static __inline__ int32_t __attribute__((always_inline, nodebug))
129 __qadd(int32_t t, int32_t v) {
130 return __builtin_arm_qadd(t, v);
131}
132
133static __inline__ int32_t __attribute__((always_inline, nodebug))
134 __qsub(int32_t t, int32_t v) {
135 return __builtin_arm_qsub(t, v);
136}
Renato Golin47843ef2014-07-03 10:14:52 +0000137
138static __inline__ int32_t __attribute__((always_inline, nodebug))
139__qdbl(int32_t t) {
140 return __builtin_arm_qadd(t, t);
141}
Yi Konga44c4d72014-06-27 21:25:42 +0000142#endif
143
Yi Kong4e00ce72014-07-12 22:48:13 +0000144/* 9.7 CRC32 intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +0000145#if __ARM_FEATURE_CRC32
146static __inline__ uint32_t __attribute__((always_inline, nodebug))
147 __crc32b(uint32_t a, uint8_t b) {
148 return __builtin_arm_crc32b(a, b);
149}
150
151static __inline__ uint32_t __attribute__((always_inline, nodebug))
152 __crc32h(uint32_t a, uint16_t b) {
153 return __builtin_arm_crc32h(a, b);
154}
155
156static __inline__ uint32_t __attribute__((always_inline, nodebug))
157 __crc32w(uint32_t a, uint32_t b) {
158 return __builtin_arm_crc32w(a, b);
159}
160
161static __inline__ uint32_t __attribute__((always_inline, nodebug))
162 __crc32d(uint32_t a, uint64_t b) {
163 return __builtin_arm_crc32d(a, b);
164}
165
166static __inline__ uint32_t __attribute__((always_inline, nodebug))
167 __crc32cb(uint32_t a, uint8_t b) {
168 return __builtin_arm_crc32cb(a, b);
169}
170
171static __inline__ uint32_t __attribute__((always_inline, nodebug))
172 __crc32ch(uint32_t a, uint16_t b) {
173 return __builtin_arm_crc32ch(a, b);
174}
175
176static __inline__ uint32_t __attribute__((always_inline, nodebug))
177 __crc32cw(uint32_t a, uint32_t b) {
178 return __builtin_arm_crc32cw(a, b);
179}
180
181static __inline__ uint32_t __attribute__((always_inline, nodebug))
182 __crc32cd(uint32_t a, uint64_t b) {
183 return __builtin_arm_crc32cd(a, b);
184}
185#endif
186
Saleem Abdulrasool60df0612014-07-08 05:46:00 +0000187#if defined(__cplusplus)
188}
189#endif
190
Yi Konga44c4d72014-06-27 21:25:42 +0000191#endif /* __ARM_ACLE_H */