avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Inversion of logic improves size speed


From: Anatoly Sokolov
Subject: Re: [avr-gcc-list] Inversion of logic improves size speed
Date: Mon, 27 Aug 2007 00:22:18 +0400

Hi.

This patch optimizes logic left shift of unsigned char by 4, 5, and 6, 
excluding double 'andi' instructions in some cases.


...
> uint8_t getBit4InvShift(uint8_t temp) { uint8_t r = 0; if((temp>>4)&1) 
> r|=0x1; return r; }
> uint8_t getBit5InvShift(uint8_t temp) { uint8_t r = 0; if((temp>>5)&1) 
> r|=0x1; return r; }
> uint8_t getBit6InvShift(uint8_t temp) { uint8_t r = 0; if((temp>>6)&1) 
> r|=0x1; return r; }
...
>
>
> This results in:
....
>
> 00000146 <getBit4InvShift>:
> uint8_t getBit4InvShift(uint8_t temp) { uint8_t r = 0; if((temp>>4)&1)
> r|=0x1; return r; }
> 146: 82 95       swap r24
> 148: 8f 70       andi r24, 0x0F ; 15
> 14a: 81 70       andi r24, 0x01 ; 1
> 14c: 99 27       eor r25, r25
> 14e: 08 95       ret
>
> 00000150 <getBit5InvShift>:
> uint8_t getBit5InvShift(uint8_t temp) { uint8_t r = 0; if((temp>>5)&1)
> r|=0x1; return r; }
> 150: 82 95       swap r24
> 152: 86 95       lsr r24
> 154: 87 70       andi r24, 0x07 ; 7
> 156: 81 70       andi r24, 0x01 ; 1
> 158: 99 27       eor r25, r25
> 15a: 08 95       ret
>
> 0000015c <getBit6InvShift>:
> uint8_t getBit6InvShift(uint8_t temp) { uint8_t r = 0; if((temp>>6)&1)
> r|=0x1; return r; }
> 15c: 82 95       swap r24
> 15e: 86 95       lsr r24
> 160: 86 95       lsr r24
> 162: 83 70       andi r24, 0x03 ; 3
> 164: 81 70       andi r24, 0x01 ; 1
> 166: 99 27       eor r25, r25
> 168: 08 95       ret
>

Now:

00000092 <getBit4InvShift>:
  92: 82 95        swap r24
  94: 81 70        andi r24, 0x01 ; 1
  96: 08 95        ret

00000098 <getBit5InvShift>:
  98: 82 95        swap r24
  9a: 86 95        lsr r24
  9c: 81 70        andi r24, 0x01 ; 1
  9e: 08 95        ret

000000a0 <getBit6InvShift>:
  a0: 82 95        swap r24
  a2: 86 95        lsr r24
  a4: 86 95        lsr r24
  a6: 81 70        andi r24, 0x01 ; 1
  a8: 08 95        ret


Anatoly. 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]