public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/29560]  New: Poor optimization for character shifts on Atmel AVR
@ 2006-10-23 11:39 gcc-bugzilla at gcc dot gnu dot org
  2006-10-24  7:32 ` [Bug target/29560] " r dot leitgeb at x-pin dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2006-10-23 11:39 UTC (permalink / raw)
  To: gcc-bugs


        For setting individual bits of a register, the construct
        unsigned char BitLocation = Whatever;
        REG |= (1<<BitLocation); 
        is commonly used. avr-gcc fails to realize that the target register
        is only 8 bits wide and performs an unnecessary 16-Bit shift of 1.
        Even if this code snippet is replaced by the following:
        unsigned char BitLocation = Whatever;
        const unsigned char one = 1;
        REG |= (one << BitLocation);
        The inefficient code will be generated, even with the -Os flag.
        I suppose this is because the << operator is not defined for 8-bit
        wide data types.

Environment:
System: Darwin variable.local 7.9.0 Darwin Kernel Version 7.9.0: Wed Mar 30
20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC Power Macintosh
powerpc



host: powerpc-apple-darwin7.9.0
build: powerpc-apple-darwin7.9.0
target: avr-unknown-none
configured with: ../configure --target=avr --prefix=/usr/local/atmel
--enable-languages=c --disable-libssp --enable-__cxa_atexit
--enable-clocale=gnu --disable-nls : (reconfigured) ../configure --target=avr
--prefix=/usr/local/avr --enable-languages=c --disable-libssp
--enable-__cxa_atexit --enable-clocale=gnu --disable-nls

How-To-Repeat:
        Use the following test program, compile with -Os -S to see assembler 
        code generated by avr-gcc:
        #include <avr/io.h>

        void setpin(unsigned char pin, unsigned char val) {
                if (val == 1) PORTC |= (1<<pin);
                else PORTC &= ~(1<<pin);
        }

        void setpin1(unsigned char pin, unsigned char val) {
                const unsigned char one = 1;
                if (val == 1) PORTC |= (one<<pin);
                else PORTC &= ~(one<<pin);
        }

        int main(void) {
                setpin(3, 1);
                setpin1(3, 1);
                return 0;
        }


------- Comment #1 from r dot leitgeb at x-pin dot com  2006-10-23 11:39 -------
Fix:
        Define shift operators for 8 bit wide data types, use if possible.
        I'm not a compiler expert but I know that the multiply operator
        detects the data types involved, so it should be doable with the
        shift operators as well.


-- 
           Summary: Poor optimization for character shifts on Atmel AVR
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: r dot leitgeb at x-pin dot com
 GCC build triplet: powerpc-apple-darwin7.9.0
  GCC host triplet: powerpc-apple-darwin7.9.0
GCC target triplet: avr-unknown-none


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29560


^ permalink raw reply	[flat|nested] 11+ messages in thread
[parent not found: <bug-29560-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2011-08-10  9:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-23 11:39 [Bug target/29560] New: Poor optimization for character shifts on Atmel AVR gcc-bugzilla at gcc dot gnu dot org
2006-10-24  7:32 ` [Bug target/29560] " r dot leitgeb at x-pin dot com
2009-08-24 17:18 ` [Bug target/29560] [avr] Poor optimization for byte shifts eric dot weddington at atmel dot com
2009-12-31  3:16 ` hutchinsonandy at gcc dot gnu dot org
2010-02-18 13:28 ` Rudolf dot Leitgeb at gmx dot at
     [not found] <bug-29560-4@http.gcc.gnu.org/bugzilla/>
2011-06-21 18:25 ` gjl at gcc dot gnu.org
2011-07-23 14:51 ` gjl at gcc dot gnu.org
2011-07-23 14:55 ` gjl at gcc dot gnu.org
2011-07-25 12:49 ` gjl at gcc dot gnu.org
2011-08-10  8:59 ` gjl at gcc dot gnu.org
2011-08-10  9:20 ` gjl at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).