[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/04: Add srsh, srsh/immediate instructions
From: |
Andy Wingo |
Subject: |
[Guile-commits] 01/04: Add srsh, srsh/immediate instructions |
Date: |
Mon, 13 Nov 2017 09:27:15 -0500 (EST) |
wingo pushed a commit to branch master
in repository guile.
commit b97321dbfdf550ab48eca460995004c0d6116e43
Author: Andy Wingo <address@hidden>
Date: Mon Nov 13 10:25:20 2017 +0100
Add srsh, srsh/immediate instructions
* libguile/vm-engine.c (srsh, srsh/immediate): New instructions.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (srsh, srsh/immediate):
* module/system/vm/assembler.scm: Add support for new instructions.
* module/language/cps/types.scm (ulsh, ursh): Remove type checkers, as
these are effect-free. Limit range of ursh count.
---
libguile/vm-engine.c | 34 ++++++++++++++++++++++++++--
module/language/cps/compile-bytecode.scm | 2 ++
module/language/cps/effects-analysis.scm | 2 ++
module/language/cps/reify-primitives.scm | 1 +
module/language/cps/slot-allocation.scm | 1 +
module/language/cps/specialize-primcalls.scm | 1 +
module/language/cps/types.scm | 22 ++++++++++++++----
module/system/vm/assembler.scm | 2 ++
8 files changed, 59 insertions(+), 6 deletions(-)
diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c
index c2b0156..a70f78a 100644
--- a/libguile/vm-engine.c
+++ b/libguile/vm-engine.c
@@ -4068,8 +4068,38 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
NEXT (1);
}
- VM_DEFINE_OP (216, unused_216, NULL, NOP)
- VM_DEFINE_OP (217, unused_217, NULL, NOP)
+ /* srsh dst:8 a:8 b:8
+ *
+ * Shift the s64 value in A right by B bits, and place the result in
+ * DST. Only the lower 6 bits of B are used.
+ */
+ VM_DEFINE_OP (216, srsh, "srsh", OP1 (X8_S8_S8_S8) | OP_DST)
+ {
+ scm_t_uint8 dst, a, b;
+
+ UNPACK_8_8_8 (op, dst, a, b);
+
+ SP_SET_S64 (dst, SCM_SRS (SP_REF_S64 (a), (SP_REF_U64 (b) & 63)));
+
+ NEXT (1);
+ }
+
+ /* srsh/immediate dst:8 a:8 b:8
+ *
+ * Shift the s64 value in A right by the immediate B bits, and place
+ * the result in DST. Only the lower 6 bits of B are used.
+ */
+ VM_DEFINE_OP (217, srsh_immediate, "srsh/immediate", OP1 (X8_S8_S8_C8) |
OP_DST)
+ {
+ scm_t_uint8 dst, a, b;
+
+ UNPACK_8_8_8 (op, dst, a, b);
+
+ SP_SET_S64 (dst, SCM_SRS (SP_REF_S64 (a), b & 63));
+
+ NEXT (1);
+ }
+
VM_DEFINE_OP (218, unused_218, NULL, NOP)
VM_DEFINE_OP (219, unused_219, NULL, NOP)
VM_DEFINE_OP (220, unused_220, NULL, NOP)
diff --git a/module/language/cps/compile-bytecode.scm
b/module/language/cps/compile-bytecode.scm
index 2e3697b..6be05c7 100644
--- a/module/language/cps/compile-bytecode.scm
+++ b/module/language/cps/compile-bytecode.scm
@@ -202,6 +202,8 @@
(emit-lsh/immediate asm (from-sp dst) (from-sp (slot x)) y))
(($ $primcall 'ursh/immediate y (x))
(emit-ursh/immediate asm (from-sp dst) (from-sp (slot x)) y))
+ (($ $primcall 'srsh/immediate y (x))
+ (emit-srsh/immediate asm (from-sp dst) (from-sp (slot x)) y))
(($ $primcall 'ulsh/immediate y (x))
(emit-ulsh/immediate asm (from-sp dst) (from-sp (slot x)) y))
(($ $primcall 'builtin-ref idx ())
diff --git a/module/language/cps/effects-analysis.scm
b/module/language/cps/effects-analysis.scm
index 144f15c..29b36c6 100644
--- a/module/language/cps/effects-analysis.scm
+++ b/module/language/cps/effects-analysis.scm
@@ -472,8 +472,10 @@ is or might be a read or a write to the same location as
A."
((ulogxor . _))
((ulogsub . _))
((ursh . _))
+ ((srsh . _))
((ulsh . _))
((ursh/immediate . _))
+ ((srsh/immediate . _))
((ulsh/immediate . _))
((logtest a b) &type-check)
((logbit? a b) &type-check)
diff --git a/module/language/cps/reify-primitives.scm
b/module/language/cps/reify-primitives.scm
index a473f95..1c5b319 100644
--- a/module/language/cps/reify-primitives.scm
+++ b/module/language/cps/reify-primitives.scm
@@ -199,6 +199,7 @@
((rsh/immediate (u6? y) x) (rsh x y))
((lsh/immediate (u6? y) x) (lsh x y))
((ursh/immediate (u6? y) x) (ursh x y))
+ ((srsh/immediate (u6? y) x) (srsh x y))
((ulsh/immediate (u6? y) x) (ulsh x y))
(_ cps))))))
(param (error "unexpected param to reified primcall" name))
diff --git a/module/language/cps/slot-allocation.scm
b/module/language/cps/slot-allocation.scm
index 8259f48..b8b6681 100644
--- a/module/language/cps/slot-allocation.scm
+++ b/module/language/cps/slot-allocation.scm
@@ -770,6 +770,7 @@ are comparable with eqv?. A tmp slot may be used."
(intmap-add representations var 'u64))
(($ $primcall (or 'untag-fixnum
'scm->s64 'load-s64
+ 'srsh 'srsh/immediate
'bv-s8-ref 'bv-s16-ref 'bv-s32-ref 'bv-s64-ref))
(intmap-add representations var 's64))
(_
diff --git a/module/language/cps/specialize-primcalls.scm
b/module/language/cps/specialize-primcalls.scm
index 6e92365..b26eb16 100644
--- a/module/language/cps/specialize-primcalls.scm
+++ b/module/language/cps/specialize-primcalls.scm
@@ -74,6 +74,7 @@
(('umul x (? uint? y)) (umul/immediate y (x)))
(('umul (? uint? y) x) (umul/immediate y (x)))
(('ursh x (? uint? y)) (ursh/immediate y (x)))
+ (('srsh x (? uint? y)) (srsh/immediate y (x)))
(('ulsh x (? uint? y)) (ulsh/immediate y (x)))
(('scm->f64 (? f64? var)) (load-f64 var ()))
(('scm->u64 (? u64? var)) (load-u64 var ()))
diff --git a/module/language/cps/types.scm b/module/language/cps/types.scm
index 1443841..81cb377 100644
--- a/module/language/cps/types.scm
+++ b/module/language/cps/types.scm
@@ -1344,17 +1344,31 @@ minimum, and maximum."
(- count) (- count))))
(define-exact-integer! result min max)))
-(define-simple-type-checker (ursh &u64 &u64))
(define-type-inferrer (ursh a b result)
(define! result &u64
- (ash (&min/0 a) (- (&max/u64 b)))
- (ash (&max/u64 a) (- (&min/0 b)))))
+ (ash (&min/0 a) (- (min 64 (&max/u64 b))))
+ (ash (&max/u64 a) (- (min 64 (&min/0 b))))))
(define-type-inferrer/param (ursh/immediate param a result)
(define! result &u64
(ash (&min/0 a) (- param))
(ash (&max/u64 a) (- param))))
-(define-simple-type-checker (ulsh &u64 &u64))
+(define-type-inferrer (srsh a b result)
+ (let-values (((min max) (compute-ash-range (&min/s64 a)
+ (&max/s64 a)
+ (- (&min/0 b))
+ (- (&max/u64 b)))))
+ (if (<= &s64-min min max &s64-max)
+ (define! result &s64 min max)
+ (define! result &s64 &s64-min &s64-max))))
+(define-type-inferrer/param (srsh/immediate count val result)
+ (let-values (((min max) (compute-ash-range (&min/s64 val)
+ (&max/s64 val)
+ (- count) (- count))))
+ (if (<= &s64-min min max &s64-max)
+ (define! result &s64 min max)
+ (define! result &s64 &s64-min &s64-max))))
+
(define-type-inferrer (ulsh a b result)
(if (and (< (&max/u64 b) 64)
(<= (ash (&max/u64 a) (&max/u64 b)) &u64-max))
diff --git a/module/system/vm/assembler.scm b/module/system/vm/assembler.scm
index dbbe812..718ff5e 100644
--- a/module/system/vm/assembler.scm
+++ b/module/system/vm/assembler.scm
@@ -217,8 +217,10 @@
emit-ulogxor
emit-ulogsub
emit-ursh
+ emit-srsh
emit-ulsh
emit-ursh/immediate
+ emit-srsh/immediate
emit-ulsh/immediate
emit-char->integer
emit-integer->char