Fast double -> short conversion with clamping using SSE?
- by gct
Is there a fast way to cast double values to shorts (16 bits signed), currently I'm doing something like this:
double dval = <sum junk>
int16_t sval;
if (val > int16_max) {
sval = int16_max;
} else if (val < int16_min) {
sval = int16_min;
} else
sval = (int16_t)val;
I suspect there's a fast way to do this using SSE that will be significantly more efficient.