| 1 |
/* |
| 2 |
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2023 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-dsp-lib |
| 6 |
* Created on: 23 сент. 2023 г. |
| 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_GRAPHICS_FILL_H_ |
| 23 |
#define PRIVATE_DSP_ARCH_X86_SSE_GRAPHICS_FILL_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 FILL4_CORE \ |
| 34 |
__ASM_EMIT("movss %[c0], %%xmm0") /* xmm0 = c0 */ \ |
| 35 |
__ASM_EMIT("movss %[c1], %%xmm1") /* xmm1 = c1 */ \ |
| 36 |
__ASM_EMIT("movss %[c2], %%xmm2") /* xmm2 = c2 */ \ |
| 37 |
__ASM_EMIT("movss %[c3], %%xmm3") /* xmm3 = c3 */ \ |
| 38 |
__ASM_EMIT("unpcklps %%xmm1, %%xmm0") /* xmm0 = c0 c1 ? ? */ \ |
| 39 |
__ASM_EMIT("unpcklps %%xmm3, %%xmm2") /* xmm2 = c2 c3 ? ? */ \ |
| 40 |
__ASM_EMIT("movlhps %%xmm2, %%xmm0") /* xmm0 = c0 c1 c2 c3 */ \ |
| 41 |
__ASM_EMIT("movaps %%xmm0, %%xmm1") /* xmm1 = c0 c1 c2 c3 */ \ |
| 42 |
__ASM_EMIT("movaps %%xmm0, %%xmm2") \ |
| 43 |
__ASM_EMIT("movaps %%xmm1, %%xmm3") \ |
| 44 |
\ |
| 45 |
/* 8x blocks */ \ |
| 46 |
__ASM_EMIT("sub $8, %[count]") \ |
| 47 |
__ASM_EMIT("jb 2f") \ |
| 48 |
__ASM_EMIT("1:") \ |
| 49 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") \ |
| 50 |
__ASM_EMIT("movups %%xmm1, 0x10(%[dst])") \ |
| 51 |
__ASM_EMIT("movups %%xmm2, 0x20(%[dst])") \ |
| 52 |
__ASM_EMIT("movups %%xmm3, 0x30(%[dst])") \ |
| 53 |
__ASM_EMIT("movups %%xmm0, 0x40(%[dst])") \ |
| 54 |
__ASM_EMIT("movups %%xmm1, 0x50(%[dst])") \ |
| 55 |
__ASM_EMIT("movups %%xmm2, 0x60(%[dst])") \ |
| 56 |
__ASM_EMIT("movups %%xmm3, 0x70(%[dst])") \ |
| 57 |
__ASM_EMIT("add $0x80, %[dst]") \ |
| 58 |
__ASM_EMIT("sub $8, %[count]") \ |
| 59 |
__ASM_EMIT("jae 1b") \ |
| 60 |
/* 4x block */ \ |
| 61 |
__ASM_EMIT("2:") \ |
| 62 |
__ASM_EMIT("add $4, %[count]") \ |
| 63 |
__ASM_EMIT("jl 4f") \ |
| 64 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") \ |
| 65 |
__ASM_EMIT("movups %%xmm1, 0x10(%[dst])") \ |
| 66 |
__ASM_EMIT("movups %%xmm2, 0x20(%[dst])") \ |
| 67 |
__ASM_EMIT("movups %%xmm3, 0x30(%[dst])") \ |
| 68 |
__ASM_EMIT("sub $4, %[count]") \ |
| 69 |
__ASM_EMIT("add $0x40, %[dst]") \ |
| 70 |
/* 2x block */ \ |
| 71 |
__ASM_EMIT("4:") \ |
| 72 |
__ASM_EMIT("add $2, %[count]") \ |
| 73 |
__ASM_EMIT("jl 6f") \ |
| 74 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") \ |
| 75 |
__ASM_EMIT("movups %%xmm1, 0x10(%[dst])") \ |
| 76 |
__ASM_EMIT("sub $2, %[count]") \ |
| 77 |
__ASM_EMIT("add $0x20, %[dst]") \ |
| 78 |
/* 1x block */ \ |
| 79 |
__ASM_EMIT("6:") \ |
| 80 |
__ASM_EMIT("add $1, %[count]") \ |
| 81 |
__ASM_EMIT("jl 8f") \ |
| 82 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") \ |
| 83 |
__ASM_EMIT("8:") |
| 84 |
|
| 85 |
void fill_rgba(float *dst, float r, float g, float b, float a, size_t count) |
| 86 |
{ |
| 87 |
ARCH_X86_ASM |
| 88 |
( |
| 89 |
FILL4_CORE |
| 90 |
: [dst] "+r" (dst), [count] "+r" (count) |
| 91 |
: [c0] "m" (r), [c1] "m" (g), [c2] "m" (b), [c3] "m" (a) |
| 92 |
: "cc", "memory", |
| 93 |
"%xmm0", "%xmm1", "%xmm2", "%xmm3" |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
void fill_hsla(float *dst, float h, float s, float l, float a, size_t count) |
| 98 |
{ |
| 99 |
ARCH_X86_ASM |
| 100 |
( |
| 101 |
FILL4_CORE |
| 102 |
: [dst] "+r" (dst), [count] "+r" (count) |
| 103 |
: [c0] "m" (h), [c1] "m" (s), [c2] "m" (l), [c3] "m" (a) |
| 104 |
: "cc", "memory", |
| 105 |
"%xmm0", "%xmm1", "%xmm2", "%xmm3" |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
#undef FILL4_CORE |
| 110 |
|
| 111 |
} /* namespace sse */ |
| 112 |
} /* namespace lsp */ |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
#endif /* PRIVATE_DSP_ARCH_X86_SSE_GRAPHICS_FILL_H_ */ |