| 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-dsp-lib |
| 6 |
* Created on: 31 мар. 2020 г. |
| 7 |
* |
| 8 |
* lsp-dsp-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-dsp-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-dsp-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef PRIVATE_DSP_ARCH_X86_SSE_PMATH_OP_VV_H_ |
| 23 |
#define PRIVATE_DSP_ARCH_X86_SSE_PMATH_OP_VV_H_ |
| 24 |
|
| 25 |
#ifndef PRIVATE_DSP_ARCH_X86_SSE_IMPL |
| 26 |
#error "This header should not be included directly" |
| 27 |
#endif /* PRIVATE_DSP_ARCH_X86_SSE_IMPL */ |
| 28 |
|
| 29 |
namespace lsp |
| 30 |
{ |
| 31 |
namespace sse |
| 32 |
{ |
| 33 |
#define OP_CORE(OP, SRC1, SRC2, DST) \ |
| 34 |
__ASM_EMIT("xor %[off], %[off]") \ |
| 35 |
__ASM_EMIT("sub $16, %[count]") \ |
| 36 |
__ASM_EMIT("jb 2f") \ |
| 37 |
/* 16x blocks */ \ |
| 38 |
__ASM_EMIT("1:") \ |
| 39 |
__ASM_EMIT("movups 0x00(%[" SRC1 "], %[off]), %%xmm0") \ |
| 40 |
__ASM_EMIT("movups 0x10(%[" SRC1 "], %[off]), %%xmm1") \ |
| 41 |
__ASM_EMIT("movups 0x20(%[" SRC1 "], %[off]), %%xmm2") \ |
| 42 |
__ASM_EMIT("movups 0x30(%[" SRC1 "], %[off]), %%xmm3") \ |
| 43 |
__ASM_EMIT("movups 0x00(%[" SRC2 "], %[off]), %%xmm4") \ |
| 44 |
__ASM_EMIT("movups 0x10(%[" SRC2 "], %[off]), %%xmm5") \ |
| 45 |
__ASM_EMIT("movups 0x20(%[" SRC2 "], %[off]), %%xmm6") \ |
| 46 |
__ASM_EMIT("movups 0x30(%[" SRC2 "], %[off]), %%xmm7") \ |
| 47 |
__ASM_EMIT(OP "ps %%xmm4, %%xmm0") \ |
| 48 |
__ASM_EMIT(OP "ps %%xmm5, %%xmm1") \ |
| 49 |
__ASM_EMIT(OP "ps %%xmm6, %%xmm2") \ |
| 50 |
__ASM_EMIT(OP "ps %%xmm7, %%xmm3") \ |
| 51 |
__ASM_EMIT("movups %%xmm0, 0x00(%[" DST "], %[off])") \ |
| 52 |
__ASM_EMIT("movups %%xmm1, 0x10(%[" DST "], %[off])") \ |
| 53 |
__ASM_EMIT("movups %%xmm2, 0x20(%[" DST "], %[off])") \ |
| 54 |
__ASM_EMIT("movups %%xmm3, 0x30(%[" DST "], %[off])") \ |
| 55 |
__ASM_EMIT("add $0x40, %[off]") \ |
| 56 |
__ASM_EMIT("sub $0x10, %[count]") \ |
| 57 |
__ASM_EMIT("jae 1b") \ |
| 58 |
/* 8x blocks */ \ |
| 59 |
__ASM_EMIT("2:") \ |
| 60 |
__ASM_EMIT("add $8, %[count]") \ |
| 61 |
__ASM_EMIT("jl 4f") \ |
| 62 |
__ASM_EMIT("movups 0x00(%[" SRC1 "], %[off]), %%xmm0") \ |
| 63 |
__ASM_EMIT("movups 0x10(%[" SRC1 "], %[off]), %%xmm1") \ |
| 64 |
__ASM_EMIT("movups 0x00(%[" SRC2 "], %[off]), %%xmm4") \ |
| 65 |
__ASM_EMIT("movups 0x10(%[" SRC2 "], %[off]), %%xmm5") \ |
| 66 |
__ASM_EMIT(OP "ps %%xmm4, %%xmm0") \ |
| 67 |
__ASM_EMIT(OP "ps %%xmm5, %%xmm1") \ |
| 68 |
__ASM_EMIT("movups %%xmm0, 0x00(%[" DST "], %[off])") \ |
| 69 |
__ASM_EMIT("movups %%xmm1, 0x10(%[" DST "], %[off])") \ |
| 70 |
__ASM_EMIT("sub $8, %[count]") \ |
| 71 |
__ASM_EMIT("add $0x20, %[off]") \ |
| 72 |
/* 4x blocks */ \ |
| 73 |
__ASM_EMIT("4:") \ |
| 74 |
__ASM_EMIT("add $4, %[count]") \ |
| 75 |
__ASM_EMIT("jl 6f") \ |
| 76 |
__ASM_EMIT("movups 0x00(%[" SRC1 "], %[off]), %%xmm0") \ |
| 77 |
__ASM_EMIT("movups 0x00(%[" SRC2 "], %[off]), %%xmm4") \ |
| 78 |
__ASM_EMIT(OP "ps %%xmm4, %%xmm0") \ |
| 79 |
__ASM_EMIT("movups %%xmm0, 0x00(%[" DST "], %[off])") \ |
| 80 |
__ASM_EMIT("sub $4, %[count]") \ |
| 81 |
__ASM_EMIT("add $0x10, %[off]") \ |
| 82 |
/* 1x blocks */ \ |
| 83 |
__ASM_EMIT("6:") \ |
| 84 |
__ASM_EMIT("add $3, %[count]") \ |
| 85 |
__ASM_EMIT("jl 8f") \ |
| 86 |
__ASM_EMIT("7:") \ |
| 87 |
__ASM_EMIT("movss 0x00(%[" SRC1 "], %[off]), %%xmm0") \ |
| 88 |
__ASM_EMIT("movss 0x00(%[" SRC2 "], %[off]), %%xmm4") \ |
| 89 |
__ASM_EMIT(OP "ss %%xmm4, %%xmm0") \ |
| 90 |
__ASM_EMIT("movss %%xmm0, 0x00(%[" DST "], %[off])") \ |
| 91 |
__ASM_EMIT("add $0x04, %[off]") \ |
| 92 |
__ASM_EMIT("dec %[count]") \ |
| 93 |
__ASM_EMIT("jge 7b") \ |
| 94 |
__ASM_EMIT("8:") |
| 95 |
|
| 96 |
void add2(float *dst, const float *src, size_t count) |
| 97 |
{ |
| 98 |
size_t off; |
| 99 |
ARCH_X86_ASM |
| 100 |
( |
| 101 |
OP_CORE("add", "dst", "src", "dst") |
| 102 |
: [off] "=&r" (off), [count] "+r" (count) |
| 103 |
: [dst] "r" (dst), [src] "r" (src) |
| 104 |
: "%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 105 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
void sub2(float *dst, const float *src, size_t count) |
| 110 |
{ |
| 111 |
size_t off; |
| 112 |
ARCH_X86_ASM |
| 113 |
( |
| 114 |
OP_CORE("sub", "dst", "src", "dst") |
| 115 |
: [off] "=&r" (off), [count] "+r" (count) |
| 116 |
: [dst] "r" (dst), [src] "r" (src) |
| 117 |
: "%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 118 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
void rsub2(float *dst, const float *src, size_t count) |
| 123 |
{ |
| 124 |
size_t off; |
| 125 |
ARCH_X86_ASM |
| 126 |
( |
| 127 |
OP_CORE("sub", "src", "dst", "dst") |
| 128 |
: [off] "=&r" (off), [count] "+r" (count) |
| 129 |
: [dst] "r" (dst), [src] "r" (src) |
| 130 |
: "%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 131 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 132 |
); |
| 133 |
} |
| 134 |
|
| 135 |
void mul2(float *dst, const float *src, size_t count) |
| 136 |
{ |
| 137 |
size_t off; |
| 138 |
ARCH_X86_ASM |
| 139 |
( |
| 140 |
OP_CORE("mul", "dst", "src", "dst") |
| 141 |
: [off] "=&r" (off), [count] "+r" (count) |
| 142 |
: [dst] "r" (dst), [src] "r" (src) |
| 143 |
: "%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 144 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 145 |
); |
| 146 |
} |
| 147 |
|
| 148 |
void div2(float *dst, const float *src, size_t count) |
| 149 |
{ |
| 150 |
size_t off; |
| 151 |
ARCH_X86_ASM |
| 152 |
( |
| 153 |
OP_CORE("div", "dst", "src", "dst") |
| 154 |
: [off] "=&r" (off), [count] "+r" (count) |
| 155 |
: [dst] "r" (dst), [src] "r" (src) |
| 156 |
: "%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 157 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 158 |
); |
| 159 |
} |
| 160 |
|
| 161 |
void rdiv2(float *dst, const float *src, size_t count) |
| 162 |
{ |
| 163 |
size_t off; |
| 164 |
ARCH_X86_ASM |
| 165 |
( |
| 166 |
OP_CORE("div", "src", "dst", "dst") |
| 167 |
: [off] "=&r" (off), [count] "+r" (count) |
| 168 |
: [dst] "r" (dst), [src] "r" (src) |
| 169 |
: "%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 170 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 171 |
); |
| 172 |
} |
| 173 |
|
| 174 |
void add3(float *dst, const float *src1, const float *src2, size_t count) |
| 175 |
{ |
| 176 |
size_t off; |
| 177 |
ARCH_X86_ASM |
| 178 |
( |
| 179 |
OP_CORE("add", "src1", "src2", "dst") |
| 180 |
: [off] "=&r" (off), [count] "+r" (count) |
| 181 |
: [dst] "r" (dst), [src1] "r" (src1), [src2] "r" (src2) |
| 182 |
: "%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 183 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 184 |
); |
| 185 |
} |
| 186 |
|
| 187 |
void sub3(float *dst, const float *src1, const float *src2, size_t count) |
| 188 |
{ |
| 189 |
size_t off; |
| 190 |
ARCH_X86_ASM |
| 191 |
( |
| 192 |
OP_CORE("sub", "src1", "src2", "dst") |
| 193 |
: [off] "=&r" (off), [count] "+r" (count) |
| 194 |
: [dst] "r" (dst), [src1] "r" (src1), [src2] "r" (src2) |
| 195 |
: "%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 196 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 197 |
); |
| 198 |
} |
| 199 |
|
| 200 |
void mul3(float *dst, const float *src1, const float *src2, size_t count) |
| 201 |
{ |
| 202 |
size_t off; |
| 203 |
ARCH_X86_ASM |
| 204 |
( |
| 205 |
OP_CORE("mul", "src1", "src2", "dst") |
| 206 |
: [off] "=&r" (off), [count] "+r" (count) |
| 207 |
: [dst] "r" (dst), [src1] "r" (src1), [src2] "r" (src2) |
| 208 |
: "%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 209 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 210 |
); |
| 211 |
} |
| 212 |
|
| 213 |
void div3(float *dst, const float *src1, const float *src2, size_t count) |
| 214 |
{ |
| 215 |
size_t off; |
| 216 |
ARCH_X86_ASM |
| 217 |
( |
| 218 |
OP_CORE("div", "src1", "src2", "dst") |
| 219 |
: [off] "=&r" (off), [count] "+r" (count) |
| 220 |
: [dst] "r" (dst), [src1] "r" (src1), [src2] "r" (src2) |
| 221 |
: "%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 222 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 223 |
); |
| 224 |
} |
| 225 |
|
| 226 |
#undef OP_CORE |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
#endif /* PRIVATE_DSP_ARCH_X86_SSE_PMATH_OP_VV_H_ */ |