File: op_vv.h

package info (click to toggle)
lsp-plugins 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 91,856 kB
  • sloc: cpp: 427,831; xml: 57,779; makefile: 9,961; php: 1,005; sh: 18
file content (230 lines) | stat: -rw-r--r-- 8,957 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
 *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
 *
 * This file is part of lsp-dsp-lib
 * Created on: 31 мар. 2020 г.
 *
 * lsp-dsp-lib 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 3 of the License, or
 * any later version.
 *
 * lsp-dsp-lib 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 lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef PRIVATE_DSP_ARCH_X86_SSE_PMATH_OP_VV_H_
#define PRIVATE_DSP_ARCH_X86_SSE_PMATH_OP_VV_H_

#ifndef PRIVATE_DSP_ARCH_X86_SSE_IMPL
    #error "This header should not be included directly"
#endif /* PRIVATE_DSP_ARCH_X86_SSE_IMPL */

namespace lsp
{
    namespace sse
    {
    #define OP_CORE(OP, SRC1, SRC2, DST)   \
        __ASM_EMIT("xor         %[off], %[off]") \
        __ASM_EMIT("sub         $16, %[count]") \
        __ASM_EMIT("jb          2f") \
        /* 16x blocks */ \
        __ASM_EMIT("1:") \
        __ASM_EMIT("movups      0x00(%[" SRC1 "], %[off]), %%xmm0") \
        __ASM_EMIT("movups      0x10(%[" SRC1 "], %[off]), %%xmm1") \
        __ASM_EMIT("movups      0x20(%[" SRC1 "], %[off]), %%xmm2") \
        __ASM_EMIT("movups      0x30(%[" SRC1 "], %[off]), %%xmm3") \
        __ASM_EMIT("movups      0x00(%[" SRC2 "], %[off]), %%xmm4") \
        __ASM_EMIT("movups      0x10(%[" SRC2 "], %[off]), %%xmm5") \
        __ASM_EMIT("movups      0x20(%[" SRC2 "], %[off]), %%xmm6") \
        __ASM_EMIT("movups      0x30(%[" SRC2 "], %[off]), %%xmm7") \
        __ASM_EMIT(OP "ps       %%xmm4, %%xmm0") \
        __ASM_EMIT(OP "ps       %%xmm5, %%xmm1") \
        __ASM_EMIT(OP "ps       %%xmm6, %%xmm2") \
        __ASM_EMIT(OP "ps       %%xmm7, %%xmm3") \
        __ASM_EMIT("movups      %%xmm0, 0x00(%[" DST "], %[off])") \
        __ASM_EMIT("movups      %%xmm1, 0x10(%[" DST "], %[off])") \
        __ASM_EMIT("movups      %%xmm2, 0x20(%[" DST "], %[off])") \
        __ASM_EMIT("movups      %%xmm3, 0x30(%[" DST "], %[off])") \
        __ASM_EMIT("add         $0x40, %[off]") \
        __ASM_EMIT("sub         $0x10, %[count]") \
        __ASM_EMIT("jae         1b") \
        /* 8x blocks */ \
        __ASM_EMIT("2:") \
        __ASM_EMIT("add         $8, %[count]") \
        __ASM_EMIT("jl          4f") \
        __ASM_EMIT("movups      0x00(%[" SRC1 "], %[off]), %%xmm0") \
        __ASM_EMIT("movups      0x10(%[" SRC1 "], %[off]), %%xmm1") \
        __ASM_EMIT("movups      0x00(%[" SRC2 "], %[off]), %%xmm4") \
        __ASM_EMIT("movups      0x10(%[" SRC2 "], %[off]), %%xmm5") \
        __ASM_EMIT(OP "ps       %%xmm4, %%xmm0") \
        __ASM_EMIT(OP "ps       %%xmm5, %%xmm1") \
        __ASM_EMIT("movups      %%xmm0, 0x00(%[" DST "], %[off])") \
        __ASM_EMIT("movups      %%xmm1, 0x10(%[" DST "], %[off])") \
        __ASM_EMIT("sub         $8, %[count]") \
        __ASM_EMIT("add         $0x20, %[off]") \
        /* 4x blocks */ \
        __ASM_EMIT("4:") \
        __ASM_EMIT("add         $4, %[count]") \
        __ASM_EMIT("jl          6f") \
        __ASM_EMIT("movups      0x00(%[" SRC1 "], %[off]), %%xmm0") \
        __ASM_EMIT("movups      0x00(%[" SRC2 "], %[off]), %%xmm4") \
        __ASM_EMIT(OP "ps       %%xmm4, %%xmm0") \
        __ASM_EMIT("movups      %%xmm0, 0x00(%[" DST "], %[off])") \
        __ASM_EMIT("sub         $4, %[count]") \
        __ASM_EMIT("add         $0x10, %[off]") \
        /* 1x blocks */ \
        __ASM_EMIT("6:") \
        __ASM_EMIT("add         $3, %[count]") \
        __ASM_EMIT("jl          8f") \
        __ASM_EMIT("7:") \
        __ASM_EMIT("movss       0x00(%[" SRC1 "], %[off]), %%xmm0") \
        __ASM_EMIT("movss       0x00(%[" SRC2 "], %[off]), %%xmm4") \
        __ASM_EMIT(OP "ss       %%xmm4, %%xmm0") \
        __ASM_EMIT("movss       %%xmm0, 0x00(%[" DST "], %[off])") \
        __ASM_EMIT("add         $0x04, %[off]") \
        __ASM_EMIT("dec         %[count]") \
        __ASM_EMIT("jge         7b") \
        __ASM_EMIT("8:")

        void add2(float *dst, const float *src, size_t count)
        {
            size_t off;
            ARCH_X86_ASM
            (
                OP_CORE("add", "dst", "src", "dst")
                : [off] "=&r" (off), [count] "+r" (count)
                : [dst] "r" (dst), [src] "r" (src)
                : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
                  "%xmm4", "%xmm5", "%xmm6", "%xmm7"
            );
        }

        void sub2(float *dst, const float *src, size_t count)
        {
            size_t off;
            ARCH_X86_ASM
            (
                OP_CORE("sub", "dst", "src", "dst")
                : [off] "=&r" (off), [count] "+r" (count)
                : [dst] "r" (dst), [src] "r" (src)
                : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
                  "%xmm4", "%xmm5", "%xmm6", "%xmm7"
            );
        }

        void rsub2(float *dst, const float *src, size_t count)
        {
            size_t off;
            ARCH_X86_ASM
            (
                OP_CORE("sub", "src", "dst", "dst")
                : [off] "=&r" (off), [count] "+r" (count)
                : [dst] "r" (dst), [src] "r" (src)
                : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
                  "%xmm4", "%xmm5", "%xmm6", "%xmm7"
            );
        }

        void mul2(float *dst, const float *src, size_t count)
        {
            size_t off;
            ARCH_X86_ASM
            (
                OP_CORE("mul", "dst", "src", "dst")
                : [off] "=&r" (off), [count] "+r" (count)
                : [dst] "r" (dst), [src] "r" (src)
                : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
                  "%xmm4", "%xmm5", "%xmm6", "%xmm7"
            );
        }

        void div2(float *dst, const float *src, size_t count)
        {
            size_t off;
            ARCH_X86_ASM
            (
                OP_CORE("div", "dst", "src", "dst")
                : [off] "=&r" (off), [count] "+r" (count)
                : [dst] "r" (dst), [src] "r" (src)
                : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
                  "%xmm4", "%xmm5", "%xmm6", "%xmm7"
            );
        }

        void rdiv2(float *dst, const float *src, size_t count)
        {
            size_t off;
            ARCH_X86_ASM
            (
                OP_CORE("div", "src", "dst", "dst")
                : [off] "=&r" (off), [count] "+r" (count)
                : [dst] "r" (dst), [src] "r" (src)
                : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
                  "%xmm4", "%xmm5", "%xmm6", "%xmm7"
            );
        }

        void add3(float *dst, const float *src1, const float *src2, size_t count)
        {
            size_t off;
            ARCH_X86_ASM
            (
                OP_CORE("add", "src1", "src2", "dst")
                : [off] "=&r" (off), [count] "+r" (count)
                : [dst] "r" (dst), [src1] "r" (src1), [src2] "r" (src2)
                : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
                  "%xmm4", "%xmm5", "%xmm6", "%xmm7"
            );
        }

        void sub3(float *dst, const float *src1, const float *src2, size_t count)
        {
            size_t off;
            ARCH_X86_ASM
            (
                OP_CORE("sub", "src1", "src2", "dst")
                : [off] "=&r" (off), [count] "+r" (count)
                : [dst] "r" (dst), [src1] "r" (src1), [src2] "r" (src2)
                : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
                  "%xmm4", "%xmm5", "%xmm6", "%xmm7"
            );
        }

        void mul3(float *dst, const float *src1, const float *src2, size_t count)
        {
            size_t off;
            ARCH_X86_ASM
            (
                OP_CORE("mul", "src1", "src2", "dst")
                : [off] "=&r" (off), [count] "+r" (count)
                : [dst] "r" (dst), [src1] "r" (src1), [src2] "r" (src2)
                : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
                  "%xmm4", "%xmm5", "%xmm6", "%xmm7"
            );
        }

        void div3(float *dst, const float *src1, const float *src2, size_t count)
        {
            size_t off;
            ARCH_X86_ASM
            (
                OP_CORE("div", "src1", "src2", "dst")
                : [off] "=&r" (off), [count] "+r" (count)
                : [dst] "r" (dst), [src1] "r" (src1), [src2] "r" (src2)
                : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
                  "%xmm4", "%xmm5", "%xmm6", "%xmm7"
            );
        }

    #undef OP_CORE
    }
}

#endif /* PRIVATE_DSP_ARCH_X86_SSE_PMATH_OP_VV_H_ */