#166 Why does sdcc store string constants extremly inefficiently?

open
nobody
None
5
2016-04-12
2006-09-26
No

sdcc sometimes stores string constants extremly
inefficiently. It seems all ports are affected (I tried
Z80 and PIC14).

I compiled with
sdcc -c -mz80 --std-c99
and
sdcc -c -mpic14 -p16c745 --std-c99
sdcc --version gives
SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.6.0 #4309 (Aug 16 2006) (UNIX)

The follwing small program shows the problem:

const char test1[] = "testtest1";

void test(void)
{
const char test2[] = "testtest2";
const static char test3[] = "testtest3";
}

sdcc generates optimal code for test1. For both test2
and test3 suboptimal code is generated.
The pic14 port generates a movlw and a movwf for every
byte of test2 or test3.
The z80 port generates 6 ld instructions, one add and
one adc for every byte of test2. It generates two ld
instructions per byte of test3.

All of the string constants used could be stored as
efficiently as test1, since they are constants and thus
could reside in ROM. Now the generated code is a waste
of RAM, ROM and runtime.

Philipp Krause

Discussion

  • b-s-a

    b-s-a - 2010-11-11

    This problem also related to struct intialization.

     
  • Philipp Klaus Krause

    The test3 case is the same as RFE #3034739.

    Philipp

     
  • Philipp Klaus Krause

    test3 is fine on current SDCC; only leaving test2 for this feature request.

    Philipp

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks