blob: a7406fbf0a888076359fd5c3b97a82c20856ac6f [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
Yi Kong4e00ce72014-07-12 22:48:13 +000037/* 9 DATA-PROCESSING INTRINSICS */
38/* 9.2 Miscellaneous data-processing intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +000039static __inline__ uint32_t __attribute__((always_inline, nodebug))
40 __clz(uint32_t t) {
41 return __builtin_clz(t);
42}
43
44static __inline__ unsigned long __attribute__((always_inline, nodebug))
45 __clzl(unsigned long t) {
46 return __builtin_clzl(t);
47}
48
49static __inline__ uint64_t __attribute__((always_inline, nodebug))
50 __clzll(uint64_t t) {
51#if __SIZEOF_LONG_LONG__ == 8
52 return __builtin_clzll(t);
53#else
54 return __builtin_clzl(t);
55#endif
56}
57
58static __inline__ uint32_t __attribute__((always_inline, nodebug))
59 __rev(uint32_t t) {
60 return __builtin_bswap32(t);
61}
62
63static __inline__ unsigned long __attribute__((always_inline, nodebug))
64 __revl(unsigned long t) {
65#if __SIZEOF_LONG__ == 4
66 return __builtin_bswap32(t);
67#else
68 return __builtin_bswap64(t);
69#endif
70}
71
72static __inline__ uint64_t __attribute__((always_inline, nodebug))
73 __revll(uint64_t t) {
74 return __builtin_bswap64(t);
75}
76
Yi Konga44c4d72014-06-27 21:25:42 +000077/*
Yi Kong4e00ce72014-07-12 22:48:13 +000078 * 9.4 Saturating intrinsics
Yi Konga44c4d72014-06-27 21:25:42 +000079 *
80 * FIXME: Change guard to their corrosponding __ARM_FEATURE flag when Q flag
81 * intrinsics are implemented and the flag is enabled.
82 */
Yi Kong4e00ce72014-07-12 22:48:13 +000083/* 9.4.1 Width-specified saturation intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +000084#if __ARM_32BIT_STATE
85#define __ssat(x, y) __builtin_arm_ssat(x, y)
86#define __usat(x, y) __builtin_arm_usat(x, y)
Yi Kong4e00ce72014-07-12 22:48:13 +000087#endif
Yi Konga44c4d72014-06-27 21:25:42 +000088
Yi Kong4e00ce72014-07-12 22:48:13 +000089/* 9.4.2 Saturating addition and subtraction intrinsics */
90#if __ARM_32BIT_STATE
Yi Konga44c4d72014-06-27 21:25:42 +000091static __inline__ int32_t __attribute__((always_inline, nodebug))
92 __qadd(int32_t t, int32_t v) {
93 return __builtin_arm_qadd(t, v);
94}
95
96static __inline__ int32_t __attribute__((always_inline, nodebug))
97 __qsub(int32_t t, int32_t v) {
98 return __builtin_arm_qsub(t, v);
99}
Renato Golin47843ef2014-07-03 10:14:52 +0000100
101static __inline__ int32_t __attribute__((always_inline, nodebug))
102__qdbl(int32_t t) {
103 return __builtin_arm_qadd(t, t);
104}
Yi Konga44c4d72014-06-27 21:25:42 +0000105#endif
106
Yi Kong4e00ce72014-07-12 22:48:13 +0000107/* 9.7 CRC32 intrinsics */
Yi Konga44c4d72014-06-27 21:25:42 +0000108#if __ARM_FEATURE_CRC32
109static __inline__ uint32_t __attribute__((always_inline, nodebug))
110 __crc32b(uint32_t a, uint8_t b) {
111 return __builtin_arm_crc32b(a, b);
112}
113
114static __inline__ uint32_t __attribute__((always_inline, nodebug))
115 __crc32h(uint32_t a, uint16_t b) {
116 return __builtin_arm_crc32h(a, b);
117}
118
119static __inline__ uint32_t __attribute__((always_inline, nodebug))
120 __crc32w(uint32_t a, uint32_t b) {
121 return __builtin_arm_crc32w(a, b);
122}
123
124static __inline__ uint32_t __attribute__((always_inline, nodebug))
125 __crc32d(uint32_t a, uint64_t b) {
126 return __builtin_arm_crc32d(a, b);
127}
128
129static __inline__ uint32_t __attribute__((always_inline, nodebug))
130 __crc32cb(uint32_t a, uint8_t b) {
131 return __builtin_arm_crc32cb(a, b);
132}
133
134static __inline__ uint32_t __attribute__((always_inline, nodebug))
135 __crc32ch(uint32_t a, uint16_t b) {
136 return __builtin_arm_crc32ch(a, b);
137}
138
139static __inline__ uint32_t __attribute__((always_inline, nodebug))
140 __crc32cw(uint32_t a, uint32_t b) {
141 return __builtin_arm_crc32cw(a, b);
142}
143
144static __inline__ uint32_t __attribute__((always_inline, nodebug))
145 __crc32cd(uint32_t a, uint64_t b) {
146 return __builtin_arm_crc32cd(a, b);
147}
148#endif
149
Saleem Abdulrasool60df0612014-07-08 05:46:00 +0000150#if defined(__cplusplus)
151}
152#endif
153
Yi Konga44c4d72014-06-27 21:25:42 +0000154#endif /* __ARM_ACLE_H */