diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c index c2b0156b6..a70f78a1c 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 2e3697bdf..6be05c72a 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 144f15cde..29b36c67f 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 a473f954f..1c5b31949 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 8259f4858..b8b668180 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 6e92365c9..b26eb16a0 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 144384165..81cb377ca 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 dbbe812ed..718ff5ea2 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