[MLton-user] PackWord32Big is great, but no PackWord16Big

Raymond Racine rracine@adelphia.net
Sun, 07 Nov 2004 14:30:17 -0500


On Sun, 2004-11-07 at 13:34, Matthew Fluet wrote:
> > Are there plans for a PackWord16Big? or was it considered unnecessary as
> > one could manually shift and/or mask and get/set a Word8Array a Word8 at
> > a time?
> 
> I don't see that it would be particularly difficult to add additional
> PackWord<N>{Big,Little} structures.  PackWord32{Big,Little} was of obvious
> utility; the others less so.  The actual implementation is only 62 lines,
> and could be further functorized to better support additional sizes.  We
> would also need to add a couple of additional primitives, but again, they
> would be natural generalizations of existing ones.

I was poking around this morning and I'm currently noted the following. 
Please correct the incorrect assumptions.

-PackWord16 is necessary to write/read a Int16 on a Socket stream (which
is the GOAL here).

-Word8Array based on the mono_array can read/write Word8s of course.
There exist _prims to sub/update Word32's in and out of Word8Array's.

ssa-to-rssa.fun: | Word8Array_updateWord =>
ssa-to-rssa.fun:       add (Move {dst = (ArrayOffset
ssa-to-rssa.fun:                     {base = a 0, index = a 1,
                                            offset = Bytes.zero,
                                            scale = Type.scale
Type.defaultWord,
                                            ty = Type.defaultWord}),

- There exists _imports of C functions found in the runtime section that
do the LittleEndian byte swaps on the Word32.

Conclusion: To accomplish the GOAL.

1) I would need to add 2 _prims:  Word8Array_updateWord16 and
Word8Array_subWord16 patterned on the above.  (scale change and
ancillary if necessary.  Have not looked deeper yet)

2) Using the 2 new _prims I can now define PackWord16Big.

How would you suggest supporting PackWord16Little?  C functions in the
runtime like the Word8Array_subWord32Rev  found in
runtime/basis/Int/Word8Array.c ?

If this sketch is accurate.  I could give it a whirl on the 2 additional
_prims, the PackWord16 and finally the little support as well.

Ray