Hello, I am still dreaming of a fast way of inline assembly code for fast addition of 64 bit variables with saturation control. (I need to write 0x7FFFFFF... to the result register, if overflow occurred).
For this purpose it would be necessary to access the BVS and BCS flags directly after addition of 2 register pairs in in line assembly (using conditional code / jump marks).
As compiler version is meanwhile 5 and I have lost a bit the survey on all the enhancements, has any one perhaps a proposal for this?
(In older versions it did not work, because first Thumb code was not allowed in inline assembly. This meanwhile seems to work, but I am frightened it is still not possible to use any sort of conditional statements within the inline assembly, is this correct?)
It works with the following asm function:
__asm LLONG qadd_ll( LLONG a, LLONG b) { ADDS R0, R0, R2 ADCS R1, R1, R3 BVS Oflw_qadd_ll BX LR Oflw_qadd_ll BPL Uflw_qadd_ll // overflow into neg. number range: limit to 0x7FFFF... MOV R0, #0 SUBS R0, #1 LSRS R1, R0, #1 BX LR Uflw_qadd_ll // underflow into pos. number range: limit to 0x8000... MOV R0, #0 MOV R1, #1 LSLS R1, R1, #31 BX LR }
This is quite ok. Just this unfortunately is quite a waste of time, especially hurting if I have to invoke this function several times in an interrupt routine.
(Typically this function will only do the 3 assembler commands ADDS,ADCS,BVS - the other lines in this function are only for overflow case, and of course overflow will happen only very seldom - So the function overhead of BL / BX generates a nearly 100% wast of time to the real add + overlfow check command, not very nice).
I tried to insert __forceinline in front of the function definition "__asm qadd_ll...", but this is just ignored - it will not be invoked inline (I am frightened inlining does not work for asm functions).
When I try to convert this into an __asm{...} construct I fail due to the impossibility to address the low-Register and high-Register of lla / llb - I would need some special "inline-assembler-construct" for this. In GnuCC this is possible, in Microchip compiler inline assembler this also works. It would be VERY nice, if in some future Keil Compiler version this would work also in Keil (as 64 bit arithmetics of course is a helpful thing from time to time ...).