This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/33049] New: AVR: bit extraction non optimal, inversing logic solves problem
- From: "wvangulik at xs4all dot nl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 Aug 2007 17:53:29 -0000
- Subject: [Bug c/33049] New: AVR: bit extraction non optimal, inversing logic solves problem
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Using this version/config:
~~~~~~~~~~~~~~~~~
Using built-in specs.
Target: avr
Configured with: ../gcc-4.1.2/configure --prefix=/c/WinAVR --target=avr
--enable
-languages=c,c++ --with-dwarf2 --enable-win32-registry=WinAVR-20070525
--disable
-nls --with-gmp=/usr/local --with-mpfr=/usr/local --enable-doc --disable-libssp
Thread model: single
gcc version 4.1.2 (WinAVR 20070525)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I compiled the source using this command line:
avr-gcc -S -Os test.c -mmcu=atmega16
These examples also suffers from double and instruction missed (bugID 11259)
The key point is that writing an expression like:
tmp = 0; if(var&(1<<N)) tmp|=1;
results in an N shift (done by loop if N larger then 3)
While rewriting to:
tmp = 0; if(var>>N)&1) tmp|=1;
This uses a swap instruction and then shifts. It's optimal (except from the
same loss as bugID 12259 for N >= 4)
Maybe this gives a hint on where the shifting is generally going wrong. I tried
3 approaches in the test.c file.
Another interresting thing is the removal off the extra and instructions in the
last examples in the file.
--
Summary: AVR: bit extraction non optimal, inversing logic solves
problem
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: wvangulik at xs4all dot nl
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33049