From 8bb51bc1bf17fd490a1646c964b67dc05fc9e519 Mon Sep 17 00:00:00 2001 From: Jatin Chowdhury Date: Fri, 17 Dec 2021 18:27:12 +0000 Subject: [PATCH 1/3] Try to fix weird isnan casting bug --- modules/chowdsp_dsp/SIMD/chowdsp_SIMDUtils.h | 4 ++-- .../chowdsp_utils_test/dsp_tests/simd_tests/SIMDUtilsTest.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/chowdsp_dsp/SIMD/chowdsp_SIMDUtils.h b/modules/chowdsp_dsp/SIMD/chowdsp_SIMDUtils.h index e31bad577..12e072303 100644 --- a/modules/chowdsp_dsp/SIMD/chowdsp_SIMDUtils.h +++ b/modules/chowdsp_dsp/SIMD/chowdsp_SIMDUtils.h @@ -277,8 +277,8 @@ Based on: https://forum.juce.com/t/divide-by-simdregister/28968/18 template inline typename juce::dsp::SIMDRegister::vMaskType isnanSIMD (juce::dsp::SIMDRegister x) { - using Vec = juce::dsp::SIMDRegister; - return Vec::notEqual ((Vec) xsimd::isnan ((x_type) x.value), (Vec) 0); + using MaskVec = typename juce::dsp::SIMDRegister::vMaskType; + return (MaskVec) xsimd::isnan ((x_type) x.value); } // Template specializations for NEON double precision diff --git a/tests/chowdsp_utils_test/dsp_tests/simd_tests/SIMDUtilsTest.cpp b/tests/chowdsp_utils_test/dsp_tests/simd_tests/SIMDUtilsTest.cpp index 3dd14b303..25f06b41c 100644 --- a/tests/chowdsp_utils_test/dsp_tests/simd_tests/SIMDUtilsTest.cpp +++ b/tests/chowdsp_utils_test/dsp_tests/simd_tests/SIMDUtilsTest.cpp @@ -165,7 +165,7 @@ class SIMDUtilsTest : public TimedUnitTest vec.set (j, (FloatType) r.nextFloat()); } } - + auto isnan = chowdsp::SIMDUtils::isnanSIMD (vec); auto testNumNans = std::abs ((int) isnan.sum()); expectEquals (testNumNans, numNans, "Incorrect number of NANs detected!"); From 4975645951213324d22dde980c612e1b8041d344 Mon Sep 17 00:00:00 2001 From: Jatin Chowdhury Date: Sat, 18 Dec 2021 12:45:43 +0000 Subject: [PATCH 2/3] Try to fix SIMDUtils::isnan compatibility between SSE and ARM NEON --- modules/chowdsp_dsp/SIMD/chowdsp_SIMDUtils.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/chowdsp_dsp/SIMD/chowdsp_SIMDUtils.h b/modules/chowdsp_dsp/SIMD/chowdsp_SIMDUtils.h index 12e072303..855aaca67 100644 --- a/modules/chowdsp_dsp/SIMD/chowdsp_SIMDUtils.h +++ b/modules/chowdsp_dsp/SIMD/chowdsp_SIMDUtils.h @@ -277,8 +277,15 @@ Based on: https://forum.juce.com/t/divide-by-simdregister/28968/18 template inline typename juce::dsp::SIMDRegister::vMaskType isnanSIMD (juce::dsp::SIMDRegister x) { + // For some reason, xsimd::isnan returns a batch of doubles when using SSE + // but returns a batch of unsigned ints when using ARM NEON. +#if JUCE_ARM using MaskVec = typename juce::dsp::SIMDRegister::vMaskType; return (MaskVec) xsimd::isnan ((x_type) x.value); +#else + using Vec = juce::dsp::SIMDRegister; + return Vec::notEqual ((Vec) xsimd::isnan ((x_type) x.value), (Vec) 0); +#endif } // Template specializations for NEON double precision From 5109c26cfa89d3f3a610ff2576b5343dc01ed191 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 18 Dec 2021 12:49:24 +0000 Subject: [PATCH 3/3] Apply clang-format --- tests/chowdsp_utils_test/dsp_tests/simd_tests/SIMDUtilsTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/chowdsp_utils_test/dsp_tests/simd_tests/SIMDUtilsTest.cpp b/tests/chowdsp_utils_test/dsp_tests/simd_tests/SIMDUtilsTest.cpp index 25f06b41c..3dd14b303 100644 --- a/tests/chowdsp_utils_test/dsp_tests/simd_tests/SIMDUtilsTest.cpp +++ b/tests/chowdsp_utils_test/dsp_tests/simd_tests/SIMDUtilsTest.cpp @@ -165,7 +165,7 @@ class SIMDUtilsTest : public TimedUnitTest vec.set (j, (FloatType) r.nextFloat()); } } - + auto isnan = chowdsp::SIMDUtils::isnanSIMD (vec); auto testNumNans = std::abs ((int) isnan.sum()); expectEquals (testNumNans, numNans, "Incorrect number of NANs detected!");