[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 09/30: Fix logand type inference
From: |
Andy Wingo |
Subject: |
[Guile-commits] 09/30: Fix logand type inference |
Date: |
Fri, 24 Nov 2017 09:24:20 -0500 (EST) |
wingo pushed a commit to branch master
in repository guile.
commit 908d5ea169c2b7f5f1ddb9eec7db5ea7d69457fc
Author: Andy Wingo <address@hidden>
Date: Thu Nov 23 18:13:56 2017 +0100
Fix logand type inference
* module/language/cps/types.scm (logand): We were computing the wrong
ranges when either argument was negative; a terrible bug!
(logsub): Also fix range when A is negative and B is non-negative.
(ulogand): Tighten up range.
---
module/language/cps/types.scm | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/module/language/cps/types.scm b/module/language/cps/types.scm
index c9cb078..e83683e 100644
--- a/module/language/cps/types.scm
+++ b/module/language/cps/types.scm
@@ -1490,12 +1490,17 @@ minimum, and maximum."
(define-type-inferrer (logand a b result)
(define (logand-min a b)
(if (and (negative? a) (negative? b))
- (min a b)
+ (let ((min (min a b)))
+ (if (inf? min)
+ -inf.0
+ (- 1 (next-power-of-two (- min)))))
0))
(define (logand-max a b)
- (if (and (positive? a) (positive? b))
- (min a b)
- 0))
+ (cond
+ ((or (and (positive? a) (positive? b))
+ (and (negative? a) (negative? b)))
+ (min a b))
+ (else (max a b))))
(restrict! a &exact-integer -inf.0 +inf.0)
(restrict! b &exact-integer -inf.0 +inf.0)
(define-exact-integer! result
@@ -1505,7 +1510,7 @@ minimum, and maximum."
(define-type-inferrer (ulogand a b result)
(restrict! a &u64 0 &u64-max)
(restrict! b &u64 0 &u64-max)
- (define! result &u64 0 (max (&max/u64 a) (&max/u64 b))))
+ (define! result &u64 0 (min (&max/u64 a) (&max/u64 b))))
(define-simple-type-checker (logsub &exact-integer &exact-integer))
(define-type-inferrer (logsub a b result)
@@ -1521,7 +1526,7 @@ minimum, and maximum."
(values min-a (if (negative? min-a) +inf.0 max-a)))
((negative? min-a)
;; Sign bit never set on B -- result will have the sign of A.
- (values min-a (if (negative? max-a) -1 max-a)))
+ (values -inf.0 max-a))
(else
;; Sign bit never set on A and never set on B -- the nice case.
(values 0 max-a))))
- [Guile-commits] branch master updated (0951551 -> 7d71d9b), Andy Wingo, 2017/11/24
- [Guile-commits] 01/30: ursh, ursh/immediate, etc only residualized if count < 64, Andy Wingo, 2017/11/24
- [Guile-commits] 05/30: Fix s64->scm reducer, Andy Wingo, 2017/11/24
- [Guile-commits] 02/30: Revert specialization of fixnum phi variables, Andy Wingo, 2017/11/24
- [Guile-commits] 09/30: Fix logand type inference,
Andy Wingo <=
- [Guile-commits] 08/30: Revert "Slot allocation allows s64/u64 representations of same var", Andy Wingo, 2017/11/24
- [Guile-commits] 07/30: Fix u64/s64 typesafety around fixnum (un)tagging, Andy Wingo, 2017/11/24
- [Guile-commits] 14/30: Fix type check elision for branches, Andy Wingo, 2017/11/24
- [Guile-commits] 06/30: Separate u64 and s64 type inferrers now that ops are monomorphic, Andy Wingo, 2017/11/24
- [Guile-commits] 18/30: Remove thunk?, integer? simple predicate inferrers, Andy Wingo, 2017/11/24
- [Guile-commits] 17/30: Add support for bignum? CPS primitive., Andy Wingo, 2017/11/24
- [Guile-commits] 22/30: Fix inference of generic < on NaN values, Andy Wingo, 2017/11/24
- [Guile-commits] 20/30: Add &exact-number helper definition, Andy Wingo, 2017/11/24
- [Guile-commits] 03/30: Better support for unboxed signed arithmetic, Andy Wingo, 2017/11/24
- [Guile-commits] 30/30: Optimize check-urange in assembler.scm, Andy Wingo, 2017/11/24