Jerry said:
The OP asked a fairly specific question, including a definition of the
structure of interest. Adding more to that structure simply because the
one he cares about doesn't "support your view" seems disingenuous at
best.
No, he didn't. It was simply an abstract question regarding
efficiency of array vs. pointer access into data aggregates,
possibly simple structs (we don't even know). How can you
say: /a fairly specific question/?
Also, he didn't give any /definition of the structure of interest/
anywhere? He used a generalized idiom that wouldn't even compile.
Whats your point in making such statements?
The problem isn't entirely with the indirection itself, as with the fact
that when making an indirect call, the compiler often can't (or at least
doesn't) carry out optimizations that it would carry out otherwise. If
the function would normally be called indirectly, that's fine and
wonderful -- but there's no indication that would be the case here. As
such, the testing method may be having a substantial effect on the
result.
Thats entirely the point. The compiler *shouldn't* do anything
that we don't want him to do. Why would we create a test case
that probably destroys our interesting part by unpredictable
*global* optimizations? So the indirect call served exactly
the purpose intended by me. Fine.
Because the OP specified exactly this structure as being what he cares
about.
No, he used some symbolic code in order to make his point.
He added even /and so on/ (whatever that means ;-)
Sure -- and it corresponds directly to what the OP said he cared about.
Yes and no ;-)
Yes and no -- I decided it got too long, but probably should have left
in a more detailed analysis of the code. The fact is that yes, there is
a difference in the generated code. The other fact is that there's not
even a theoretical difference in speed. The parts that are different are
between adding one each iteration, then multiplying by 8, or adding 8
either iteration. The addition is the same speed either way. The
multiplication by 8 doesn't change the amount of time either.
Thats not really conclusive for me. As you probably know, the scaled
index variant (mov edi, DWORD PTR [ecx+esi*8+4]) uses at least one byte
of opcode length more than the unscaled one (mov esi, DWORD PTR [ecx+4])
according to the Intel instruction set manual. So your assertion
might be probably wrong.
On the original 8088/8086, there would have been a difference -- calculating an
effective address took a variable amount of time, and the more complex a
calculation used, the longer it took. On those processors, you really
would have gained something by transforming one form to the other -- and
compilers at the time did.
On every since (at least) the 286, there has been an effective address
unit that can carry out the calculation in constant time.
I'm not exactly sure if you are correct here but it reminds me
somehow from the dark that the scaled address generation is ex-
pensive until the Pentium or even P6 (frequent AGI stalls on the P5?).
That being the case, there's no difference in speed based on the complexity of the
effective address calculation -- addressing like [esi], [esi+ebx],
[esi+ebx*8] all take _exactly_ the same amount of time to generate on
every reasonably modern processor.
You have all sorts of issues here, pipelining, instruction size
differences, used up registers (modifications under way in the
pipeline) and so on. /all take _exactly_ the same amount of time/
is nothing I would bet my hand for.
Pardon my being blunt, but "Nonsense". People who write compilers have
known about how to do this transformation for _years_. The reason they
don't do it (at least on the x86) is simple: it's no longer effective.
Nice argument. As you know, there are some implementations of
the x86 instruction set and from running the programs posted
earlier I can see 10-25% difference on effectiveness between
addressing modes with the same program on different cpus.
And this *has* to do with the OP's question: will there
be /bad performance/ or not.
What exactly is the *Nonsense* you found out in your critic
of my paragraph above?
Regards & Thanks
Mirco