[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 08/12: Compiler uses target fixnum range
From: |
Andy Wingo |
Subject: |
[Guile-commits] 08/12: Compiler uses target fixnum range |
Date: |
Sat, 11 Nov 2017 16:12:25 -0500 (EST) |
wingo pushed a commit to branch master
in repository guile.
commit a268c02fa0c7e93c390cc7adf0bfbf422e92ea29
Author: Andy Wingo <address@hidden>
Date: Thu Nov 9 14:27:49 2017 +0100
Compiler uses target fixnum range
* module/system/base/target.scm (target-most-negative-fixnum):
(target-most-positive-fixnum): New definitions.
* module/language/cps/types.scm (constant-type, define-exact-integer!)
(&min/fixnum, &max/fixnum): Use new definitions.
(&max/vector): Use target-max-vector-length.
---
module/language/cps/types.scm | 50 +++++++++++++++++++++++--------------------
module/system/base/target.scm | 15 ++++++++++++-
2 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/module/language/cps/types.scm b/module/language/cps/types.scm
index c40a807..f853c97 100644
--- a/module/language/cps/types.scm
+++ b/module/language/cps/types.scm
@@ -332,7 +332,9 @@ minimum, and maximum."
((number? val)
(cond
((exact-integer? val)
- (return (if (<= most-negative-fixnum val most-positive-fixnum)
+ (return (if (<= (target-most-negative-fixnum)
+ val
+ (target-most-positive-fixnum))
&fixnum
&bignum)
val))
@@ -382,7 +384,9 @@ minimum, and maximum."
(define-syntax-rule (define-exact-integer! result min max)
(let ((min* min) (max* max))
(define! result
- (if (<= most-negative-fixnum min* max* most-positive-fixnum)
+ (if (<= (target-most-negative-fixnum)
+ min* max*
+ (target-most-positive-fixnum))
&fixnum
&exact-integer)
min* max*)))
@@ -398,8 +402,8 @@ minimum, and maximum."
(define-syntax-rule (&max/u64 x) (min (&max x) &u64-max))
(define-syntax-rule (&min/s64 x) (max (&min x) &s64-min))
(define-syntax-rule (&max/s64 x) (min (&max x) &s64-max))
-(define-syntax-rule (&min/fixnum x) (max (&min x) most-negative-fixnum))
-(define-syntax-rule (&max/fixnum x) (min (&max x) most-positive-fixnum))
+(define-syntax-rule (&min/fixnum x) (max (&min x)
(target-most-negative-fixnum)))
+(define-syntax-rule (&max/fixnum x) (min (&max x)
(target-most-positive-fixnum)))
(define-syntax-rule (&max/size x) (min (&max x) (target-max-size-t)))
(define-syntax-rule (&max/scm-size x) (min (&max x) (target-max-size-t/scm)))
@@ -606,13 +610,14 @@ minimum, and maximum."
(define-predicate-inferrer (fixnum? val true?)
(cond
(true?
- (restrict! val &fixnum most-negative-fixnum most-positive-fixnum))
+ (restrict! val &fixnum
+ (target-most-negative-fixnum) (target-most-positive-fixnum)))
((type<=? (&type val) &exact-integer)
(cond
- ((<= (&max val) most-positive-fixnum)
- (restrict! val &bignum -inf.0 (1- most-negative-fixnum)))
- ((>= (&min val) most-negative-fixnum)
- (restrict! val &bignum most-positive-fixnum +inf.0))
+ ((<= (&max val) (target-most-positive-fixnum))
+ (restrict! val &bignum -inf.0 (1- (target-most-negative-fixnum))))
+ ((>= (&min val) (target-most-negative-fixnum))
+ (restrict! val &bignum (target-most-positive-fixnum) +inf.0))
(else
(restrict! val &bignum -inf.0 +inf.0))))
(else
@@ -717,29 +722,28 @@ minimum, and maximum."
;;; Vectors.
;;;
-;; This max-vector-len computation is a hack.
-(define *max-vector-len* (ash most-positive-fixnum -5))
-(define-syntax-rule (&max/vector x) (min (&max x) *max-vector-len*))
+(define-syntax-rule (&max/vector x)
+ (min (&max x) (target-max-vector-length)))
-(define-simple-type-checker (make-vector (&u64 0 *max-vector-len*)
+(define-simple-type-checker (make-vector (&u64 0 (target-max-vector-length))
&all-types))
(define-type-inferrer (make-vector size init result)
- (restrict! size &u64 0 *max-vector-len*)
+ (restrict! size &u64 0 (target-max-vector-length))
(define! result &vector (&min/0 size) (&max/vector size)))
(define-type-checker (vector-ref v idx)
- (and (check-type v &vector 0 *max-vector-len*)
+ (and (check-type v &vector 0 (target-max-vector-length))
(check-type idx &u64 0 (1- (&min v)))))
(define-type-inferrer (vector-ref v idx result)
- (restrict! v &vector (1+ (&min/0 idx)) *max-vector-len*)
+ (restrict! v &vector (1+ (&min/0 idx)) (target-max-vector-length))
(restrict! idx &u64 0 (1- (&max/vector v)))
(define! result &all-types -inf.0 +inf.0))
(define-type-checker (vector-set! v idx val)
- (and (check-type v &vector 0 *max-vector-len*)
+ (and (check-type v &vector 0 (target-max-vector-length))
(check-type idx &u64 0 (1- (&min v)))))
(define-type-inferrer (vector-set! v idx val)
- (restrict! v &vector (1+ (&min/0 idx)) *max-vector-len*)
+ (restrict! v &vector (1+ (&min/0 idx)) (target-max-vector-length))
(restrict! idx &u64 0 (1- (&max/vector v))))
(define-simple-type-checker (make-vector/immediate &all-types))
@@ -747,19 +751,19 @@ minimum, and maximum."
(define! result &vector size size))
(define-type-checker/param (vector-ref/immediate idx v)
- (and (check-type v &vector 0 *max-vector-len*) (< idx (&min v))))
+ (and (check-type v &vector 0 (target-max-vector-length)) (< idx (&min v))))
(define-type-inferrer/param (vector-ref/immediate idx v result)
- (restrict! v &vector (1+ idx) *max-vector-len*)
+ (restrict! v &vector (1+ idx) (target-max-vector-length))
(define! result &all-types -inf.0 +inf.0))
(define-type-checker/param (vector-set!/immediate idx v val)
- (and (check-type v &vector 0 *max-vector-len*) (< idx (&min v))))
+ (and (check-type v &vector 0 (target-max-vector-length)) (< idx (&min v))))
(define-type-inferrer/param (vector-set!/immediate idx v val)
- (restrict! v &vector (1+ idx) *max-vector-len*))
+ (restrict! v &vector (1+ idx) (target-max-vector-length)))
(define-simple-type-checker (vector-length &vector))
(define-type-inferrer (vector-length v result)
- (restrict! v &vector 0 *max-vector-len*)
+ (restrict! v &vector 0 (target-max-vector-length))
(define! result &u64 (&min/0 v) (&max/vector v)))
diff --git a/module/system/base/target.scm b/module/system/base/target.scm
index 34c9e82..7c6e0ac 100644
--- a/module/system/base/target.scm
+++ b/module/system/base/target.scm
@@ -30,7 +30,10 @@
target-max-size-t
target-max-size-t/scm
- target-max-vector-length))
+ target-max-vector-length
+
+ target-most-negative-fixnum
+ target-most-positive-fixnum))
@@ -166,3 +169,13 @@ SCM words."
;; Vector size fits in first word; the low 8 bits are taken by the
;; type tag. Additionally, restrict to 48-bit address space.
(1- (ash 1 (min (- (* (target-word-size) 8) 8) 48))))
+
+(define (target-most-negative-fixnum)
+ "Return the most negative integer representable as a fixnum on the
+target platform."
+ (- (ash 1 (- (* (target-word-size) 8) 3))))
+
+(define (target-most-positive-fixnum)
+ "Return the most positive integer representable as a fixnum on the
+target platform."
+ (1- (ash 1 (- (* (target-word-size) 8) 3))))
- [Guile-commits] branch master updated (f96a670 -> 83a03a3), Andy Wingo, 2017/11/11
- [Guile-commits] 01/12: Fix effects analysis bug introduced with primcall param, Andy Wingo, 2017/11/11
- [Guile-commits] 02/12: Refactor numeric comparison bytecode emission, Andy Wingo, 2017/11/11
- [Guile-commits] 05/12: Closure conversion uses immediate variants of vector instructions, Andy Wingo, 2017/11/11
- [Guile-commits] 06/12: Use immediate primcalls when unfolding constructors, Andy Wingo, 2017/11/11
- [Guile-commits] 09/12: Convert "ash" to "lsh"/"rsh" when lowering to CPS, Andy Wingo, 2017/11/11
- [Guile-commits] 12/12: Specialize rsh/lsh, not ash, Andy Wingo, 2017/11/11
- [Guile-commits] 07/12: Add tag-fixnum instruction, Andy Wingo, 2017/11/11
- [Guile-commits] 08/12: Compiler uses target fixnum range,
Andy Wingo <=
- [Guile-commits] 03/12: Canonicalize <=, >=, and > primcalls to <, Andy Wingo, 2017/11/11
- [Guile-commits] 11/12: Add missing lsh/immediate, rsh/immediate type inferrers, Andy Wingo, 2017/11/11
- [Guile-commits] 04/12: Specialize comparisons to SCM as s64, Andy Wingo, 2017/11/11
- [Guile-commits] 10/12: Type folding has "macro reduction" phase, Andy Wingo, 2017/11/11