| 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_SSE2_PMATH_POW_H_ |
| 23 |
#define PRIVATE_DSP_ARCH_X86_SSE2_PMATH_POW_H_ |
| 24 |
|
| 25 |
#ifndef PRIVATE_DSP_ARCH_X86_SSE2_IMPL |
| 26 |
#error "This header should not be included directly" |
| 27 |
#endif /* PRIVATE_DSP_ARCH_X86_SSE2_IMPL */ |
| 28 |
|
| 29 |
#include <private/dsp/arch/x86/sse2/pmath/exp.h> |
| 30 |
#include <private/dsp/arch/x86/sse2/pmath/log.h> |
| 31 |
|
| 32 |
namespace lsp |
| 33 |
{ |
| 34 |
namespace sse2 |
| 35 |
{ |
| 36 |
void powcv1(float *v, float c, size_t count) |
| 37 |
{ |
| 38 |
// float C = logf(c); |
| 39 |
// for (size_t i=0; i<count; ++i) |
| 40 |
// v[i] = expf(v[i] * C); |
| 41 |
|
| 42 |
IF_ARCH_X86( |
| 43 |
float *src; |
| 44 |
float C[4] __lsp_aligned16; |
| 45 |
); |
| 46 |
|
| 47 |
ARCH_X86_ASM( |
| 48 |
// Calc C = logf(c) |
| 49 |
__ASM_EMIT("shufps $0x00, %%xmm0, %%xmm0") |
| 50 |
LOGN_CORE_X4 |
| 51 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 52 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E) + R = log(c)*log2(E) |
| 53 |
__ASM_EMIT("movaps %%xmm0, %[C]") |
| 54 |
|
| 55 |
// Analyze size |
| 56 |
__ASM_EMIT("sub $8, %[count]") |
| 57 |
__ASM_EMIT("jb 2f") |
| 58 |
|
| 59 |
// x8 blocks |
| 60 |
__ASM_EMIT("1:") |
| 61 |
__ASM_EMIT("movups 0x00(%[dst]), %%xmm0") |
| 62 |
__ASM_EMIT("movups 0x10(%[dst]), %%xmm4") |
| 63 |
__ASM_EMIT("mulps %[C], %%xmm0") |
| 64 |
__ASM_EMIT("mulps %[C], %%xmm4") |
| 65 |
POW2_CORE_X8 |
| 66 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 67 |
__ASM_EMIT("movups %%xmm4, 0x10(%[dst])") |
| 68 |
__ASM_EMIT("add $0x20, %[dst]") |
| 69 |
__ASM_EMIT("sub $8, %[count]") |
| 70 |
__ASM_EMIT("jae 1b") |
| 71 |
|
| 72 |
__ASM_EMIT("2:") |
| 73 |
__ASM_EMIT("add $4, %[count]") |
| 74 |
__ASM_EMIT("jl 4f") |
| 75 |
|
| 76 |
// x4 block |
| 77 |
__ASM_EMIT("movups 0x00(%[dst]), %%xmm0") |
| 78 |
__ASM_EMIT("mulps %[C], %%xmm0") |
| 79 |
POW2_CORE_X4 |
| 80 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 81 |
__ASM_EMIT("add $0x10, %[dst]") |
| 82 |
__ASM_EMIT("sub $4, %[count]") |
| 83 |
|
| 84 |
__ASM_EMIT("4:") |
| 85 |
__ASM_EMIT("add $4, %[count]") |
| 86 |
__ASM_EMIT("jle 12f") |
| 87 |
|
| 88 |
// Tail: 1x-3x block |
| 89 |
__ASM_EMIT("mov %[dst], %[src]") |
| 90 |
__ASM_EMIT("test $1, %[count]") |
| 91 |
__ASM_EMIT("jz 6f") |
| 92 |
__ASM_EMIT("movss 0x00(%[src]), %%xmm0") |
| 93 |
__ASM_EMIT("add $4, %[src]") |
| 94 |
__ASM_EMIT("6:") |
| 95 |
__ASM_EMIT("test $2, %[count]") |
| 96 |
__ASM_EMIT("jz 8f") |
| 97 |
__ASM_EMIT("movhps 0x00(%[src]), %%xmm0") |
| 98 |
__ASM_EMIT("8:") |
| 99 |
|
| 100 |
__ASM_EMIT("mulps %[C], %%xmm0") |
| 101 |
POW2_CORE_X4 |
| 102 |
|
| 103 |
__ASM_EMIT("test $1, %[count]") |
| 104 |
__ASM_EMIT("jz 10f") |
| 105 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst])") |
| 106 |
__ASM_EMIT("add $4, %[dst]") |
| 107 |
__ASM_EMIT("10:") |
| 108 |
__ASM_EMIT("test $2, %[count]") |
| 109 |
__ASM_EMIT("jz 12f") |
| 110 |
__ASM_EMIT("movhps %%xmm0, 0x00(%[dst])") |
| 111 |
|
| 112 |
// End |
| 113 |
__ASM_EMIT("12:") |
| 114 |
|
| 115 |
: [dst] "+r" (v), [src] "=&r" (src), [count] "+r" (count), |
| 116 |
"+Yz" (c) |
| 117 |
: [E2C] "o" (EXP2_CONST), |
| 118 |
[L2C] "o" (LOG2_CONST), |
| 119 |
[LOGC] "o" (LOGB_C), |
| 120 |
[C] "m" (C) |
| 121 |
: "cc", "memory", |
| 122 |
"%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 123 |
); |
| 124 |
} |
| 125 |
|
| 126 |
void powcv2(float *dst, const float *v, float c, size_t count) |
| 127 |
{ |
| 128 |
// float C = logf(c); |
| 129 |
// for (size_t i=0; i<count; ++i) |
| 130 |
// dst[i] = expf(v[i] * C); |
| 131 |
|
| 132 |
IF_ARCH_X86( |
| 133 |
float C[4] __lsp_aligned16; |
| 134 |
); |
| 135 |
|
| 136 |
ARCH_X86_ASM( |
| 137 |
// Calc C = logf(c) |
| 138 |
__ASM_EMIT("shufps $0x00, %%xmm0, %%xmm0") |
| 139 |
LOGN_CORE_X4 |
| 140 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 141 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E) + R = log(c)*log2(E) |
| 142 |
__ASM_EMIT("movaps %%xmm0, %[C]") |
| 143 |
|
| 144 |
// Analyze size |
| 145 |
__ASM_EMIT("sub $8, %[count]") |
| 146 |
__ASM_EMIT("jb 2f") |
| 147 |
|
| 148 |
// x8 blocks |
| 149 |
__ASM_EMIT("1:") |
| 150 |
__ASM_EMIT("movups 0x00(%[src]), %%xmm0") |
| 151 |
__ASM_EMIT("movups 0x10(%[src]), %%xmm4") |
| 152 |
__ASM_EMIT("mulps %[C], %%xmm0") |
| 153 |
__ASM_EMIT("mulps %[C], %%xmm4") |
| 154 |
POW2_CORE_X8 |
| 155 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 156 |
__ASM_EMIT("movups %%xmm4, 0x10(%[dst])") |
| 157 |
__ASM_EMIT("add $0x20, %[src]") |
| 158 |
__ASM_EMIT("add $0x20, %[dst]") |
| 159 |
__ASM_EMIT("sub $8, %[count]") |
| 160 |
__ASM_EMIT("jae 1b") |
| 161 |
|
| 162 |
__ASM_EMIT("2:") |
| 163 |
__ASM_EMIT("add $4, %[count]") |
| 164 |
__ASM_EMIT("jl 4f") |
| 165 |
|
| 166 |
// x4 block |
| 167 |
__ASM_EMIT("movups 0x00(%[src]), %%xmm0") |
| 168 |
__ASM_EMIT("mulps %[C], %%xmm0") |
| 169 |
POW2_CORE_X4 |
| 170 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 171 |
__ASM_EMIT("add $0x10, %[src]") |
| 172 |
__ASM_EMIT("add $0x10, %[dst]") |
| 173 |
__ASM_EMIT("sub $4, %[count]") |
| 174 |
|
| 175 |
__ASM_EMIT("4:") |
| 176 |
__ASM_EMIT("add $4, %[count]") |
| 177 |
__ASM_EMIT("jle 12f") |
| 178 |
|
| 179 |
// Tail: 1x-3x block |
| 180 |
__ASM_EMIT("test $1, %[count]") |
| 181 |
__ASM_EMIT("jz 6f") |
| 182 |
__ASM_EMIT("movss 0x00(%[src]), %%xmm0") |
| 183 |
__ASM_EMIT("add $4, %[src]") |
| 184 |
__ASM_EMIT("6:") |
| 185 |
__ASM_EMIT("test $2, %[count]") |
| 186 |
__ASM_EMIT("jz 8f") |
| 187 |
__ASM_EMIT("movhps 0x00(%[src]), %%xmm0") |
| 188 |
__ASM_EMIT("8:") |
| 189 |
|
| 190 |
__ASM_EMIT("mulps %[C], %%xmm0") |
| 191 |
POW2_CORE_X4 |
| 192 |
|
| 193 |
__ASM_EMIT("test $1, %[count]") |
| 194 |
__ASM_EMIT("jz 10f") |
| 195 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst])") |
| 196 |
__ASM_EMIT("add $4, %[dst]") |
| 197 |
__ASM_EMIT("10:") |
| 198 |
__ASM_EMIT("test $2, %[count]") |
| 199 |
__ASM_EMIT("jz 12f") |
| 200 |
__ASM_EMIT("movhps %%xmm0, 0x00(%[dst])") |
| 201 |
|
| 202 |
// End |
| 203 |
__ASM_EMIT("12:") |
| 204 |
|
| 205 |
: [dst] "+r" (dst), [src] "+r" (v), [count] "+r" (count), |
| 206 |
"+Yz" (c) |
| 207 |
: [E2C] "o" (EXP2_CONST), |
| 208 |
[L2C] "o" (LOG2_CONST), |
| 209 |
[LOGC] "o" (LOGB_C), |
| 210 |
[C] "m" (C) |
| 211 |
: "cc", "memory", |
| 212 |
"%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 213 |
); |
| 214 |
} |
| 215 |
|
| 216 |
void powvc1(float *c, float v, size_t count) |
| 217 |
{ |
| 218 |
// for (size_t i=0; i<count; ++i) |
| 219 |
// c[i] = expf(v * logf(c[i])); |
| 220 |
|
| 221 |
IF_ARCH_X86( |
| 222 |
float *src; |
| 223 |
float V[4] __lsp_aligned16; |
| 224 |
); |
| 225 |
|
| 226 |
ARCH_X86_ASM( |
| 227 |
__ASM_EMIT("shufps $0x00, %%xmm0, %%xmm0") |
| 228 |
__ASM_EMIT("movaps %%xmm0, %[V]") |
| 229 |
|
| 230 |
// Analyze size |
| 231 |
__ASM_EMIT("sub $8, %[count]") |
| 232 |
__ASM_EMIT("jb 2f") |
| 233 |
|
| 234 |
// x8 blocks |
| 235 |
__ASM_EMIT("1:") |
| 236 |
__ASM_EMIT("movups 0x00(%[dst]), %%xmm0") |
| 237 |
__ASM_EMIT("movups 0x10(%[dst]), %%xmm4") |
| 238 |
// logf(c) |
| 239 |
LOGN_CORE_X8 |
| 240 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 241 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm4") |
| 242 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E)+R |
| 243 |
__ASM_EMIT("addps %%xmm5, %%xmm4") |
| 244 |
__ASM_EMIT("mulps %[V], %%xmm0") // xmm0 = (2*y*L*log2(E)+R)*v |
| 245 |
__ASM_EMIT("mulps %[V], %%xmm4") |
| 246 |
// expf(v * logf(c)) |
| 247 |
POW2_CORE_X8 |
| 248 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 249 |
__ASM_EMIT("movups %%xmm4, 0x10(%[dst])") |
| 250 |
__ASM_EMIT("add $0x20, %[dst]") |
| 251 |
__ASM_EMIT("sub $8, %[count]") |
| 252 |
__ASM_EMIT("jae 1b") |
| 253 |
|
| 254 |
__ASM_EMIT("2:") |
| 255 |
__ASM_EMIT("add $4, %[count]") |
| 256 |
__ASM_EMIT("jl 4f") |
| 257 |
|
| 258 |
// x4 block |
| 259 |
__ASM_EMIT("movups 0x00(%[dst]), %%xmm0") |
| 260 |
// logf(c) |
| 261 |
LOGN_CORE_X4 |
| 262 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 263 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E)+R |
| 264 |
__ASM_EMIT("mulps %[V], %%xmm0") // xmm0 = (2*y*L*log2(E)+R)*v |
| 265 |
// expf(v * logf(c)) |
| 266 |
POW2_CORE_X4 |
| 267 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 268 |
__ASM_EMIT("add $0x10, %[dst]") |
| 269 |
__ASM_EMIT("sub $4, %[count]") |
| 270 |
|
| 271 |
__ASM_EMIT("4:") |
| 272 |
__ASM_EMIT("add $4, %[count]") |
| 273 |
__ASM_EMIT("jle 12f") |
| 274 |
|
| 275 |
// Tail: 1x-3x block |
| 276 |
__ASM_EMIT("mov %[dst], %[src]") |
| 277 |
__ASM_EMIT("test $1, %[count]") |
| 278 |
__ASM_EMIT("jz 6f") |
| 279 |
__ASM_EMIT("movss 0x00(%[src]), %%xmm0") |
| 280 |
__ASM_EMIT("add $4, %[src]") |
| 281 |
__ASM_EMIT("6:") |
| 282 |
__ASM_EMIT("test $2, %[count]") |
| 283 |
__ASM_EMIT("jz 8f") |
| 284 |
__ASM_EMIT("movhps 0x00(%[src]), %%xmm0") |
| 285 |
__ASM_EMIT("8:") |
| 286 |
|
| 287 |
// logf(c) |
| 288 |
LOGN_CORE_X4 |
| 289 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 290 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E)+R |
| 291 |
__ASM_EMIT("mulps %[V], %%xmm0") // xmm0 = (2*y*L*log2(E)+R)*v |
| 292 |
// expf(v * logf(c)) |
| 293 |
POW2_CORE_X4 |
| 294 |
|
| 295 |
__ASM_EMIT("test $1, %[count]") |
| 296 |
__ASM_EMIT("jz 10f") |
| 297 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst])") |
| 298 |
__ASM_EMIT("add $4, %[dst]") |
| 299 |
__ASM_EMIT("10:") |
| 300 |
__ASM_EMIT("test $2, %[count]") |
| 301 |
__ASM_EMIT("jz 12f") |
| 302 |
__ASM_EMIT("movhps %%xmm0, 0x00(%[dst])") |
| 303 |
|
| 304 |
// End |
| 305 |
__ASM_EMIT("12:") |
| 306 |
|
| 307 |
: [dst] "+r" (c), [src] "=&r" (src), [count] "+r" (count), |
| 308 |
"+Yz" (v) |
| 309 |
: [E2C] "o" (EXP2_CONST), |
| 310 |
[L2C] "o" (LOG2_CONST), |
| 311 |
[LOGC] "o" (LOGB_C), |
| 312 |
[V] "m" (V) |
| 313 |
: "cc", "memory", |
| 314 |
"%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 315 |
); |
| 316 |
} |
| 317 |
|
| 318 |
void powvc2(float *dst, const float *c, float v, size_t count) |
| 319 |
{ |
| 320 |
// for (size_t i=0; i<count; ++i) |
| 321 |
// dst[i] = expf(v * logf(c[i])); |
| 322 |
|
| 323 |
IF_ARCH_X86( |
| 324 |
float V[4] __lsp_aligned16; |
| 325 |
); |
| 326 |
|
| 327 |
ARCH_X86_ASM( |
| 328 |
__ASM_EMIT("shufps $0x00, %%xmm0, %%xmm0") |
| 329 |
__ASM_EMIT("movaps %%xmm0, %[V]") |
| 330 |
|
| 331 |
// Analyze size |
| 332 |
__ASM_EMIT("sub $8, %[count]") |
| 333 |
__ASM_EMIT("jb 2f") |
| 334 |
|
| 335 |
// x8 blocks |
| 336 |
__ASM_EMIT("1:") |
| 337 |
__ASM_EMIT("movups 0x00(%[src]), %%xmm0") |
| 338 |
__ASM_EMIT("movups 0x10(%[src]), %%xmm4") |
| 339 |
// logf(c) |
| 340 |
LOGN_CORE_X8 |
| 341 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 342 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm4") |
| 343 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E)+R |
| 344 |
__ASM_EMIT("addps %%xmm5, %%xmm4") |
| 345 |
__ASM_EMIT("mulps %[V], %%xmm0") // xmm0 = (2*y*L*log2(E)+R)*v |
| 346 |
__ASM_EMIT("mulps %[V], %%xmm4") |
| 347 |
// expf(v * logf(c)) |
| 348 |
POW2_CORE_X8 |
| 349 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 350 |
__ASM_EMIT("movups %%xmm4, 0x10(%[dst])") |
| 351 |
__ASM_EMIT("add $0x20, %[src]") |
| 352 |
__ASM_EMIT("add $0x20, %[dst]") |
| 353 |
__ASM_EMIT("sub $8, %[count]") |
| 354 |
__ASM_EMIT("jae 1b") |
| 355 |
|
| 356 |
__ASM_EMIT("2:") |
| 357 |
__ASM_EMIT("add $4, %[count]") |
| 358 |
__ASM_EMIT("jl 4f") |
| 359 |
|
| 360 |
// x4 block |
| 361 |
__ASM_EMIT("movups 0x00(%[src]), %%xmm0") |
| 362 |
// logf(c) |
| 363 |
LOGN_CORE_X4 |
| 364 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 365 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E)+R |
| 366 |
__ASM_EMIT("mulps %[V], %%xmm0") // xmm0 = (2*y*L*log2(E)+R)*v |
| 367 |
// expf(v * logf(c)) |
| 368 |
POW2_CORE_X4 |
| 369 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 370 |
__ASM_EMIT("add $0x10, %[src]") |
| 371 |
__ASM_EMIT("add $0x10, %[dst]") |
| 372 |
__ASM_EMIT("sub $4, %[count]") |
| 373 |
|
| 374 |
__ASM_EMIT("4:") |
| 375 |
__ASM_EMIT("add $4, %[count]") |
| 376 |
__ASM_EMIT("jle 12f") |
| 377 |
|
| 378 |
// Tail: 1x-3x block |
| 379 |
__ASM_EMIT("test $1, %[count]") |
| 380 |
__ASM_EMIT("jz 6f") |
| 381 |
__ASM_EMIT("movss 0x00(%[src]), %%xmm0") |
| 382 |
__ASM_EMIT("add $4, %[src]") |
| 383 |
__ASM_EMIT("6:") |
| 384 |
__ASM_EMIT("test $2, %[count]") |
| 385 |
__ASM_EMIT("jz 8f") |
| 386 |
__ASM_EMIT("movhps 0x00(%[src]), %%xmm0") |
| 387 |
__ASM_EMIT("8:") |
| 388 |
|
| 389 |
// logf(c) |
| 390 |
LOGN_CORE_X4 |
| 391 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 392 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E)+R |
| 393 |
__ASM_EMIT("mulps %[V], %%xmm0") // xmm0 = (2*y*L*log2(E)+R)*v |
| 394 |
// expf(v * logf(c)) |
| 395 |
POW2_CORE_X4 |
| 396 |
|
| 397 |
__ASM_EMIT("test $1, %[count]") |
| 398 |
__ASM_EMIT("jz 10f") |
| 399 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst])") |
| 400 |
__ASM_EMIT("add $4, %[dst]") |
| 401 |
__ASM_EMIT("10:") |
| 402 |
__ASM_EMIT("test $2, %[count]") |
| 403 |
__ASM_EMIT("jz 12f") |
| 404 |
__ASM_EMIT("movhps %%xmm0, 0x00(%[dst])") |
| 405 |
|
| 406 |
// End |
| 407 |
__ASM_EMIT("12:") |
| 408 |
|
| 409 |
: [dst] "+r" (dst), [src] "+r" (c), [count] "+r" (count), |
| 410 |
"+Yz" (v) |
| 411 |
: [E2C] "o" (EXP2_CONST), |
| 412 |
[L2C] "o" (LOG2_CONST), |
| 413 |
[LOGC] "o" (LOGB_C), |
| 414 |
[V] "m" (V) |
| 415 |
: "cc", "memory", |
| 416 |
"%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 417 |
); |
| 418 |
} |
| 419 |
|
| 420 |
void powvx1(float *v, const float *x, size_t count) |
| 421 |
{ |
| 422 |
// for (size_t i=0; i<count; ++i) |
| 423 |
// v[i] = expf(x[i] * logf(v[i])); |
| 424 |
|
| 425 |
IF_ARCH_X86(float *src;); |
| 426 |
|
| 427 |
ARCH_X86_ASM( |
| 428 |
// Analyze size |
| 429 |
__ASM_EMIT("sub $8, %[count]") |
| 430 |
__ASM_EMIT("jb 2f") |
| 431 |
|
| 432 |
// x8 blocks |
| 433 |
__ASM_EMIT("1:") |
| 434 |
__ASM_EMIT("movups 0x00(%[dst]), %%xmm0") |
| 435 |
__ASM_EMIT("movups 0x10(%[dst]), %%xmm4") |
| 436 |
// logf(v) |
| 437 |
LOGN_CORE_X8 |
| 438 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 439 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm4") |
| 440 |
__ASM_EMIT("movups 0x00(%[x]), %%xmm2") // xmm2 = x |
| 441 |
__ASM_EMIT("movups 0x10(%[x]), %%xmm6") |
| 442 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E) + R |
| 443 |
__ASM_EMIT("addps %%xmm5, %%xmm4") |
| 444 |
__ASM_EMIT("mulps %%xmm2, %%xmm0") // xmm0 = (2*y*L*log2(E) + R)*x |
| 445 |
__ASM_EMIT("mulps %%xmm6, %%xmm4") |
| 446 |
// expf(x * logf(v)) |
| 447 |
POW2_CORE_X8 |
| 448 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 449 |
__ASM_EMIT("movups %%xmm4, 0x10(%[dst])") |
| 450 |
__ASM_EMIT("add $0x20, %[x]") |
| 451 |
__ASM_EMIT("add $0x20, %[dst]") |
| 452 |
__ASM_EMIT("sub $8, %[count]") |
| 453 |
__ASM_EMIT("jae 1b") |
| 454 |
|
| 455 |
__ASM_EMIT("2:") |
| 456 |
__ASM_EMIT("add $4, %[count]") |
| 457 |
__ASM_EMIT("jl 4f") |
| 458 |
|
| 459 |
// x4 block |
| 460 |
__ASM_EMIT("movups 0x00(%[dst]), %%xmm0") |
| 461 |
// logf(v) |
| 462 |
LOGN_CORE_X4 |
| 463 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 464 |
__ASM_EMIT("movups 0x00(%[x]), %%xmm2") // xmm2 = x |
| 465 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E) + R |
| 466 |
__ASM_EMIT("mulps %%xmm2, %%xmm0") // xmm0 = (2*y*L*log2(E) + R)*x |
| 467 |
// expf(x * logf(x)) |
| 468 |
POW2_CORE_X8 |
| 469 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 470 |
__ASM_EMIT("add $0x10, %[x]") |
| 471 |
__ASM_EMIT("add $0x10, %[dst]") |
| 472 |
__ASM_EMIT("sub $4, %[count]") |
| 473 |
|
| 474 |
__ASM_EMIT("4:") |
| 475 |
__ASM_EMIT("add $4, %[count]") |
| 476 |
__ASM_EMIT("jle 12f") |
| 477 |
|
| 478 |
// Tail: 1x-3x block |
| 479 |
__ASM_EMIT("mov %[dst], %[src]") |
| 480 |
__ASM_EMIT("test $1, %[count]") |
| 481 |
__ASM_EMIT("jz 6f") |
| 482 |
__ASM_EMIT("movss 0x00(%[src]), %%xmm0") |
| 483 |
__ASM_EMIT("movss 0x00(%[x]), %%xmm7") |
| 484 |
__ASM_EMIT("add $4, %[src]") |
| 485 |
__ASM_EMIT("add $4, %[x]") |
| 486 |
__ASM_EMIT("6:") |
| 487 |
__ASM_EMIT("test $2, %[count]") |
| 488 |
__ASM_EMIT("jz 8f") |
| 489 |
__ASM_EMIT("movhps 0x00(%[src]), %%xmm0") |
| 490 |
__ASM_EMIT("movhps 0x00(%[x]), %%xmm7") |
| 491 |
__ASM_EMIT("8:") |
| 492 |
|
| 493 |
// logf(x) |
| 494 |
LOGN_CORE_X4 |
| 495 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 496 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E) + R |
| 497 |
__ASM_EMIT("mulps %%xmm7, %%xmm0") // xmm0 = (2*y*L*log2(E) + R)*x |
| 498 |
// expf(v * logf(x)) |
| 499 |
POW2_CORE_X8 |
| 500 |
|
| 501 |
__ASM_EMIT("test $1, %[count]") |
| 502 |
__ASM_EMIT("jz 10f") |
| 503 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst])") |
| 504 |
__ASM_EMIT("add $4, %[dst]") |
| 505 |
__ASM_EMIT("10:") |
| 506 |
__ASM_EMIT("test $2, %[count]") |
| 507 |
__ASM_EMIT("jz 12f") |
| 508 |
__ASM_EMIT("movhps %%xmm0, 0x00(%[dst])") |
| 509 |
|
| 510 |
// End |
| 511 |
__ASM_EMIT("12:") |
| 512 |
|
| 513 |
: [dst] "+r" (v), [x] "+r" (x), [src] "=&r" (src), [count] "+r" (count) |
| 514 |
: [E2C] "o" (EXP2_CONST), |
| 515 |
[L2C] "o" (LOG2_CONST), |
| 516 |
[LOGC] "o" (LOGB_C) |
| 517 |
: "cc", "memory", |
| 518 |
"%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 519 |
); |
| 520 |
} |
| 521 |
|
| 522 |
void powvx2(float *dst, const float *v, const float *x, size_t count) |
| 523 |
{ |
| 524 |
// for (size_t i=0; i<count; ++i) |
| 525 |
// dst[i] = expf(x[i] * logf(v[i])); |
| 526 |
|
| 527 |
ARCH_X86_ASM( |
| 528 |
// Analyze size |
| 529 |
__ASM_EMIT("sub $8, %[count]") |
| 530 |
__ASM_EMIT("jb 2f") |
| 531 |
|
| 532 |
// x8 blocks |
| 533 |
__ASM_EMIT("1:") |
| 534 |
__ASM_EMIT("movups 0x00(%[src]), %%xmm0") |
| 535 |
__ASM_EMIT("movups 0x10(%[src]), %%xmm4") |
| 536 |
// logf(v) |
| 537 |
LOGN_CORE_X8 |
| 538 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 539 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm4") |
| 540 |
__ASM_EMIT("movups 0x00(%[x]), %%xmm2") // xmm2 = x |
| 541 |
__ASM_EMIT("movups 0x10(%[x]), %%xmm6") |
| 542 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E) + R |
| 543 |
__ASM_EMIT("addps %%xmm5, %%xmm4") |
| 544 |
__ASM_EMIT("mulps %%xmm2, %%xmm0") // xmm0 = (2*y*L*log2(E) + R)*x |
| 545 |
__ASM_EMIT("mulps %%xmm6, %%xmm4") |
| 546 |
// expf(x * logf(v)) |
| 547 |
POW2_CORE_X8 |
| 548 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 549 |
__ASM_EMIT("movups %%xmm4, 0x10(%[dst])") |
| 550 |
__ASM_EMIT("add $0x20, %[src]") |
| 551 |
__ASM_EMIT("add $0x20, %[dst]") |
| 552 |
__ASM_EMIT("add $0x20, %[x]") |
| 553 |
__ASM_EMIT("sub $8, %[count]") |
| 554 |
__ASM_EMIT("jae 1b") |
| 555 |
|
| 556 |
__ASM_EMIT("2:") |
| 557 |
__ASM_EMIT("add $4, %[count]") |
| 558 |
__ASM_EMIT("jl 4f") |
| 559 |
|
| 560 |
// x4 block |
| 561 |
__ASM_EMIT("movups 0x00(%[src]), %%xmm0") |
| 562 |
// logf(x) |
| 563 |
LOGN_CORE_X4 |
| 564 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 565 |
__ASM_EMIT("movups 0x00(%[x]), %%xmm2") // xmm2 = x |
| 566 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E) + R |
| 567 |
__ASM_EMIT("mulps %%xmm2, %%xmm0") // xmm0 = (2*y*L*log2(E) + R)*x |
| 568 |
// expf(x * logf(v)) |
| 569 |
POW2_CORE_X8 |
| 570 |
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])") |
| 571 |
__ASM_EMIT("add $0x10, %[src]") |
| 572 |
__ASM_EMIT("add $0x10, %[dst]") |
| 573 |
__ASM_EMIT("add $0x10, %[x]") |
| 574 |
__ASM_EMIT("sub $4, %[count]") |
| 575 |
|
| 576 |
__ASM_EMIT("4:") |
| 577 |
__ASM_EMIT("add $4, %[count]") |
| 578 |
__ASM_EMIT("jle 12f") |
| 579 |
|
| 580 |
// Tail: 1x-3x block |
| 581 |
__ASM_EMIT("test $1, %[count]") |
| 582 |
__ASM_EMIT("jz 6f") |
| 583 |
__ASM_EMIT("movss 0x00(%[src]), %%xmm0") |
| 584 |
__ASM_EMIT("movss 0x00(%[x]), %%xmm7") |
| 585 |
__ASM_EMIT("add $4, %[src]") |
| 586 |
__ASM_EMIT("add $4, %[x]") |
| 587 |
__ASM_EMIT("6:") |
| 588 |
__ASM_EMIT("test $2, %[count]") |
| 589 |
__ASM_EMIT("jz 8f") |
| 590 |
__ASM_EMIT("movhps 0x00(%[src]), %%xmm0") |
| 591 |
__ASM_EMIT("movhps 0x00(%[x]), %%xmm7") |
| 592 |
__ASM_EMIT("8:") |
| 593 |
|
| 594 |
// logf(v) |
| 595 |
LOGN_CORE_X4 |
| 596 |
__ASM_EMIT("mulps 0x00 + %[LOGC], %%xmm0") // xmm0 = 2*y*L*log2(E) |
| 597 |
__ASM_EMIT("addps %%xmm1, %%xmm0") // xmm0 = 2*y*L*log2(E) + R |
| 598 |
__ASM_EMIT("mulps %%xmm7, %%xmm0") // xmm0 = (2*y*L*log2(E) + R)*x |
| 599 |
// expf(x * logf(v)) |
| 600 |
POW2_CORE_X8 |
| 601 |
|
| 602 |
__ASM_EMIT("test $1, %[count]") |
| 603 |
__ASM_EMIT("jz 10f") |
| 604 |
__ASM_EMIT("movss %%xmm0, 0x00(%[dst])") |
| 605 |
__ASM_EMIT("add $4, %[dst]") |
| 606 |
__ASM_EMIT("10:") |
| 607 |
__ASM_EMIT("test $2, %[count]") |
| 608 |
__ASM_EMIT("jz 12f") |
| 609 |
__ASM_EMIT("movhps %%xmm0, 0x00(%[dst])") |
| 610 |
|
| 611 |
// End |
| 612 |
__ASM_EMIT("12:") |
| 613 |
|
| 614 |
: [dst] "+r" (dst), [x] "+r" (x), [src] "+r" (v), [count] "+r" (count) |
| 615 |
: [E2C] "o" (EXP2_CONST), |
| 616 |
[L2C] "o" (LOG2_CONST), |
| 617 |
[LOGC] "o" (LOGB_C) |
| 618 |
: "cc", "memory", |
| 619 |
"%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7" |
| 620 |
); |
| 621 |
} |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
#endif /* PRIVATE_DSP_ARCH_X86_SSE2_PMATH_POW_H_ */ |