|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 | + * (C) 2025 Vladimir Sadovnikov <sadko4u@gmail.com> |
| 4 | + * |
| 5 | + * This file is part of lsp-dsp-lib |
| 6 | + * Created on: 18 авг. 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/stdlib/math.h> |
| 26 | +#include <lsp-plug.in/test-fw/helpers.h> |
| 27 | +#include <lsp-plug.in/test-fw/ptest.h> |
| 28 | + |
| 29 | +#define N_MATRICES 0x1000 |
| 30 | + |
| 31 | +namespace lsp |
| 32 | +{ |
| 33 | + namespace generic |
| 34 | + { |
| 35 | + void transpose_matrix3d1(dsp::matrix3d_t *r); |
| 36 | + void transpose_matrix3d2(dsp::matrix3d_t *r, const dsp::matrix3d_t *m); |
| 37 | + } |
| 38 | + |
| 39 | + IF_ARCH_X86( |
| 40 | + namespace sse |
| 41 | + { |
| 42 | + void transpose_matrix3d1(dsp::matrix3d_t *r); |
| 43 | + void transpose_matrix3d2(dsp::matrix3d_t *r, const dsp::matrix3d_t *m); |
| 44 | + } |
| 45 | + |
| 46 | + namespace sse2 |
| 47 | + { |
| 48 | + void transpose_matrix3d1(dsp::matrix3d_t *r); |
| 49 | + void transpose_matrix3d2(dsp::matrix3d_t *r, const dsp::matrix3d_t *m); |
| 50 | + } |
| 51 | + |
| 52 | + namespace avx |
| 53 | + { |
| 54 | + void transpose_matrix3d1(dsp::matrix3d_t *r); |
| 55 | + void transpose_matrix3d2(dsp::matrix3d_t *r, const dsp::matrix3d_t *m); |
| 56 | + } |
| 57 | + ) |
| 58 | + |
| 59 | + typedef void (* transpose_matrix3d1_t)(dsp::matrix3d_t *r); |
| 60 | + typedef void (* transpose_matrix3d2_t)(dsp::matrix3d_t *r, const dsp::matrix3d_t *m); |
| 61 | +} |
| 62 | + |
| 63 | +//----------------------------------------------------------------------------- |
| 64 | +// Performance test |
| 65 | +PTEST_BEGIN("dsp.3d", mat4_transpose, 5, 1000) |
| 66 | + |
| 67 | + void call(const char *label, dsp::matrix3d_t *dst, const dsp::matrix3d_t *src, transpose_matrix3d2_t func) |
| 68 | + { |
| 69 | + if (!PTEST_SUPPORTED(func)) |
| 70 | + return; |
| 71 | + |
| 72 | + char buf[80]; |
| 73 | + snprintf(buf, sizeof(buf), "%s", label); |
| 74 | + printf("Testing %s ...\n", buf); |
| 75 | + |
| 76 | + PTEST_LOOP(buf, |
| 77 | + for (size_t i=0; i<N_MATRICES; ++i) |
| 78 | + func(&dst[i], &src[i]); |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + void call(const char *label, dsp::matrix3d_t *dst, transpose_matrix3d1_t func) |
| 83 | + { |
| 84 | + if (!PTEST_SUPPORTED(func)) |
| 85 | + return; |
| 86 | + |
| 87 | + char buf[80]; |
| 88 | + snprintf(buf, sizeof(buf), "%s", label); |
| 89 | + printf("Testing %s ...\n", buf); |
| 90 | + |
| 91 | + PTEST_LOOP(buf, |
| 92 | + for (size_t i=0; i<N_MATRICES; ++i) |
| 93 | + func(&dst[i]); |
| 94 | + ); |
| 95 | + } |
| 96 | + |
| 97 | + PTEST_MAIN |
| 98 | + { |
| 99 | + size_t buf_size = N_MATRICES * sizeof(dsp::matrix3d_t); |
| 100 | + uint8_t *data = NULL; |
| 101 | + uint8_t *ptr = alloc_aligned<uint8_t>(data, buf_size * 2, 64); |
| 102 | + |
| 103 | + dsp::matrix3d_t *dst = reinterpret_cast<dsp::matrix3d_t *>(ptr); |
| 104 | + dsp::matrix3d_t *src = reinterpret_cast<dsp::matrix3d_t *>(&dst[N_MATRICES]); |
| 105 | + |
| 106 | + // Initialize matrices |
| 107 | + for (size_t i=0; i < N_MATRICES;) |
| 108 | + { |
| 109 | + randomize_sign(src[i].m, 16); |
| 110 | + ++i; |
| 111 | + } |
| 112 | + |
| 113 | + #define CALL1(func) \ |
| 114 | + memcpy(dst, src, buf_size); \ |
| 115 | + call(#func, dst, func); |
| 116 | + |
| 117 | + #define CALL2(func) \ |
| 118 | + memcpy(dst, src, buf_size); \ |
| 119 | + call(#func, dst, src, func); |
| 120 | + |
| 121 | + CALL1(generic::transpose_matrix3d1); |
| 122 | + CALL1(sse::transpose_matrix3d1); |
| 123 | + CALL1(sse2::transpose_matrix3d1); |
| 124 | + CALL1(avx::transpose_matrix3d1); |
| 125 | + PTEST_SEPARATOR; |
| 126 | + |
| 127 | + CALL2(generic::transpose_matrix3d2); |
| 128 | + CALL2(sse::transpose_matrix3d2); |
| 129 | + CALL2(sse2::transpose_matrix3d2); |
| 130 | + CALL2(avx::transpose_matrix3d2); |
| 131 | + PTEST_SEPARATOR; |
| 132 | + |
| 133 | + free_aligned(data); |
| 134 | + } |
| 135 | +PTEST_END |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
0 commit comments