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.

signum() aka sgn() function

Is there an efficient way to implement the signum function efficiently using compiler intrinsics on the C2000 family?

Assuming x is a 16 bit signed int.

sgn(x) = 1 if x>0, -1 if x<0, and 0 if x=0

Using if statements results in slow code due to the branches/pipeline hits ect.

I'm assuing there is a very clever way to implement this using the sign bit or a right shift with sign extend by 15.