1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-19 19:20:23 +02:00

Add compiler support for s64 comparisons.

* module/language/cps/compile-bytecode.scm (compile-function): Add
  emitters for s64 comparisons.
* module/language/cps/effects-analysis.scm: Add entries.
* module/language/cps/primitives.scm (*comparisons*):
* module/language/cps/type-fold.scm (s64-<, s64-<=, s64-=, s64->=)
  (s64->): Add folders.
* module/language/cps/types.scm (s64-<, s64-<=, s64-=, s64->=, s64->):
  Add type checkers and inferrers.
This commit is contained in:
Andy Wingo 2017-10-29 19:33:00 +01:00
parent 73d1502630
commit 79a2748f83
5 changed files with 58 additions and 0 deletions

View file

@ -458,6 +458,11 @@
(($ $primcall 'u64-= (a b)) (binary-test emit-u64=? a b))
(($ $primcall 'u64->= (a b)) (binary* emit-u64<? emit-jnl emit-jl a b))
(($ $primcall 'u64-> (a b)) (binary* emit-u64<? emit-jl emit-jnl b a))
(($ $primcall 's64-< (a b)) (binary* emit-s64<? emit-jl emit-jnl a b))
(($ $primcall 's64-<= (a b)) (binary* emit-s64<? emit-jnl emit-jl b a))
(($ $primcall 's64-= (a b)) (binary-test emit-s64=? a b))
(($ $primcall 's64->= (a b)) (binary* emit-s64<? emit-jnl emit-jl a b))
(($ $primcall 's64-> (a b)) (binary* emit-s64<? emit-jl emit-jnl b a))
(($ $primcall 'f64-< (a b)) (binary* emit-f64<? emit-jl emit-jnl a b))
(($ $primcall 'f64-<= (a b)) (binary* emit-f64<? emit-jge emit-jnge b a))
(($ $primcall 'f64-= (a b)) (binary-test emit-f64=? a b))

View file

@ -449,6 +449,11 @@ is or might be a read or a write to the same location as A."
((u64-=-scm . _) &type-check)
((u64->=-scm . _) &type-check)
((u64->-scm . _) &type-check)
((s64-= . _))
((s64-< . _))
((s64-> . _))
((s64-<= . _))
((s64->= . _))
((f64-= . _))
((f64-< . _))
((f64-> . _))

View file

@ -134,6 +134,9 @@ before it is lowered to CPS?"
u64-<
u64-<=
u64-=
s64-<
s64-<=
s64-=
f64-=
f64-<
f64-<=
@ -149,6 +152,8 @@ before it is lowered to CPS?"
>=
u64->
u64->=
s64->
s64->=
u64->=-scm
u64->-scm
f64->

View file

@ -144,6 +144,7 @@
((= >= >) (values #t #f))
(else (values #f #f))))
(define-branch-folder-alias u64-< <)
(define-branch-folder-alias s64-< <)
(define-branch-folder-alias u64-<-scm <)
;; We currently cannot define branch folders for floating point
;; comparison ops like the commented one below because we can't prove
@ -157,6 +158,7 @@
((>) (values #t #f))
(else (values #f #f))))
(define-branch-folder-alias u64-<= <=)
(define-branch-folder-alias s64-<= <=)
(define-branch-folder-alias u64-<=-scm <=)
(define-binary-branch-folder (= type0 min0 max0 type1 min1 max1)
@ -165,6 +167,7 @@
((< >) (values #t #f))
(else (values #f #f))))
(define-branch-folder-alias u64-= =)
(define-branch-folder-alias s64-= =)
(define-branch-folder-alias u64-=-scm =)
(define-binary-branch-folder (>= type0 min0 max0 type1 min1 max1)
@ -173,6 +176,7 @@
((<) (values #t #f))
(else (values #f #f))))
(define-branch-folder-alias u64->= >=)
(define-branch-folder-alias s64->= >=)
(define-branch-folder-alias u64->=-scm >=)
(define-binary-branch-folder (> type0 min0 max0 type1 min1 max1)
@ -181,6 +185,7 @@
((= <= <) (values #t #f))
(else (values #f #f))))
(define-branch-folder-alias u64-> >)
(define-branch-folder-alias s64-> >)
(define-branch-folder-alias u64->-scm >)
(define-binary-branch-folder (logtest type0 min0 max0 type1 min1 max1)

View file

@ -1032,6 +1032,44 @@ minimum, and maximum."
(define-simple-type-checker (u64-> &u64 &u64))
(define-u64-comparison-inferrer (u64-> > <=))
;; Signed unboxed comparisons.
(define-simple-type-checker (s64-= &s64 &s64))
(define-predicate-inferrer (s64-= a b true?)
(when true?
(let ((min (max (&min/s64 a) (&min/s64 b)))
(max (min (&max/s64 a) (&max/s64 b))))
(restrict! a &s64 min max)
(restrict! b &s64 min max))))
(define (infer-s64-comparison-ranges op min0 max0 min1 max1)
(match op
('< (values min0 (min max0 (1- max1)) (max (1+ min0) min1) max1))
('<= (values min0 (min max0 max1) (max min0 min1) max1))
('>= (values (max min0 min1) max0 min1 (min max0 max1)))
('> (values (max min0 (1+ min1)) max0 min1 (min (1- max0) max1)))))
(define-syntax-rule (define-s64-comparison-inferrer (s64-op op inverse))
(define-predicate-inferrer (s64-op a b true?)
(call-with-values
(lambda ()
(infer-s64-comparison-ranges (if true? 'op 'inverse)
(&min/s64 a) (&max/s64 a)
(&min/s64 b) (&max/s64 b)))
(lambda (min0 max0 min1 max1)
(restrict! a &s64 min0 max0)
(restrict! b &s64 min1 max1)))))
(define-simple-type-checker (s64-< &s64 &s64))
(define-s64-comparison-inferrer (s64-< < >=))
(define-simple-type-checker (s64-<= &s64 &s64))
(define-s64-comparison-inferrer (s64-<= <= >))
(define-simple-type-checker (s64->= &s64 &s64))
(define-s64-comparison-inferrer (s64-<= >= <))
(define-simple-type-checker (s64-> &s64 &s64))
(define-s64-comparison-inferrer (s64-> > <=))
;; Arithmetic.
(define-syntax-rule (define-unary-result! a result min max)
(let ((min* min)