mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-01 12:20:26 +02:00
bv-f{32,64}-{ref,set!} take unboxed u64 index
* module/language/tree-il/compile-cps.scm (convert): bv-f32-ref, bv-f32-set!, bv-f64-ref, and bv-f64-set! take the index as an untagged u64 value. * module/language/cps/types.scm (define-bytevector-uaccessors): New helper, used while migrating bytevectors to take unboxed indexes. Adapt f32/f64 accessors to use this definition helper. * libguile/vm-engine.c (BV_FLOAT_REF, BV_FLOAT_SET): The index is unboxed.
This commit is contained in:
parent
8464cc576c
commit
87cc8b0f97
3 changed files with 65 additions and 30 deletions
|
@ -2990,17 +2990,19 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
|
|||
|
||||
#define BV_FLOAT_REF(stem, fn_stem, type, size) \
|
||||
do { \
|
||||
scm_t_signed_bits i; \
|
||||
const type *float_ptr; \
|
||||
ARGS2 (bv, idx); \
|
||||
scm_t_uint8 dst, src, idx; \
|
||||
SCM bv; \
|
||||
scm_t_uint64 c_idx; \
|
||||
UNPACK_8_8_8 (op, dst, src, idx); \
|
||||
bv = SP_REF (src); \
|
||||
c_idx = SP_REF_U64 (idx); \
|
||||
\
|
||||
VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-ref"); \
|
||||
i = SCM_I_INUM (idx); \
|
||||
float_ptr = (type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
|
||||
float_ptr = (type *) (SCM_BYTEVECTOR_CONTENTS (bv) + c_idx); \
|
||||
\
|
||||
if (SCM_LIKELY (SCM_I_INUMP (idx) \
|
||||
&& (i >= 0) \
|
||||
&& (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
|
||||
if (SCM_LIKELY (size <= SCM_BYTEVECTOR_LENGTH (bv) \
|
||||
&& (c_idx <= SCM_BYTEVECTOR_LENGTH (bv) - size) \
|
||||
&& (ALIGNED_P (float_ptr, type)))) \
|
||||
{ \
|
||||
SP_SET_F64 (dst, *float_ptr); \
|
||||
|
@ -3008,9 +3010,10 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
|
|||
} \
|
||||
else \
|
||||
{ \
|
||||
SCM val; \
|
||||
SCM scm_idx, val; \
|
||||
SYNC_IP (); \
|
||||
val = scm_bytevector_ ## fn_stem ## _native_ref (bv, idx); \
|
||||
scm_idx = scm_from_uint64 (c_idx); \
|
||||
val = scm_bytevector_ ## fn_stem ## _native_ref (bv, scm_idx); \
|
||||
SP_SET_F64 (dst, scm_to_double (val)); \
|
||||
NEXT (1); \
|
||||
} \
|
||||
|
@ -3130,29 +3133,30 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
|
|||
#define BV_FLOAT_SET(stem, fn_stem, type, size) \
|
||||
do { \
|
||||
scm_t_uint8 dst, idx, src; \
|
||||
scm_t_signed_bits i; \
|
||||
SCM bv, scm_idx; \
|
||||
SCM bv; \
|
||||
scm_t_uint64 c_idx; \
|
||||
double val; \
|
||||
type *float_ptr; \
|
||||
\
|
||||
UNPACK_8_8_8 (op, dst, idx, src); \
|
||||
bv = SP_REF (dst); \
|
||||
scm_idx = SP_REF (idx); \
|
||||
c_idx = SP_REF_U64 (idx); \
|
||||
val = SP_REF_F64 (src); \
|
||||
VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-set!"); \
|
||||
i = SCM_I_INUM (scm_idx); \
|
||||
float_ptr = (type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
|
||||
float_ptr = (type *) (SCM_BYTEVECTOR_CONTENTS (bv) + c_idx); \
|
||||
\
|
||||
if (SCM_LIKELY (SCM_I_INUMP (scm_idx) \
|
||||
&& (i >= 0) \
|
||||
&& (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
|
||||
&& (ALIGNED_P (float_ptr, type)))) \
|
||||
if (SCM_LIKELY (size <= SCM_BYTEVECTOR_LENGTH (bv) \
|
||||
&& c_idx <= SCM_BYTEVECTOR_LENGTH (bv) - size \
|
||||
&& ALIGNED_P (float_ptr, type))) \
|
||||
*float_ptr = val; \
|
||||
else \
|
||||
{ \
|
||||
SCM boxed = scm_from_double (val); \
|
||||
SCM boxed_idx, boxed_val; \
|
||||
boxed_idx = scm_from_uint64 (c_idx); \
|
||||
boxed_val = scm_from_double (val); \
|
||||
SYNC_IP (); \
|
||||
scm_bytevector_ ## fn_stem ## _native_set_x (bv, scm_idx, boxed); \
|
||||
scm_bytevector_ ## fn_stem ## _native_set_x (bv, boxed_idx, \
|
||||
boxed_val); \
|
||||
} \
|
||||
NEXT (1); \
|
||||
} while (0)
|
||||
|
|
|
@ -756,8 +756,28 @@ minimum, and maximum."
|
|||
&exact-integer 8 #x0000000000000000 #xffffFFFFffffFFFF)
|
||||
(define-bytevector-accessors bv-s64-ref bv-s64-set!
|
||||
&exact-integer 8 (- #x8000000000000000) #x7fffFFFFffffFFFF)
|
||||
(define-bytevector-accessors bv-f32-ref bv-f32-set! &f64 4 -inf.0 +inf.0)
|
||||
(define-bytevector-accessors bv-f64-ref bv-f64-set! &f64 8 -inf.0 +inf.0)
|
||||
|
||||
(define-syntax-rule (define-bytevector-uaccessors ref set type size min max)
|
||||
(begin
|
||||
(define-type-checker (ref bv idx)
|
||||
(and (check-type bv &bytevector 0 +inf.0)
|
||||
(check-type idx &u64 0 +inf.0)
|
||||
(< (&max idx) (- (&min bv) size))))
|
||||
(define-type-inferrer (ref bv idx result)
|
||||
(restrict! bv &bytevector (+ (&min idx) size) +inf.0)
|
||||
(restrict! idx &u64 0 (- (&max bv) size))
|
||||
(define! result type min max))
|
||||
(define-type-checker (set bv idx val)
|
||||
(and (check-type bv &bytevector 0 +inf.0)
|
||||
(check-type idx &u64 0 +inf.0)
|
||||
(check-type val type min max)
|
||||
(< (&max idx) (- (&min bv) size))))
|
||||
(define-type-inferrer (set! bv idx val)
|
||||
(restrict! bv &bytevector (+ (&min idx) size) +inf.0)
|
||||
(restrict! idx &exact-integer 0 (- (&max bv) size))
|
||||
(restrict! val type min max))))
|
||||
(define-bytevector-uaccessors bv-f32-ref bv-f32-set! &f64 4 -inf.0 +inf.0)
|
||||
(define-bytevector-uaccessors bv-f64-ref bv-f64-set! &f64 8 -inf.0 +inf.0)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -585,21 +585,32 @@
|
|||
kbox))
|
||||
(else
|
||||
(adapt-arity cps k src out))))
|
||||
(define (unbox-arg cps arg have-arg)
|
||||
(define (unbox-arg cps arg unbox-op have-arg)
|
||||
(with-cps cps
|
||||
(letv f64)
|
||||
(let$ body (have-arg f64))
|
||||
(letk kunboxed ($kargs ('f64) (f64) ,body))
|
||||
(letv unboxed)
|
||||
(let$ body (have-arg unboxed))
|
||||
(letk kunboxed ($kargs ('unboxed) (unboxed) ,body))
|
||||
(build-term
|
||||
($continue kunboxed src ($primcall 'scm->f64 (arg))))))
|
||||
($continue kunboxed src ($primcall unbox-op (arg))))))
|
||||
(define (unbox-args cps args have-args)
|
||||
(case instruction
|
||||
((bv-f32-ref bv-f64-ref)
|
||||
(match args
|
||||
((bv idx)
|
||||
(unbox-arg
|
||||
cps idx 'scm->u64
|
||||
(lambda (cps idx)
|
||||
(have-args cps (list bv idx)))))))
|
||||
((bv-f32-set! bv-f64-set!)
|
||||
(match args
|
||||
((bv idx val)
|
||||
(unbox-arg cps val
|
||||
(unbox-arg
|
||||
cps idx 'scm->u64
|
||||
(lambda (cps idx)
|
||||
(unbox-arg
|
||||
cps val 'scm->f64
|
||||
(lambda (cps val)
|
||||
(have-args cps (list bv idx val)))))))
|
||||
(have-args cps (list bv idx val)))))))))
|
||||
(else (have-args cps args))))
|
||||
(convert-args cps args
|
||||
(lambda (cps args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue