[fpc-devel] Array indexing vs. pointers
Martin
lazarus at mfriebe.de
Thu Nov 7 21:22:43 CET 2013
On 07/11/2013 19:57, Jim Leonard wrote:
> On 11/7/2013 6:21 AM, Sven Barth wrote:
>> The resulting instructions depend highly on the architecture. E.g. on
>> x86 and m68k for the first case a MOV/MOVE instruction with a multiplier
>> will be used while on other platforms this might involve an explicit
>> multiplication. Also it will depend on the optimization level you use
>> (e.g. on x86 the generated code for the first case is very different
>> between -O2 and -O3). In the end you'd need to calculate the instruction
>> timings to know whether one of the two is really faster than the other
>> (and then you can compare that later on with your own implementation to
>> check whether your code or the compiler's is faster ^^)
>
> I'm on x86. I was hoping for a little more than "profile it to find
> out" (for example, if pointers are optimized to be in indexing
> registers then it should be obvious that is fastest), but if I have to
> do that, then I guess that's what I'll have to do.
>
> I suppose I can just write a short program that indexes data many
> different ways and then examine the asm output.
If you know the execution times of the underlying asm code, you can
compile with -al
Then you get asm sources that you can look at.
You need to look through which optimization flags are available, and
check different fpc versions.
IIRC (but not sure) fpc 2.6.0 would calculate the address of the array
element in every run of the loop (via multiplication / from scratch)
I do not know if having a pointer, and increasing it (addition) is
indeed faster (I would expect it, but ... / actually I did it on intel
once and it was faster).
But looking at the asm, you can see if it is done or not
More information about the fpc-devel
mailing list