-
Notifications
You must be signed in to change notification settings - Fork 126
/
dsp.h
129 lines (120 loc) · 4.92 KB
/
dsp.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
/*
* Copyright (c) 2019-2020, Dmitry (DiSlord) dislordlive@gmail.com
* All rights reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* The software 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
// Cortex M4 DSP instructions assembly
// __smlabb inserts a SMLABB instruction. __smlabb returns the equivalent of
// int32_t res = x[0] * y[0] + acc
// where [0] is the lower 16 bits and [1] is the upper 16 bits. This operation sets the Q flag if overflow occurs on the addition.
__attribute__((always_inline)) __STATIC_INLINE int32_t __smlabb(int32_t x, int32_t y, int32_t acc)
{
register int32_t r;
__asm__ ("smlabb %[r], %[x], %[y], %[a]"
: [r] "=r" (r) : [x] "r" (x), [y] "r" (y), [a] "r" (acc) : );
return r;
}
// __smlabt inserts a SMLABT instruction. __smlabt returns the equivalent of
// int32_t res = x[0] * y[1] + acc
// where [0] is the lower 16 bits and [1] is the upper 16 bits. This operation sets the Q flag if overflow occurs on the addition.
__attribute__((always_inline)) __STATIC_INLINE int32_t __smlabt(int32_t x, int32_t y, int32_t acc)
{
register int32_t r;
__asm__ ("smlabt %[r], %[x], %[y], %[a]"
: [r] "=r" (r) : [x] "r" (x), [y] "r" (y), [a] "r" (acc) : );
return r;
}
// __smlatb inserts a SMLATB instruction. __smlatb returns the equivalent of
// int32_t res = x[1] * y[0] + acc
// where [0] is the lower 16 bits and [1] is the upper 16 bits. This operation sets the Q flag if overflow occurs on the addition.
__attribute__((always_inline)) __STATIC_INLINE int32_t __smlatb(int32_t x, int32_t y, int32_t acc)
{
register int32_t r;
__asm__ ("smlatb %[r], %[x], %[y], %[a]"
: [r] "=r" (r) : [x] "r" (x), [y] "r" (y), [a] "r" (acc) : );
return r;
}
// __smlatt inserts a SMLATT instruction. __smlatt returns the equivalent of
// int32_t res = x[1] * y[1] + acc
// where [0] is the lower 16 bits and [1] is the upper 16 bits. This operation sets the Q flag if overflow occurs on the addition.
__attribute__((always_inline)) __STATIC_INLINE int32_t __smlatt(int32_t x, int32_t y, int32_t acc)
{
register int32_t r;
__asm__ ("smlatt %[r], %[x], %[y], %[a]"
: [r] "=r" (r) : [x] "r" (x), [y] "r" (y), [a] "r" (acc) : );
return r;
}
// __smlalbb inserts a SMLALBB instruction. __smlalbb returns the equivalent of
// int64_t res = x[0] * y[0] + acc
// where [0] is the lower 16 bits and [1] is the upper 16 bits.
__attribute__((always_inline)) __STATIC_INLINE int64_t __smlalbb(int64_t acc, int32_t x, int32_t y)
{
register union {
struct { uint32_t lo; uint32_t hi; } s_rep;
int64_t i_rep;
} r;
r.i_rep = acc;
__asm__ ("smlalbb %[r_lo], %[r_hi], %[x], %[y]"
: [r_lo] "+r" (r.s_rep.lo), [r_hi] "+r" (r.s_rep.hi)
: [x] "r" (x), [y] "r" (y) : );
return r.i_rep;
}
// __smlalbt inserts a SMLALBT instruction. __smlalbt returns the equivalent of
// int64_t res = x[0] * y[1] + acc
// where [0] is the lower 16 bits and [1] is the upper 16 bits.
__attribute__((always_inline)) __STATIC_INLINE int64_t __smlalbt(int64_t acc, int32_t x, int32_t y)
{
register union {
struct { uint32_t lo; uint32_t hi; } s_rep;
int64_t i_rep;
} r;
r.i_rep = acc;
__asm__ ("smlalbt %[r_lo], %[r_hi], %[x], %[y]"
: [r_lo] "+r" (r.s_rep.lo), [r_hi] "+r" (r.s_rep.hi)
: [x] "r" (x), [y] "r" (y) : );
return r.i_rep;
}
// __smlaltb inserts a SMLALTB instruction. __smlaltb returns the equivalent of
// int64_t res = x[1] * y[0] + acc
// where [0] is the lower 16 bits and [1] is the upper 16 bits.
__attribute__((always_inline)) __STATIC_INLINE int64_t __smlaltb(int64_t acc, int32_t x, int32_t y)
{
register union {
struct { uint32_t lo; uint32_t hi; } s_rep;
int64_t i_rep;
} r;
r.i_rep = acc;
__asm__ ("smlaltb %[r_lo], %[r_hi], %[x], %[y]"
: [r_lo] "+r" (r.s_rep.lo), [r_hi] "+r" (r.s_rep.hi)
: [x] "r" (x), [y] "r" (y) : );
return r.i_rep;
}
// __smlaltt inserts a SMLALTT instruction. __smlaltt returns the equivalent of
// int64_t res = x[1] * y[1] + acc
// where [0] is the lower 16 bits and [1] is the upper 16 bits.
__attribute__((always_inline)) __STATIC_INLINE int64_t __smlaltt(int64_t acc, int32_t x, int32_t y)
{
register union {
struct { uint32_t lo; uint32_t hi; } s_rep;
int64_t i_rep;
} r;
r.i_rep = acc;
__asm__ ("smlaltt %[r_lo], %[r_hi], %[x], %[y]"
: [r_lo] "+r" (r.s_rep.lo), [r_hi] "+r" (r.s_rep.hi)
: [x] "r" (x), [y] "r" (y) : );
return r.i_rep;
}