QuState / PhastFT

A high-performance, "quantum-inspired" Fast Fourier Transform (FFT) library written in pure and safe Rust.
Apache License 2.0
203 stars 8 forks source link

Swapped out use of sincos() for more portability across platforms #11

Closed dmtrinh closed 7 months ago

dmtrinh commented 7 months ago

sincos() is a GNU extension provided by glibc. With Xcode 15.1 on Apple Silicon, we get the following error:

gcc -Wall -Wextra -Werror -O3 -march=native -o bench_fftw main.c -lfftw3 -lm
main.c:49:9: error: call to undeclared function 'sincos'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        sincos(angles[i], &sin_a, &cos_a);
        ^
main.c:49:9: note: did you mean '__sincos'?
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:658:29: note: '__sincos' declared here
__header_always_inline void __sincos(double __x, double *__sinp, double *__cosp) {

We can, technically, use preprocessor directives to get around this; for example:

        #ifdef __APPLE__
            __sincos(angles[i], &sin_a, &cos_a);
        #else
            sincos(angles[i], &sin_a, &cos_a);
        #endif

However, I feel that's not really elegant. To improve portability across platforms, we should switch to invoking sin() and cos() separately. Yes, this will be theoretically slower -- BUT many good compilers can detect this situation and perform optimization as necessary:

Compiler optimizations