Sorry guys, mistakenly deleted the previous post.

Sorry guys, mistakenly deleted the previous post.

Ok, guys A. Bouchez​​
I have a weird scenario here.
I have a piece of code which I am trying to optimize as much as possible.
It involves an array and a loop in which the loop is used to transverse the array (the array length is known at compile time), retrieve its contents and perform some pretty simple integer and bit shifting operations (to be precise, rotate left) on it (the contents) and write back to that index in the array.
In my quest for optimizations, I manually unrolled the loop and got the shock of my life,
The unrolled variant was way slower, in fact, 2 times slower than the rolled variant.
Fuelled by my inquisitiveness, I decided to try out the same code in Free Pascal to verify my doubts, and true to my doubts, the unrolled version was faster in Free Pascal.
Below is a little benchmark info

Delphi 10 Berlin Starter Rolled variant 10.2 secs
Delphi 10 Berlin Starter Unrolled variant 21.5 secs
Free Pascal Rolled variant 7.4 secs
Free Pascal Unrolled variant 3.6 secs

Both compilers were set to their highest optimizations levels (release mode).


So my question is why does Delphi "hate" manually unrolled loops and has anyone encountered such scenario before ?

Thanks.

Comments

  1. Just a wild guess that it doesn't fit into lowest level cache anymore and have to do extra work...

    ReplyDelete

Post a Comment