CHAPTER 16. REPLACING ARITHMETIC INSTRUCTIONS TO OTHER ONES CHAPTER 16. REPLACING ARITHMETIC INSTRUCTIONS TO OTHER ONES
But there are no such modifiers in Thumb mode. It also can’t optimizef2():
Listing 16.7: Optimizing Keil 6/2013 (Thumb mode)
; a7
||f1|| PROC
LSLS r1,r0,#3
; R1=R0<<3=a<<3=a8
SUBS r0,r1,r0
; R0=R1-R0=a8-a=a7
BX lr
ENDP
; a28
||f2|| PROC
MOVS r1,#0x1c ; 28
; R1=28
MULS r0,r1,r0
; R0=R1R0=28*a
BX lr
ENDP
; a17
||f3|| PROC
LSLS r1,r0,#4
; R1=R0<<4=R016=a16
ADDS r0,r0,r1
; R0=R0+R1=a+a16=a*17
BX lr
ENDP
MIPS
Listing 16.8: Optimizing GCC 4.4.5 (IDA)
_f1:
sll $v0, $a0, 3
; $v0 = $a0<<3 = $a08
jr $ra
subu $v0, $a0 ; branch delay slot
; $v0 = $v0-$a0 = $a08-$a0 = $a0*7
_f2:
sll $v0, $a0, 5
; $v0 = $a0<<5 = $a032
sll $a0, 2
; $a0 = $a0<<2 = $a04
jr $ra
subu $v0, $a0 ; branch delay slot
; $v0 = $a032-$a04 = $a0*28
_f3:
sll $v0, $a0, 4
; $v0 = $a0<<4 = $a016
jr $ra
addu $v0, $a0 ; branch delay slot
; $v0 = $a016+$a0 = $a0*17
64-bit
#include <stdint.h>
int64_t f1(int64_t a)
{
return a*7;
};