0

What is most efficient way to saturate int64 value to int32 with ARMv4 instruction set?

  • http://stackoverflow.com/questions/121240/saturating-addition-in-c – auselen Dec 04 '13 at 20:45
  • @auselen I need a signed saturation with 64-bit numbers. I know how to do it in C, but I think it can be somehow optimized in assembler. –  Dec 05 '13 at 04:53

1 Answers1

1

This is close, but the negative clipping to 0x80000000 isn't working. I'll have to think about it a bit longer.

; saturate signed 64-bit int in rhi:rlo to a signed 32-bit int in rlo
    CMP rhi, rlo, ASR #31
    ; if EQ then the high 33-bit are all the same and the answer is rlo
    ; else the answer is (rhi:31 is set) ? 0x80000000 : 0x7fffffff
    MOVNE rlo, rhi, ASR #31
    MVNNE rtmp, rlo ; 'rtmp' can be 'rhi'
    EORNE rlo, rlo, rtmp, LSR #1
scott
  • 728
  • 4
  • 8