abs_s

Absolute value of a 16-bit integer or fractional value returning a 16-bit result. Returns 0x7FFF for an input of 0x8000.

Assumptions

OMR's SA bit was set to 1 at least three cycles before this code, that is, saturation on data ALU results enabled.

Prototype

  Word16 abs_s(Word16 svar1)

  

  
Example
int result, s1 = 0xE000;  /*  - 0.25    */

result = abs_s(s1);

// Expected value of result: 0x2000 = 0.25