10 ms·
I would guess that Fortran's advantage is because Fortran's semantics prohibit aliasing - it is clear to the Fortran compiler whether a variable will ever have
by nostrademons 12y ago
I would guess that Fortran's advantage is because Fortran's semantics prohibit aliasing - it is clear to the Fortran compiler whether a variable will ever have its address taken, and the compiler doesn't have to be as conservative in assuming that some pointer may silently change the value within a function's execution. This opens up a lot of optimizations for inlining and storing variables - even complex structs - in registers, which in turn opens up options for SIMD vectorization.
- srean 12y agoI am aware of the aliasing issue and that is exactly what I hinting at with (a) and (b) I think aliasing is only a part of the story. I have benchmarked (now long lost) Fortran and C++ with __restrict__ pointers(non-standard, but supported on gcc which is what I was using). Fortran still came out faster, and yes __restrict__ did make a difference in the runtime of the loop. In retrospect I should have kept the code around so that I could show the assembly to someone who could read and see whats going on. I dont really know Fortran, it was just a one-off noodling fueled by curiosity.