Can someone explain when it's beneficial to use the parallel add/subtract ARM instructions ASX
and/or SAX
? In what situation/algorithm would one need to exhange the halfwords, then add AND subtract the upper/lower halfwords? Below is the explanation of each:
ASX
- Exchange halfwords of
Rm
, then Add top halfwords and Subtract bottom halfwords.SAX
- Exchange halfwords of
Rm
, then Subtract top halfwords and Add bottom halfwords.
Like Russ Schultz said in a comment it would be useful audio encoded with L+R and L-R channels. It would be used something like:
ldr r1, [r0] ; R1 = (L-R):(L+R)
shasx r1, r1, r1 ; R1 = ((L-R)+(L+R))/2:((L+R)-(L-R))/2
; = (2L/2):(2R/2)
; = L:R
ror r1, r1, #16 ; R1 = R:L
str r1, [r0]
The swapping of the third operand's top and bottom halfwords is necessary so the two different components can be added/subtracted with each other. Without the exchange you'd get ((L-R)+(L-R))/2:((L+R)-(L+R))/2 = (2(L-R)/2):(0/2) = (L-R):0
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With