round_val

Rounds a 32-bit fractional value into a 16-bit result. When an accumulator is the destination, zeroes out the LSP portion.

Assumptions

OMR's R bit was set to 1 at least three cycles before this code, that is, two's complement rounding, not convergent rounding.

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 round(Word32 lvar1)

  
Example
long l = 0x12348002;/*if low 16 bits = 0xFFFF > 0x8000 then add 1 */

short result;



result = round_val(l);

// Expected value of result: 0x1235