| 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_COPY_H_ |
| 23 |
#define PRIVATE_DSP_ARCH_X86_SSE_COPY_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 |
void copy(float *dst, const float *src, size_t count) |
| 34 |
{ |
| 35 |
IF_ARCH_X86(size_t off); |
| 36 |
|
| 37 |
ARCH_X86_ASM |
| 38 |
( |
| 39 |
__ASM_EMIT("cmp %[dst], %[src]") |
| 40 |
__ASM_EMIT("je 10f") |
| 41 |
|
| 42 |
/* Destination is aligned */ |
| 43 |
__ASM_EMIT("xor %[off], %[off]") |
| 44 |
__ASM_EMIT("sub $0x20, %[count]") |
| 45 |
__ASM_EMIT("jb 2f") |
| 46 |
|
| 47 |
/* Block of 32 items */ |
| 48 |
__ASM_EMIT("1:") |
| 49 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 50 |
__ASM_EMIT("movups 0x10(%[src], %[off]), %%xmm1") |
| 51 |
__ASM_EMIT("movups 0x20(%[src], %[off]), %%xmm2") |
| 52 |
__ASM_EMIT("movups 0x30(%[src], %[off]), %%xmm3") |
| 53 |
__ASM_EMIT("movups 0x40(%[src], %[off]), %%xmm4") |
| 54 |
__ASM_EMIT("movups 0x50(%[src], %[off]), %%xmm5") |
| 55 |
__ASM_EMIT("movups 0x60(%[src], %[off]), %%xmm6") |
| 56 |
__ASM_EMIT("movups 0x70(%[src], %[off]), %%xmm7") |
| 57 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst], %[off])") |
| 58 |
__ASM_EMIT("movups %%xmm1, 0x10(%[dst], %[off])") |
| 59 |
__ASM_EMIT("movups %%xmm2, 0x20(%[dst], %[off])") |
| 60 |
__ASM_EMIT("movups %%xmm3, 0x30(%[dst], %[off])") |
| 61 |
__ASM_EMIT("movups %%xmm4, 0x40(%[dst], %[off])") |
| 62 |
__ASM_EMIT("movups %%xmm5, 0x50(%[dst], %[off])") |
| 63 |
__ASM_EMIT("movups %%xmm6, 0x60(%[dst], %[off])") |
| 64 |
__ASM_EMIT("movups %%xmm7, 0x70(%[dst], %[off])") |
| 65 |
__ASM_EMIT("add $0x80, %[off]") |
| 66 |
__ASM_EMIT("sub $0x20, %[count]") |
| 67 |
__ASM_EMIT("jae 1b") |
| 68 |
/* Block of 16 items */ |
| 69 |
__ASM_EMIT("2:") |
| 70 |
__ASM_EMIT("add $0x10, %[count]") |
| 71 |
__ASM_EMIT("jl 4f") |
| 72 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 73 |
__ASM_EMIT("movups 0x10(%[src], %[off]), %%xmm1") |
| 74 |
__ASM_EMIT("movups 0x20(%[src], %[off]), %%xmm2") |
| 75 |
__ASM_EMIT("movups 0x30(%[src], %[off]), %%xmm3") |
| 76 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst], %[off])") |
| 77 |
__ASM_EMIT("movups %%xmm1, 0x10(%[dst], %[off])") |
| 78 |
__ASM_EMIT("movups %%xmm2, 0x20(%[dst], %[off])") |
| 79 |
__ASM_EMIT("movups %%xmm3, 0x30(%[dst], %[off])") |
| 80 |
__ASM_EMIT("add $0x40, %[off]") |
| 81 |
__ASM_EMIT("sub $0x10, %[count]") |
| 82 |
/* Block of 8 items */ |
| 83 |
__ASM_EMIT("4:") |
| 84 |
__ASM_EMIT("add $0x08, %[count]") |
| 85 |
__ASM_EMIT("jl 6f") |
| 86 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 87 |
__ASM_EMIT("movups 0x10(%[src], %[off]), %%xmm1") |
| 88 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst], %[off])") |
| 89 |
__ASM_EMIT("movups %%xmm1, 0x10(%[dst], %[off])") |
| 90 |
__ASM_EMIT("add $0x20, %[off]") |
| 91 |
__ASM_EMIT("sub $0x08, %[count]") |
| 92 |
/* Block of 4 items */ |
| 93 |
__ASM_EMIT("6:") |
| 94 |
__ASM_EMIT("add $0x04, %[count]") |
| 95 |
__ASM_EMIT("jl 8f") |
| 96 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 97 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst], %[off])") |
| 98 |
__ASM_EMIT("add $0x10, %[off]") |
| 99 |
__ASM_EMIT("sub $0x04, %[count]") |
| 100 |
/* 1x items */ |
| 101 |
__ASM_EMIT("8:") |
| 102 |
__ASM_EMIT("add $0x03, %[count]") |
| 103 |
__ASM_EMIT("jl 10f") |
| 104 |
__ASM_EMIT("9:") |
| 105 |
__ASM_EMIT("movss 0x00(%[src], %[off]), %%xmm0") |
| 106 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst], %[off])") |
| 107 |
__ASM_EMIT("add $0x04, %[off]") |
| 108 |
__ASM_EMIT("dec %[count]") |
| 109 |
__ASM_EMIT("jge 9b") |
| 110 |
|
| 111 |
__ASM_EMIT("10:") |
| 112 |
|
| 113 |
: [src] "+r" (src), [dst] "+r"(dst), |
| 114 |
[count] "+r" (count), [off] "=&r" (off) |
| 115 |
: |
| 116 |
: "cc", "memory", |
| 117 |
"%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 118 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
void copy_movntps(float *dst, const float *src, size_t count) |
| 123 |
{ |
| 124 |
IF_ARCH_X86(size_t off); |
| 125 |
|
| 126 |
ARCH_X86_ASM |
| 127 |
( |
| 128 |
__ASM_EMIT("cmp %[dst], %[src]") |
| 129 |
__ASM_EMIT("je 100f") |
| 130 |
__ASM_EMIT("test %[count], %[count]") |
| 131 |
__ASM_EMIT("jz 100f") |
| 132 |
|
| 133 |
/* Align destination */ |
| 134 |
__ASM_EMIT("test $0x0f, %[dst]") |
| 135 |
__ASM_EMIT("jz 2f") |
| 136 |
__ASM_EMIT("1:") |
| 137 |
__ASM_EMIT("movss (%[src]), %%xmm0") |
| 138 |
__ASM_EMIT("movss %%xmm0, (%[dst])") |
| 139 |
__ASM_EMIT("add $4, %[src]") |
| 140 |
__ASM_EMIT("add $4, %[dst]") |
| 141 |
__ASM_EMIT("dec %[count]") |
| 142 |
__ASM_EMIT("jz 100f") |
| 143 |
__ASM_EMIT("test $0x0f, %[dst]") |
| 144 |
__ASM_EMIT("jnz 1b") |
| 145 |
|
| 146 |
/* Block of 32 items */ |
| 147 |
__ASM_EMIT("2:") |
| 148 |
__ASM_EMIT("xor %[off], %[off]") |
| 149 |
__ASM_EMIT("sub $0x20, %[count]") |
| 150 |
__ASM_EMIT("jb 4f") |
| 151 |
|
| 152 |
__ASM_EMIT("3:") |
| 153 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 154 |
__ASM_EMIT("movups 0x10(%[src], %[off]), %%xmm1") |
| 155 |
__ASM_EMIT("movups 0x20(%[src], %[off]), %%xmm2") |
| 156 |
__ASM_EMIT("movups 0x30(%[src], %[off]), %%xmm3") |
| 157 |
__ASM_EMIT("movups 0x40(%[src], %[off]), %%xmm4") |
| 158 |
__ASM_EMIT("movups 0x50(%[src], %[off]), %%xmm5") |
| 159 |
__ASM_EMIT("movups 0x60(%[src], %[off]), %%xmm6") |
| 160 |
__ASM_EMIT("movups 0x70(%[src], %[off]), %%xmm7") |
| 161 |
__ASM_EMIT("movntps %%xmm0, 0x00(%[dst], %[off])") |
| 162 |
__ASM_EMIT("movntps %%xmm1, 0x10(%[dst], %[off])") |
| 163 |
__ASM_EMIT("movntps %%xmm2, 0x20(%[dst], %[off])") |
| 164 |
__ASM_EMIT("movntps %%xmm3, 0x30(%[dst], %[off])") |
| 165 |
__ASM_EMIT("movntps %%xmm4, 0x40(%[dst], %[off])") |
| 166 |
__ASM_EMIT("movntps %%xmm5, 0x50(%[dst], %[off])") |
| 167 |
__ASM_EMIT("movntps %%xmm6, 0x60(%[dst], %[off])") |
| 168 |
__ASM_EMIT("movntps %%xmm7, 0x70(%[dst], %[off])") |
| 169 |
__ASM_EMIT("add $0x80, %[off]") |
| 170 |
__ASM_EMIT("sub $0x20, %[count]") |
| 171 |
__ASM_EMIT("jae 3b") |
| 172 |
|
| 173 |
/* Block of 16 items */ |
| 174 |
__ASM_EMIT("4:") |
| 175 |
__ASM_EMIT("add $0x10, %[count]") |
| 176 |
__ASM_EMIT("jl 6f") |
| 177 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 178 |
__ASM_EMIT("movups 0x10(%[src], %[off]), %%xmm1") |
| 179 |
__ASM_EMIT("movups 0x20(%[src], %[off]), %%xmm2") |
| 180 |
__ASM_EMIT("movups 0x30(%[src], %[off]), %%xmm3") |
| 181 |
__ASM_EMIT("movntps %%xmm0, 0x00(%[dst], %[off])") |
| 182 |
__ASM_EMIT("movntps %%xmm1, 0x10(%[dst], %[off])") |
| 183 |
__ASM_EMIT("movntps %%xmm2, 0x20(%[dst], %[off])") |
| 184 |
__ASM_EMIT("movntps %%xmm3, 0x30(%[dst], %[off])") |
| 185 |
__ASM_EMIT("add $0x40, %[off]") |
| 186 |
__ASM_EMIT("sub $0x10, %[count]") |
| 187 |
/* Block of 8 items */ |
| 188 |
__ASM_EMIT("6:") |
| 189 |
__ASM_EMIT("add $0x08, %[count]") |
| 190 |
__ASM_EMIT("jl 8f") |
| 191 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 192 |
__ASM_EMIT("movups 0x10(%[src], %[off]), %%xmm1") |
| 193 |
__ASM_EMIT("movntps %%xmm0, 0x00(%[dst], %[off])") |
| 194 |
__ASM_EMIT("movntps %%xmm1, 0x10(%[dst], %[off])") |
| 195 |
__ASM_EMIT("add $0x20, %[off]") |
| 196 |
__ASM_EMIT("sub $0x08, %[count]") |
| 197 |
/* Block of 4 items */ |
| 198 |
__ASM_EMIT("8:") |
| 199 |
__ASM_EMIT("add $0x04, %[count]") |
| 200 |
__ASM_EMIT("jl 10f") |
| 201 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 202 |
__ASM_EMIT("movntps %%xmm0, 0x00(%[dst], %[off])") |
| 203 |
__ASM_EMIT("add $0x10, %[off]") |
| 204 |
__ASM_EMIT("sub $0x04, %[count]") |
| 205 |
/* 1x items */ |
| 206 |
__ASM_EMIT("10:") |
| 207 |
__ASM_EMIT("add $0x03, %[count]") |
| 208 |
__ASM_EMIT("jl 12f") |
| 209 |
__ASM_EMIT("9:") |
| 210 |
__ASM_EMIT("movss 0x00(%[src], %[off]), %%xmm0") |
| 211 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst], %[off])") |
| 212 |
__ASM_EMIT("add $0x04, %[off]") |
| 213 |
__ASM_EMIT("dec %[count]") |
| 214 |
__ASM_EMIT("jge 9b") |
| 215 |
|
| 216 |
__ASM_EMIT("12:") |
| 217 |
__ASM_EMIT("sfence") |
| 218 |
|
| 219 |
__ASM_EMIT("100:") |
| 220 |
|
| 221 |
: [src] "+r" (src), [dst] "+r"(dst), |
| 222 |
[count] "+r" (count), [off] "=&r" (off) |
| 223 |
: |
| 224 |
: "cc", "memory", |
| 225 |
"%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 226 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 227 |
); |
| 228 |
} |
| 229 |
|
| 230 |
void copy_backward(float *dst, const float *src, size_t count) |
| 231 |
{ |
| 232 |
IF_ARCH_X86(size_t off); |
| 233 |
|
| 234 |
ARCH_X86_ASM |
| 235 |
( |
| 236 |
__ASM_EMIT("cmp %[dst], %[src]") |
| 237 |
__ASM_EMIT("je 10f") |
| 238 |
|
| 239 |
__ASM_EMIT("lea (,%[count], 4), %[off]") |
| 240 |
__ASM_EMIT("sub $0x20, %[count]") |
| 241 |
__ASM_EMIT("jb 2f") |
| 242 |
|
| 243 |
/* Block of 32 items */ |
| 244 |
__ASM_EMIT("1:") |
| 245 |
__ASM_EMIT("sub $0x80, %[off]") |
| 246 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 247 |
__ASM_EMIT("movups 0x10(%[src], %[off]), %%xmm1") |
| 248 |
__ASM_EMIT("movups 0x20(%[src], %[off]), %%xmm2") |
| 249 |
__ASM_EMIT("movups 0x30(%[src], %[off]), %%xmm3") |
| 250 |
__ASM_EMIT("movups 0x40(%[src], %[off]), %%xmm4") |
| 251 |
__ASM_EMIT("movups 0x50(%[src], %[off]), %%xmm5") |
| 252 |
__ASM_EMIT("movups 0x60(%[src], %[off]), %%xmm6") |
| 253 |
__ASM_EMIT("movups 0x70(%[src], %[off]), %%xmm7") |
| 254 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst], %[off])") |
| 255 |
__ASM_EMIT("movups %%xmm1, 0x10(%[dst], %[off])") |
| 256 |
__ASM_EMIT("movups %%xmm2, 0x20(%[dst], %[off])") |
| 257 |
__ASM_EMIT("movups %%xmm3, 0x30(%[dst], %[off])") |
| 258 |
__ASM_EMIT("movups %%xmm4, 0x40(%[dst], %[off])") |
| 259 |
__ASM_EMIT("movups %%xmm5, 0x50(%[dst], %[off])") |
| 260 |
__ASM_EMIT("movups %%xmm6, 0x60(%[dst], %[off])") |
| 261 |
__ASM_EMIT("movups %%xmm7, 0x70(%[dst], %[off])") |
| 262 |
__ASM_EMIT("sub $0x20, %[count]") |
| 263 |
__ASM_EMIT("jae 1b") |
| 264 |
/* Block of 16 items */ |
| 265 |
__ASM_EMIT("2:") |
| 266 |
__ASM_EMIT("add $0x10, %[count]") |
| 267 |
__ASM_EMIT("jl 4f") |
| 268 |
__ASM_EMIT("sub $0x40, %[off]") |
| 269 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 270 |
__ASM_EMIT("movups 0x10(%[src], %[off]), %%xmm1") |
| 271 |
__ASM_EMIT("movups 0x20(%[src], %[off]), %%xmm2") |
| 272 |
__ASM_EMIT("movups 0x30(%[src], %[off]), %%xmm3") |
| 273 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst], %[off])") |
| 274 |
__ASM_EMIT("movups %%xmm1, 0x10(%[dst], %[off])") |
| 275 |
__ASM_EMIT("movups %%xmm2, 0x20(%[dst], %[off])") |
| 276 |
__ASM_EMIT("movups %%xmm3, 0x30(%[dst], %[off])") |
| 277 |
__ASM_EMIT("sub $0x10, %[count]") |
| 278 |
/* Block of 8 items */ |
| 279 |
__ASM_EMIT("4:") |
| 280 |
__ASM_EMIT("add $0x08, %[count]") |
| 281 |
__ASM_EMIT("jl 6f") |
| 282 |
__ASM_EMIT("sub $0x20, %[off]") |
| 283 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 284 |
__ASM_EMIT("movups 0x10(%[src], %[off]), %%xmm1") |
| 285 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst], %[off])") |
| 286 |
__ASM_EMIT("movups %%xmm1, 0x10(%[dst], %[off])") |
| 287 |
__ASM_EMIT("sub $0x08, %[count]") |
| 288 |
/* Block of 4 items */ |
| 289 |
__ASM_EMIT("6:") |
| 290 |
__ASM_EMIT("add $0x04, %[count]") |
| 291 |
__ASM_EMIT("jl 8f") |
| 292 |
__ASM_EMIT("sub $0x10, %[off]") |
| 293 |
__ASM_EMIT("movups 0x00(%[src], %[off]), %%xmm0") |
| 294 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst], %[off])") |
| 295 |
__ASM_EMIT("sub $0x04, %[count]") |
| 296 |
/* 1x items */ |
| 297 |
__ASM_EMIT("8:") |
| 298 |
__ASM_EMIT("add $0x03, %[count]") |
| 299 |
__ASM_EMIT("jl 10f") |
| 300 |
__ASM_EMIT("9:") |
| 301 |
__ASM_EMIT("sub $0x04, %[off]") |
| 302 |
__ASM_EMIT("movss 0x00(%[src], %[off]), %%xmm0") |
| 303 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst], %[off])") |
| 304 |
__ASM_EMIT("dec %[count]") |
| 305 |
__ASM_EMIT("jge 9b") |
| 306 |
|
| 307 |
__ASM_EMIT("10:") |
| 308 |
|
| 309 |
: [src] "+r" (src), [dst] "+r"(dst), |
| 310 |
[count] "+r" (count), [off] "=&r" (off) |
| 311 |
: |
| 312 |
: "cc", "memory", |
| 313 |
"%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 314 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 315 |
); |
| 316 |
} |
| 317 |
|
| 318 |
void move(float *dst, const float *src, size_t count) |
| 319 |
{ |
| 320 |
if (dst < src) |
| 321 |
sse::copy(dst, src, count); |
| 322 |
else if (dst > src) |
| 323 |
sse::copy_backward(dst, src, count); |
| 324 |
} |
| 325 |
|
| 326 |
void fill(float *dst, float value, size_t count) |
| 327 |
{ |
| 328 |
#define FILL_CORE \ |
| 329 |
/* Blocks of 32 items */ \ |
| 330 |
__ASM_EMIT("sub $0x20, %[count]") \ |
| 331 |
__ASM_EMIT("jb 4f") \ |
| 332 |
__ASM_EMIT("movaps %%xmm0, %%xmm4") \ |
| 333 |
__ASM_EMIT("movaps %%xmm1, %%xmm5") \ |
| 334 |
__ASM_EMIT("movaps %%xmm2, %%xmm6") \ |
| 335 |
__ASM_EMIT("movaps %%xmm3, %%xmm7") \ |
| 336 |
__ASM_EMIT("3:") \ |
| 337 |
__ASM_EMIT("movaps %%xmm0, 0x00(%[dst])") \ |
| 338 |
__ASM_EMIT("movaps %%xmm1, 0x10(%[dst])") \ |
| 339 |
__ASM_EMIT("movaps %%xmm2, 0x20(%[dst])") \ |
| 340 |
__ASM_EMIT("movaps %%xmm3, 0x30(%[dst])") \ |
| 341 |
__ASM_EMIT("movaps %%xmm4, 0x40(%[dst])") \ |
| 342 |
__ASM_EMIT("movaps %%xmm5, 0x50(%[dst])") \ |
| 343 |
__ASM_EMIT("movaps %%xmm6, 0x60(%[dst])") \ |
| 344 |
__ASM_EMIT("movaps %%xmm7, 0x70(%[dst])") \ |
| 345 |
__ASM_EMIT("add $0x80, %[dst]") \ |
| 346 |
__ASM_EMIT("sub $0x20, %[count]") \ |
| 347 |
__ASM_EMIT("jae 3b") \ |
| 348 |
/* Blocks of 16 items */ \ |
| 349 |
__ASM_EMIT("4:") \ |
| 350 |
__ASM_EMIT("add $0x20, %[count]") \ |
| 351 |
__ASM_EMIT("test $0x10, %[count]") \ |
| 352 |
__ASM_EMIT("jz 5f") \ |
| 353 |
__ASM_EMIT("movaps %%xmm0, 0x00(%[dst])") \ |
| 354 |
__ASM_EMIT("movaps %%xmm1, 0x10(%[dst])") \ |
| 355 |
__ASM_EMIT("movaps %%xmm2, 0x20(%[dst])") \ |
| 356 |
__ASM_EMIT("movaps %%xmm3, 0x30(%[dst])") \ |
| 357 |
__ASM_EMIT("add $0x40, %[dst]") \ |
| 358 |
/* Blocks of 8 items */ \ |
| 359 |
__ASM_EMIT("5:") \ |
| 360 |
__ASM_EMIT("test $0x08, %[count]") \ |
| 361 |
__ASM_EMIT("jz 6f") \ |
| 362 |
__ASM_EMIT("movaps %%xmm0, 0x00(%[dst])") \ |
| 363 |
__ASM_EMIT("movaps %%xmm1, 0x10(%[dst])") \ |
| 364 |
__ASM_EMIT("add $0x20, %[dst]") \ |
| 365 |
/* Blocks of 4 items */ \ |
| 366 |
__ASM_EMIT("6:") \ |
| 367 |
__ASM_EMIT("test $0x04, %[count]") \ |
| 368 |
__ASM_EMIT("jz 7f") \ |
| 369 |
__ASM_EMIT("movaps %%xmm0, 0x00(%[dst])") \ |
| 370 |
__ASM_EMIT("add $0x10, %[dst]") \ |
| 371 |
/* Tail */ \ |
| 372 |
__ASM_EMIT("7:") \ |
| 373 |
__ASM_EMIT("and $0x03, %[count]") \ |
| 374 |
__ASM_EMIT("jz 2000f") \ |
| 375 |
__ASM_EMIT("8:") \ |
| 376 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst])") \ |
| 377 |
__ASM_EMIT("add $0x04, %[dst]") \ |
| 378 |
__ASM_EMIT("dec %[count]") \ |
| 379 |
__ASM_EMIT("jnz 8b") |
| 380 |
|
| 381 |
ARCH_X86_ASM |
| 382 |
( |
| 383 |
__ASM_EMIT("test %[count], %[count]") |
| 384 |
__ASM_EMIT("jz 2000f") |
| 385 |
__ASM_EMIT("shufps $0x00, %%xmm0, %%xmm0") |
| 386 |
|
| 387 |
/* Align destination */ |
| 388 |
__ASM_EMIT("1:") |
| 389 |
__ASM_EMIT("test $0x0f, %[dst]") |
| 390 |
__ASM_EMIT("jz 2f") |
| 391 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst])") |
| 392 |
__ASM_EMIT("add $0x4, %[dst]") |
| 393 |
__ASM_EMIT("dec %[count]") |
| 394 |
__ASM_EMIT("jnz 1b") |
| 395 |
__ASM_EMIT("jmp 2000f") |
| 396 |
|
| 397 |
__ASM_EMIT("2:") |
| 398 |
__ASM_EMIT("movaps %%xmm0, %%xmm1") |
| 399 |
__ASM_EMIT("movaps %%xmm0, %%xmm2") |
| 400 |
__ASM_EMIT("movaps %%xmm1, %%xmm3") |
| 401 |
|
| 402 |
/* Destination is aligned */ |
| 403 |
FILL_CORE |
| 404 |
|
| 405 |
__ASM_EMIT("2000:") |
| 406 |
|
| 407 |
: [dst] "+r"(dst), [count] "+r" (count), "+Yz"(value) : |
| 408 |
: "cc", "memory", |
| 409 |
"%xmm1", "%xmm2", "%xmm3", |
| 410 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 411 |
); |
| 412 |
|
| 413 |
#undef FILL_CORE |
| 414 |
} |
| 415 |
|
| 416 |
void fill_zero(float *dst, size_t count) |
| 417 |
{ |
| 418 |
fill(dst, 0.0f, count); |
| 419 |
} |
| 420 |
|
| 421 |
void fill_one(float *dst, size_t count) |
| 422 |
{ |
| 423 |
fill(dst, 1.0f, count); |
| 424 |
} |
| 425 |
|
| 426 |
void fill_minus_one(float *dst, size_t count) |
| 427 |
{ |
| 428 |
fill(dst, -1.0f, count); |
| 429 |
} |
| 430 |
|
| 431 |
#define REVERSE1_CORE(MV_TAIL) \ |
| 432 |
__ASM_EMIT("sub $0x10, %[count]") \ |
| 433 |
__ASM_EMIT("jb 4f") \ |
| 434 |
/* x16 blocks */ \ |
| 435 |
__ASM_EMIT("3:") \ |
| 436 |
__ASM_EMIT("sub $0x40, %[tail]") \ |
| 437 |
__ASM_EMIT("movaps 0x00(%[head]), %%xmm3") \ |
| 438 |
__ASM_EMIT("movaps 0x10(%[head]), %%xmm2") \ |
| 439 |
__ASM_EMIT("movaps 0x20(%[head]), %%xmm1") \ |
| 440 |
__ASM_EMIT("movaps 0x30(%[head]), %%xmm0") \ |
| 441 |
__ASM_EMIT(MV_TAIL " 0x00(%[tail]), %%xmm7") \ |
| 442 |
__ASM_EMIT(MV_TAIL " 0x10(%[tail]), %%xmm6") \ |
| 443 |
__ASM_EMIT(MV_TAIL " 0x20(%[tail]), %%xmm5") \ |
| 444 |
__ASM_EMIT(MV_TAIL " 0x30(%[tail]), %%xmm4") \ |
| 445 |
__ASM_EMIT("shufps $0x1b, %%xmm0, %%xmm0") \ |
| 446 |
__ASM_EMIT("shufps $0x1b, %%xmm1, %%xmm1") \ |
| 447 |
__ASM_EMIT("shufps $0x1b, %%xmm2, %%xmm2") \ |
| 448 |
__ASM_EMIT("shufps $0x1b, %%xmm3, %%xmm3") \ |
| 449 |
__ASM_EMIT("shufps $0x1b, %%xmm4, %%xmm4") \ |
| 450 |
__ASM_EMIT("shufps $0x1b, %%xmm5, %%xmm5") \ |
| 451 |
__ASM_EMIT("shufps $0x1b, %%xmm6, %%xmm6") \ |
| 452 |
__ASM_EMIT("shufps $0x1b, %%xmm7, %%xmm7") \ |
| 453 |
__ASM_EMIT("movaps %%xmm4, 0x00(%[head])") \ |
| 454 |
__ASM_EMIT("movaps %%xmm5, 0x10(%[head])") \ |
| 455 |
__ASM_EMIT("movaps %%xmm6, 0x20(%[head])") \ |
| 456 |
__ASM_EMIT("movaps %%xmm7, 0x30(%[head])") \ |
| 457 |
__ASM_EMIT(MV_TAIL " %%xmm0, 0x00(%[tail])") \ |
| 458 |
__ASM_EMIT(MV_TAIL " %%xmm1, 0x10(%[tail])") \ |
| 459 |
__ASM_EMIT(MV_TAIL " %%xmm2, 0x20(%[tail])") \ |
| 460 |
__ASM_EMIT(MV_TAIL " %%xmm3, 0x30(%[tail])") \ |
| 461 |
__ASM_EMIT("add $0x40, %[head]") \ |
| 462 |
__ASM_EMIT("sub $0x10, %[count]") \ |
| 463 |
__ASM_EMIT("jae 3b") \ |
| 464 |
/* x8 block */ \ |
| 465 |
__ASM_EMIT("4:") \ |
| 466 |
__ASM_EMIT("add $0x10, %[count]") \ |
| 467 |
__ASM_EMIT("test $0x08, %[count]") \ |
| 468 |
__ASM_EMIT("jz 5f") \ |
| 469 |
__ASM_EMIT("sub $0x20, %[tail]") \ |
| 470 |
__ASM_EMIT("movaps 0x00(%[head]), %%xmm1") \ |
| 471 |
__ASM_EMIT("movaps 0x10(%[head]), %%xmm0") \ |
| 472 |
__ASM_EMIT(MV_TAIL " 0x00(%[tail]), %%xmm3") \ |
| 473 |
__ASM_EMIT(MV_TAIL " 0x10(%[tail]), %%xmm2") \ |
| 474 |
__ASM_EMIT("shufps $0x1b, %%xmm0, %%xmm0") \ |
| 475 |
__ASM_EMIT("shufps $0x1b, %%xmm1, %%xmm1") \ |
| 476 |
__ASM_EMIT("shufps $0x1b, %%xmm2, %%xmm2") \ |
| 477 |
__ASM_EMIT("shufps $0x1b, %%xmm3, %%xmm3") \ |
| 478 |
__ASM_EMIT("movaps %%xmm2, 0x00(%[head])") \ |
| 479 |
__ASM_EMIT("movaps %%xmm3, 0x10(%[head])") \ |
| 480 |
__ASM_EMIT(MV_TAIL " %%xmm0, 0x00(%[tail])") \ |
| 481 |
__ASM_EMIT(MV_TAIL " %%xmm1, 0x10(%[tail])") \ |
| 482 |
__ASM_EMIT("add $0x20, %[head]") \ |
| 483 |
/* x4 block */ \ |
| 484 |
__ASM_EMIT("5:") \ |
| 485 |
__ASM_EMIT("test $0x04, %[count]") \ |
| 486 |
__ASM_EMIT("jz 3000f") \ |
| 487 |
__ASM_EMIT("sub $0x10, %[tail]") \ |
| 488 |
__ASM_EMIT("movaps 0x00(%[head]), %%xmm0") \ |
| 489 |
__ASM_EMIT(MV_TAIL " 0x00(%[tail]), %%xmm1") \ |
| 490 |
__ASM_EMIT("shufps $0x1b, %%xmm0, %%xmm0") \ |
| 491 |
__ASM_EMIT("shufps $0x1b, %%xmm1, %%xmm1") \ |
| 492 |
__ASM_EMIT("movaps %%xmm1, 0x00(%[head])") \ |
| 493 |
__ASM_EMIT(MV_TAIL " %%xmm0, 0x00(%[tail])") \ |
| 494 |
__ASM_EMIT("add $0x10, %[head]") |
| 495 |
|
| 496 |
void reverse1(float *dst, size_t count) |
| 497 |
{ |
| 498 |
const float *src; |
| 499 |
|
| 500 |
ARCH_X86_ASM |
| 501 |
( |
| 502 |
__ASM_EMIT("lea (%[head], %[count], 4), %[tail]") |
| 503 |
__ASM_EMIT("shr $1, %[count]") |
| 504 |
__ASM_EMIT("jz 2000f") |
| 505 |
|
| 506 |
// Align head |
| 507 |
__ASM_EMIT("1:") |
| 508 |
__ASM_EMIT("test $0x0f, %[head]") |
| 509 |
__ASM_EMIT("jz 2f") |
| 510 |
__ASM_EMIT("sub $0x04, %[tail]") |
| 511 |
__ASM_EMIT("movss 0x00(%[head]), %%xmm0") |
| 512 |
__ASM_EMIT("movss 0x00(%[tail]), %%xmm1") |
| 513 |
__ASM_EMIT("movss %%xmm1, 0x00(%[head])") |
| 514 |
__ASM_EMIT("movss %%xmm0, 0x00(%[tail])") |
| 515 |
__ASM_EMIT("add $0x04, %[head]") |
| 516 |
__ASM_EMIT("dec %[count]") |
| 517 |
__ASM_EMIT("jnz 1b") |
| 518 |
__ASM_EMIT("jmp 2000f") |
| 519 |
|
| 520 |
// Block operation |
| 521 |
__ASM_EMIT("2:") |
| 522 |
__ASM_EMIT("test $0x0f, %[tail]") |
| 523 |
__ASM_EMIT("jnz 1001f") |
| 524 |
REVERSE1_CORE("movaps") |
| 525 |
__ASM_EMIT("jmp 3000f") |
| 526 |
__ASM_EMIT("1001:") |
| 527 |
REVERSE1_CORE("movups") |
| 528 |
|
| 529 |
/* x1 blocks */ |
| 530 |
__ASM_EMIT("3000:") |
| 531 |
__ASM_EMIT("and $0x03, %[count]") |
| 532 |
__ASM_EMIT("jz 2000f") |
| 533 |
__ASM_EMIT("7:") |
| 534 |
__ASM_EMIT("sub $0x04, %[tail]") |
| 535 |
__ASM_EMIT("movss 0x00(%[head]), %%xmm0") |
| 536 |
__ASM_EMIT("movss 0x00(%[tail]), %%xmm1") |
| 537 |
__ASM_EMIT("movss %%xmm1, 0x00(%[head])") |
| 538 |
__ASM_EMIT("movss %%xmm0, 0x00(%[tail])") |
| 539 |
__ASM_EMIT("add $0x04, %[head]") |
| 540 |
__ASM_EMIT("dec %[count]") |
| 541 |
__ASM_EMIT("jnz 7b") |
| 542 |
|
| 543 |
__ASM_EMIT("2000:") |
| 544 |
|
| 545 |
: [head] "+r" (dst), [tail] "=&r" (src), [count] "+r" (count) |
| 546 |
: |
| 547 |
: "cc", "memory", |
| 548 |
"%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 549 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 550 |
); |
| 551 |
} |
| 552 |
|
| 553 |
#undef REVERSE1_CORE |
| 554 |
|
| 555 |
#define REVERSE2_CORE(MV_TAIL) \ |
| 556 |
__ASM_EMIT("sub $0x20, %[count]") \ |
| 557 |
__ASM_EMIT("jb 4f") \ |
| 558 |
/* x32 blocks */ \ |
| 559 |
__ASM_EMIT("3:") \ |
| 560 |
__ASM_EMIT(MV_TAIL " -0x80(%[tail]), %%xmm7") \ |
| 561 |
__ASM_EMIT(MV_TAIL " -0x70(%[tail]), %%xmm6") \ |
| 562 |
__ASM_EMIT(MV_TAIL " -0x60(%[tail]), %%xmm5") \ |
| 563 |
__ASM_EMIT(MV_TAIL " -0x50(%[tail]), %%xmm4") \ |
| 564 |
__ASM_EMIT(MV_TAIL " -0x40(%[tail]), %%xmm3") \ |
| 565 |
__ASM_EMIT(MV_TAIL " -0x30(%[tail]), %%xmm2") \ |
| 566 |
__ASM_EMIT(MV_TAIL " -0x20(%[tail]), %%xmm1") \ |
| 567 |
__ASM_EMIT(MV_TAIL " -0x10(%[tail]), %%xmm0") \ |
| 568 |
__ASM_EMIT("shufps $0x1b, %%xmm4, %%xmm4") \ |
| 569 |
__ASM_EMIT("shufps $0x1b, %%xmm5, %%xmm5") \ |
| 570 |
__ASM_EMIT("shufps $0x1b, %%xmm6, %%xmm6") \ |
| 571 |
__ASM_EMIT("shufps $0x1b, %%xmm7, %%xmm7") \ |
| 572 |
__ASM_EMIT("shufps $0x1b, %%xmm0, %%xmm0") \ |
| 573 |
__ASM_EMIT("shufps $0x1b, %%xmm1, %%xmm1") \ |
| 574 |
__ASM_EMIT("shufps $0x1b, %%xmm2, %%xmm2") \ |
| 575 |
__ASM_EMIT("shufps $0x1b, %%xmm3, %%xmm3") \ |
| 576 |
__ASM_EMIT("movaps %%xmm0, 0x00(%[head])") \ |
| 577 |
__ASM_EMIT("movaps %%xmm1, 0x10(%[head])") \ |
| 578 |
__ASM_EMIT("movaps %%xmm2, 0x20(%[head])") \ |
| 579 |
__ASM_EMIT("movaps %%xmm3, 0x30(%[head])") \ |
| 580 |
__ASM_EMIT("movaps %%xmm4, 0x40(%[head])") \ |
| 581 |
__ASM_EMIT("movaps %%xmm5, 0x50(%[head])") \ |
| 582 |
__ASM_EMIT("movaps %%xmm6, 0x60(%[head])") \ |
| 583 |
__ASM_EMIT("movaps %%xmm7, 0x70(%[head])") \ |
| 584 |
__ASM_EMIT("sub $0x80, %[tail]") \ |
| 585 |
__ASM_EMIT("add $0x80, %[head]") \ |
| 586 |
__ASM_EMIT("sub $0x20, %[count]") \ |
| 587 |
__ASM_EMIT("jae 3b") \ |
| 588 |
/* x16 block */ \ |
| 589 |
__ASM_EMIT("4:") \ |
| 590 |
__ASM_EMIT("add $0x20, %[count]") \ |
| 591 |
__ASM_EMIT("test $0x10, %[count]") \ |
| 592 |
__ASM_EMIT("jz 5f") \ |
| 593 |
__ASM_EMIT(MV_TAIL " -0x40(%[tail]), %%xmm3") \ |
| 594 |
__ASM_EMIT(MV_TAIL " -0x30(%[tail]), %%xmm2") \ |
| 595 |
__ASM_EMIT(MV_TAIL " -0x20(%[tail]), %%xmm1") \ |
| 596 |
__ASM_EMIT(MV_TAIL " -0x10(%[tail]), %%xmm0") \ |
| 597 |
__ASM_EMIT("shufps $0x1b, %%xmm2, %%xmm2") \ |
| 598 |
__ASM_EMIT("shufps $0x1b, %%xmm3, %%xmm3") \ |
| 599 |
__ASM_EMIT("shufps $0x1b, %%xmm0, %%xmm0") \ |
| 600 |
__ASM_EMIT("shufps $0x1b, %%xmm1, %%xmm1") \ |
| 601 |
__ASM_EMIT("movaps %%xmm0, 0x00(%[head])") \ |
| 602 |
__ASM_EMIT("movaps %%xmm1, 0x10(%[head])") \ |
| 603 |
__ASM_EMIT("movaps %%xmm2, 0x20(%[head])") \ |
| 604 |
__ASM_EMIT("movaps %%xmm3, 0x30(%[head])") \ |
| 605 |
__ASM_EMIT("sub $0x40, %[tail]") \ |
| 606 |
__ASM_EMIT("add $0x40, %[head]") \ |
| 607 |
/* x8 block */ \ |
| 608 |
__ASM_EMIT("5:") \ |
| 609 |
__ASM_EMIT("test $0x08, %[count]") \ |
| 610 |
__ASM_EMIT("jz 6f") \ |
| 611 |
__ASM_EMIT(MV_TAIL " -0x20(%[tail]), %%xmm1") \ |
| 612 |
__ASM_EMIT(MV_TAIL " -0x10(%[tail]), %%xmm0") \ |
| 613 |
__ASM_EMIT("shufps $0x1b, %%xmm1, %%xmm1") \ |
| 614 |
__ASM_EMIT("shufps $0x1b, %%xmm0, %%xmm0") \ |
| 615 |
__ASM_EMIT("movaps %%xmm0, 0x00(%[head])") \ |
| 616 |
__ASM_EMIT("movaps %%xmm1, 0x10(%[head])") \ |
| 617 |
__ASM_EMIT("sub $0x20, %[tail]") \ |
| 618 |
__ASM_EMIT("add $0x20, %[head]") \ |
| 619 |
/* x4 block */ \ |
| 620 |
__ASM_EMIT("6:") \ |
| 621 |
__ASM_EMIT("test $0x04, %[count]") \ |
| 622 |
__ASM_EMIT("jz 3000f") \ |
| 623 |
__ASM_EMIT(MV_TAIL " -0x10(%[tail]), %%xmm0") \ |
| 624 |
__ASM_EMIT("shufps $0x1b, %%xmm0, %%xmm0") \ |
| 625 |
__ASM_EMIT("movaps %%xmm0, 0x00(%[head])") \ |
| 626 |
__ASM_EMIT("sub $0x10, %[tail]") \ |
| 627 |
__ASM_EMIT("add $0x10, %[head]") |
| 628 |
|
| 629 |
void reverse2(float *dst, const float *src, size_t count) |
| 630 |
{ |
| 631 |
if (dst == src) |
| 632 |
{ |
| 633 |
reverse1(dst, count); |
| 634 |
return; |
| 635 |
} |
| 636 |
|
| 637 |
ARCH_X86_ASM |
| 638 |
( |
| 639 |
__ASM_EMIT("test %[count], %[count]") |
| 640 |
__ASM_EMIT("jz 2000f") |
| 641 |
|
| 642 |
__ASM_EMIT("lea (%[tail], %[count], 4), %[tail]") |
| 643 |
|
| 644 |
// Align head |
| 645 |
__ASM_EMIT("1:") |
| 646 |
__ASM_EMIT("test $0x0f, %[head]") |
| 647 |
__ASM_EMIT("jz 2f") |
| 648 |
__ASM_EMIT("sub $0x04, %[tail]") |
| 649 |
__ASM_EMIT("movss 0x00(%[tail]), %%xmm0") |
| 650 |
__ASM_EMIT("movss %%xmm0, 0x00(%[head])") |
| 651 |
__ASM_EMIT("add $0x04, %[head]") |
| 652 |
__ASM_EMIT("dec %[count]") |
| 653 |
__ASM_EMIT("jnz 1b") |
| 654 |
__ASM_EMIT("jmp 2000f") |
| 655 |
|
| 656 |
// Block operation |
| 657 |
__ASM_EMIT("2:") |
| 658 |
__ASM_EMIT("test $0x0f, %[tail]") |
| 659 |
__ASM_EMIT("jnz 1001f") |
| 660 |
REVERSE2_CORE("movaps") |
| 661 |
__ASM_EMIT("jmp 3000f") |
| 662 |
__ASM_EMIT("1001:") |
| 663 |
REVERSE2_CORE("movups") |
| 664 |
|
| 665 |
/* x1 blocks */ |
| 666 |
__ASM_EMIT("3000:") |
| 667 |
__ASM_EMIT("and $0x03, %[count]") |
| 668 |
__ASM_EMIT("jz 2000f") |
| 669 |
__ASM_EMIT("8:") |
| 670 |
__ASM_EMIT("sub $0x04, %[tail]") |
| 671 |
__ASM_EMIT("movss 0x00(%[tail]), %%xmm0") |
| 672 |
__ASM_EMIT("movss %%xmm0, 0x00(%[head])") |
| 673 |
__ASM_EMIT("add $0x04, %[head]") |
| 674 |
__ASM_EMIT("dec %[count]") |
| 675 |
__ASM_EMIT("jnz 8b") |
| 676 |
|
| 677 |
__ASM_EMIT("2000:") |
| 678 |
|
| 679 |
: [head] "+r" (dst), [tail] "+r" (src), [count] "+r" (count) |
| 680 |
: |
| 681 |
: "cc", "memory", |
| 682 |
"%xmm0", "%xmm1", "%xmm2", "%xmm3", |
| 683 |
"%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 684 |
); |
| 685 |
} |
| 686 |
|
| 687 |
#undef REVERSE2_CORE |
| 688 |
} /* namespace sse */ |
| 689 |
} /* namespace lsp */ |
| 690 |
|
| 691 |
#endif /* PRIVATE_DSP_ARCH_X86_SSE_COPY_H_ */ |