-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathxtrxdsp.h
415 lines (324 loc) · 12.2 KB
/
xtrxdsp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/*
* Public xtrxdsp header file
* Copyright (c) 2017 Sergey Kostanbaev <[email protected]>
* For more information, please visit: http://xtrx.io
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef XTRXDSP_H
#define XTRXDSP_H
#include <stdint.h>
#include <stdlib.h>
#include <xtrxdsp_config.h>
void xtrxdsp_init(void);
/* dynamically choise at runtime */
#define DECLARE_IQ16_SC32_FUNC(funcname) \
void xtrxdsp_iq16_sc32_##funcname(const int16_t *__restrict iq, \
float *__restrict out, \
float scale, \
size_t bytes)
#define DECLARE_IQ12_SC32_FUNC(funcname) \
uint64_t xtrxdsp_iq12_sc32_##funcname(const void *__restrict iq, \
float *__restrict out, \
size_t inbytes, \
uint64_t prevstate)
#define DECLARE_IQ8_SC32_FUNC(funcname) \
void xtrxdsp_iq8_sc32_##funcname(const int8_t *__restrict iq, \
float *__restrict out, \
size_t bytes)
#define DECLARE_IQ8_IC16_FUNC(funcname) \
void xtrxdsp_iq8_ic16_##funcname(const int8_t *__restrict iq, \
int16_t *__restrict out, \
size_t bytes)
#define DECLARE_SC32_IQ16_FUNC(funcname) \
void xtrxdsp_sc32_iq16_##funcname(const float *__restrict iq, \
int16_t *__restrict out, \
float scale, \
size_t bytes)
#define DECLARE_IQ16_SC32I_FUNC(funcname) \
void xtrxdsp_iq16_sc32i_##funcname(const int16_t *__restrict iq, \
float *__restrict outa, \
float *__restrict outb, \
float scale, \
size_t bytes)
#define DECLARE_IQ16_IC16I_FUNC(funcname) \
void xtrxdsp_iq16_ic16i_##funcname(const int16_t *__restrict iq, \
int16_t *__restrict outa, \
int16_t *__restrict outb, \
size_t bytes)
#define DECLARE_IQ12_SC32I_FUNC(funcname) \
uint64_t xtrxdsp_iq12_sc32i_##funcname(const void *__restrict iq, \
float *__restrict outa, \
float *__restrict outb, \
size_t inbytes, \
uint64_t prevstate)
#define DECLARE_IQ8_SC32I_FUNC(funcname) \
void xtrxdsp_iq8_sc32i_##funcname(const int8_t *__restrict iq, \
float *__restrict outa, \
float *__restrict outb, \
size_t bytes)
#define DECLARE_IQ8_IC16I_FUNC(funcname) \
void xtrxdsp_iq8_ic16i_##funcname(const int8_t *__restrict iq, \
int16_t *__restrict outa, \
int16_t *__restrict outb, \
size_t bytes)
#define DECLARE_IQ8_IC8I_FUNC(funcname) \
void xtrxdsp_iq8_ic8i_##funcname(const int8_t *__restrict iq, \
int8_t *__restrict outa, \
int8_t *__restrict outb, \
size_t bytes)
#define DECLARE_SC32I_IQ16_FUNC(funcname) \
void xtrxdsp_sc32i_iq16_##funcname(const float *__restrict i, \
const float *__restrict q, \
int16_t *__restrict out, \
float scale, \
size_t bytes)
#define DECLARE_IC16I_IQ16_FUNC(funcname) \
void xtrxdsp_ic16i_iq16_##funcname(const int16_t *__restrict i, \
const int16_t *__restrict q, \
int16_t *__restrict out, \
size_t bytes)
#define DECLARE_IQ16_SC32_FUNC_TEMPLATE(funcname) \
DECLARE_IQ16_SC32_FUNC(funcname) { xtrxdsp_iq16_sc32_template(iq, out, scale, bytes); }
#define DECLARE_IQ12_SC32_FUNC_TEMPLATE(funcname) \
DECLARE_IQ12_SC32_FUNC(funcname) { return xtrxdsp_iq12_sc32_template(iq, out, inbytes, prevstate); }
#define DECLARE_IQ8_SC32_FUNC_TEMPLATE(funcname) \
DECLARE_IQ8_SC32_FUNC(funcname) { xtrxdsp_iq8_sc32_template(iq, out, bytes); }
#define DECLARE_IQ8_IC16_FUNC_TEMPLATE(funcname) \
DECLARE_IQ8_IC16_FUNC(funcname) { xtrxdsp_iq8_ic16_template(iq, out, bytes); }
#define DECLARE_SC32_IQ16_FUNC_TEMPLATE(funcname) \
DECLARE_SC32_IQ16_FUNC(funcname) { xtrxdsp_sc32_iq16_template(iq, out, scale, bytes); }
#define DECLARE_IQ16_SC32I_FUNC_TEMPLATE(funcname) \
DECLARE_IQ16_SC32I_FUNC(funcname) { xtrxdsp_iq16_sc32i_template(iq, outa, outb, scale, bytes); }
#define DECLARE_IQ16_IC16I_FUNC_TEMPLATE(funcname) \
DECLARE_IQ16_IC16I_FUNC(funcname) { xtrxdsp_iq16_ic16i_template(iq, outa, outb, bytes); }
#define DECLARE_IQ12_SC32I_FUNC_TEMPLATE(funcname) \
DECLARE_IQ12_SC32I_FUNC(funcname) { return xtrxdsp_iq12_sc32i_template(iq, outa, outb, inbytes, prevstate); }
#define DECLARE_IQ8_SC32I_FUNC_TEMPLATE(funcname) \
DECLARE_IQ8_SC32I_FUNC(funcname) { xtrxdsp_iq8_sc32i_template(iq, outa, outb, bytes); }
#define DECLARE_IQ8_IC8I_FUNC_TEMPLATE(funcname) \
DECLARE_IQ8_IC8I_FUNC(funcname) { xtrxdsp_iq8_ic8i_template(iq, outa, outb, bytes); }
#define DECLARE_IQ8_IC16I_FUNC_TEMPLATE(funcname) \
DECLARE_IQ8_IC16I_FUNC(funcname) { xtrxdsp_iq8_ic16i_template(iq, outa, outb, bytes); }
#define DECLARE_SC32I_IQ16_FUNC_TEMPLATE(funcname) \
DECLARE_SC32I_IQ16_FUNC(funcname) { xtrxdsp_sc32i_iq16_template(i, q, out, scale, bytes); }
#define DECLARE_IC16I_IQ16_FUNC_TEMPLATE(funcname) \
DECLARE_IC16I_IQ16_FUNC(funcname) { xtrxdsp_ic16i_iq16_template(i, q, out, bytes); }
#define DECLARE_TEMPLATES(funcname) \
DECLARE_IQ16_SC32_FUNC_TEMPLATE(funcname) \
DECLARE_IQ12_SC32_FUNC_TEMPLATE(funcname) \
DECLARE_IQ8_SC32_FUNC_TEMPLATE(funcname) \
DECLARE_IQ8_IC16_FUNC_TEMPLATE(funcname) \
DECLARE_SC32_IQ16_FUNC_TEMPLATE(funcname) \
DECLARE_IQ16_SC32I_FUNC_TEMPLATE(funcname) \
DECLARE_IQ16_IC16I_FUNC_TEMPLATE(funcname) \
DECLARE_IQ12_SC32I_FUNC_TEMPLATE(funcname) \
DECLARE_IQ8_SC32I_FUNC_TEMPLATE(funcname) \
DECLARE_SC32I_IQ16_FUNC_TEMPLATE(funcname) \
DECLARE_IC16I_IQ16_FUNC_TEMPLATE(funcname) \
DECLARE_IQ8_IC16I_FUNC_TEMPLATE(funcname) \
DECLARE_IQ8_IC8I_FUNC_TEMPLATE(funcname)
extern void xtrxdsp_iq16_sc32(const int16_t *__restrict iq,
float *__restrict out,
float scale,
size_t bytes);
extern uint64_t xtrxdsp_iq12_sc32(const void *__restrict iq,
float *__restrict out,
size_t inbytes,
uint64_t prevstate);
extern void xtrxdsp_iq8_sc32(const int8_t *__restrict iq,
float *__restrict out,
size_t bytes);
extern void xtrxdsp_iq8_ic16(const int8_t *__restrict iq,
int16_t *__restrict out,
size_t bytes);
extern void xtrxdsp_iq16_sc32i(const int16_t *__restrict iq,
float *__restrict outa,
float *__restrict outb,
float scale,
size_t bytes);
extern void xtrxdsp_iq16_ic16i(const int16_t *__restrict iq,
int16_t *__restrict outa,
int16_t *__restrict outb,
size_t bytes);
#if 0
extern uint64_t xtrxdsp_iq12_sc32i(const void *__restrict iq,
float *__restrict outa,
float *__restrict outb,
size_t inbytes,
uint64_t prevstate);
#endif
extern void xtrxdsp_iq8_sc32i(const int8_t *__restrict iq,
float *__restrict outa,
float *__restrict outb,
size_t bytes);
extern void xtrxdsp_sc32_iq16(const float *__restrict iq,
int16_t *__restrict out,
float scale,
size_t outbytes);
extern void xtrxdsp_sc32i_iq16(const float *__restrict i,
const float *__restrict q,
int16_t *__restrict out,
float scale,
size_t outbytes);
extern void xtrxdsp_ic16i_iq16(const int16_t *__restrict i,
const int16_t *__restrict q,
int16_t *__restrict out,
size_t outbytes);
extern void xtrxdsp_iq8_ic8i(const int8_t *__restrict iq,
int8_t *__restrict outa,
int8_t *__restrict outb,
size_t bytes);
extern void xtrxdsp_iq8_ic16i(const int8_t *__restrict iq,
int16_t *__restrict outa,
int16_t *__restrict outb,
size_t bytes);
/* non vector optimized version */
DECLARE_IQ16_SC32_FUNC(no);
DECLARE_IQ12_SC32_FUNC(no);
DECLARE_IQ8_SC32_FUNC(no);
DECLARE_IQ8_IC16_FUNC(no);
DECLARE_IQ16_SC32I_FUNC(no);
DECLARE_IQ12_SC32I_FUNC(no);
DECLARE_IQ8_SC32I_FUNC(no);
DECLARE_IQ8_IC16I_FUNC(no);
DECLARE_IQ8_IC8I_FUNC(no);
DECLARE_SC32_IQ16_FUNC(no);
DECLARE_SC32I_IQ16_FUNC(no);
DECLARE_IC16I_IQ16_FUNC(no);
DECLARE_IQ16_IC16I_FUNC(no);
#define CONCAT(x, y) x##y
/* CONVOLUTIONS */
#define DECLARE_SC32_CONV64_BASE(func) \
void func (const float *__restrict data, \
const float *__restrict conv, \
float *__restrict out, \
unsigned count, \
unsigned decim_bits)
#define DECLARE_SC32_CONV64_FUNC(funcname) \
DECLARE_SC32_CONV64_BASE(CONCAT(xtrxdsp_sc32_conv64,funcname))
#define DECLARE_BX_EXPAND_X_BASE(func) \
void func (const void *__restrict data, \
void *__restrict out, \
unsigned count_blocks)
#define DECLARE_B8_EXPAND_X2_FUNC(funcname) \
DECLARE_BX_EXPAND_X_BASE(CONCAT(xtrxdsp_b8_expand_x2,funcname))
#define DECLARE_B8_EXPAND_X4_FUNC(funcname) \
DECLARE_BX_EXPAND_X_BASE(CONCAT(xtrxdsp_b8_expand_x4,funcname))
#define DECLARE_IQ16_CONV64_BASE(func) \
void func (const int16_t *__restrict data, \
const int16_t *__restrict conv, \
int16_t *__restrict out, \
unsigned count, \
unsigned decim_bits)
#define DECLARE_IQ16_CONV64_FUNC(funcname) \
DECLARE_IQ16_CONV64_BASE(CONCAT(xtrxdsp_iq16_conv64,funcname))
#define DECLARE_B4_EXPAND_X2_FUNC(funcname) \
DECLARE_BX_EXPAND_X_BASE(CONCAT(xtrxdsp_b4_expand_x2,funcname))
#define DECLARE_B4_EXPAND_X4_FUNC(funcname) \
DECLARE_BX_EXPAND_X_BASE(CONCAT(xtrxdsp_b4_expand_x4,funcname))
DECLARE_SC32_CONV64_FUNC();
DECLARE_B8_EXPAND_X2_FUNC();
DECLARE_B8_EXPAND_X4_FUNC();
DECLARE_IQ16_CONV64_FUNC();
DECLARE_B4_EXPAND_X2_FUNC();
DECLARE_B4_EXPAND_X4_FUNC();
DECLARE_SC32_CONV64_FUNC(_no);
DECLARE_B8_EXPAND_X2_FUNC(_no);
DECLARE_B8_EXPAND_X4_FUNC(_no);
DECLARE_IQ16_CONV64_FUNC(_no);
DECLARE_B4_EXPAND_X2_FUNC(_no);
DECLARE_B4_EXPAND_X4_FUNC(_no);
#if defined(__x86_64__) || defined(__i386__)
#include <immintrin.h>
#ifdef XTRXDSP_HAS__SSE2__
/* SSE2 */
DECLARE_IQ16_SC32_FUNC(sse2);
DECLARE_IQ12_SC32_FUNC(sse2);
DECLARE_IQ8_SC32_FUNC(sse2);
DECLARE_IQ8_IC16_FUNC(sse2);
DECLARE_IQ16_SC32I_FUNC(sse2);
DECLARE_IQ12_SC32I_FUNC(sse2);
DECLARE_IQ8_SC32I_FUNC(sse2);
DECLARE_IQ8_IC16I_FUNC(sse2);
DECLARE_IQ8_IC8I_FUNC(sse2);
DECLARE_SC32_IQ16_FUNC(sse2);
DECLARE_SC32I_IQ16_FUNC(sse2);
DECLARE_IC16I_IQ16_FUNC(sse2);
DECLARE_IQ16_IC16I_FUNC(sse2);
#endif
#ifdef XTRXDSP_HAS__SSSE3__
/* SSSE3 */
DECLARE_IQ12_SC32_FUNC(ssse3);
DECLARE_IQ12_SC32_FUNC(ssse3_nh);
#endif
/* SSE4.1 */
#ifdef XTRXDSP_HAS__SSE4_1__
DECLARE_IQ12_SC32_FUNC(sse41);
DECLARE_IQ8_SC32_FUNC(sse41);
#endif
/* AVX */
#ifdef XTRXDSP_HAS__AVX__
DECLARE_IQ16_SC32_FUNC(avx);
DECLARE_IQ12_SC32_FUNC(avx);
DECLARE_IQ8_SC32_FUNC(avx);
DECLARE_IQ8_IC16_FUNC(avx);
DECLARE_IQ16_SC32I_FUNC(avx);
DECLARE_IQ12_SC32I_FUNC(avx);
DECLARE_IQ8_SC32I_FUNC(avx);
DECLARE_IQ8_IC16I_FUNC(avx);
DECLARE_IQ8_IC8I_FUNC(avx);
DECLARE_SC32_IQ16_FUNC(avx);
DECLARE_SC32I_IQ16_FUNC(avx);
DECLARE_IC16I_IQ16_FUNC(avx);
DECLARE_IQ16_IC16I_FUNC(avx);
#endif
/* AVX2 */
#ifdef XTRXDSP_HAS__AVX2__
DECLARE_IQ16_SC32_FUNC(avx2);
DECLARE_IQ12_SC32_FUNC(avx2);
DECLARE_IQ8_SC32_FUNC(avx2);
DECLARE_IQ16_SC32I_FUNC(avx2);
DECLARE_IQ12_SC32I_FUNC(avx2);
DECLARE_IQ8_SC32I_FUNC(avx2);
DECLARE_SC32_IQ16_FUNC(avx2);
DECLARE_SC32I_IQ16_FUNC(avx2);
#endif
#ifdef XTRXDSP_HAS__SSE2__
DECLARE_SC32_CONV64_FUNC(_sse2);
//DECLARE_B8_EXPAND_X2_FUNC(_sse2);
//DECLARE_B8_EXPAND_X4_FUNC(_sse2);
DECLARE_IQ16_CONV64_FUNC(_sse2);
#endif
#ifdef XTRXDSP_HAS__AVX__
DECLARE_SC32_CONV64_FUNC(_avx);
//DECLARE_B8_EXPAND_X2_FUNC(_avx);
//DECLARE_B8_EXPAND_X4_FUNC(_avx);
DECLARE_IQ16_CONV64_FUNC(_avx);
#ifdef XTRXDSP_HAS__FMA__
DECLARE_SC32_CONV64_FUNC(_avx_fma);
#endif
#endif
#endif /* defined(__x86_64__) || defined(__i386__) */
typedef DECLARE_BX_EXPAND_X_BASE( (*func_xtrxdsp_bx_expand_t) );
typedef DECLARE_SC32_CONV64_BASE( (*func_xtrxdsp_sc32_conv64_t) );
func_xtrxdsp_sc32_conv64_t resolve_xtrxdsp_sc32_conv64(void);
func_xtrxdsp_bx_expand_t resolve_xtrxdsp_b8_expand_x2(void);
func_xtrxdsp_bx_expand_t resolve_xtrxdsp_b8_expand_x4(void);
typedef DECLARE_IQ16_CONV64_BASE( (*func_xtrxdsp_iq16_conv64_t) );
func_xtrxdsp_iq16_conv64_t resolve_xtrxdsp_iq16_conv64(void);
func_xtrxdsp_bx_expand_t resolve_xtrxdsp_b4_expand_x2(void);
func_xtrxdsp_bx_expand_t resolve_xtrxdsp_b4_expand_x4(void);
#endif /* _XTRXDSP_H_ */