Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of ARM parallel instructions ASX and SAX?

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 image 499
barnie82 Avatar asked Dec 18 '22 15:12

barnie82


1 Answers

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.

like image 72
Ross Ridge Avatar answered Jan 05 '23 03:01

Ross Ridge