How to implement saturation instructions in ARMv8 architecture?

Is there a way to write an equivalent of 32-bit saturation instruction such  as QADD or QSUB without using neon saturation instructions for Armv8 architecture?  

Parents
  • It should be do-able in C. QADD saturates to the signed integer range -2^31 to (2^31) - 1.

    You can do a regular add and then check that the result. If the result is less than -2^31 or more than (2^31) - 1 you know saturation has occurred (and you can force the result to that value.)

    Stackoverflow has a few posts on the various flavours of singed/unsigned saturating maths you can do, usually with portable C examples.
Reply
  • It should be do-able in C. QADD saturates to the signed integer range -2^31 to (2^31) - 1.

    You can do a regular add and then check that the result. If the result is less than -2^31 or more than (2^31) - 1 you know saturation has occurred (and you can force the result to that value.)

    Stackoverflow has a few posts on the various flavours of singed/unsigned saturating maths you can do, usually with portable C examples.
Children