[MLton] Int Overflow detection
Jesper Louis Andersen
Thu, 17 Mar 2005 10:36:53 +0100
Quoting Neophytos Michael (firstname.lastname@example.org):
> I am only showing the main loop here (this is with int overflow turned off).
> So it's 4 instructions for gcc versus 9 for mlton.
> Some comments:
It might not matter that much. There are more than one execution unit in
modern processors, so comparing number of instructions does not lead to
a direct performance comparison.
> 1. There are two jumps in mlton's case and only one for gcc. This is because
> gcc checks for the exit condition outside the loop and only enters the loop if
> it will do at least one iteration. This saves one jump instruction within the
Branch prediction often eliminates the overhead with having too many jumps. I
think with a trace cache added, that the jump gets totally removed from tight
code as this.
> 2. There are two extra movl instructions that Mlton could easily get rid of by
> noticing that the incremented value is not used until the next iteration of the
> loop and so it could be done at the end. But it doesn't seem to do instruction
Instruction reordering is quite tricky when you also have to consider overflow
exceptions. It greatly reduces the amount of reordering possible. While this is
an extra cost, it greatly enhances the program correctness in the overflow
Anyway, time them. Let us see if it factors to 4/9 in speed.