Version française
Home     About     Download     Resources     Contact us    
Browse thread
Comparison of OCaml and MLton for numerics
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Comparison of OCaml and MLton for numerics
On Fri, 2007-06-01 at 19:49 -0400, Brian Hurt wrote:
> 
> On Sat, 2 Jun 2007, skaller wrote:
> 
> > On Fri, 2007-06-01 at 10:57 -0400, Brian Hurt wrote:
> >>  And the third case, where inlining opens up new
> >> possibilities for optimization- that almost has to be done by the
> >> compiler, as it depends upon what optimizations the compiler can, and
> >> will, apply to the newly inlined function.  This is something I trust
> >> the compiler to do more than I trust even me to do correctly.
> >
> > It's NOT so easy to predict how much optimisation will result
> > from inlining. Just think about it, you have a tree of inlining
> > opportunities, if do you really want to attempt to estimate the
> > coefficients on N inlining choices just to decide if you'll
> > inline or not?
> 
> Nor is it easy for the programmer to guess how much optimization will 
> result from inlining! 

That's partly true. For Felix, some functions are 'generated
by the system'. For example

	val x  = if a then b else c endif;

looks cute, but actually is just sugar for:

	val x = match a with
	| true => b
	| _ => c
	endmatch

which in turn is just sugar for

	val arg = a;
	fun matches_1 () => a == true;
	fun matches_2 () => true;
	fun handler_1() { tmp = b; }
	fun handler_2() { tmp = c; }

	if matches_1 () then handler_1()
	elif matches_2 () then handler_2()
	else error "Match failure";
	x = tmp;

except the real code is even worse than that. Felix guarantees
compiler generated functions are inlined: such functions are
always children and never recursive without going through a
user function .. however they might
exceed the inlining threshold .. they're inlined anyhow.

This is because such 'automagically' generated functions can't
be tagged 'inline' or 'noinline' by the end user.

The reason the guarantee is made is simple: it's the only way
to be sure the compiler reduces 'dumb C looking code' into
'dumb C code', that is, to ensure WYSIWIG. For example
the above code 'had better' result in code like:

	if(!a) goto l1;
	x = b;
	goto l2;
l1:
	x = c;
l2:


or Felix won't be as fast as C. The guarantee makes it possible
to simplify the front end, by reducing 'everything' to lambdas,
applications, and other fairly simply terms.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net