1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 22:10:21 +02:00

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.
This commit is contained in:
Andy Wingo 2017-11-13 10:25:20 +01:00
parent 83a03a324b
commit b97321dbfd
8 changed files with 59 additions and 6 deletions

View file

@ -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)

View file

@ -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 ())

View file

@ -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)

View file

@ -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))

View file

@ -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))
(_

View file

@ -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 ()))

View file

@ -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))

View file

@ -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