Feature Requests item #1839786, was opened at 2007-11-27 12:58
Message generated for change (Comment added) made by nobody
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=350599&aid=1839786&group_id=599
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Priority: 5
Private: No
Submitted By: Laszlo BORTEL (bortel)
Assigned to: Nobody/Anonymous (nobody)
Summary: Optimisation of structure array access
Initial Comment:
This is not a bug report but an optimisation request.
When accessing an element of a structure array with constant array index the constant array index offset and the constant element offset could be added first at compile time and then the array's base address added to the combined offset at runtime. This would result both in halved code size and halved execution time.
Presently produced code:
mov r2,dpl
mov r3,dph
BugReport13.c:11: return s1[3].ch;
mov a,#0x15 ;array index offset 3*7=21
add a,r2
mov r2,a
clr a
addc a,r3
mov r3,a
mov a,#0x06 ;structure element offset
add a,r2
mov dpl,a
clr a
addc a,r3
mov dph,a
clr a
movc a,@a+dptr
mov dpl,a
ret
Optimised code according to the proposal:
mov r2,dpl
mov r3,dph
BugReport13.c:11: return s1[3].ch;
mov a,#0x1B ;combined offset 3*7+6
add a,r2
mov dpl,a
clr a
addc a,r3
mov dph,a
clr a
movc a,@a+dptr
mov dpl,a
ret
I do not know the inner workings of the compiler so I cannot judge the complexity of such combined evaluation but from efficiency point of view it is definitely reasonable.
Command to compile:
C:\Laci\GCR250>sdcc -v
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.7.4 #4972 (Nov 24 2007) (MINGW32)
C:\Laci\GCR250>ver
Microsoft Windows XP [Version 5.1.2600]
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2007-12-27 15:14
Message:
Logged In: NO
i think, it would be great if there was a standalone optimizer that is
working with an intermediate representation, so that these things can be
decoupled from the rest of sdcc and do not unnecessarily bloat sdcc but
rather become a separate component of sdcc, which may optionally be
extended using plugins or scripts
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=350599&aid=1839786&group_id=599

Feature Requests item #1839786, was opened at 2007-11-27 12:58
Message generated for change (Comment added) made by nobody
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=350599&aid=1839786&group_id=599
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Priority: 5
Private: No
Submitted By: Laszlo BORTEL (bortel)
Assigned to: Nobody/Anonymous (nobody)
Summary: Optimisation of structure array access
Initial Comment:
This is not a bug report but an optimisation request.
When accessing an element of a structure array with constant array index the constant array index offset and the constant element offset could be added first at compile time and then the array's base address added to the combined offset at runtime. This would result both in halved code size and halved execution time.
Presently produced code:
mov r2,dpl
mov r3,dph
BugReport13.c:11: return s1[3].ch;
mov a,#0x15 ;array index offset 3*7=21
add a,r2
mov r2,a
clr a
addc a,r3
mov r3,a
mov a,#0x06 ;structure element offset
add a,r2
mov dpl,a
clr a
addc a,r3
mov dph,a
clr a
movc a,@a+dptr
mov dpl,a
ret
Optimised code according to the proposal:
mov r2,dpl
mov r3,dph
BugReport13.c:11: return s1[3].ch;
mov a,#0x1B ;combined offset 3*7+6
add a,r2
mov dpl,a
clr a
addc a,r3
mov dph,a
clr a
movc a,@a+dptr
mov dpl,a
ret
I do not know the inner workings of the compiler so I cannot judge the complexity of such combined evaluation but from efficiency point of view it is definitely reasonable.
Command to compile:
C:\Laci\GCR250>sdcc -v
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.7.4 #4972 (Nov 24 2007) (MINGW32)
C:\Laci\GCR250>ver
Microsoft Windows XP [Version 5.1.2600]
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2007-12-27 15:14
Message:
Logged In: NO
i think, it would be great if there was a standalone optimizer that is
working with an intermediate representation, so that these things can be
decoupled from the rest of sdcc and do not unnecessarily bloat sdcc but
rather become a separate component of sdcc, which may optionally be
extended using plugins or scripts
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=350599&aid=1839786&group_id=599