public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/49857] New: Put constant switch-tables into flash
@ 2011-07-26 20:50 gjl at gcc dot gnu.org
  2011-07-26 20:57 ` [Bug target/49857] " eric.weddington at atmel dot com
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-07-26 20:50 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Put constant switch-tables into flash
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: gjl@gcc.gnu.org
                CC: eric.weddington@atmel.com
            Target: avr


Created attachment 24837
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24837
C source with constant switch statement

For constant switches like

int sw_2 (char x)
{
    switch(x) 
    { 
        case '0': return -1;
        case '1': return  2;
        case '2': return  3;
        case '3': return  5;
        case '4': return  7;
        case '5': return 11;
        case '6': return 13;
        case '7': return 17;
        case '8': return 19;
        case '9': return 23;
        case 'a':return 29;
        case 'A':return 29;
    }

    return -1;
}

avr-gcc 4.6.1 generates a lookup table (-Os -mmcu=atmega8 -S -fverbose-asm)

sw_2:
    subi r24,lo8(-(-49))     ;  csui.0,
    cpi r24,lo8(49)     ;  csui.0,
    brsh .L3     ; ,
    mov r30,r24     ;  tmp50, csui.0
    ldi r31,lo8(0)     ; ,
    subi r30,lo8(-(CSWTCH.1))     ;  tmp50,
    sbci r31,hi8(-(CSWTCH.1))     ;  tmp50,
    ld r24,Z     ;  tmp51, CSWTCH.1
    clr r25     ;  D.1929
    sbrc r24,7     ;  D.1929
    com r25     ;  D.1929
    ret
.L3:
    ldi r24,lo8(-1)     ;  D.1929,
    ldi r25,hi8(-1)     ;  D.1929,
    ret
    .size    sw_2, .-sw_2
    .data
    .type    CSWTCH.1, @object
    .size    CSWTCH.1, 49
CSWTCH.1:
    .byte    2
    .byte    3
    .byte    5
    .byte    7
    .byte    11
    .byte    13
    .byte    17
    .byte    19
    .byte    23
    .byte    -1
    .byte    -1
    .byte    -1
...

CSWTCH.1 is put in .data (.rodata would not be better) so that the lookup table
ends up in RAM.  

The table is constant and could go into flash memory, i.e. .progmem.data.

===================================

avr-gcc -v -Os -fverbose-asm -mmcu=atmega8 -W -Wall -S foo.c # dp
-mmcu=atmega128 foo.c -save-temps -Os -c
Using built-in specs.
COLLECT_GCC=e:\WinAVR\4.6.1\bin\avr-gcc.exe
COLLECT_LTO_WRAPPER=e:/winavr/4.6.1/bin/../libexec/gcc/avr/4.6.1/lto-wrapper.exe
Target: avr
Configured with: ../../gcc.gnu.org/gcc-4_6-branch/configure --target=avr
--prefix=/local/gnu/install/gcc-4.6-mingw32 --host=i586-mingw32
--build=i686-linux-gnu --enable-languages=c,c++ --disable-nls --disable-shared
--with-dwarf2
Thread model: single
gcc version 4.6.1 20110620 (prerelease) (GCC) 

GNU C (GCC) version 4.6.1 20110620 (prerelease) (avr)
    compiled by GNU C version 3.3.1 (mingw special 20030804-1), GMP version
4.3.2, MPFR version 2.4.2, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32702


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-07-16  9:18 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-26 20:50 [Bug target/49857] New: Put constant switch-tables into flash gjl at gcc dot gnu.org
2011-07-26 20:57 ` [Bug target/49857] " eric.weddington at atmel dot com
2011-12-01 12:49 ` eric.weddington at atmel dot com
2012-01-07 12:23 ` gjl at gcc dot gnu.org
2012-01-29 16:24 ` [Bug tree-optimization/49857] " gjl at gcc dot gnu.org
2012-01-29 17:42 ` [Bug rtl-optimization/49857] " steven at gcc dot gnu.org
2012-01-29 18:32 ` steven at gcc dot gnu.org
2013-03-22 14:45 ` jakub at gcc dot gnu.org
2013-05-31 10:59 ` jakub at gcc dot gnu.org
2013-06-01 13:41 ` gjl at gcc dot gnu.org
2014-04-22 11:37 ` jakub at gcc dot gnu.org
2014-04-22 14:30 ` gjl at gcc dot gnu.org
2015-04-22 12:06 ` jakub at gcc dot gnu.org
2015-07-16  9:18 ` rguenth 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).