[MLton] MLton misses 'assumed' Word optimization

Wesley W. Terpstra wesley@terpstra.ca
Mon, 23 May 2005 19:40:10 +0200


>From <http://www.standardml.org/Basis/word.html>

	It also is assumed that implementations will catch the idiom of
	converting between words and integers of differing precisions using
	an intermediate representation (e.g., Word32.fromLargeWord o
	Word8.toLargeWord) and optimize these conversions.

Compile the program:
	val convertWord = Word32.fromLarge o Word16.toLarge
	val opt = (hd o CommandLine.arguments) ()
	val out = (convertWord o valOf o Word16.fromString) opt
	val () = print (Word32.toString out ^ "\n")

See the assembler:
L_728:
        movl (c_stackP+(0*4)),%esi
        xchgl %esi,%esp
        pushw (localWord16+((0*2)+(0*1)))
        call WordU16_toWord64
        addl $2,%esp
L_727:
        pushl %edx
        pushl %eax
        call WordU64_toWord32
        addl $8,%esp

I'm surpised by two things here:
	1. MLton didn't use WordU16_toWord32
	2. That WordU16_toWord32 requires a C function call at all

Am I off my rocker here; should MLton really be doing this?
It seems that this works for Int..?

-- 
Wesley W. Terpstra