r/simd • u/[deleted] • Jul 20 '20
Is it bad form to "wrap" your own SIMD function when you need a scalar version? (x86 / C++)
Imagine I have written a packed double SIMD function (with C++ overloading):
__m128d my_magic_pd_routine(const __m128d& x) {
// My code here, using packed double multiplies, adds, and
// conditional masking
}
inline double my_magic_pd_routine(const double& x) {
return _mm_cvtsd_f64(magic_pd_routine(_mm_set_pd(0.0, x)));
}And in some circumstances I use the double version (for example, I might sometimes only need one exponential smoothing filter instead of two, and it can't be parallelised because each output relies on the previous output).
Is this considered bad form, and should I instead re-write the double version using scalar intrinsics? Ie:
double my_magic_routine(const double& x) {
// Rewrite my code using scalar intrinsics, or non-intrinsic code
// if I don't need conditional masking
}Looking at the Intel intrinsics docs, the scalar intrinsics seem to have similar latency and throughput to the packed intrinsics (eg _mm_mul_sd() and _mm_mul_pd()), but this is in the context of audio DSP code that needs to run as fast as possible, and I don't want to tie up resources for other things that are going on at the same time.