kfrlib / kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
https://www.kfrlib.com
GNU General Public License v2.0
1.62k stars 248 forks source link

Any chance to get the generic neon simd backend build fixed? #172

Closed jcelerier closed 1 year ago

jcelerier commented 1 year ago

e.g. i'm getting a lot of these:

from kfr/dsp/../base/expression.hpp:29:
     kfr/dsp/../base/../simd/impl/../impl/backend_generic.hpp: In function 'kfr::neon::intrinsics::simd<float, 4> kfr::neon::intrinsics::simd_from_halves(simd_t<float, 4>, simd<float, 2>&, simd<float, 2>&)':
     kfr/dsp/../base/../simd/impl/../impl/backend_generic.hpp:1499:40: error: 'kfr::neon::intrinsics::simd<float, 2>' {aka 'const struct kfr::neon::intrinsics::simd_halves<float, 2>'} has no member named 'whole'
      1499 |     return _mm_castpd_ps(_mm_setr_pd(x.whole, y.whole));
           |                                        ^~~~~

with GCC 12 on RPi (can be tried with the x-tools-armv8-rpi3-linux-gnueabihf.tar.xz cross toolchain here: https://github.com/tttapa/docker-arm-cross-toolchain/releases/tag/0.0.9)

jcelerier commented 1 year ago

i'm also not sure why it calls _mm_$$$$ intrinsincs which definitely does not look like NEON...

jcelerier commented 1 year ago

also seeing:

kfr/dsp/../base/../simd/impl/../impl/../impl/select.hpp:223:24: error: cannot convert 'const kfr::neon::vec<kfr::bit<float>, 4>::simd_type' {aka 'const float32x4_t'} to 'uint32x4_t'
  223 |     return vbslq_f32(m.v, x.v, y.v);
      |                      ~~^
      |                        |
      |                        const kfr::neon::vec<kfr::bit<float>, 4>::simd_type {aka const float32x4_t}

this allows to get through, is it a correct fix ? I also need to pass -flax-vector-conversions

KFR_INTRINSIC f32neon select(const mf32neon& m, const f32neon& x, const f32neon& y)
{
    return vbslq_f32(std::bit_cast<uint32x4_t>(m.v), x.v, y.v);
}
jcelerier commented 1 year ago

for the first error, the following patch makes my build pass:

diff --git a/include/kfr/simd/impl/backend_generic.hpp b/include/kfr/simd/impl/backend_generic.hpp
index b6a3270..590304d 100644
--- a/include/kfr/simd/impl/backend_generic.hpp
+++ b/include/kfr/simd/impl/backend_generic.hpp
@@ -1493,6 +1493,7 @@ KFR_INTRINSIC simd<T, N> simd_from_halves(simd_t<T, N>, const simd<T, N / 2>& x,
     return { x, y };
 }

+#if defined(CMT_ARCH_SSE2)
 KFR_INTRINSIC simd<float, 4> simd_from_halves(simd_t<float, 4>, const simd<float, 2>& x,
                                               const simd<float, 2>& y)
 {
@@ -1507,6 +1508,7 @@ KFR_INTRINSIC simd<double, 2> simd_from_halves(simd_t<double, 2>, const simd<dou

 SIMD_TYPE_INTRIN(f32, 4, _mm_cvtss_f32(x), _mm_set_ss(x), _mm_set1_ps(x), _mm_setzero_ps())
 SIMD_TYPE_INTRIN(f64, 2, _mm_cvtsd_f64(x), _mm_set_sd(x), _mm_set1_pd(x), _mm_setzero_pd())
+#endif 
dancazarin commented 1 year ago

Hi,

Clang is required for non-x86 builds, including ARM. backend_generic that causes these errors is intended for GCC and MSVC on x86 architecture. KFR has been tested on Raspberry Pi with clang and passes all tests.