blob: c51a5dcbef2dfa2d545f40622be0d519d10e0ff0 [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 Kong472e5212014-07-14 15:32:29 +000036
37/* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
38/* 8.4 Hints */
Saleem Abdulrasool07257fe2014-07-12 23:27:26 +000039
40#if !defined(_MSC_VER)
41static __inline__ void __attribute__((always_inline, nodebug)) __wfi(void) {
42 __builtin_arm_wfi();
43}
44
45static __inline__ void __attribute__((always_inline, nodebug)) __wfe(void) {
46 __builtin_arm_wfe();
47}
48
49static __inline__ void __attribute__((always_inline, nodebug)) __sev(void) {
50 __builtin_arm_sev();
51}
52
53static __inline__ void __attribute__((always_inline, nodebug)) __sevl(void) {
54 __builtin_arm_sevl();
55}
56
57static __inline__ void __attribute__((always_inline, nodebug)) __yield(void) {
58 __builtin_arm_yield();
59}
60#endif
61
Yi Kong472e5212014-07-14 15:32:29 +000062/* 8.7 NOP */
63static __inline__ void __attribute__((always_inline, nodebug)) __nop(void) {
64 __builtin_arm_nop();
65}
66
Yi Kong4e00ce72014-07-12 22:48:13 +000067/* 9 DATA-PROCESSING INTRINSICS */
68/* 9.2 Miscellaneous data-processing intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +000069static __inline__ uint32_t __attribute__((always_inline, nodebug))
70 __clz(uint32_t t) {
71 return __builtin_clz(t);
72}
73
74static __inline__ unsigned long __attribute__((always_inline, nodebug))
75 __clzl(unsigned long t) {
76 return __builtin_clzl(t);
77}
78
79static __inline__ uint64_t __attribute__((always_inline, nodebug))
80 __clzll(uint64_t t) {
81#if __SIZEOF_LONG_LONG__ == 8
82 return __builtin_clzll(t);
83#else
84 return __builtin_clzl(t);
85#endif
86}
87
88static __inline__ uint32_t __attribute__((always_inline, nodebug))
89 __rev(uint32_t t) {
90 return __builtin_bswap32(t);
91}
92
93static __inline__ unsigned long __attribute__((always_inline, nodebug))
94 __revl(unsigned long t) {
95#if __SIZEOF_LONG__ == 4
96 return __builtin_bswap32(t);
97#else
98 return __builtin_bswap64(t);
99#endif
100}
101
102static __inline__ uint64_t __attribute__((always_inline, nodebug))
103 __revll(uint64_t t) {
104 return __builtin_bswap64(t);
105}
106
Yi Konga44c4d72014-06-27 21:25:42 +0000107/*
Yi Kong4e00ce72014-07-12 22:48:13 +0000108 * 9.4 Saturating intrinsics
Yi Konga44c4d72014-06-27 21:25:42 +0000109 *
110 * FIXME: Change guard to their corrosponding __ARM_FEATURE flag when Q flag
111 * intrinsics are implemented and the flag is enabled.
112 */
Yi Kong4e00ce72014-07-12 22:48:13 +0000113/* 9.4.1 Width-specified saturation intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +0000114#if __ARM_32BIT_STATE
115#define __ssat(x, y) __builtin_arm_ssat(x, y)
116#define __usat(x, y) __builtin_arm_usat(x, y)
Yi Kong4e00ce72014-07-12 22:48:13 +0000117#endif
Yi Konga44c4d72014-06-27 21:25:42 +0000118
Yi Kong4e00ce72014-07-12 22:48:13 +0000119/* 9.4.2 Saturating addition and subtraction intrinsics */
120#if __ARM_32BIT_STATE
Yi Konga44c4d72014-06-27 21:25:42 +0000121static __inline__ int32_t __attribute__((always_inline, nodebug))
122 __qadd(int32_t t, int32_t v) {
123 return __builtin_arm_qadd(t, v);
124}
125
126static __inline__ int32_t __attribute__((always_inline, nodebug))
127 __qsub(int32_t t, int32_t v) {
128 return __builtin_arm_qsub(t, v);
129}
Renato Golin47843ef2014-07-03 10:14:52 +0000130
131static __inline__ int32_t __attribute__((always_inline, nodebug))
132__qdbl(int32_t t) {
133 return __builtin_arm_qadd(t, t);
134}
Yi Konga44c4d72014-06-27 21:25:42 +0000135#endif
136
Yi Kong4e00ce72014-07-12 22:48:13 +0000137/* 9.7 CRC32 intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +0000138#if __ARM_FEATURE_CRC32
139static __inline__ uint32_t __attribute__((always_inline, nodebug))
140 __crc32b(uint32_t a, uint8_t b) {
141 return __builtin_arm_crc32b(a, b);
142}
143
144static __inline__ uint32_t __attribute__((always_inline, nodebug))
145 __crc32h(uint32_t a, uint16_t b) {
146 return __builtin_arm_crc32h(a, b);
147}
148
149static __inline__ uint32_t __attribute__((always_inline, nodebug))
150 __crc32w(uint32_t a, uint32_t b) {
151 return __builtin_arm_crc32w(a, b);
152}
153
154static __inline__ uint32_t __attribute__((always_inline, nodebug))
155 __crc32d(uint32_t a, uint64_t b) {
156 return __builtin_arm_crc32d(a, b);
157}
158
159static __inline__ uint32_t __attribute__((always_inline, nodebug))
160 __crc32cb(uint32_t a, uint8_t b) {
161 return __builtin_arm_crc32cb(a, b);
162}
163
164static __inline__ uint32_t __attribute__((always_inline, nodebug))
165 __crc32ch(uint32_t a, uint16_t b) {
166 return __builtin_arm_crc32ch(a, b);
167}
168
169static __inline__ uint32_t __attribute__((always_inline, nodebug))
170 __crc32cw(uint32_t a, uint32_t b) {
171 return __builtin_arm_crc32cw(a, b);
172}
173
174static __inline__ uint32_t __attribute__((always_inline, nodebug))
175 __crc32cd(uint32_t a, uint64_t b) {
176 return __builtin_arm_crc32cd(a, b);
177}
178#endif
179
Saleem Abdulrasool60df0612014-07-08 05:46:00 +0000180#if defined(__cplusplus)
181}
182#endif
183
Yi Konga44c4d72014-06-27 21:25:42 +0000184#endif /* __ARM_ACLE_H */