hi,
is there a documentation about what code optimization is doing at any level?
How exactly is code optimized at which level?
is it possible (in doubt) to protect variables from being optimized away like by the keyword volatile ?
NXC: code optimization - what and how?
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: NXC: code optimization - what and how?
AFAIK:
No documentation exists.
Volatile has been requested once in the wishlist topic. For now you can only avoid unused variables to be removed by using it somehow without affecting your program (if you don't want to change the optimization level).
Level 0 does nothing. Level 1 removes unused functions and perhaps does other stuff too.
No documentation exists.
Volatile has been requested once in the wishlist topic. For now you can only avoid unused variables to be removed by using it somehow without affecting your program (if you don't want to change the optimization level).
Level 0 does nothing. Level 1 removes unused functions and perhaps does other stuff too.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Re: NXC: code optimization - what and how?
yes, I suspect this, but I mostly use level 2, just out of habit.
-
- Posts: 8
- Joined: 29 Sep 2010, 07:00
Re: NXC: code optimization - what and how?
Can you clarify what functions you are talking about? Is it user's functions declared but not used or system functions?spillerrec wrote:Level 0 does nothing. Level 1 removes unused functions and perhaps does other stuff too.
On the latest test_release (Sept, 9th) I see the following behavior:
Quite simple program:
Code: Select all
task main() {
SetSensorLowspeed(IN_4);
Wait(500);
int tmp;
long strt = CurrentTick();
for(int i=0;i <1000;i++) {
tmp = SensorUS(IN_4);
}
NumOut(12,LCD_LINE4, CurrentTick()-strt);
until(ButtonPressed(BTNCENTER, false) > 0);
}
nxc_002_usp.rxe - 21024
It is for optimization level "0". But I recall that it was not so in the past - such kind of programs were pretty small. Of course, if I enable level 2 of optimization the program takes just 954 bytes.
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: NXC: code optimization - what and how?
It is both user and system functions and most likely variables as well. At some point of time level 0 started including all system functions, I don't know why. Level 0 might have worked differently back then.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Who is online
Users browsing this forum: No registered users and 0 guests