From 2c756975ae13c13a074f6ce350f0c0a397ae144c Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 7 Dec 2005 04:09:51 +0000 Subject: [PATCH] updated intrinsics tests for 64-bit --- library/bootstrap/boot-stage2.factor | 2 +- library/cli.factor | 1 + library/compiler/ppc/fixnum.factor | 9 --------- library/math/integer.factor | 12 +++++++++++- library/test/compiler/intrinsics.factor | 21 +++++++++++++++++++++ 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor index 7b4676b1c4..5fec971529 100644 --- a/library/bootstrap/boot-stage2.factor +++ b/library/bootstrap/boot-stage2.factor @@ -37,7 +37,7 @@ cpu "amd64" = [ ! Handle -libraries:... overrides parse-command-line -"compile" get supported-cpu? and [ +"compile" get "native-io" get and supported-cpu? and [ unix? [ "/library/unix/load.factor" run-resource ] when diff --git a/library/cli.factor b/library/cli.factor index d79155fb9a..06c4f74342 100644 --- a/library/cli.factor +++ b/library/cli.factor @@ -47,6 +47,7 @@ parser sequences strings ; #! -no- CLI switch "user-init" on "compile" on + "native-io" on "null-stdio" off os "win32" = "ui" "tty" ? "shell" set ; diff --git a/library/compiler/ppc/fixnum.factor b/library/compiler/ppc/fixnum.factor index f96dce5e6d..a5441aa4a6 100644 --- a/library/compiler/ppc/fixnum.factor +++ b/library/compiler/ppc/fixnum.factor @@ -56,15 +56,6 @@ M: %fixnum* generate-node ( vop -- ) "end" get save-xt 3 6 MR ; -: first-bignum ( -- n ) - 1 cell 8 * tag-bits - 1- shift ; inline - -: most-positive-fixnum ( -- n ) - first-bignum 1- >fixnum ; inline - -: most-negative-fixnum ( -- n ) - first-bignum neg >fixnum ; inline - : generate-fixnum/i 6 3 4 DIVW ! divide in2 by in1, store result in out1 ! if the result is greater than the most positive fixnum, diff --git a/library/math/integer.factor b/library/math/integer.factor index 8902f4de6f..96c8d2124a 100644 --- a/library/math/integer.factor +++ b/library/math/integer.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2004, 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: math -USING: errors generic kernel math sequences sequences-internals ; +USING: errors generic kernel kernel-internals math sequences +sequences-internals ; UNION: integer fixnum bignum ; @@ -31,6 +32,15 @@ UNION: integer fixnum bignum ; : next-power-of-2 ( n -- n ) 1 swap (next-power-of-2) ; +: first-bignum ( -- n ) + 1 cell 8 * tag-bits - 1- shift ; inline + +: most-positive-fixnum ( -- n ) + first-bignum 1- >fixnum ; inline + +: most-negative-fixnum ( -- n ) + first-bignum neg >fixnum ; inline + IN: math-internals : fraction> ( a b -- a/b ) diff --git a/library/test/compiler/intrinsics.factor b/library/test/compiler/intrinsics.factor index 374f72794b..b86afe405f 100644 --- a/library/test/compiler/intrinsics.factor +++ b/library/test/compiler/intrinsics.factor @@ -187,3 +187,24 @@ math-internals sequences strings test words ; 100001 3 100000 pick set-nth [ 100000 swap array-nth ] compile-1 ] unit-test + +! 64-bit overflow +cell 8 = [ + [ t ] [ 1 59 fixnum-shift dup [ fixnum+ ] compile-1 1 60 fixnum-shift = ] unit-test + [ -1152921504606846977 ] [ 1 60 shift neg >fixnum [ -1 fixnum+ ] compile-1 ] unit-test + + [ 18446744073709551616 ] [ 1 64 [ fixnum-shift ] compile-1 ] unit-test + [ 18446744073709551616 ] [ 1 [ 64 fixnum-shift ] compile-1 ] unit-test + [ 18446744073709551616 ] [ 1 [ 32 fixnum-shift 32 fixnum-shift ] compile-1 ] unit-test + [ -18446744073709551616 ] [ -1 64 [ fixnum-shift ] compile-1 ] unit-test + [ -18446744073709551616 ] [ -1 [ 64 fixnum-shift ] compile-1 ] unit-test + [ -18446744073709551616 ] [ -1 [ 32 fixnum-shift 32 fixnum-shift ] compile-1 ] unit-test + + [ t ] [ 1 40 shift 1 40 shift [ fixnum* ] compile-1 1 80 shift = ] unit-test + [ t ] [ 1 40 shift neg 1 40 shift [ fixnum* ] compile-1 1 80 shift neg = ] unit-test + [ t ] [ 1 40 shift neg 1 40 shift neg [ fixnum* ] compile-1 1 80 shift = ] unit-test + + [ 1152921504606846976 ] [ -1152921504606846976 >fixnum -1 [ fixnum/i ] compile-1 ] unit-test + + [ 1152921504606846976 0 ] [ -1152921504606846976 >fixnum -1 [ fixnum/mod ] compile-1 ] unit-test +] when