On Sat, Jul 04, 2020 at 09:07:35AM -0400, Brian Brombacher wrote: > > >> On Jul 1, 2020, at 1:14 PM, gwes <g...@oat.com> wrote: > >> > >> On 7/1/20 8:05 AM, Luke Small wrote: > >> I spoke to my favorite university computer science professor who said > >> ++n is faster than n++ because the function needs to store the initial > >> value, increment, then return the stored value in the former case, > >> while the later merely increments, and returns the value. Apparently, > >> he is still correct on modern hardware. > > For decades the ++ and *p could be out of order, in different > > execution units, writes speculatively queued, assigned to aliased registers, > > etc, etc, etc. > > > > Geoff Steckel > > Hey Luke, > > I love the passion but try to focus your attention on the fact that their are > multiple architectures supported and compiler optimizations are key here. Go > with Marc’s approach using arch/ asm. Implementations can be made over time > for the various arch’s, if such an approach is desirable by the project. You > can pull a well-optimized version based on your code, for your arch, and then > slim it down a bunch. > > Cheers, > Brian > > [Not a project developer. Just an observer.] > >
Another data point for consideration: the pdp11 instruction set had post-increment and pre-decrement indirect memory reference instructions. If I'm not mistaken, using pre-increment or post decrement on this architecture would impose a penalty. So your university computer science professor making such sweeping statements maybe doesn't deserve to be your favorite. -Otto