Rust
Posted Apr 7, 2013 21:50 UTC (Sun) by
HelloWorld (guest, #56129)
In reply to:
Rust by hummassa
Parent article:
Mozilla and Samsung building a new browser engine
The restrict keyword, by itself, does not add some opportunities for loop unrollings where aliased things are used inside the loops.
I don't understand that, can you give an example?
The lack of defining pure functions, without side-effects, also elide some opportunities for repeated code removal.
Modern optimising compilers try to figure out whether a function is pure and optimise accordingly. Example:
#include <stdio.h>
int sq(int i) {
return i*i;
}
int main(int argc, char **argv) {
int i = strtol(argv[1], 0, 0);
printf("%d\n", sq(i) * sq(i));
return 0;
}
Compiled with
gcc -O3 -fno-inline-small-functions -S -masm=intel (gcc 4.7.2) this yields
...
call strtol
mov edi, eax
call sq
imul eax, eax
mov edi, OFFSET FLAT:.LC0
mov esi, eax
xor eax, eax
call printf
...
So gcc sees that
sq is a pure function and only calls it once, even though it's called twice in the source code. Granted, this isn't quite the same as in Fortran as the compiler needs to be able to see the definition of the relevant function for this to work. But due to link-time optimisation this isn't as big a limitation as it used to be. I'm not convinced the Fortran way offers significant benefits in the real world.
(
Log in to post comments)