[MLton-user] PackWord32Big is great, but no PackWord16Big
Matthew Fluet
fluet@cs.cornell.edu
Sun, 7 Nov 2004 14:49:09 -0500 (EST)
> > > 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).
PackWord16 is necessary to "efficiently" read/write an Int16 on a
Word8{Array,Vector}; as you point out above, one can manually grab the
Word8.words and combine as necessary.
> 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)
This is a place where you might as well generalize. That is, replace
| Word8Array_subWord (* ssa to rssa *)
| Word8Array_updateWord (* ssa to rssa *)
| Word8Vector_subWord (* ssa to rssa *)
with
| Word8Array_subWord of WordSize.t (* ssa to rssa *)
| Word8Array_updateWord of WordSize.t (* ssa to rssa *)
| Word8Vector_subWord of WordSize.t (* ssa to rssa *)
Then you'll get PackWord{8,16,32,64}Big with one go.
> 2) Using the 2 new _prims I can now define PackWord16Big.
Again, if you make the above generalization, then you ought to be able to
generalize the PackWord32 functor (/basis-library/integer/pack-word32.sml)
to take the six primitive functions and bytesPerElem as arguments.
> How would you suggest supporting PackWord16Little? C functions in the
> runtime like the Word8Array_subWord32Rev found in
> runtime/basis/Int/Word8Array.c ?
I suppose so.