[MLton-commit] r5421

Matthew Fluet fluet at mlton.org
Sun Mar 11 19:07:55 PST 2007


Restored use of Word8{Array,Vector}_{sub,update} primitives for PackWord{N} structures; we should also implement bswap in ML and eliminate the *Rev functions
----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/pack-word.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-pack-word.sml

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/pack-word.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/pack-word.sml	2007-03-11 19:26:59 UTC (rev 5420)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/pack-word.sml	2007-03-12 03:07:55 UTC (rev 5421)
@@ -10,11 +10,11 @@
                         type word
                         val wordSize: int
                         val isBigEndian: bool
-                        val subArr: Word8.word array * C_Ptrdiff.t -> word
+                        val subArr: Word8.word array * SeqIndex.int -> word
                         val subArrRev: Word8.word array * C_Ptrdiff.t -> word
-                        val subVec: Word8.word vector * C_Ptrdiff.t -> word
+                        val subVec: Word8.word vector * SeqIndex.int -> word
                         val subVecRev: Word8.word vector * C_Ptrdiff.t -> word
-                        val update: Word8.word array * C_Ptrdiff.t * word -> unit
+                        val update: Word8.word array * SeqIndex.int * word -> unit
                         val updateRev: Word8.word array * C_Ptrdiff.t * word -> unit
                         val toLarge: word -> LargeWord.word
                         val toLargeX: word -> LargeWord.word
@@ -26,12 +26,7 @@
 
 val bytesPerElem = Int.div (wordSize, 8)
 
-val (subA, subV, updA) =
-   if isBigEndian = Primitive.MLton.Platform.Arch.hostIsBigEndian
-      then (subArr, subVec, update)
-   else (subArrRev, subVecRev, updateRev)
-
-fun offset (i, n) =
+fun offsetForC (i, n) =
    let
       val i = Int.* (bytesPerElem, i)
       val () =
@@ -44,6 +39,24 @@
    end
    handle Overflow => raise Subscript
 
+fun offsetForML (i, n) = 
+   let
+      val i' = Int.* (bytesPerElem, i)
+      val () =
+         if Primitive.Controls.safe
+            andalso (Int.geu (Int.+ (i', Int.- (bytesPerElem, 1)), n))
+            then raise Subscript
+            else ()
+   in
+      SeqIndex.fromInt i
+   end
+   handle Overflow => raise Subscript
+
+val (subA, subV, updA, offset) =
+   if isBigEndian = Primitive.MLton.Platform.Arch.hostIsBigEndian
+      then (subArr, subVec, update, offsetForML)
+   else (subArrRev, subVecRev, updateRev, offsetForC)
+
 fun update (a, i, w) =
    let
       val i = offset (i, Word8Array.length a)
@@ -85,61 +98,73 @@
    PackWord (val wordSize = Word8.wordSize
              val isBigEndian = true
              open PrimitiveFFI.PackWord8
+             open Primitive.PackWord8
              open Word8)
 structure PackWord8Little: PACK_WORD =
    PackWord (val wordSize = Word8.wordSize
              val isBigEndian = false
              open PrimitiveFFI.PackWord8
+             open Primitive.PackWord8
              open Word8)
 structure PackWord8Host: PACK_WORD =
    PackWord (val wordSize = Word8.wordSize
              val isBigEndian = Primitive.MLton.Platform.Arch.hostIsBigEndian
              open PrimitiveFFI.PackWord8
+             open Primitive.PackWord8
              open Word8)
 structure PackWord16Big: PACK_WORD =
    PackWord (val wordSize = Word16.wordSize
              val isBigEndian = true
              open PrimitiveFFI.PackWord16
+             open Primitive.PackWord16
              open Word16)
 structure PackWord16Little: PACK_WORD =
    PackWord (val wordSize = Word16.wordSize
              val isBigEndian = false
              open PrimitiveFFI.PackWord16
+             open Primitive.PackWord16
              open Word16)
 structure PackWord16Host: PACK_WORD =
    PackWord (val wordSize = Word16.wordSize
              val isBigEndian = Primitive.MLton.Platform.Arch.hostIsBigEndian
              open PrimitiveFFI.PackWord16
+             open Primitive.PackWord16
              open Word16)
 structure PackWord32Big: PACK_WORD =
    PackWord (val wordSize = Word32.wordSize
              val isBigEndian = true
              open PrimitiveFFI.PackWord32
+             open Primitive.PackWord32
              open Word32)
 structure PackWord32Little: PACK_WORD =
    PackWord (val wordSize = Word32.wordSize
              val isBigEndian = false
              open PrimitiveFFI.PackWord32
+             open Primitive.PackWord32
              open Word32)
 structure PackWord32Host: PACK_WORD =
    PackWord (val wordSize = Word32.wordSize
              val isBigEndian = Primitive.MLton.Platform.Arch.hostIsBigEndian
              open PrimitiveFFI.PackWord32
+             open Primitive.PackWord32
              open Word32)
 structure PackWord64Big: PACK_WORD =
    PackWord (val wordSize = Word64.wordSize
              val isBigEndian = true
              open PrimitiveFFI.PackWord64
+             open Primitive.PackWord64
              open Word64)
 structure PackWord64Little: PACK_WORD =
    PackWord (val wordSize = Word64.wordSize
              val isBigEndian = false
              open PrimitiveFFI.PackWord64
+             open Primitive.PackWord64
              open Word64)
 structure PackWord64Host: PACK_WORD =
    PackWord (val wordSize = Word64.wordSize
              val isBigEndian = Primitive.MLton.Platform.Arch.hostIsBigEndian
              open PrimitiveFFI.PackWord64
+             open Primitive.PackWord64
              open Word64)
 local
    local

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-pack-word.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-pack-word.sml	2007-03-11 19:26:59 UTC (rev 5420)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-pack-word.sml	2007-03-12 03:07:55 UTC (rev 5421)
@@ -17,15 +17,15 @@
       type word = Word8.word
 
       val subArr = 
-         _import "PackWord8_subArr": Word8.word array * C_Ptrdiff.t -> word;
+         _prim "Word8Array_subWord8": Word8.word array * SeqIndex.int -> word;
       val subArrRev = 
          _import "PackWord8_subArrRev": Word8.word array * C_Ptrdiff.t -> word;
       val subVec = 
-         _import "PackWord8_subVec": Word8.word vector * C_Ptrdiff.t -> word;
+         _prim "Word8Vector_subWord8": Word8.word vector * SeqIndex.int -> word;
       val subVecRev = 
          _import "PackWord8_subVecRev": Word8.word vector * C_Ptrdiff.t -> word;
       val update = 
-         _import "PackWord8_update": Word8.word array * C_Ptrdiff.t * word -> unit;
+         _prim "Word8Array_updateWord8": Word8.word array * SeqIndex.int * word -> unit;
       val updateRev = 
          _import "PackWord8_updateRev": Word8.word array * C_Ptrdiff.t * word -> unit;
    end
@@ -35,15 +35,15 @@
       type word = Word16.word
 
       val subArr = 
-         _import "PackWord16_subArr": Word8.word array * C_Ptrdiff.t -> word;
+         _prim "Word8Array_subWord16": Word8.word array * SeqIndex.int -> word;
       val subArrRev = 
          _import "PackWord16_subArrRev": Word8.word array * C_Ptrdiff.t -> word;
       val subVec = 
-         _import "PackWord16_subVec": Word8.word vector * C_Ptrdiff.t -> word;
+         _prim "Word8Vector_subWord16": Word8.word vector * SeqIndex.int -> word;
       val subVecRev = 
          _import "PackWord16_subVecRev": Word8.word vector * C_Ptrdiff.t -> word;
       val update = 
-         _import "PackWord16_update": Word8.word array * C_Ptrdiff.t * word -> unit;
+         _prim "Word8Array_updateWord16": Word8.word array * SeqIndex.int * word -> unit;
       val updateRev = 
          _import "PackWord16_updateRev": Word8.word array * C_Ptrdiff.t * word -> unit;
    end
@@ -53,15 +53,15 @@
       type word = Word32.word
 
       val subArr = 
-         _import "PackWord32_subArr": Word8.word array * C_Ptrdiff.t -> word;
+         _prim "Word8Array_subWord32": Word8.word array * SeqIndex.int -> word;
       val subArrRev = 
          _import "PackWord32_subArrRev": Word8.word array * C_Ptrdiff.t -> word;
       val subVec = 
-         _import "PackWord32_subVec": Word8.word vector * C_Ptrdiff.t -> word;
+         _prim "Word8Vector_subWord32": Word8.word vector * SeqIndex.int -> word;
       val subVecRev = 
          _import "PackWord32_subVecRev": Word8.word vector * C_Ptrdiff.t -> word;
       val update = 
-         _import "PackWord32_update": Word8.word array * C_Ptrdiff.t * word -> unit;
+         _prim "Word8Array_updateWord32": Word8.word array * SeqIndex.int * word -> unit;
       val updateRev = 
          _import "PackWord32_updateRev": Word8.word array * C_Ptrdiff.t * word -> unit;
    end
@@ -71,15 +71,15 @@
       type word = Word64.word
 
       val subArr = 
-         _import "PackWord64_subArr": Word8.word array * C_Ptrdiff.t -> word;
+         _prim "Word8Array_subWord64": Word8.word array * SeqIndex.int -> word;
       val subArrRev = 
          _import "PackWord64_subArrRev": Word8.word array * C_Ptrdiff.t -> word;
       val subVec = 
-         _import "PackWord64_subVec": Word8.word vector * C_Ptrdiff.t -> word;
+         _prim "Word8Vector_subWord64": Word8.word vector * SeqIndex.int -> word;
       val subVecRev = 
          _import "PackWord64_subVecRev": Word8.word vector * C_Ptrdiff.t -> word;
       val update = 
-         _import "PackWord64_update": Word8.word array * C_Ptrdiff.t * word -> unit;
+         _prim "Word8Array_updateWord64": Word8.word array * SeqIndex.int * word -> unit;
       val updateRev = 
          _import "PackWord64_updateRev": Word8.word array * C_Ptrdiff.t * word -> unit;
    end




More information about the MLton-commit mailing list