Saturated arithmetic SSE2
I am writing some kind of audio processing software and I need to know how to do rich arithmetic using SSE2 double precision instructions. My values ββneed to be normalized between -1 and 1. Is there a sane way to do this with the built-in SSE2 or do I need 2 sets of if / else statements (one for each value)?
+3
source to share
1 answer
To copy double precision values ββin the range -1.0 to +1.0, you can use max / min operations. For example. if you have a buffer,, buff
from N values double
:
const __m128d kMax = _mm_set1_pd(1.0);
const __m128d kMin = _mm_set1_pd(-1.0);
for (int i = 0; i < N; i += 2)
{
__m128d v = _mm_loadu_pd(&buff[i]);
v = _mm_max_pd(v, kMin);
v = _mm_min_pd(v, kMax);
_mm_storeu_pd(&buff[i], v);
}
+4
source to share