subs t0, a0, b0noprsblt t0, t0, #0subs t1, b0, c0rsblt t1, t1, #0cmp t0, #25bge .exitcmp t1, #30bge .exitsubs t2, c0, a0rsblt t2, t2, #0nopcmp t2, # 45bge .bloc2 // modify the values of a0,b0,c0b .exit.bloc2 //modify the values of a0 and b0.exit
SUB r3,r0,r1 SUB r4,r1,r2 ADDS r3,r3,#(25-1) ADDS r4,r4,#(30-1) CMP r3,#(2*(25-1)) SUB r3,r2,r0 CMPLS r4,#(2*(30-1)) ADD r3,r3,#(45-1) BHI Take_None // modify none CMP r3,#(2*(45-1)) BHI Take_Second // modify a0,b0 B Take_First // modify a0,b0,c0
How can optimize the above condition ladder using thumb instructions. i replace the abs() library function by substraction.
; r0 = a0 ; r1 = b0 ; r2 = c0 ; r3 = scratch ; r4 = scratch SUB r3,r0,r1 SUB r4,r1,r2 ADDS r3,r3,#(25-1) ADDS r4,r4,#(30-1) CMP r3,#(2*(25-1)) SUB r3,r2,r0 CMPLS r4,#(2*(30-1)) ADD r3,r3,#(45-1) BHI Take_None // modify none CMP r3,#(2*(45-1)) BHI Take_Second // modify a0,b0 B Take_First // modify a0,b0,c0