Fast double -> short conversion with clamping using SSE?

Posted by gct on Stack Overflow See other posts from Stack Overflow or by gct
Published on 2010-06-08T21:25:43Z Indexed on 2010/06/08 21:32 UTC
Read the original article Hit count: 314

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about c

    Related posts about cast