Nick Sabalausky wrote:
"Walter Bright" <[email protected]> wrote in message news:[email protected]...
bearophile wrote:
Nick Sabalausky:

Then you're wasting cycles every iteration (by doing an extra addition and maybe an extra shift or even multiplication depending on T: Ie, (cast(ubyte*)myArray.ptr) + i * T.sizeof). That was a pretty common inner-loop optimization back in my C days.
With D sometimes array-based code is faster than pointer-based. With LDC they are usually equally efficient.
??? This makes no sense.

The (ptr+i*T.sizeof) is an addressing mode on the x86, and comes at ZERO cost.


Guess it's been way too long since I've touched x86 asm and my memory's warped :/

OTOH, not all platforms are x86 (but maybe that's still a common thing on other architectures).

Those hardware addressing modes are not there for the 16 bit x86, and dmd's optimizer has a lot of code to rewrite loops to avoid needing them (called loop induction variables). These rewrites speed things up on 16 bit code, but slow things down for 32 bit code, and so are disabled for 32 bit code.

Write a simple loop, try it and see.

Reply via email to