| 1 |
/* |
| 2 |
* Copyright (C) 2022 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2022 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-dsp-lib |
| 6 |
* Created on: 27 июл. 2022 г. |
| 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_AVX_GRAPHICS_PIXELFMT_H_ |
| 23 |
#define PRIVATE_DSP_ARCH_X86_AVX_GRAPHICS_PIXELFMT_H_ |
| 24 |
|
| 25 |
#ifndef PRIVATE_DSP_ARCH_X86_AVX_IMPL |
| 26 |
#error "This header should not be included directly" |
| 27 |
#endif /* PRIVATE_DSP_ARCH_X86_AVX_IMPL */ |
| 28 |
|
| 29 |
namespace lsp |
| 30 |
{ |
| 31 |
namespace avx |
| 32 |
{ |
| 33 |
IF_ARCH_X86( |
| 34 |
static const uint32_t pabc32_set_alpha_const[] __lsp_aligned16 = |
| 35 |
{ |
| 36 |
LSP_DSP_VEC4(0x00ffffff) |
| 37 |
}; |
| 38 |
) |
| 39 |
|
| 40 |
void pabc32_set_alpha(void *dst, const void *src, uint8_t alpha, size_t count) |
| 41 |
{ |
| 42 |
IF_ARCH_X86( |
| 43 |
size_t off; |
| 44 |
uint32_t value = uint32_t(alpha) << 24; |
| 45 |
); |
| 46 |
|
| 47 |
ARCH_X86_ASM |
| 48 |
( |
| 49 |
__ASM_EMIT("vmovdqa %[MASK], %%xmm1") // xmm1 = 00 ff ff ff |
| 50 |
__ASM_EMIT("vpshufd $0x00, %%xmm0, %%xmm0") // xmm0 = vv vv vv vv |
| 51 |
__ASM_EMIT("xor %[off], %[off]") // off = 0 |
| 52 |
|
| 53 |
// 24-element blocks |
| 54 |
__ASM_EMIT("sub $24, %[count]") |
| 55 |
__ASM_EMIT("jb 2f") |
| 56 |
__ASM_EMIT("1:") |
| 57 |
__ASM_EMIT("vpand 0x00(%[src], %[off]), %%xmm1, %%xmm2") // xmm2 = 00 XX YY ZZ |
| 58 |
__ASM_EMIT("vpand 0x10(%[src], %[off]), %%xmm1, %%xmm3") |
| 59 |
__ASM_EMIT("vpand 0x20(%[src], %[off]), %%xmm1, %%xmm4") |
| 60 |
__ASM_EMIT("vpor %%xmm0, %%xmm2, %%xmm2") // xmm2 = VV XX YY ZZ |
| 61 |
__ASM_EMIT("vpand 0x30(%[src], %[off]), %%xmm1, %%xmm5") |
| 62 |
__ASM_EMIT("vpor %%xmm0, %%xmm3, %%xmm3") |
| 63 |
__ASM_EMIT("vpand 0x40(%[src], %[off]), %%xmm1, %%xmm6") |
| 64 |
__ASM_EMIT("vpor %%xmm0, %%xmm4, %%xmm4") |
| 65 |
__ASM_EMIT("vpand 0x50(%[src], %[off]), %%xmm1, %%xmm7") |
| 66 |
__ASM_EMIT("vmovdqu %%xmm2, 0x00(%[dst], %[off])") |
| 67 |
__ASM_EMIT("vpor %%xmm0, %%xmm5, %%xmm5") |
| 68 |
__ASM_EMIT("vmovdqu %%xmm3, 0x10(%[dst], %[off])") |
| 69 |
__ASM_EMIT("vpor %%xmm0, %%xmm6, %%xmm6") |
| 70 |
__ASM_EMIT("vmovdqu %%xmm4, 0x20(%[dst], %[off])") |
| 71 |
__ASM_EMIT("vpor %%xmm0, %%xmm7, %%xmm7") |
| 72 |
__ASM_EMIT("vmovdqu %%xmm5, 0x30(%[dst], %[off])") |
| 73 |
__ASM_EMIT("vmovdqu %%xmm6, 0x40(%[dst], %[off])") |
| 74 |
__ASM_EMIT("vmovdqu %%xmm7, 0x50(%[dst], %[off])") |
| 75 |
__ASM_EMIT("add $0x60, %[off]") |
| 76 |
__ASM_EMIT("sub $24, %[count]") |
| 77 |
__ASM_EMIT("jae 1b") |
| 78 |
|
| 79 |
// 16-element block |
| 80 |
__ASM_EMIT("2:") |
| 81 |
__ASM_EMIT("add $8, %[count]") |
| 82 |
__ASM_EMIT("jl 4f") |
| 83 |
__ASM_EMIT("vpand 0x00(%[src], %[off]), %%xmm1, %%xmm2") // xmm2 = 00 XX YY ZZ |
| 84 |
__ASM_EMIT("vpand 0x10(%[src], %[off]), %%xmm1, %%xmm3") |
| 85 |
__ASM_EMIT("vpand 0x20(%[src], %[off]), %%xmm1, %%xmm4") |
| 86 |
__ASM_EMIT("vpand 0x30(%[src], %[off]), %%xmm1, %%xmm5") |
| 87 |
__ASM_EMIT("vpor %%xmm0, %%xmm2, %%xmm2") // xmm2 = VV XX YY ZZ |
| 88 |
__ASM_EMIT("vpor %%xmm0, %%xmm3, %%xmm3") |
| 89 |
__ASM_EMIT("vpor %%xmm0, %%xmm4, %%xmm4") |
| 90 |
__ASM_EMIT("vpor %%xmm0, %%xmm5, %%xmm5") |
| 91 |
__ASM_EMIT("vmovdqu %%xmm2, 0x00(%[dst], %[off])") |
| 92 |
__ASM_EMIT("vmovdqu %%xmm3, 0x10(%[dst], %[off])") |
| 93 |
__ASM_EMIT("vmovdqu %%xmm4, 0x20(%[dst], %[off])") |
| 94 |
__ASM_EMIT("vmovdqu %%xmm5, 0x30(%[dst], %[off])") |
| 95 |
__ASM_EMIT("add $0x40, %[off]") |
| 96 |
__ASM_EMIT("sub $16, %[count]") |
| 97 |
|
| 98 |
// 8-element block |
| 99 |
__ASM_EMIT("4:") |
| 100 |
__ASM_EMIT("add $8, %[count]") |
| 101 |
__ASM_EMIT("jl 6f") |
| 102 |
__ASM_EMIT("vpand 0x00(%[src], %[off]), %%xmm1, %%xmm2") // xmm2 = 00 XX YY ZZ |
| 103 |
__ASM_EMIT("vpand 0x10(%[src], %[off]), %%xmm1, %%xmm3") |
| 104 |
__ASM_EMIT("vpor %%xmm0, %%xmm2, %%xmm2") // xmm2 = VV XX YY ZZ |
| 105 |
__ASM_EMIT("vpor %%xmm0, %%xmm3, %%xmm3") |
| 106 |
__ASM_EMIT("vmovdqu %%xmm2, 0x00(%[dst], %[off])") |
| 107 |
__ASM_EMIT("vmovdqu %%xmm3, 0x10(%[dst], %[off])") |
| 108 |
__ASM_EMIT("add $0x20, %[off]") |
| 109 |
__ASM_EMIT("sub $8, %[count]") |
| 110 |
|
| 111 |
// 4-element block |
| 112 |
__ASM_EMIT("6:") |
| 113 |
__ASM_EMIT("add $4, %[count]") |
| 114 |
__ASM_EMIT("jl 8f") |
| 115 |
__ASM_EMIT("vpand 0x00(%[src], %[off]), %%xmm1, %%xmm2") // xmm2 = 00 XX YY ZZ |
| 116 |
__ASM_EMIT("vpor %%xmm0, %%xmm2, %%xmm2") // xmm2 = VV XX YY ZZ |
| 117 |
__ASM_EMIT("vmovdqu %%xmm2, 0x00(%[dst], %[off])") |
| 118 |
__ASM_EMIT("add $0x10, %[off]") |
| 119 |
__ASM_EMIT("sub $4, %[count]") |
| 120 |
|
| 121 |
// Tail |
| 122 |
__ASM_EMIT("8:") |
| 123 |
__ASM_EMIT("add $3, %[count]") |
| 124 |
__ASM_EMIT("jl 10f") |
| 125 |
__ASM_EMIT("9:") |
| 126 |
__ASM_EMIT("vmovd 0x00(%[src], %[off]), %%xmm2") // xmm2 = AA XX YY ZZ |
| 127 |
__ASM_EMIT("vpand %%xmm1, %%xmm2, %%xmm2") // xmm2 = 00 XX YY ZZ |
| 128 |
__ASM_EMIT("vpor %%xmm0, %%xmm2, %%xmm2") // xmm2 = VV XX YY ZZ |
| 129 |
__ASM_EMIT("vmovd %%xmm2, 0x00(%[dst], %[off])") |
| 130 |
__ASM_EMIT("add $4, %[off]") |
| 131 |
__ASM_EMIT("dec %[count]") |
| 132 |
__ASM_EMIT("jge 9b") |
| 133 |
|
| 134 |
// End |
| 135 |
__ASM_EMIT("10:") |
| 136 |
|
| 137 |
: [dst] "+r"(dst), [src] "+r"(src), [count] "+r" (count), |
| 138 |
[off] "=&r" (off), [value] "+Yz" (value) |
| 139 |
: [MASK] "m" (pabc32_set_alpha_const) |
| 140 |
: "cc", "memory", |
| 141 |
"%xmm1", "%xmm2", "%xmm3", |
| 142 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 143 |
); |
| 144 |
} |
| 145 |
} /* namespace avx */ |
| 146 |
} /* namespace lsp */ |
| 147 |
|
| 148 |
#endif /* PRIVATE_DSP_ARCH_X86_AVX_GRAPHICS_PIXELFMT_H_ */ |