[MLton-commit] r5524

Matthew Fluet fluet at mlton.org
Fri Apr 13 16:20:48 PDT 2007


Implement Real{32,64}_nextAfter{Down,Up} in ML
----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/basis-ffi.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/check-real.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/real/real.sml
D   mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/nextAfter.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/basis-ffi.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def
U   mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.sml

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

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/basis-ffi.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/basis-ffi.sml	2007-04-13 16:48:04 UTC (rev 5523)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/basis-ffi.sml	2007-04-13 23:20:47 UTC (rev 5524)
@@ -943,8 +943,6 @@
 val muladd = _import "Real32_muladd" : Real32.t * Real32.t * Real32.t -> Real32.t;
 val mulsub = _import "Real32_mulsub" : Real32.t * Real32.t * Real32.t -> Real32.t;
 val neg = _import "Real32_neg" : Real32.t -> Real32.t;
-val nextAfterDown = _import "Real32_nextAfterDown" : Real32.t -> Real32.t;
-val nextAfterUp = _import "Real32_nextAfterUp" : Real32.t -> Real32.t;
 val rndToReal32 = _import "Real32_rndToReal32" : Real32.t -> Real32.t;
 val rndToReal64 = _import "Real32_rndToReal64" : Real32.t -> Real64.t;
 val rndToWordS16 = _import "Real32_rndToWordS16" : Real32.t -> Int16.t;
@@ -1005,8 +1003,6 @@
 val muladd = _import "Real64_muladd" : Real64.t * Real64.t * Real64.t -> Real64.t;
 val mulsub = _import "Real64_mulsub" : Real64.t * Real64.t * Real64.t -> Real64.t;
 val neg = _import "Real64_neg" : Real64.t -> Real64.t;
-val nextAfterDown = _import "Real64_nextAfterDown" : Real64.t -> Real64.t;
-val nextAfterUp = _import "Real64_nextAfterUp" : Real64.t -> Real64.t;
 val rndToReal32 = _import "Real64_rndToReal32" : Real64.t -> Real32.t;
 val rndToReal64 = _import "Real64_rndToReal64" : Real64.t -> Real64.t;
 val rndToWordS16 = _import "Real64_rndToWordS16" : Real64.t -> Int16.t;

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/check-real.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/check-real.sml	2007-04-13 16:48:04 UTC (rev 5523)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/check-real.sml	2007-04-13 23:20:47 UTC (rev 5524)
@@ -49,8 +49,6 @@
       val () = check (R1.*+, R2.muladd)
       val () = check (R1.*-, R2.mulsub)
       val () = check (R1.~, R2.neg)
-      val () = check (R1.nextAfterDown, R2.nextAfterDown)
-      val () = check (R1.nextAfterUp, R2.nextAfterUp)
       val () = check (R1.round, R2.round)
       val () = check (R1.signBit, R2.signBit)
       val () = check (R1.strto, R2.strto)
@@ -97,8 +95,6 @@
       val () = check (R1.*+, R2.muladd)
       val () = check (R1.*-, R2.mulsub)
       val () = check (R1.~, R2.neg)
-      val () = check (R1.nextAfterDown, R2.nextAfterDown)
-      val () = check (R1.nextAfterUp, R2.nextAfterUp)
       val () = check (R1.round, R2.round)
       val () = check (R1.signBit, R2.signBit)
       val () = check (R1.strto, R2.strto)

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	2007-04-13 16:48:04 UTC (rev 5523)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/real/real.sml	2007-04-13 23:20:47 UTC (rev 5524)
@@ -872,5 +872,27 @@
          end
    end
 
-structure Real32 = Real (Primitive.Real32)
-structure Real64 = Real (Primitive.Real64)
+(* All of the Real{32,64}.nextAfter{Down,Up} functions work by
+ * converting the real to a word of equivalent size and doing an
+ * increment or decrement on the word.  This works because the SML
+ * Basis Library code that calls these functions handles all the
+ * special cases (nans and infs).  Also, because of the way IEEE
+ * floating point numbers are represented, word {de,in}crement
+ * automatically does the right thing at the boundary between normals
+ * and denormals.  Also, convienently, maxFinite+1 = posInf.  
+ *)
+
+structure Real32 = Real (open Primitive.Real32
+                         local open Primitive.PackReal32 in
+                            fun nextAfterDown r = 
+                               castFromWord (Word32.- (castToWord r, 0wx1))
+                            fun nextAfterUp r = 
+                               castFromWord (Word32.+ (castToWord r, 0wx1))
+                         end)
+structure Real64 = Real (open Primitive.Real64
+                         local open Primitive.PackReal64 in
+                            fun nextAfterDown r = 
+                               castFromWord (Word64.- (castToWord r, 0wx1))
+                            fun nextAfterUp r = 
+                               castFromWord (Word64.+ (castToWord r, 0wx1))
+                         end)

Deleted: mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/nextAfter.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/nextAfter.c	2007-04-13 16:48:04 UTC (rev 5523)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/nextAfter.c	2007-04-13 23:20:47 UTC (rev 5524)
@@ -1,48 +0,0 @@
-#include "platform.h"
-
-/* All of the Real{32,64}_nextAfter{Down,Up} functions work by converting the
- * real to a word of equivalent size and doing an increment or decrement on the
- * word.  This works because the SML Basis Library code that calls these
- * functions handles all the special cases (nans and infs).  Also, because of
- * the way IEEE floating point numbers are represented, word {de,in}crement
- * automatically does the right thing at the boundary between normals and
- * denormals.  Also, convienently, maxFinite+1 = posInf.
- */
-
-typedef union {
-  Real32_t r;
-  Word32_t w;
-} rw32;
-
-Real32_t Real32_nextAfterDown (Real32_t r) {
-  rw32 rw;
-  rw.r = r;
-  rw.w--;
-  return rw.r;
-}
-
-Real32_t Real32_nextAfterUp (Real32_t r) {
-  rw32 rw;
-  rw.r = r;
-  rw.w++;
-  return rw.r;
-}
-
-typedef union {
-  Real64_t r;
-  Word64_t w;
-} rw64;
-
-Real64_t Real64_nextAfterDown (Real64_t r) {
-  rw64 rw;
-  rw.r = r;
-  rw.w--;
-  return rw.r;
-}
-
-Real64_t Real64_nextAfterUp (Real64_t r) {
-  rw64 rw;
-  rw.r = r;
-  rw.w++;
-  return rw.r;
-}

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/basis-ffi.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis-ffi.h	2007-04-13 16:48:04 UTC (rev 5523)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis-ffi.h	2007-04-13 23:20:47 UTC (rev 5524)
@@ -780,8 +780,6 @@
 MLTON_CODEGEN_STATIC_INLINE Real32_t Real32_muladd(Real32_t,Real32_t,Real32_t);
 MLTON_CODEGEN_STATIC_INLINE Real32_t Real32_mulsub(Real32_t,Real32_t,Real32_t);
 MLTON_CODEGEN_STATIC_INLINE Real32_t Real32_neg(Real32_t);
-Real32_t Real32_nextAfterDown(Real32_t);
-Real32_t Real32_nextAfterUp(Real32_t);
 MLTON_CODEGEN_STATIC_INLINE Real32_t Real32_rndToReal32(Real32_t);
 MLTON_CODEGEN_STATIC_INLINE Real64_t Real32_rndToReal64(Real32_t);
 MLTON_CODEGEN_STATIC_INLINE Int16_t Real32_rndToWordS16(Real32_t);
@@ -835,8 +833,6 @@
 MLTON_CODEGEN_STATIC_INLINE Real64_t Real64_muladd(Real64_t,Real64_t,Real64_t);
 MLTON_CODEGEN_STATIC_INLINE Real64_t Real64_mulsub(Real64_t,Real64_t,Real64_t);
 MLTON_CODEGEN_STATIC_INLINE Real64_t Real64_neg(Real64_t);
-Real64_t Real64_nextAfterDown(Real64_t);
-Real64_t Real64_nextAfterUp(Real64_t);
 MLTON_CODEGEN_STATIC_INLINE Real32_t Real64_rndToReal32(Real64_t);
 MLTON_CODEGEN_STATIC_INLINE Real64_t Real64_rndToReal64(Real64_t);
 MLTON_CODEGEN_STATIC_INLINE Int16_t Real64_rndToWordS16(Real64_t);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def	2007-04-13 16:48:04 UTC (rev 5523)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def	2007-04-13 23:20:47 UTC (rev 5524)
@@ -860,8 +860,6 @@
 Real32.muladd = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * Real32.t * Real32.t -> Real32.t
 Real32.mulsub = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t * Real32.t * Real32.t -> Real32.t
 Real32.neg = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t -> Real32.t
-Real32.nextAfterDown = _import : Real32.t -> Real32.t
-Real32.nextAfterUp = _import : Real32.t -> Real32.t
 Real32.rndToReal32 = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t -> Real32.t
 Real32.rndToReal64 = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t -> Real64.t
 Real32.rndToWordS16 = _import MLTON_CODEGEN_STATIC_INLINE : Real32.t -> Int16.t
@@ -915,8 +913,6 @@
 Real64.muladd = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * Real64.t * Real64.t -> Real64.t
 Real64.mulsub = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t * Real64.t * Real64.t -> Real64.t
 Real64.neg = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t -> Real64.t
-Real64.nextAfterDown = _import : Real64.t -> Real64.t
-Real64.nextAfterUp = _import : Real64.t -> Real64.t
 Real64.rndToReal32 = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t -> Real32.t
 Real64.rndToReal64 = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t -> Real64.t
 Real64.rndToWordS16 = _import MLTON_CODEGEN_STATIC_INLINE : Real64.t -> Int16.t

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.h	2007-04-13 16:48:04 UTC (rev 5523)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.h	2007-04-13 23:20:47 UTC (rev 5524)
@@ -780,8 +780,6 @@
 MLTON_CODEGEN_STATIC_INLINE Real32_t Real32_muladd(Real32_t,Real32_t,Real32_t);
 MLTON_CODEGEN_STATIC_INLINE Real32_t Real32_mulsub(Real32_t,Real32_t,Real32_t);
 MLTON_CODEGEN_STATIC_INLINE Real32_t Real32_neg(Real32_t);
-Real32_t Real32_nextAfterDown(Real32_t);
-Real32_t Real32_nextAfterUp(Real32_t);
 MLTON_CODEGEN_STATIC_INLINE Real32_t Real32_rndToReal32(Real32_t);
 MLTON_CODEGEN_STATIC_INLINE Real64_t Real32_rndToReal64(Real32_t);
 MLTON_CODEGEN_STATIC_INLINE Int16_t Real32_rndToWordS16(Real32_t);
@@ -835,8 +833,6 @@
 MLTON_CODEGEN_STATIC_INLINE Real64_t Real64_muladd(Real64_t,Real64_t,Real64_t);
 MLTON_CODEGEN_STATIC_INLINE Real64_t Real64_mulsub(Real64_t,Real64_t,Real64_t);
 MLTON_CODEGEN_STATIC_INLINE Real64_t Real64_neg(Real64_t);
-Real64_t Real64_nextAfterDown(Real64_t);
-Real64_t Real64_nextAfterUp(Real64_t);
 MLTON_CODEGEN_STATIC_INLINE Real32_t Real64_rndToReal32(Real64_t);
 MLTON_CODEGEN_STATIC_INLINE Real64_t Real64_rndToReal64(Real64_t);
 MLTON_CODEGEN_STATIC_INLINE Int16_t Real64_rndToWordS16(Real64_t);

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.sml	2007-04-13 16:48:04 UTC (rev 5523)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.sml	2007-04-13 23:20:47 UTC (rev 5524)
@@ -943,8 +943,6 @@
 val muladd = _import "Real32_muladd" : Real32.t * Real32.t * Real32.t -> Real32.t;
 val mulsub = _import "Real32_mulsub" : Real32.t * Real32.t * Real32.t -> Real32.t;
 val neg = _import "Real32_neg" : Real32.t -> Real32.t;
-val nextAfterDown = _import "Real32_nextAfterDown" : Real32.t -> Real32.t;
-val nextAfterUp = _import "Real32_nextAfterUp" : Real32.t -> Real32.t;
 val rndToReal32 = _import "Real32_rndToReal32" : Real32.t -> Real32.t;
 val rndToReal64 = _import "Real32_rndToReal64" : Real32.t -> Real64.t;
 val rndToWordS16 = _import "Real32_rndToWordS16" : Real32.t -> Int16.t;
@@ -1005,8 +1003,6 @@
 val muladd = _import "Real64_muladd" : Real64.t * Real64.t * Real64.t -> Real64.t;
 val mulsub = _import "Real64_mulsub" : Real64.t * Real64.t * Real64.t -> Real64.t;
 val neg = _import "Real64_neg" : Real64.t -> Real64.t;
-val nextAfterDown = _import "Real64_nextAfterDown" : Real64.t -> Real64.t;
-val nextAfterUp = _import "Real64_nextAfterUp" : Real64.t -> Real64.t;
 val rndToReal32 = _import "Real64_rndToReal32" : Real64.t -> Real32.t;
 val rndToReal64 = _import "Real64_rndToReal64" : Real64.t -> Real64.t;
 val rndToWordS16 = _import "Real64_rndToWordS16" : Real64.t -> Int16.t;




More information about the MLton-commit mailing list