blob: 460f2975d46105e17b397535e53da2f60f4f50ff [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
36
Saleem Abdulrasool07257fe2014-07-12 23:27:26 +000037/* 8.4 - Hints */
38
39#if !defined(_MSC_VER)
40static __inline__ void __attribute__((always_inline, nodebug)) __wfi(void) {
41 __builtin_arm_wfi();
42}
43
44static __inline__ void __attribute__((always_inline, nodebug)) __wfe(void) {
45 __builtin_arm_wfe();
46}
47
48static __inline__ void __attribute__((always_inline, nodebug)) __sev(void) {
49 __builtin_arm_sev();
50}
51
52static __inline__ void __attribute__((always_inline, nodebug)) __sevl(void) {
53 __builtin_arm_sevl();
54}
55
56static __inline__ void __attribute__((always_inline, nodebug)) __yield(void) {
57 __builtin_arm_yield();
58}
59#endif
60
Yi Kong4e00ce72014-07-12 22:48:13 +000061/* 9 DATA-PROCESSING INTRINSICS */
62/* 9.2 Miscellaneous data-processing intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +000063static __inline__ uint32_t __attribute__((always_inline, nodebug))
64 __clz(uint32_t t) {
65 return __builtin_clz(t);
66}
67
68static __inline__ unsigned long __attribute__((always_inline, nodebug))
69 __clzl(unsigned long t) {
70 return __builtin_clzl(t);
71}
72
73static __inline__ uint64_t __attribute__((always_inline, nodebug))
74 __clzll(uint64_t t) {
75#if __SIZEOF_LONG_LONG__ == 8
76 return __builtin_clzll(t);
77#else
78 return __builtin_clzl(t);
79#endif
80}
81
82static __inline__ uint32_t __attribute__((always_inline, nodebug))
83 __rev(uint32_t t) {
84 return __builtin_bswap32(t);
85}
86
87static __inline__ unsigned long __attribute__((always_inline, nodebug))
88 __revl(unsigned long t) {
89#if __SIZEOF_LONG__ == 4
90 return __builtin_bswap32(t);
91#else
92 return __builtin_bswap64(t);
93#endif
94}
95
96static __inline__ uint64_t __attribute__((always_inline, nodebug))
97 __revll(uint64_t t) {
98 return __builtin_bswap64(t);
99}
100
Yi Konga44c4d72014-06-27 21:25:42 +0000101/*
Yi Kong4e00ce72014-07-12 22:48:13 +0000102 * 9.4 Saturating intrinsics
Yi Konga44c4d72014-06-27 21:25:42 +0000103 *
104 * FIXME: Change guard to their corrosponding __ARM_FEATURE flag when Q flag
105 * intrinsics are implemented and the flag is enabled.
106 */
Yi Kong4e00ce72014-07-12 22:48:13 +0000107/* 9.4.1 Width-specified saturation intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +0000108#if __ARM_32BIT_STATE
109#define __ssat(x, y) __builtin_arm_ssat(x, y)
110#define __usat(x, y) __builtin_arm_usat(x, y)
Yi Kong4e00ce72014-07-12 22:48:13 +0000111#endif
Yi Konga44c4d72014-06-27 21:25:42 +0000112
Yi Kong4e00ce72014-07-12 22:48:13 +0000113/* 9.4.2 Saturating addition and subtraction intrinsics */
114#if __ARM_32BIT_STATE
Yi Konga44c4d72014-06-27 21:25:42 +0000115static __inline__ int32_t __attribute__((always_inline, nodebug))
116 __qadd(int32_t t, int32_t v) {
117 return __builtin_arm_qadd(t, v);
118}
119
120static __inline__ int32_t __attribute__((always_inline, nodebug))
121 __qsub(int32_t t, int32_t v) {
122 return __builtin_arm_qsub(t, v);
123}
Renato Golin47843ef2014-07-03 10:14:52 +0000124
125static __inline__ int32_t __attribute__((always_inline, nodebug))
126__qdbl(int32_t t) {
127 return __builtin_arm_qadd(t, t);
128}
Yi Konga44c4d72014-06-27 21:25:42 +0000129#endif
130
Yi Kong4e00ce72014-07-12 22:48:13 +0000131/* 9.7 CRC32 intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +0000132#if __ARM_FEATURE_CRC32
133static __inline__ uint32_t __attribute__((always_inline, nodebug))
134 __crc32b(uint32_t a, uint8_t b) {
135 return __builtin_arm_crc32b(a, b);
136}
137
138static __inline__ uint32_t __attribute__((always_inline, nodebug))
139 __crc32h(uint32_t a, uint16_t b) {
140 return __builtin_arm_crc32h(a, b);
141}
142
143static __inline__ uint32_t __attribute__((always_inline, nodebug))
144 __crc32w(uint32_t a, uint32_t b) {
145 return __builtin_arm_crc32w(a, b);
146}
147
148static __inline__ uint32_t __attribute__((always_inline, nodebug))
149 __crc32d(uint32_t a, uint64_t b) {
150 return __builtin_arm_crc32d(a, b);
151}
152
153static __inline__ uint32_t __attribute__((always_inline, nodebug))
154 __crc32cb(uint32_t a, uint8_t b) {
155 return __builtin_arm_crc32cb(a, b);
156}
157
158static __inline__ uint32_t __attribute__((always_inline, nodebug))
159 __crc32ch(uint32_t a, uint16_t b) {
160 return __builtin_arm_crc32ch(a, b);
161}
162
163static __inline__ uint32_t __attribute__((always_inline, nodebug))
164 __crc32cw(uint32_t a, uint32_t b) {
165 return __builtin_arm_crc32cw(a, b);
166}
167
168static __inline__ uint32_t __attribute__((always_inline, nodebug))
169 __crc32cd(uint32_t a, uint64_t b) {
170 return __builtin_arm_crc32cd(a, b);
171}
172#endif
173
Saleem Abdulrasool60df0612014-07-08 05:46:00 +0000174#if defined(__cplusplus)
175}
176#endif
177
Yi Konga44c4d72014-06-27 21:25:42 +0000178#endif /* __ARM_ACLE_H */