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?  

  • 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.
  • Thank you Peter for replying. I know it is pretty straightforward in C but I want to implement it in assembly and that too in ARMv8 architecture. The thing is that in ARMv7 we have a single instruction for that i.e. QADD. But we don't have such instruction in v8 so we need to use neon instruction such as SQADD. Do we have a single instruction to perform such operation in v8?
  • Ah, sorry, I missed the intent of your question.

    The only way to perform saturation in a single instruction is using the SIMD&FP instructions. They do have scalar variants (effectively ignoring all but a single lane - including for flag setting,) but they still operate on the FP register bank and set flags in FPSR rather than PSTATE.