[MLton-commit] r4865

Matthew Fluet fluet at mlton.org
Tue Nov 28 11:39:57 PST 2006


Avoid a redundant Overflow check when zero-extending a Word<N>.word to
{,Large}Int.int.  Cannot overflow if the wordSize of Word<N>.word is
less-than the precision of {,Large}Int.int.


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

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

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

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf0.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf0.sml	2006-11-28 15:49:10 UTC (rev 4864)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf0.sml	2006-11-28 19:39:53 UTC (rev 4865)
@@ -11,10 +11,7 @@
       eqtype int
       type t = int
 
-      datatype rep =
-         Big of C_MPLimb.word vector
-       | Small of ObjptrInt.int
-      val rep: int -> rep
+      val precision: Primitive.Int32.int option
 
       val maxInt: int option
       val minInt: int option
@@ -23,6 +20,11 @@
       val one: int
       val negOne: int
 
+      datatype rep =
+         Big of C_MPLimb.word vector
+       | Small of ObjptrInt.int
+      val rep: int -> rep
+
       structure Prim : 
          sig
             val isSmall: int -> bool
@@ -1229,6 +1231,8 @@
       type int = bigInt
       type t = int
 
+      val precision = NONE
+
       val maxInt = NONE
       val minInt = NONE
          

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sml	2006-11-28 15:49:10 UTC (rev 4864)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sml	2006-11-28 19:39:53 UTC (rev 4865)
@@ -37,6 +37,10 @@
       val i = W.zchckToInt w
    in
       if Primitive.Controls.detectOverflow
+         andalso (case Int.precision of
+                     NONE => false
+                   | SOME precision => 
+                        Int32.<= (precision, W.sizeInBits))
          andalso Int.< (i, 0)
          then raise Overflow
          else i
@@ -48,6 +52,10 @@
       val i = W.zchckToLargeInt w
    in
       if Primitive.Controls.detectOverflow
+         andalso (case LargeInt.precision of
+                     NONE => false
+                   | SOME precision => 
+                        Int32.<= (precision, W.sizeInBits))
          andalso LargeInt.< (i, 0)
          then raise Overflow
          else i

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-int.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-int.sml	2006-11-28 15:49:10 UTC (rev 4864)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-int.sml	2006-11-28 19:39:53 UTC (rev 4865)
@@ -15,6 +15,7 @@
 
       val sizeInBits: Primitive.Int32.int
       val sizeInBitsWord: Primitive.Word32.word
+      val precision: Primitive.Int32.int option
        
       val +? : int * int -> int
       val + : int * int -> int
@@ -103,7 +104,8 @@
       val sizeInBits: Int32.int = 8
       val sizeInBitsWord: Word32.word = 
          IntWordConv.zextdFromInt32ToWord32 sizeInBits
-         
+      val precision = SOME sizeInBits
+
       val +? = _prim "Word8_add": int * int -> int;
       val + =
          if Controls.detectOverflow
@@ -201,6 +203,7 @@
       val sizeInBits: Int32.int = 16
       val sizeInBitsWord: Word32.word = 
          IntWordConv.zextdFromInt32ToWord32 sizeInBits
+      val precision = SOME sizeInBits
          
       val +? = _prim "Word16_add": int * int -> int;
       val + =
@@ -363,6 +366,7 @@
       val sizeInBits: Int32.int = 32
       val sizeInBitsWord: Word32.word = 
          IntWordConv.zextdFromInt32ToWord32 sizeInBits
+      val precision = SOME sizeInBits
          
       val +? = _prim "Word32_add": int * int -> int;
       val + =
@@ -405,6 +409,7 @@
       val sizeInBits: Int32.int = 64
       val sizeInBitsWord: Word32.word = 
          IntWordConv.zextdFromInt32ToWord32 sizeInBits
+      val precision = SOME sizeInBits
          
       val +? = _prim "Word64_add": int * int -> int;
       val + =

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/real/real.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/real/real.sml	2006-11-28 15:49:10 UTC (rev 4864)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/real/real.sml	2006-11-28 19:39:53 UTC (rev 4865)
@@ -374,6 +374,7 @@
                      Fix => 3
                    | Gen => 0
                    | Sci => 2
+               val ndig : C_Int.int = C_Int.fromInt ndig
             in
                One.use (one, fn decpt =>
                         (Prim.gdtoa (x, mode, ndig, decpt), 




More information about the MLton-commit mailing list