Skip to content

Commit

Permalink
Implemented SSE, AVX and AVX512-optimized sign_min, sign_max and sign…
Browse files Browse the repository at this point in the history
…_minmax functions
  • Loading branch information
sadko4u committed Nov 28, 2024
1 parent 3a7a00f commit 9cd5ce0
Show file tree
Hide file tree
Showing 12 changed files with 1,555 additions and 111 deletions.
229 changes: 225 additions & 4 deletions include/private/dsp/arch/x86/avx/search/minmax.h

Large diffs are not rendered by default.

264 changes: 264 additions & 0 deletions include/private/dsp/arch/x86/avx512/search/minmax.h

Large diffs are not rendered by default.

452 changes: 346 additions & 106 deletions include/private/dsp/arch/x86/sse/search/minmax.h

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/main/x86/avx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@
CEXPORT1(favx, abs_min);
CEXPORT1(favx, abs_max);
CEXPORT1(favx, abs_minmax);
CEXPORT1(favx, sign_min);
CEXPORT1(favx, sign_max);
CEXPORT1(favx, sign_minmax);

CEXPORT1(favx, lr_to_ms);
CEXPORT1(favx, lr_to_mid);
Expand Down
3 changes: 3 additions & 0 deletions src/main/x86/avx512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@
CEXPORT1(vl, abs_min);
CEXPORT1(vl, abs_max);
CEXPORT1(vl, abs_minmax);
CEXPORT1(vl, sign_min);
CEXPORT1(vl, sign_max);
CEXPORT1(vl, sign_minmax);

CEXPORT1(vl, min_index);
CEXPORT1(vl, max_index);
Expand Down
5 changes: 4 additions & 1 deletion src/main/x86/sse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,13 @@

EXPORT1(min);
EXPORT1(max);
EXPORT1(abs_max);
EXPORT1(abs_min);
EXPORT1(abs_max);
EXPORT1(sign_min);
EXPORT1(sign_max);
EXPORT1(minmax);
EXPORT1(abs_minmax);
EXPORT1(sign_minmax);

EXPORT1(add2);
EXPORT1(sub2);
Expand Down
121 changes: 121 additions & 0 deletions src/test/ptest/search/sign_max.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2024 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-dsp-lib
* Created on: 28 нояб. 2024 г.
*
* lsp-dsp-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-dsp-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>.
*/

#include <lsp-plug.in/common/alloc.h>
#include <lsp-plug.in/common/types.h>
#include <lsp-plug.in/test-fw/helpers.h>
#include <lsp-plug.in/test-fw/ptest.h>

#define MIN_RANK 5
#define MAX_RANK 16

namespace lsp
{
namespace generic
{
float sign_max(const float *src, size_t count);
}

IF_ARCH_X86(
namespace sse
{
float sign_max(const float *src, size_t count);
}

namespace avx
{
float sign_max(const float *src, size_t count);
}

namespace avx512
{
float sign_max(const float *src, size_t count);
}
)

IF_ARCH_ARM(
namespace neon_d32
{
// float sign_max(const float *src, size_t count);
}
)

IF_ARCH_AARCH64(
namespace asimd
{
// float sign_max(const float *src, size_t count);
}
)

typedef float (* search1_t) (const float *src, size_t count);
}

//-----------------------------------------------------------------------------
// Performance test for minimum and maximum searching
PTEST_BEGIN("dsp.search", sign_max, 5, 1000)

void call(const char *label, const float *in, size_t count, search1_t func)
{
if (!PTEST_SUPPORTED(func))
return;

char buf[80];
sprintf(buf, "%s x %d", label, int(count));
printf("Testing %s numbers...\n", buf);

PTEST_LOOP(buf,
func(in, count);
);
}

PTEST_MAIN
{
size_t buf_size = 1 << MAX_RANK;
uint8_t *data = NULL;

float *in = alloc_aligned<float>(data, buf_size, 64);
randomize_sign(in, 1 << MAX_RANK);

#define CALL(func) \
call(#func, in, count, func)

for (size_t i=MIN_RANK; i <= MAX_RANK; ++i)
{
size_t count = 1 << i;

CALL(generic::sign_max);
IF_ARCH_X86(CALL(sse::sign_max));
IF_ARCH_X86(CALL(avx::sign_max));
IF_ARCH_X86(CALL(avx512::sign_max));
// IF_ARCH_ARM(CALL(neon_d32::sign_max));
// IF_ARCH_AARCH64(CALL(asimd::sign_max));
PTEST_SEPARATOR;
}

free_aligned(data);
}

PTEST_END





121 changes: 121 additions & 0 deletions src/test/ptest/search/sign_min.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2024 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-dsp-lib
* Created on: 28 нояб. 2024 г.
*
* lsp-dsp-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-dsp-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>.
*/

#include <lsp-plug.in/common/alloc.h>
#include <lsp-plug.in/common/types.h>
#include <lsp-plug.in/test-fw/helpers.h>
#include <lsp-plug.in/test-fw/ptest.h>

#define MIN_RANK 5
#define MAX_RANK 16

namespace lsp
{
namespace generic
{
float sign_min(const float *src, size_t count);
}

IF_ARCH_X86(
namespace sse
{
float sign_min(const float *src, size_t count);
}

namespace avx
{
float sign_min(const float *src, size_t count);
}

namespace avx512
{
float sign_min(const float *src, size_t count);
}
)

IF_ARCH_ARM(
namespace neon_d32
{
// float sign_min(const float *src, size_t count);
}
)

IF_ARCH_AARCH64(
namespace asimd
{
// float sign_min(const float *src, size_t count);
}
)

typedef float (* search1_t) (const float *src, size_t count);
}

//-----------------------------------------------------------------------------
// Performance test for minimum and maximum searching
PTEST_BEGIN("dsp.search", sign_min, 5, 1000)

void call(const char *label, const float *in, size_t count, search1_t func)
{
if (!PTEST_SUPPORTED(func))
return;

char buf[80];
sprintf(buf, "%s x %d", label, int(count));
printf("Testing %s numbers...\n", buf);

PTEST_LOOP(buf,
func(in, count);
);
}

PTEST_MAIN
{
size_t buf_size = 1 << MAX_RANK;
uint8_t *data = NULL;

float *in = alloc_aligned<float>(data, buf_size, 64);
randomize_sign(in, 1 << MAX_RANK);

#define CALL(func) \
call(#func, in, count, func)

for (size_t i=MIN_RANK; i <= MAX_RANK; ++i)
{
size_t count = 1 << i;

CALL(generic::sign_min);
IF_ARCH_X86(CALL(sse::sign_min));
IF_ARCH_X86(CALL(avx::sign_min));
IF_ARCH_X86(CALL(avx512::sign_min));
// IF_ARCH_ARM(CALL(neon_d32::sign_min));
// IF_ARCH_AARCH64(CALL(asimd::sign_min));
PTEST_SEPARATOR;
}

free_aligned(data);
}

PTEST_END





119 changes: 119 additions & 0 deletions src/test/ptest/search/sign_minmax.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2024 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-dsp-lib
* Created on: 31 мар. 2020 г.
*
* lsp-dsp-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-dsp-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>.
*/

#include <lsp-plug.in/common/alloc.h>
#include <lsp-plug.in/common/types.h>
#include <lsp-plug.in/test-fw/helpers.h>
#include <lsp-plug.in/test-fw/ptest.h>

#define MIN_RANK 5
#define MAX_RANK 16

namespace lsp
{
namespace generic
{
void sign_minmax(const float *src, size_t count, float *min, float *max);
}

IF_ARCH_X86(
namespace sse
{
void sign_minmax(const float *src, size_t count, float *min, float *max);
}

namespace avx
{
void sign_minmax(const float *src, size_t count, float *min, float *max);
}

namespace avx512
{
void sign_minmax(const float *src, size_t count, float *min, float *max);
}
)

IF_ARCH_ARM(
namespace neon_d32
{
// void sign_minmax(const float *src, size_t count, float *min, float *max);
}
)

IF_ARCH_AARCH64(
namespace asimd
{
// void sign_minmax(const float *src, size_t count, float *min, float *max);
}
)

typedef void (* search2_t) (const float *src, size_t count, float *min, float *max);
}

//-----------------------------------------------------------------------------
// Performance test for minimum and maximum searching
PTEST_BEGIN("dsp.search", sign_minmax, 5, 1000)

void call(const char *label, const float *in, size_t count, search2_t func)
{
if (!PTEST_SUPPORTED(func))
return;

char buf[80];
sprintf(buf, "%s x %d", label, int(count));
printf("Testing %s numbers...\n", buf);

float min, max;
PTEST_LOOP(buf,
func(in, count, &min, &max);
);
}

PTEST_MAIN
{
size_t buf_size = 1 << MAX_RANK;
uint8_t *data = NULL;

float *in = alloc_aligned<float>(data, buf_size, 64);
randomize_sign(in, 1 << MAX_RANK);

#define CALL(func) \
call(#func, in, count, func)

for (size_t i=MIN_RANK; i <= MAX_RANK; ++i)
{
size_t count = 1 << i;

CALL(generic::sign_minmax);
IF_ARCH_X86(CALL(sse::sign_minmax));
IF_ARCH_X86(CALL(avx::sign_minmax));
IF_ARCH_X86(CALL(avx512::sign_minmax));
// IF_ARCH_ARM(CALL(neon_d32::sign_minmax));
// IF_ARCH_AARCH64(CALL(asimd::sign_minmax));
PTEST_SEPARATOR;
}

free_aligned(data);
}

PTEST_END


Loading

0 comments on commit 9cd5ce0

Please sign in to comment.