Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » SDCC
  • » [Sdcc-user] Another optimization missing for the 8051 compiler [RSS Feed]

#1 Dec. 18, 2010 19:01:00

Rod B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] Another optimization missing for the 8051 compiler


All,

I have the following code fragment:
unsigned int test0;
unsigned int test1;

if( 0 == test0 )
{
test0 = 1;
}

if( !test1 )
{
test1 = 1
}

The list output shows the following:
0000 E5*00 113 mov a,_test0
0002 70 04 114 jnz 00109$
0004 E5*01 115 mov a,(_test0 + 1)
0006 60 02 116 jz 00110$
0008 117 00109$:
0008 80 06 118 sjmp 00102$
000A 119 00110$:
120 ; test51.c:8: test0 = 1;
000A 75*00 01 121 mov _test0,#0x01
000D E4 122 clr a
000E F5*01 123 mov (_test0 + 1),a
0010 124 00102$:
125 ; test51.c:11: if( !test1 )
0010 E5*02 126 mov a,_test1
0012 45*03 127 orl a,(_test1 + 1)
128 ; test51.c:13: test1 = 0;
0014 70 04 129 jnz 00105$
0016 F5*02 130 mov _test1,a
0018 F5*03 131 mov (_test1 + 1),a


My question is why is the first 'if' statement not optimized to be the
same as the 2nd if statement. This is using an extra 4-code space bytes.

Lets not have any code stylistic comments I personally think the 1st if
statement is clearer and that is what the companies coding standard
mandates.

I currently don't need the missing 4-bytes of code space and will only
note this in the delivery notes.

Regards,
Rod Boyce



Sdcc-user mailing list
Sdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user

Offline

#2 Dec. 19, 2010 18:01:32

Rod B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] Another optimization missing for the 8051 compiler


All,

I have the following code fragment:
unsigned int test0;
unsigned int test1;

if( 0 == test0 )
{
test0 = 1;
}

if( !test1 )
{
test1 = 1
}

The list output shows the following:
0000 E5*00 113 mov a,_test0
0002 70 04 114 jnz 00109$
0004 E5*01 115 mov a,(_test0 + 1)
0006 60 02 116 jz 00110$
0008 117 00109$:
0008 80 06 118 sjmp 00102$
000A 119 00110$:
120 ; test51.c:8: test0 = 1;
000A 75*00 01 121 mov _test0,#0x01
000D E4 122 clr a
000E F5*01 123 mov (_test0 + 1),a
0010 124 00102$:
125 ; test51.c:11: if( !test1 )
0010 E5*02 126 mov a,_test1
0012 45*03 127 orl a,(_test1 + 1)
128 ; test51.c:13: test1 = 0;
0014 70 04 129 jnz 00105$
0016 F5*02 130 mov _test1,a
0018 F5*03 131 mov (_test1 + 1),a


My question is why is the first 'if' statement not optimized to be the
same as the 2nd if statement. This is using an extra 4-code space bytes.

Lets not have any code stylistic comments I personally think the 1st if
statement is clearer and that is what the companies coding standard
mandates.

I currently don't need the missing 4-bytes of code space and will only
note this in the delivery notes.

Regards,
Rod Boyce




Sdcc-user mailing list
Sdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user

Offline

  • Root
  • » SDCC
  • » [Sdcc-user] Another optimization missing for the 8051 compiler [RSS Feed]

Board footer

Moderator control

Enjoy the 23rd of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support