[MLton] Re: [MLton-user] How to write performant network code
Wesley W. Terpstra
wesley at terpstra.ca
Thu Jan 15 07:52:35 PST 2009
(moved from mlton-user)
On Wed, Jan 14, 2009 at 10:24 PM, Wesley W. Terpstra <wesley at terpstra.ca> wrote:
> Have you noticed that calling Word32.fromLarge o
> PackWord32Little.subVec will generate this:
> call WordU32_extdToWord64
> call WordU64_extdToWord32
In general, 64-bit Words/Ints suck in MLton 32-bit because it just
passes the work to a C call. Wouldn't it make more sense to implement
a Word64 using Word32 * Word32 and do the arithmetic in the basis
library? The conversion to/from LargeWord would then be automatically
detected by the optimizer as being useless. Then we would just pick to
use the real Word64 for 64-bit machines and the fake Word64 on 32-bit.
The problem with my proposal is of course that tuples are not
FFI-friendly.
I looked into the ssa directory to see how to implement an
optimization pass that detects and simplifies these cases:
x_1107: word64 = WordU8_extdToWord64 (x_1108)
x_1106: word32 = WordU64_extdToWord32 (x_1107)
x_1227: word32 = Word8Vector_subWord32 (x_1072, x_1074)
x_1226: word64 = WordU32_extdToWord64 (x_1227)
x_1225: word32 = WordU64_extdToWord32 (x_1226)
I'm not really sure how to do this. It seems fairly easy to detect two
lines one after another that can be combined (like the above example),
but I don't know how to be sure that x_122[56] are used nowhere else.
Also, this approach wouldn't result in nearly the same performance
gains as the Word64 = Word32 * Word32 approach. One could also
implement the Word64_ primapps in the x86 codegen to avoid some of the
overhead (seems fairly straight-forward).
> How about I just add a MLton.Socket.Address.toVector which simply
> exposes the underlying Word8Vector.vector in network byte order?
The (completely trivial) patch is attached. Ok to commit?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: addressToVecctor.patch
Type: text/x-patch
Size: 739 bytes
Desc: not available
Url : http://mlton.org/pipermail/mlton/attachments/20090115/2b55d95f/addressToVecctor.bin
More information about the MLton
mailing list