This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CLIP function Intrinsic

Guru 10750 points

Hi All,

Is there a CLIP function Intrinsic?

Many Thanks

HR

  • I'm not sure what a CLIP function intrinsic is, but it might help to know with which platform you are working (e.g., MSP430, C6000, etc.). For what it's worth it doesn't look like the C6000 family has anything like this - see pp. 169-174 of the Compiler Guide.

  • Hi TimHarron,

    Platform - C6x+

    CLIP - #define ClipToInt16(V)    (((V)>MAX_INT16)? MAX_INT16 : ( ((V)<-MAX_INT16)? -MAX_INT16 : (V) ))

    Many Thanks,

    HR

  • It looks like you are trying to saturate a 32-bit number down into a 16-bit number? I don't see any intrinsics listed in the Compiler Guide I pointed out previously that would handle this operation. There are some arithmetic operations which saturate rather than allow for overflow, but these all appear to be for 32-bit values only. I think your best bet is to use the #define equation or write a function instead.

  • Tim,

    OK, Many Thanks for the help,

    HR

  • Your most negative value is -MAX_INT16 instead of MIN_INT16.  If you can accept MIN_INT16 as the most negative value, you could use "_sshl(V, 16)>>16".