Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Float array to double array and back, quickly

I need to convert large arrays of float in memory to arrays of double and back. Are there any SSE compiler intrinsics in Visual C++ 15 update 3 that would help?

EDIT: it's a conversion between two wire formats, so #define won't help. A data structure is stored as floats, but a third party processing library expects an array of double.

like image 340
Seva Alekseyev Avatar asked Jul 18 '26 04:07

Seva Alekseyev


1 Answers

You can use SSE for this:

float -> double: _mm_cvtps_pd

double -> float: _mm_cvtpd_ps

Try a simple scalar loop first though as (a) the compiler may vectorize for you anyway and (b) you may well be memory-bound, so SIMD optimisation may not help much.

like image 120
Paul R Avatar answered Jul 21 '26 04:07

Paul R