| 1 |
/* |
| 2 |
* Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2026 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-dsp-lib |
| 6 |
* Created on: 23 фев. 2025 г. |
| 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 |
#include <lsp-plug.in/common/alloc.h> |
| 23 |
#include <lsp-plug.in/common/types.h> |
| 24 |
#include <lsp-plug.in/dsp/dsp.h> |
| 25 |
#include <lsp-plug.in/test-fw/helpers.h> |
| 26 |
#include <lsp-plug.in/test-fw/ptest.h> |
| 27 |
|
| 28 |
#define MIN_RANK 8 |
| 29 |
#define MAX_RANK 16 |
| 30 |
|
| 31 |
namespace lsp |
| 32 |
{ |
| 33 |
namespace generic |
| 34 |
{ |
| 35 |
void packed_direct_fft(float *dst, const float *src, size_t rank); |
| 36 |
} |
| 37 |
|
| 38 |
IF_ARCH_X86( |
| 39 |
namespace sse |
| 40 |
{ |
| 41 |
void packed_direct_fft(float *dst, const float *src, size_t rank); |
| 42 |
} |
| 43 |
|
| 44 |
namespace avx |
| 45 |
{ |
| 46 |
void packed_direct_fft(float *dst, const float *src, size_t rank); |
| 47 |
void packed_direct_fft_fma3(float *dst, const float *src, size_t rank); |
| 48 |
} |
| 49 |
|
| 50 |
namespace avx512 |
| 51 |
{ |
| 52 |
void packed_direct_fft(float *dst, const float *src, size_t rank); |
| 53 |
} |
| 54 |
) |
| 55 |
|
| 56 |
IF_ARCH_ARM( |
| 57 |
namespace neon_d32 |
| 58 |
{ |
| 59 |
void packed_direct_fft(float *dst, const float *src, size_t rank); |
| 60 |
} |
| 61 |
) |
| 62 |
|
| 63 |
IF_ARCH_AARCH64( |
| 64 |
namespace asimd |
| 65 |
{ |
| 66 |
void packed_direct_fft(float *dst, const float *src, size_t rank); |
| 67 |
} |
| 68 |
) |
| 69 |
|
| 70 |
typedef void (* packed_direct_fft_t) (float *dst, const float *src, size_t rank); |
| 71 |
} |
| 72 |
|
| 73 |
//----------------------------------------------------------------------------- |
| 74 |
// Performance test for complex multiplication |
| 75 |
PTEST_BEGIN("dsp.fft", pfft, 10, 1000) |
| 76 |
|
| 77 |
void call(const char *label, float *dst, const float *src, size_t rank, packed_direct_fft_t fft) |
| 78 |
{ |
| 79 |
if (!PTEST_SUPPORTED(fft)) |
| 80 |
return; |
| 81 |
|
| 82 |
char buf[80]; |
| 83 |
snprintf(buf, sizeof(buf), "%s x %d", label, int(1 << rank)); |
| 84 |
printf("Testing %s samples (rank = %d) ...\n", buf, int(rank)); |
| 85 |
|
| 86 |
PTEST_LOOP(buf, |
| 87 |
fft(dst, src, rank); |
| 88 |
) |
| 89 |
} |
| 90 |
|
| 91 |
PTEST_MAIN |
| 92 |
{ |
| 93 |
size_t fft_size = 1 << MAX_RANK; |
| 94 |
|
| 95 |
uint8_t *data = NULL; |
| 96 |
|
| 97 |
float *sig_re = alloc_aligned<float>(data, fft_size * 4, 64); |
| 98 |
float *sig_im = &sig_re[fft_size]; |
| 99 |
float *fft_re = &sig_im[fft_size]; |
| 100 |
|
| 101 |
for (size_t i=0; i < (1 << MAX_RANK); ++i) |
| 102 |
{ |
| 103 |
sig_re[i] = randf(0.0f, 1.0f); |
| 104 |
sig_im[i] = 0.0f; |
| 105 |
} |
| 106 |
|
| 107 |
#define CALL(func) \ |
| 108 |
call(#func, fft_re, sig_re, i, func) |
| 109 |
|
| 110 |
for (size_t i=MIN_RANK; i <= MAX_RANK; ++i) |
| 111 |
{ |
| 112 |
CALL(generic::packed_direct_fft); |
| 113 |
IF_ARCH_X86(CALL(sse::packed_direct_fft)); |
| 114 |
IF_ARCH_X86(CALL(avx::packed_direct_fft)); |
| 115 |
IF_ARCH_X86(CALL(avx::packed_direct_fft_fma3)); |
| 116 |
IF_ARCH_X86(CALL(avx512::packed_direct_fft)); |
| 117 |
IF_ARCH_ARM(CALL(neon_d32::packed_direct_fft)); |
| 118 |
IF_ARCH_AARCH64(CALL(asimd::packed_direct_fft)); |
| 119 |
PTEST_SEPARATOR; |
| 120 |
} |
| 121 |
|
| 122 |
free_aligned(data); |
| 123 |
} |
| 124 |
PTEST_END |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|