Debian Codegraph @

modules/lsp-common-lib/include/lsp-plug.in/common/arch/aarch64/bits/reverse.h

raw
1 /*
2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2020 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-common-lib
6 * Created on: 1 апр. 2020 г.
7 *
8 * lsp-common-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-common-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-common-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_COMMON_ARCH_AARCH64_BITS_REVERSE_H_
23 #define LSP_PLUG_IN_COMMON_ARCH_AARCH64_BITS_REVERSE_H_
24
25 #ifndef LSP_PLUG_IN_COMMON_BITS_IMPL
26 #error "This file should not be included directly"
27 #endif /* LSP_PLUG_IN_COMMON_BITS_IMPL */
28
29 namespace lsp
30 {
31 inline uint64_t reverse_bits(uint64_t src)
32 {
33 uint64_t res;
34
35 ARCH_AARCH64_ASM (
36 __ASM_EMIT("rbit %x[res], %x[src]")
37 : [res] "=r" (res)
38 : [src] "r" (src)
39 :
40 );
41
42 return res;
43 }
44
45 inline uint64_t reverse_bits(uint64_t src, size_t count)
46 {
47 uint64_t res, tmp;
48
49 ARCH_AARCH64_ASM (
50 __ASM_EMIT("rbit %x[res], %x[src]")
51 __ASM_EMIT("mov %x[tmp], #64")
52 __ASM_EMIT("sub %x[count], %x[tmp], %x[count]")
53 __ASM_EMIT("lsr %x[res], %x[res], %x[count]")
54 : [res] "=r" (res), [count] "+r" (count), [tmp] "=&r" (tmp)
55 : [src] "r" (src)
56 :
57 );
58
59 return res;
60 }
61
62 inline int64_t reverse_bits(int64_t src)
63 {
64 int64_t res;
65
66 ARCH_AARCH64_ASM (
67 __ASM_EMIT("rbit %x[res], %x[src]")
68 : [res] "=r" (res)
69 : [src] "r" (src)
70 :
71 );
72
73 return res;
74 }
75
76 inline int64_t reverse_bits(int64_t src, size_t count)
77 {
78 int64_t res, tmp;
79
80 ARCH_AARCH64_ASM (
81 __ASM_EMIT("rbit %x[res], %x[src]")
82 __ASM_EMIT("mov %x[tmp], #64")
83 __ASM_EMIT("sub %x[count], %x[tmp], %x[count]")
84 __ASM_EMIT("lsr %x[res], %x[res], %x[count]")
85 : [res] "=r" (res), [count] "+r" (count), [tmp] "=&r" (tmp)
86 : [src] "r" (src)
87 :
88 );
89
90 return res;
91 }
92
93 inline uint32_t reverse_bits(uint32_t src)
94 {
95 uint32_t res;
96
97 ARCH_AARCH64_ASM (
98 __ASM_EMIT("rbit %w[res], %w[src]")
99 : [res] "=r" (res)
100 : [src] "r" (src)
101 :
102 );
103
104 return res;
105 }
106
107 inline uint32_t reverse_bits(uint32_t src, size_t count)
108 {
109 uint32_t res;
110 uint64_t tmp;
111
112 ARCH_AARCH64_ASM (
113 __ASM_EMIT("rbit %x[res], %x[src]")
114 __ASM_EMIT("mov %x[tmp], #64")
115 __ASM_EMIT("sub %x[count], %x[tmp], %x[count]")
116 __ASM_EMIT("lsr %x[res], %x[res], %x[count]")
117 : [res] "=r" (res), [count] "+r" (count), [tmp] "=&r" (tmp)
118 : [src] "r" (src)
119 :
120 );
121
122 return res;
123 }
124
125 inline int32_t reverse_bits(int32_t src)
126 {
127 int32_t res;
128
129 ARCH_AARCH64_ASM (
130 __ASM_EMIT("rbit %w[res], %w[src]")
131 : [res] "=r" (res)
132 : [src] "r" (src)
133 :
134 );
135
136 return res;
137 }
138
139 inline int32_t reverse_bits(int32_t src, size_t count)
140 {
141 int32_t res;
142 uint64_t tmp;
143
144 ARCH_AARCH64_ASM (
145 __ASM_EMIT("rbit %x[res], %x[src]")
146 __ASM_EMIT("mov %x[tmp], #64")
147 __ASM_EMIT("sub %x[count], %x[tmp], %x[count]")
148 __ASM_EMIT("lsr %x[res], %x[res], %x[count]")
149 : [res] "=r" (res), [count] "+r" (count), [tmp] "=&r" (tmp)
150 : [src] "r" (src)
151 :
152 );
153
154 return res;
155 }
156
157 inline uint16_t reverse_bits(uint16_t src)
158 {
159 uint16_t res;
160
161 ARCH_AARCH64_ASM (
162 __ASM_EMIT("rbit %x[res], %x[src]")
163 __ASM_EMIT("lsr %x[res], %x[res], #48")
164 : [res] "=r" (res)
165 : [src] "r" (src)
166 :
167 );
168
169 return res;
170 }
171
172 inline uint16_t reverse_bits(uint16_t src, size_t count)
173 {
174 uint16_t res;
175 uint64_t tmp;
176
177 ARCH_AARCH64_ASM (
178 __ASM_EMIT("rbit %x[res], %x[src]")
179 __ASM_EMIT("mov %x[tmp], #64")
180 __ASM_EMIT("sub %x[count], %x[tmp], %x[count]")
181 __ASM_EMIT("lsr %x[res], %x[res], %x[count]")
182 : [res] "=r" (res), [count] "+r" (count), [tmp] "=&r" (tmp)
183 : [src] "r" (src)
184 :
185 );
186
187 return res;
188 }
189
190 inline int16_t reverse_bits(int16_t src)
191 {
192 int16_t res;
193
194 ARCH_AARCH64_ASM (
195 __ASM_EMIT("rbit %x[res], %x[src]")
196 __ASM_EMIT("lsr %x[res], %x[res], #48")
197 : [res] "=r" (res)
198 : [src] "r" (src)
199 :
200 );
201
202 return res;
203 }
204
205 inline int16_t reverse_bits(int16_t src, size_t count)
206 {
207 int16_t res;
208 uint64_t tmp;
209
210 ARCH_AARCH64_ASM (
211 __ASM_EMIT("rbit %x[res], %x[src]")
212 __ASM_EMIT("mov %x[tmp], #64")
213 __ASM_EMIT("sub %x[count], %x[tmp], %x[count]")
214 __ASM_EMIT("lsr %x[res], %x[res], %x[count]")
215 : [res] "=r" (res), [count] "+r" (count), [tmp] "=&r" (tmp)
216 : [src] "r" (src)
217 :
218 );
219
220 return res;
221 }
222
223 inline uint8_t reverse_bits(uint8_t src)
224 {
225 uint8_t res;
226
227 ARCH_AARCH64_ASM (
228 __ASM_EMIT("rbit %x[res], %x[src]")
229 __ASM_EMIT("lsr %x[res], %x[res], #56")
230 : [res] "=r" (res)
231 : [src] "r" (src)
232 :
233 );
234
235 return res;
236 }
237
238 inline uint8_t reverse_bits(uint8_t src, size_t count)
239 {
240 uint8_t res;
241 uint64_t tmp;
242
243 ARCH_AARCH64_ASM (
244 __ASM_EMIT("rbit %x[res], %x[src]")
245 __ASM_EMIT("mov %x[tmp], #64")
246 __ASM_EMIT("sub %x[count], %x[tmp], %x[count]")
247 __ASM_EMIT("lsr %x[res], %x[res], %x[count]")
248 : [res] "=r" (res), [count] "+r" (count), [tmp] "=&r" (tmp)
249 : [src] "r" (src)
250 :
251 );
252
253 return res;
254 }
255
256 inline int8_t reverse_bits(int8_t src)
257 {
258 int8_t res;
259
260 ARCH_AARCH64_ASM (
261 __ASM_EMIT("rbit %x[res], %x[src]")
262 __ASM_EMIT("lsr %x[res], %x[res], #56")
263 : [res] "=r" (res)
264 : [src] "r" (src)
265 :
266 );
267
268 return res;
269 }
270
271 inline int8_t reverse_bits(int8_t src, size_t count)
272 {
273 int8_t res;
274 uint64_t tmp;
275
276 ARCH_AARCH64_ASM (
277 __ASM_EMIT("rbit %x[res], %x[src]")
278 __ASM_EMIT("mov %x[tmp], #64")
279 __ASM_EMIT("sub %x[count], %x[tmp], %x[count]")
280 __ASM_EMIT("lsr %x[res], %x[res], %x[count]")
281 : [res] "=r" (res), [count] "+r" (count), [tmp] "=&r" (tmp)
282 : [src] "r" (src)
283 :
284 );
285
286 return res;
287 }
288
289 } /* namespace lsp */
290
291 #endif /* LSP_PLUG_IN_COMMON_ARCH_AARCH64_BITS_REVERSE_H_ */