Subject:
|
NQC, what gives the fastest code ?
|
Newsgroups:
|
lugnet.robotics.rcx.nqc
|
Date:
|
Tue, 8 May 2001 21:25:50 GMT
|
Viewed:
|
2116 times
|
| |
| |
hi All,
I'm not a C-programmer, so maybe I'm asking a (very) stupid question.
In searching for the fastest algoritme, I looked into the code generated by NQC (through RCXcc-orginal ;-)).
I noticed that when you write your code in basic elementary 2 operand instructions, it becomes a lot faster.
In the example below, I would like (as a Pascal programmer) to write the code surrounded by "AAAA",
but the code surrounded with "BBBB" is much faster.
The differences become larger as the calculations become more complex.
Am I using the C-language wrong ?
Is this general behaviour of C ?
Is this the behaviour of the used compiler ?
or what else ??
THE EXAMPLE PROGRAM
task testnqc()
{
int x;
// AAAA the code I prefer to write
x=SENSOR_1;
SetSerialData(1,x);
SetSerialData(2,(x / 128));
// AAAA
// BBBB but this code is more efficient
x=SENSOR_1;
SetSerialData(1,x);
x=x/128;
SetSerialData(2,x);
// BBBB
}
CODE GENERATED BY NQC
*** Task 1 = testnqc
000 setv var[47], Input(0) 14 2f 09 00 00
005 set SerSetting(1), var[47] 05 21 01 00 2f 00
011 setv var[46], var[47] 14 2e 00 2f 00
016 divv var[46], 128 44 2e 02 80 00
021 set SerSetting(2), var[46] 05 21 02 00 2e 00
027 setv var[47], Input(0) 14 2f 09 00 00
032 set SerSetting(1), var[47] 05 21 01 00 2f 00
038 divv var[47], 128 44 2f 02 80 00
043 set SerSetting(2), var[47] 05 21 02 00 2f 00
Stef Mientki
|
|
Message has 1 Reply: | | Re: NQC, what gives the fastest code ?
|
| It has very little to do with C itself - its really a question of compiler optimization. NQC doesn't have any explicit optimization passes, and there is no data flow or variable lifetime analysis, so often the assembly will be a bit inefficient. (...) (24 years ago, 9-May-01, to lugnet.robotics.rcx.nqc)
|
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|