#75 only use direct assignment if it's faster

open
nobody
None
5
2004-08-11
2004-06-04
Anonymous
No

I has found several mistakes in SDCC:

Source:
#include <8052.h>

#define ppl_in_lev3 P0_0
#define ppl_in_lev2 P0_1
#define ppl_in_lev1 P0_2
#define ppl_in_lev0 P0_3

unsigned char tmp;

unsigned char get_ppl(void)
{
register unsigned char tmp;
tmp=4;
if (ppl_in_lev3==1)
{
tmp--;
if (ppl_in_lev2==1)
{
tmp--;
if (ppl_in_lev1==1)
{
tmp--;
if (ppl_in_lev0==1)
{
tmp--;
}
}
}
}
return tmp;
}

void main(void)
{
get_ppl();
}

SDCC run command:

sdcc --verbose --model-small --peep-asm -mmcs51 --
iram-size 256
--xram-size 0 --code-size 12288 --nojtbound test.c

SDCC version:

SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51
/ds400/hc08 2.4.1 (Jun 3 2004) (MINGW32)

Asm list:
353 ;test.c:10: unsigned char
get_ppl(void)
354 ; ---------------------------
--------------
355 ; function get_ppl
356 ; ---------------------------
--------------
0031 357 _get_ppl:
0002 358 ar2 = 0x02
0003 359 ar3 = 0x03
0004 360 ar4 = 0x04
0005 361 ar5 = 0x05
0006 362 ar6 = 0x06
0007 363 ar7 = 0x07
0000 364 ar0 = 0x00
0001 365 ar1 = 0x01
366 ;test.c:13: tmp=4;
367 ; genAssign
0031 7A 04 368 mov
r2,#0x04 <======
assign ok
369 ; genIfx
370 ; genIfxJump
371 ; Peephole 111 removed
ljmp by inverse jump logic
0033 30 80 0F 372 jnb
_P0_0,00108$
0036 373 00115$:
374 ;test.c:16: tmp--;
375 ; genAssign
0036 7A 03 376 mov
r2,#0x03 <======
may be: dec r2 ?
377 ; genIfx
378 ; genIfxJump
379 ; Peephole 111 removed
ljmp by inverse jump logic
0038 30 81 0A 380 jnb
_P0_1,00108$
003B 381 00116$:
382 ;test.c:19: tmp--;
383 ; genAssign
003B 7A 02 384 mov
r2,#0x02 <======
may be: dec r2 ?
385 ; genIfx
386 ; genIfxJump
387 ; Peephole 111 removed
ljmp by inverse jump logic
003D 30 82 05 388 jnb
_P0_2,00108$
0040 389 00117$:
390 ;test.c:22: tmp--;
391 ; genMinus
392 ; genMinusDec
0040 1A 393 dec
r2 <====== OK
394 ; genIfx
395 ; genIfxJump
396 ; Peephole 111 removed
ljmp by inverse jump logic
0041 30 83 01 397 jnb
_P0_3,00108$
0044 398 00118$:
399 ;test.c:25: tmp--;
400 ; genMinus
401 ; genMinusDec
0044 1A 402 dec
r2 <====== OK
0045 403 00108$:
404 ;test.c:30: return tmp;
405 ; genRet
0045 8A 82 406 mov dpl,r2
0047 407 00109$:
0047 22 408 ret

Discussion

  • Maarten Brock

    Maarten Brock - 2004-08-11
    • summary: SDCC MCS51 code generation bug 3 --> only use direct assignment if it's faster
     
  • Maarten Brock

    Maarten Brock - 2004-08-11

    Logged In: YES
    user_id=888171

    Another nice feature request, but no bug

     
  • Yee_Keat Phuah

    Yee_Keat Phuah - 2004-08-17

    Logged In: YES
    user_id=940150

    Assuming a "- 1" or "+ 1" will always be cheaper than
    assignment, below is a quick and dirty patch:

    Index: SDCCcse.c

    RCS file: /cvsroot/sdcc/sdcc/src/SDCCcse.c,v
    retrieving revision 1.94
    diff -r1.94 SDCCcse.c
    1955c1955,1958
    < !computeOnly && ic->op != ADDRESS_OF)
    ---
    > !computeOnly && ic->op != ADDRESS_OF &&
    > ((operandLitValue(IC_RIGHT(ic))!=1.0) &&
    (ic->op!='+' && ic->op!='-'))
    >
    > )

    Which prompts me to question whether we should propagate
    "++" and "--" all the way to the ports code generation,
    instead of converting them to general addition/subtraction,
    and have genMinus to check if it can use genMinusDec.

     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks