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.65k stars 253 forks source link

change constexpr constants to functions #83

Closed slarew closed 2 years ago

slarew commented 4 years ago

Using clang 8.0.1 and lld 8.0.1 linker, I had to make the changes in this PR to fix the following error messages:

/usr/bin/clang++-8  -march=native -Og -ggdb -fPIC -fvisibility=hidden -DKFR_STD_COMPLEX -mstackrealign -mavx2 -mno-avx512f -mno-avx512pf -mno-avx512er -mno-avx512cd -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512ifma -mno-avx512vbmi -DKFR_DEBUG -std=gnu++14 -o thing.cpp.o -c thing.cpp

/usr/bin/clang++-8 -fPIC -march=native -Og -ggdb  -shared -Wl,-soname,thing.so -o thing.so abunchof.o -Wl,--no-undefined -fuse-ld=lld thing.so libkfr_dft.so 
ld.lld: error: undefined symbol: kfr::scalar_constants<float>::recip_log_10
>>> referenced by log_exp.hpp:146 (kfr/include/kfr/cometa/../math/impl/log_exp.hpp:146)
>>>               thing.cpp.o:(kfr::avx2::vec<float, 8ul> kfr::avx2::intrinsics::log10<float, 8ul, float>(kfr::avx2::vec<float, 8ul> const&))

ld.lld: error: undefined symbol: kfr::scalar_constants<float>::qnan
>>> referenced by log_exp.hpp:98 (kfr/include/kfr/cometa/../math/impl/log_exp.hpp:98)
>>>               thing.cpp.o:(kfr::avx2::vec<float, 8ul> kfr::avx2::intrinsics::log<8ul>(kfr::avx2::vec<float, 8ul> const&))

ld.lld: error: undefined symbol: kfr::scalar_constants<float>::neginfinity
>>> referenced by log_exp.hpp:98 (kfr/include/kfr/cometa/../math/impl/log_exp.hpp:98)
>>>               thing.cpp.o:(kfr::avx2::vec<float, 8ul> kfr::avx2::intrinsics::log<8ul>(kfr::avx2::vec<float, 8ul> const&))

ld.lld: error: undefined symbol: kfr::scalar_constants<float>::recip_log_10
>>> referenced by log_exp.hpp:146 (kfr/include/kfr/cometa/../math/impl/log_exp.hpp:146)
>>>               thing.cpp.o:(kfr::avx2::vec<float, 1ul> kfr::avx2::intrinsics::log10<float, 1ul, float>(kfr::avx2::vec<float, 1ul> const&))

ld.lld: error: undefined symbol: kfr::scalar_constants<float>::qnan
>>> referenced by log_exp.hpp:98 (kfr/include/kfr/cometa/../math/impl/log_exp.hpp:98)
>>>               thing.cpp.o:(kfr::avx2::vec<float, 1ul> kfr::avx2::intrinsics::log<1ul>(kfr::avx2::vec<float, 1ul> const&))

ld.lld: error: undefined symbol: kfr::scalar_constants<float>::neginfinity
>>> referenced by log_exp.hpp:98 (kfr/include/kfr/cometa/../math/impl/log_exp.hpp:98)
>>>               thing.cpp.o:(kfr::avx2::vec<float, 1ul> kfr::avx2::intrinsics::log<1ul>(kfr::avx2::vec<float, 1ul> const&))

A snippet of the code that eventually uses those missing constants is:

thing = log10(real(cabssqr(fft_frame_univector)));
dancazarin commented 4 years ago

Hi,

KFR requires C++17 standard since version 4.0. In C++17 class static fields are implicitly inline, so ADL issues (undefined symbol errors as in your example) don't happen here in C++17. I can merge this pull request into a separate branch c++14 but there are many other places where C++17 features are actively used, if constexpr, fold expressions etc, so moving back to C++14 is impractical at least for main development.

Do you have problems with changing -std=gnu++14 to -std=gnu++17?

slarew commented 2 years ago

I upgraded to C++17.