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
|
/*
* 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_MSMATRIX_H_
#define PRIVATE_DSP_ARCH_X86_SSE_MSMATRIX_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
{
IF_ARCH_X86(
static const float msmatrix_const[] __lsp_aligned16 =
{
LSP_DSP_VEC4(0.5f)
};
);
void lr_to_ms(float *m, float *s, const float *l, const float *r, size_t count)
{
size_t off;
ARCH_X86_ASM
(
__ASM_EMIT("xor %[off], %[off]")
__ASM_EMIT("movaps %[X_HALF], %%xmm7")
__ASM_EMIT64("sub $8, %[count]")
__ASM_EMIT32("subl $8, %[count]")
__ASM_EMIT("movaps %%xmm7, %%xmm6")
__ASM_EMIT("jb 2f")
// 8x blocks
__ASM_EMIT("1:")
__ASM_EMIT("movups 0x00(%[left], %[off]), %%xmm0") // xmm0 = l
__ASM_EMIT("movups 0x10(%[left], %[off]), %%xmm3")
__ASM_EMIT("movups 0x00(%[right], %[off]), %%xmm2") // xmm2 = r
__ASM_EMIT("movups 0x10(%[right], %[off]), %%xmm5")
__ASM_EMIT("movaps %%xmm0, %%xmm1") // xmm1 = l
__ASM_EMIT("movaps %%xmm3, %%xmm4")
__ASM_EMIT("addps %%xmm2, %%xmm0") // xmm0 = l + r
__ASM_EMIT("addps %%xmm5, %%xmm3")
__ASM_EMIT("subps %%xmm2, %%xmm1") // xmm1 = l - r
__ASM_EMIT("subps %%xmm5, %%xmm4")
__ASM_EMIT("mulps %%xmm6, %%xmm0") // xmm0 = (l + r) * 0.5f
__ASM_EMIT("mulps %%xmm7, %%xmm3")
__ASM_EMIT("mulps %%xmm6, %%xmm1") // xmm1 = (l - r) * 0.5f
__ASM_EMIT("mulps %%xmm7, %%xmm4")
__ASM_EMIT("movups %%xmm0, 0x00(%[mid], %[off])")
__ASM_EMIT("movups %%xmm3, 0x10(%[mid], %[off])")
__ASM_EMIT("movups %%xmm1, 0x00(%[side], %[off])")
__ASM_EMIT("movups %%xmm4, 0x10(%[side], %[off])")
__ASM_EMIT("add $0x20, %[off]")
__ASM_EMIT64("sub $8, %[count]")
__ASM_EMIT32("subl $8, %[count]")
__ASM_EMIT("jae 1b")
// 4x block
__ASM_EMIT("2:")
__ASM_EMIT64("add $4, %[count]")
__ASM_EMIT32("addl $4, %[count]")
__ASM_EMIT("jl 4f")
__ASM_EMIT("movups 0x00(%[left], %[off]), %%xmm0") // xmm0 = l
__ASM_EMIT("movups 0x00(%[right], %[off]), %%xmm2") // xmm2 = r
__ASM_EMIT("movaps %%xmm0, %%xmm1") // xmm1 = l
__ASM_EMIT("addps %%xmm2, %%xmm0") // xmm0 = l + r
__ASM_EMIT("subps %%xmm2, %%xmm1") // xmm1 = l - r
__ASM_EMIT("mulps %%xmm6, %%xmm0") // xmm0 = (l + r) * 0.5f
__ASM_EMIT("mulps %%xmm7, %%xmm1") // xmm1 = (l - r) * 0.5f
__ASM_EMIT("movups %%xmm0, 0x00(%[mid], %[off])")
__ASM_EMIT("movups %%xmm1, 0x00(%[side], %[off])")
__ASM_EMIT64("sub $4, %[count]")
__ASM_EMIT32("subl $4, %[count]")
__ASM_EMIT("add $0x10, %[off]")
// 1x blocks
__ASM_EMIT("4:")
__ASM_EMIT64("add $3, %[count]")
__ASM_EMIT32("addl $3, %[count]")
__ASM_EMIT("jl 6f")
__ASM_EMIT("5:")
__ASM_EMIT("movss 0x00(%[left], %[off]), %%xmm0") // xmm0 = l
__ASM_EMIT("movss 0x00(%[right], %[off]), %%xmm2") // xmm2 = r
__ASM_EMIT("movaps %%xmm0, %%xmm1") // xmm1 = l
__ASM_EMIT("addss %%xmm2, %%xmm0") // xmm0 = l + r
__ASM_EMIT("subss %%xmm2, %%xmm1") // xmm1 = l - r
__ASM_EMIT("mulss %%xmm6, %%xmm0") // xmm0 = (l + r) * 0.5f
__ASM_EMIT("mulss %%xmm7, %%xmm1") // xmm1 = (l - r) * 0.5f
__ASM_EMIT("movss %%xmm0, 0x00(%[mid], %[off])")
__ASM_EMIT("movss %%xmm1, 0x00(%[side], %[off])")
__ASM_EMIT("add $0x04, %[off]")
__ASM_EMIT64("dec %[count]")
__ASM_EMIT32("decl %[count]")
__ASM_EMIT("jge 5b")
__ASM_EMIT("6:")
: [off] "=&r" (off),
[count] X86_PGREG (count)
: [left] "r"(l), [right] "r" (r),
[mid] "r" (m), [side] "r" (s),
[X_HALF] "m" (msmatrix_const)
: "cc", "memory",
"%xmm0", "%xmm1", "%xmm2", "%xmm3",
"%xmm4", "%xmm5", "%xmm6", "%xmm7"
);
}
void ms_to_lr(float *l, float *r, const float *m, const float *s, size_t count)
{
size_t off;
ARCH_X86_ASM
(
__ASM_EMIT("xor %[off], %[off]")
__ASM_EMIT64("sub $8, %[count]")
__ASM_EMIT32("subl $8, %[count]")
__ASM_EMIT("jb 2f")
// 8x blocks
__ASM_EMIT("1:")
__ASM_EMIT("movups 0x00(%[mid], %[off]), %%xmm0") // xmm0 = m
__ASM_EMIT("movups 0x10(%[mid], %[off]), %%xmm4")
__ASM_EMIT("movups 0x00(%[side], %[off]), %%xmm2") // xmm2 = s
__ASM_EMIT("movups 0x10(%[side], %[off]), %%xmm6")
__ASM_EMIT("movaps %%xmm0, %%xmm1") // xmm1 = m
__ASM_EMIT("movaps %%xmm4, %%xmm5")
__ASM_EMIT("addps %%xmm2, %%xmm0") // xmm0 = m + s
__ASM_EMIT("addps %%xmm6, %%xmm4")
__ASM_EMIT("subps %%xmm2, %%xmm1") // xmm1 = m - s
__ASM_EMIT("subps %%xmm6, %%xmm5")
__ASM_EMIT("movups %%xmm0, 0x00(%[left], %[off])")
__ASM_EMIT("movups %%xmm4, 0x10(%[left], %[off])")
__ASM_EMIT("movups %%xmm1, 0x00(%[right], %[off])")
__ASM_EMIT("movups %%xmm5, 0x10(%[right], %[off])")
__ASM_EMIT("add $0x20, %[off]")
__ASM_EMIT64("sub $8, %[count]")
__ASM_EMIT32("subl $8, %[count]")
__ASM_EMIT("jae 1b")
// 4x block
__ASM_EMIT("2:")
__ASM_EMIT64("add $4, %[count]")
__ASM_EMIT32("addl $4, %[count]")
__ASM_EMIT("jl 4f")
__ASM_EMIT("movups 0x00(%[mid], %[off]), %%xmm0") // xmm0 = m
__ASM_EMIT("movups 0x00(%[side], %[off]), %%xmm2") // xmm2 = s
__ASM_EMIT("movaps %%xmm0, %%xmm1") // xmm1 = m
__ASM_EMIT("addps %%xmm2, %%xmm0") // xmm0 = m + s
__ASM_EMIT("subps %%xmm2, %%xmm1") // xmm1 = m - s
__ASM_EMIT("movups %%xmm0, 0x00(%[left], %[off])")
__ASM_EMIT("movups %%xmm1, 0x00(%[right], %[off])")
__ASM_EMIT64("sub $4, %[count]")
__ASM_EMIT32("subl $4, %[count]")
__ASM_EMIT("add $0x10, %[off]")
// 1x blocks
__ASM_EMIT("4:")
__ASM_EMIT64("add $3, %[count]")
__ASM_EMIT32("addl $3, %[count]")
__ASM_EMIT("jl 6f")
__ASM_EMIT("5:")
__ASM_EMIT("movss 0x00(%[mid], %[off]), %%xmm0") // xmm0 = m
__ASM_EMIT("movss 0x00(%[side], %[off]), %%xmm2") // xmm2 = s
__ASM_EMIT("movaps %%xmm0, %%xmm1") // xmm1 = m
__ASM_EMIT("addss %%xmm2, %%xmm0") // xmm0 = m + s
__ASM_EMIT("subss %%xmm2, %%xmm1") // xmm1 = m - s
__ASM_EMIT("movss %%xmm0, 0x00(%[left], %[off])")
__ASM_EMIT("movss %%xmm1, 0x00(%[right], %[off])")
__ASM_EMIT("add $0x04, %[off]")
__ASM_EMIT64("dec %[count]")
__ASM_EMIT32("decl %[count]")
__ASM_EMIT("jge 5b")
__ASM_EMIT("6:")
: [off] "=&r" (off),
[count] X86_PGREG (count)
: [left] "r"(l), [right] "r" (r),
[mid] "r" (m), [side] "r" (s)
: "cc", "memory",
"%xmm0", "%xmm1", "%xmm2", "%xmm3",
"%xmm4", "%xmm5", "%xmm6", "%xmm7"
);
}
#define LR_CVT_BODY(d, l, r, op) \
__ASM_EMIT("xor %[off], %[off]") \
__ASM_EMIT("movaps %[X_HALF], %%xmm7") \
__ASM_EMIT("sub $12, %[count]") \
__ASM_EMIT("movaps %%xmm7, %%xmm6") \
__ASM_EMIT("jb 2f") \
/* x12 blocks */ \
__ASM_EMIT("1:") \
__ASM_EMIT("movups 0x00(%[" l "], %[off]), %%xmm0") \
__ASM_EMIT("movups 0x10(%[" l "], %[off]), %%xmm1") \
__ASM_EMIT("movups 0x20(%[" l "], %[off]), %%xmm2") \
__ASM_EMIT("movups 0x00(%[" r "], %[off]), %%xmm3") \
__ASM_EMIT("movups 0x10(%[" r "], %[off]), %%xmm4") \
__ASM_EMIT("movups 0x20(%[" r "], %[off]), %%xmm5") \
__ASM_EMIT(op "ps %%xmm3, %%xmm0") /* xmm0 = l <+-> r */ \
__ASM_EMIT(op "ps %%xmm4, %%xmm1") \
__ASM_EMIT(op "ps %%xmm5, %%xmm2") \
__ASM_EMIT("mulps %%xmm7, %%xmm0") /* xmm0 = (l <+-> r) * 0.5f */ \
__ASM_EMIT("mulps %%xmm6, %%xmm1") \
__ASM_EMIT("mulps %%xmm7, %%xmm2") \
__ASM_EMIT("movups %%xmm0, 0x00(%[" d "], %[off])") \
__ASM_EMIT("movups %%xmm1, 0x10(%[" d "], %[off])") \
__ASM_EMIT("movups %%xmm2, 0x20(%[" d "], %[off])") \
\
__ASM_EMIT("add $0x30, %[off]") \
__ASM_EMIT("sub $12, %[count]") \
__ASM_EMIT("jae 1b") \
/* x8 block */ \
__ASM_EMIT("2:") \
__ASM_EMIT("add $4, %[count]") \
__ASM_EMIT("jl 4f") \
__ASM_EMIT("movups 0x00(%[" l "], %[off]), %%xmm0") \
__ASM_EMIT("movups 0x10(%[" l "], %[off]), %%xmm1") \
__ASM_EMIT("movups 0x00(%[" r "], %[off]), %%xmm3") \
__ASM_EMIT("movups 0x10(%[" r "], %[off]), %%xmm4") \
__ASM_EMIT(op "ps %%xmm3, %%xmm0") /* xmm0 = l <+-> r */ \
__ASM_EMIT(op "ps %%xmm4, %%xmm1") \
__ASM_EMIT("mulps %%xmm6, %%xmm0") /* xmm0 = (l <+-> r) * 0.5f */ \
__ASM_EMIT("mulps %%xmm7, %%xmm1") \
__ASM_EMIT("movups %%xmm0, 0x00(%[" d "], %[off])") \
__ASM_EMIT("movups %%xmm1, 0x10(%[" d "], %[off])") \
__ASM_EMIT("sub $8, %[count]") \
__ASM_EMIT("add $0x20, %[off]") \
/* x4 block */ \
__ASM_EMIT("4:") \
__ASM_EMIT("add $4, %[count]") \
__ASM_EMIT("jl 6f") \
__ASM_EMIT("movups 0x00(%[" l "], %[off]), %%xmm0") \
__ASM_EMIT("movups 0x00(%[" r "], %[off]), %%xmm3") \
__ASM_EMIT(op "ps %%xmm3, %%xmm0") /* xmm0 = l <+-> r */ \
__ASM_EMIT("mulps %%xmm7, %%xmm0") /* xmm0 = (l <+-> r) * 0.5f */ \
__ASM_EMIT("movups %%xmm0, 0x00(%[" d "], %[off])") \
__ASM_EMIT("sub $4, %[count]") \
__ASM_EMIT("add $0x10, %[off]") \
/* x1 blocks */ \
__ASM_EMIT("6:") \
__ASM_EMIT("add $3, %[count]") \
__ASM_EMIT("jl 8f") \
__ASM_EMIT("7:") \
__ASM_EMIT("movss 0x00(%[" l "], %[off]), %%xmm0") \
__ASM_EMIT("movss 0x00(%[" r "], %[off]), %%xmm3") \
__ASM_EMIT(op "ss %%xmm3, %%xmm0") /* xmm0 = l <+-> r */ \
__ASM_EMIT("mulss %%xmm7, %%xmm0") /* xmm0 = (l <+-> r) * 0.5f */ \
__ASM_EMIT("movss %%xmm0, 0x00(%[" d "], %[off])") \
__ASM_EMIT("add $0x04, %[off]") \
__ASM_EMIT("dec %[count]") \
__ASM_EMIT("jge 7b") \
\
__ASM_EMIT("8:")
void lr_to_mid(float *m, const float *l, const float *r, size_t count)
{
size_t off;
ARCH_X86_ASM
(
LR_CVT_BODY("mid", "left", "right", "add")
: [off] "=&r" (off), [count] "+r" (count)
: [left] "r"(l), [right] "r" (r),
[mid] "r" (m),
[X_HALF] "m" (msmatrix_const)
: "cc", "memory",
"%xmm0", "%xmm1", "%xmm2", "%xmm3",
"%xmm4", "%xmm5", "%xmm6", "%xmm7"
);
}
void lr_to_side(float *s, const float *l, const float *r, size_t count)
{
size_t off;
ARCH_X86_ASM
(
LR_CVT_BODY("side", "left", "right", "sub")
: [off] "=&r" (off), [count] "+r" (count)
: [left] "r"(l), [right] "r" (r),
[side] "r" (s),
[X_HALF] "m" (msmatrix_const)
: "cc", "memory",
"%xmm0", "%xmm1", "%xmm2", "%xmm3",
"%xmm4", "%xmm5", "%xmm6", "%xmm7"
);
}
#undef LR_CVT_BODY
#define MS_CVT_BODY(d, m, s, op) \
__ASM_EMIT("xor %[off], %[off]") \
__ASM_EMIT("sub $16, %[count]") \
__ASM_EMIT("jb 2f") \
\
/* x16 blocks */ \
__ASM_EMIT("1:") \
__ASM_EMIT("movups 0x00(%[" m "], %[off]), %%xmm0") \
__ASM_EMIT("movups 0x10(%[" m "], %[off]), %%xmm1") \
__ASM_EMIT("movups 0x20(%[" m "], %[off]), %%xmm2") \
__ASM_EMIT("movups 0x30(%[" m "], %[off]), %%xmm3") \
__ASM_EMIT("movups 0x00(%[" s "], %[off]), %%xmm4") \
__ASM_EMIT("movups 0x10(%[" s "], %[off]), %%xmm5") \
__ASM_EMIT("movups 0x20(%[" s "], %[off]), %%xmm6") \
__ASM_EMIT("movups 0x30(%[" s "], %[off]), %%xmm7") \
__ASM_EMIT(op "ps %%xmm4, %%xmm0") /* xmm0 = m <+-> s */ \
__ASM_EMIT(op "ps %%xmm5, %%xmm1") \
__ASM_EMIT(op "ps %%xmm6, %%xmm2") \
__ASM_EMIT(op "ps %%xmm7, %%xmm3") \
__ASM_EMIT("movups %%xmm0, 0x00(%[" d "], %[off])") \
__ASM_EMIT("movups %%xmm1, 0x10(%[" d "], %[off])") \
__ASM_EMIT("movups %%xmm2, 0x20(%[" d "], %[off])") \
__ASM_EMIT("movups %%xmm3, 0x30(%[" d "], %[off])") \
\
__ASM_EMIT("add $0x40, %[off]") \
__ASM_EMIT("sub $16, %[count]") \
__ASM_EMIT("jae 1b") \
/* x8 block */ \
__ASM_EMIT("2:") \
__ASM_EMIT("add $8, %[count]") \
__ASM_EMIT("jl 4f") \
__ASM_EMIT("movups 0x00(%[" m "], %[off]), %%xmm0") \
__ASM_EMIT("movups 0x10(%[" m "], %[off]), %%xmm1") \
__ASM_EMIT("movups 0x00(%[" s "], %[off]), %%xmm4") \
__ASM_EMIT("movups 0x10(%[" s "], %[off]), %%xmm5") \
__ASM_EMIT(op "ps %%xmm4, %%xmm0") /* xmm0 = m <+-> s */ \
__ASM_EMIT(op "ps %%xmm5, %%xmm1") \
__ASM_EMIT("movups %%xmm0, 0x00(%[" d "], %[off])") \
__ASM_EMIT("movups %%xmm1, 0x10(%[" d "], %[off])") \
__ASM_EMIT("sub $8, %[count]") \
__ASM_EMIT("add $0x20, %[off]") \
/* x4 block */ \
__ASM_EMIT("4:") \
__ASM_EMIT("add $4, %[count]") \
__ASM_EMIT("jl 6f") \
__ASM_EMIT("movups 0x00(%[" m "], %[off]), %%xmm0") \
__ASM_EMIT("movups 0x00(%[" s "], %[off]), %%xmm4") \
__ASM_EMIT(op "ps %%xmm4, %%xmm0") /* xmm0 = m <+-> s */ \
__ASM_EMIT("movups %%xmm0, 0x00(%[" d "], %[off])") \
__ASM_EMIT("sub $4, %[count]") \
__ASM_EMIT("add $0x10, %[off]") \
/* x1 blocks */ \
__ASM_EMIT("6:") \
__ASM_EMIT("add $3, %[count]") \
__ASM_EMIT("jl 8f") \
__ASM_EMIT("7:") \
__ASM_EMIT("movss 0x00(%[" m "], %[off]), %%xmm0") \
__ASM_EMIT("movss 0x00(%[" s "], %[off]), %%xmm4") \
__ASM_EMIT(op "ss %%xmm4, %%xmm0") /* xmm0 = m <+-> s */ \
__ASM_EMIT("movss %%xmm0, 0x00(%[" d "], %[off])") \
__ASM_EMIT("add $0x04, %[off]") \
__ASM_EMIT("dec %[count]") \
__ASM_EMIT("jge 7b") \
\
__ASM_EMIT("8:")
void ms_to_left(float *l, const float *m, const float *s, size_t count)
{
size_t off;
ARCH_X86_ASM
(
MS_CVT_BODY("left", "mid", "side", "add")
: [off] "=&r" (off), [count] "+r" (count)
: [left] "r" (l),
[mid] "r" (m), [side] "r" (s)
: "cc", "memory",
"%xmm0", "%xmm1", "%xmm2", "%xmm3",
"%xmm4", "%xmm5", "%xmm6", "%xmm7"
);
}
void ms_to_right(float *r, const float *m, const float *s, size_t count)
{
size_t off;
ARCH_X86_ASM
(
MS_CVT_BODY("right", "mid", "side", "sub")
: [off] "=&r" (off), [count] "+r" (count)
: [right] "r" (r),
[mid] "r" (m), [side] "r" (s)
: "cc", "memory",
"%xmm0", "%xmm1", "%xmm2", "%xmm3",
"%xmm4", "%xmm5", "%xmm6", "%xmm7"
);
}
#undef MS_CVT_BODY
} /* namespace sse */
} /* namespace lsp */
#endif /* PRIVATE_DSP_ARCH_X86_SSE_MSMATRIX_H_ */
|