mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-17 17:20:29 +02:00
Add support for unboxed s64 values
* libguile/frames.c (enum stack_item_representation): (scm_to_stack_item_representation): (scm_frame_local_ref, scm_frame_local_set_x): Support for S64 representations. * libguile/frames.h (union scm_vm_stack_element): Add signed 64-bit integer field. * libguile/vm-engine.c (scm->s64, s64->scm, load-s64): New instructions. * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/cse.scm (compute-equivalent-subexpressions): * module/language/cps/effects-analysis.scm: * module/language/cps/slot-allocation.scm (compute-var-representations) (compute-needs-slot, allocate-slots): * module/language/cps/utils.scm (compute-constant-values): * module/language/cps/specialize-primcalls.scm (specialize-primcalls): Add support for new primcalls. * module/language/cps/types.scm (&s64): New type. (&s64-min, &s64-max, &u64-max): New convenience definitions. (&range-min, &range-max): Use &s64-min and &u64-max names. (scm->s64, load-s64, s64->scm): Add support for new primcalls. * module/system/vm/assembler.scm (emit-scm->s64, emit-s64->scm) (emit-load-s64): New exports. * module/system/vm/assembler.scm (write-arities): Support for s64 slots. * module/system/vm/debug.scm (arity-definitions): Support for s64 slots.
This commit is contained in:
parent
f34688ad25
commit
8bf77f7192
12 changed files with 116 additions and 15 deletions
|
@ -242,7 +242,8 @@ enum stack_item_representation
|
|||
{
|
||||
STACK_ITEM_SCM = 0,
|
||||
STACK_ITEM_F64 = 1,
|
||||
STACK_ITEM_U64 = 2
|
||||
STACK_ITEM_U64 = 2,
|
||||
STACK_ITEM_S64 = 3
|
||||
};
|
||||
|
||||
static enum stack_item_representation
|
||||
|
@ -254,6 +255,8 @@ scm_to_stack_item_representation (SCM x, const char *subr, int pos)
|
|||
return STACK_ITEM_F64;
|
||||
if (scm_is_eq (x, scm_from_latin1_symbol ("u64")))
|
||||
return STACK_ITEM_U64;
|
||||
if (scm_is_eq (x, scm_from_latin1_symbol ("s64")))
|
||||
return STACK_ITEM_S64;
|
||||
|
||||
scm_wrong_type_arg (subr, pos, x);
|
||||
return 0; /* Not reached. */
|
||||
|
@ -286,6 +289,8 @@ SCM_DEFINE (scm_frame_local_ref, "frame-local-ref", 3, 0, 0,
|
|||
return scm_from_double (item->as_f64);
|
||||
case STACK_ITEM_U64:
|
||||
return scm_from_uint64 (item->as_u64);
|
||||
case STACK_ITEM_S64:
|
||||
return scm_from_int64 (item->as_s64);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
@ -326,6 +331,9 @@ SCM_DEFINE (scm_frame_local_set_x, "frame-local-set!", 4, 0, 0,
|
|||
case STACK_ITEM_U64:
|
||||
item->as_u64 = scm_to_uint64 (val);
|
||||
break;
|
||||
case STACK_ITEM_S64:
|
||||
item->as_s64 = scm_to_int64 (val);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
|
|
@ -93,6 +93,7 @@ union scm_vm_stack_element
|
|||
SCM as_scm;
|
||||
double as_f64;
|
||||
scm_t_uint64 as_u64;
|
||||
scm_t_int64 as_s64;
|
||||
|
||||
/* For GC purposes. */
|
||||
void *as_ptr;
|
||||
|
|
|
@ -257,6 +257,9 @@
|
|||
#define SP_REF_U64(i) (sp[i].as_u64)
|
||||
#define SP_SET_U64(i,o) (sp[i].as_u64 = o)
|
||||
|
||||
#define SP_REF_S64(i) (sp[i].as_s64)
|
||||
#define SP_SET_S64(i,o) (sp[i].as_s64 = o)
|
||||
|
||||
#define VARIABLE_REF(v) SCM_VARIABLE_REF (v)
|
||||
#define VARIABLE_SET(v,o) SCM_VARIABLE_SET (v, o)
|
||||
#define VARIABLE_BOUNDP(v) (!scm_is_eq (VARIABLE_REF (v), SCM_UNDEFINED))
|
||||
|
@ -3530,9 +3533,49 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
|
|||
NEXT (3);
|
||||
}
|
||||
|
||||
VM_DEFINE_OP (157, unused_157, NULL, NOP)
|
||||
VM_DEFINE_OP (158, unused_158, NULL, NOP)
|
||||
VM_DEFINE_OP (159, unused_159, NULL, NOP)
|
||||
/* scm->s64 dst:12 src:12
|
||||
*
|
||||
* Unpack a signed 64-bit integer from SRC and place it in DST.
|
||||
*/
|
||||
VM_DEFINE_OP (157, scm_to_s64, "scm->s64", OP1 (X8_S12_S12) | OP_DST)
|
||||
{
|
||||
scm_t_uint16 dst, src;
|
||||
UNPACK_12_12 (op, dst, src);
|
||||
SYNC_IP ();
|
||||
SP_SET_S64 (dst, scm_to_int64 (SP_REF (src)));
|
||||
NEXT (1);
|
||||
}
|
||||
|
||||
/* s64->scm dst:12 src:12
|
||||
*
|
||||
* Pack an signed 64-bit integer into a SCM value.
|
||||
*/
|
||||
VM_DEFINE_OP (158, s64_to_scm, "s64->scm", OP1 (X8_S12_S12) | OP_DST)
|
||||
{
|
||||
scm_t_uint16 dst, src;
|
||||
UNPACK_12_12 (op, dst, src);
|
||||
SYNC_IP ();
|
||||
SP_SET (dst, scm_from_int64 (SP_REF_S64 (src)));
|
||||
NEXT (1);
|
||||
}
|
||||
|
||||
/* load-s64 dst:24 high-bits:32 low-bits:32
|
||||
*
|
||||
* Make an unsigned 64-bit integer with HIGH-BITS and LOW-BITS.
|
||||
*/
|
||||
VM_DEFINE_OP (159, load_s64, "load-s64", OP3 (X8_S24, AS32, BS32) | OP_DST)
|
||||
{
|
||||
scm_t_uint32 dst;
|
||||
scm_t_uint64 val;
|
||||
|
||||
UNPACK_24 (op, dst);
|
||||
val = ip[1];
|
||||
val <<= 32;
|
||||
val |= ip[2];
|
||||
SP_SET_U64 (dst, val);
|
||||
NEXT (3);
|
||||
}
|
||||
|
||||
VM_DEFINE_OP (160, unused_160, NULL, NOP)
|
||||
VM_DEFINE_OP (161, unused_161, NULL, NOP)
|
||||
VM_DEFINE_OP (162, unused_162, NULL, NOP)
|
||||
|
|
|
@ -206,6 +206,12 @@
|
|||
(emit-load-u64 asm (from-sp dst) (constant src)))
|
||||
(($ $primcall 'u64->scm (src))
|
||||
(emit-u64->scm asm (from-sp dst) (from-sp (slot src))))
|
||||
(($ $primcall 'scm->s64 (src))
|
||||
(emit-scm->s64 asm (from-sp dst) (from-sp (slot src))))
|
||||
(($ $primcall 'load-s64 (src))
|
||||
(emit-load-s64 asm (from-sp dst) (constant src)))
|
||||
(($ $primcall 's64->scm (src))
|
||||
(emit-s64->scm asm (from-sp dst) (from-sp (slot src))))
|
||||
(($ $primcall 'bv-length (bv))
|
||||
(emit-bv-length asm (from-sp dst) (from-sp (slot bv))))
|
||||
(($ $primcall 'bv-u8-ref (bv idx))
|
||||
|
|
|
@ -315,6 +315,14 @@ false. It could be that both true and false proofs are available."
|
|||
(match defs
|
||||
((scm)
|
||||
(add-def! `(primcall scm->u64 ,scm) u64))))
|
||||
(('primcall 'scm->s64 scm)
|
||||
(match defs
|
||||
((s64)
|
||||
(add-def! `(primcall s64->scm ,s64) scm))))
|
||||
(('primcall 's64->scm s64)
|
||||
(match defs
|
||||
((scm)
|
||||
(add-def! `(primcall scm->s64 ,scm) s64))))
|
||||
(_ #t))))
|
||||
|
||||
(define (visit-label label equiv-labels var-substs)
|
||||
|
|
|
@ -358,7 +358,10 @@ is or might be a read or a write to the same location as A."
|
|||
((f64->scm _))
|
||||
((scm->u64 _) &type-check)
|
||||
((load-u64 _))
|
||||
((u64->scm _)))
|
||||
((u64->scm _))
|
||||
((scm->s64 _) &type-check)
|
||||
((load-s64 _))
|
||||
((s64->scm _)))
|
||||
|
||||
;; Bytevectors.
|
||||
(define-primitive-effects
|
||||
|
|
|
@ -53,8 +53,8 @@
|
|||
;;
|
||||
(slots allocation-slots)
|
||||
|
||||
;; A map of VAR to representation. A representation is 'scm, 'f64, or
|
||||
;; 'u64.
|
||||
;; A map of VAR to representation. A representation is 'scm, 'f64,
|
||||
;; 'u64, or 's64.
|
||||
;;
|
||||
(representations allocation-representations)
|
||||
|
||||
|
@ -323,7 +323,7 @@ the definitions that are live before and after LABEL, as intsets."
|
|||
(match exp
|
||||
(($ $const)
|
||||
empty-intset)
|
||||
(($ $primcall (or 'load-f64 'load-u64) (val))
|
||||
(($ $primcall (or 'load-f64 'load-u64 'load-s64) (val))
|
||||
empty-intset)
|
||||
(($ $primcall 'free-ref (closure slot))
|
||||
(defs+ closure))
|
||||
|
@ -804,6 +804,8 @@ are comparable with eqv?. A tmp slot may be used."
|
|||
'uadd 'usub 'umul
|
||||
'uadd/immediate 'usub/immediate 'umul/immediate))
|
||||
(intmap-add representations var 'u64))
|
||||
(($ $primcall (or 'scm->s64 'load-s64))
|
||||
(intmap-add representations var 's64))
|
||||
(_
|
||||
(intmap-add representations var 'scm))))
|
||||
(vars
|
||||
|
@ -885,7 +887,7 @@ are comparable with eqv?. A tmp slot may be used."
|
|||
(#f slot-map)
|
||||
(slot
|
||||
(let ((desc (match (intmap-ref representations var)
|
||||
((or 'u64 'f64) slot-desc-live-raw)
|
||||
((or 'u64 'f64 's64) slot-desc-live-raw)
|
||||
('scm slot-desc-live-scm))))
|
||||
(logior slot-map (ash desc (* 2 slot)))))))
|
||||
live-vars 0))
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
(('umul (? u8? x) y) (build-exp ($primcall 'umul/immediate (y x))))
|
||||
(('scm->f64 (? f64?)) (rename 'load-f64))
|
||||
(('scm->u64 (? u64?)) (rename 'load-u64))
|
||||
(('scm->s64 (? s64?)) (rename 'load-s64))
|
||||
(_ #f)))
|
||||
(intmap-map
|
||||
(lambda (label cont)
|
||||
|
|
|
@ -120,6 +120,7 @@
|
|||
;; Untagged types.
|
||||
&f64
|
||||
&u64
|
||||
&s64
|
||||
|
||||
infer-types
|
||||
lookup-pre-type
|
||||
|
@ -171,7 +172,8 @@
|
|||
&hash-table
|
||||
|
||||
&f64
|
||||
&u64)
|
||||
&u64
|
||||
&s64)
|
||||
|
||||
(define-syntax &no-type (identifier-syntax 0))
|
||||
|
||||
|
@ -203,8 +205,12 @@
|
|||
(var (identifier? #'var)
|
||||
(datum->syntax #'var val)))))))
|
||||
|
||||
(define-compile-time-value &range-min (- #x8000000000000000))
|
||||
(define-compile-time-value &range-max #xffffFFFFffffFFFF)
|
||||
(define-compile-time-value &s64-min (- #x8000000000000000))
|
||||
(define-compile-time-value &s64-max #x7fffFFFFffffFFFF)
|
||||
(define-compile-time-value &u64-max #xffffFFFFffffFFFF)
|
||||
|
||||
(define-syntax &range-min (identifier-syntax &s64-min))
|
||||
(define-syntax &range-max (identifier-syntax &u64-max))
|
||||
|
||||
;; This is a hack that takes advantage of knowing that
|
||||
;; most-positive-fixnum is the size of a word, but with two tag bits and
|
||||
|
@ -725,6 +731,18 @@ minimum, and maximum."
|
|||
(define-type-inferrer (u64->scm u64 result)
|
||||
(define! result &exact-integer (&min u64) (&max u64)))
|
||||
|
||||
(define-type-checker (scm->s64 scm)
|
||||
(check-type scm &exact-integer &s64-min &s64-max))
|
||||
(define-type-inferrer (scm->s64 scm result)
|
||||
(restrict! scm &exact-integer &s64-min &s64-max)
|
||||
(define! result &s64 (max (&min scm) &s64-min) (min (&max scm) &s64-max)))
|
||||
(define-type-aliases scm->s64 load-s64)
|
||||
|
||||
(define-type-checker (s64->scm s64)
|
||||
#t)
|
||||
(define-type-inferrer (s64->scm s64 result)
|
||||
(define! result &exact-integer (&min s64) (&max s64)))
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -773,9 +791,9 @@ minimum, and maximum."
|
|||
(define-bytevector-accessors bv-s32-ref bv-s32-set!
|
||||
&exact-integer 4 (- #x80000000) #x7fffFFFF)
|
||||
(define-bytevector-accessors bv-u64-ref bv-u64-set!
|
||||
&exact-integer 8 #x0000000000000000 #xffffFFFFffffFFFF)
|
||||
&exact-integer 8 0 &u64-max)
|
||||
(define-bytevector-accessors bv-s64-ref bv-s64-set!
|
||||
&exact-integer 8 (- #x8000000000000000) #x7fffFFFFffffFFFF)
|
||||
&exact-integer 8 &s64-min &s64-max)
|
||||
|
||||
(define-syntax-rule (define-bytevector-uaccessors ref set type size lo hi)
|
||||
(begin
|
||||
|
|
|
@ -205,7 +205,7 @@ disjoint, an error will be signalled."
|
|||
(intmap-fold
|
||||
(lambda (var exp out)
|
||||
(match exp
|
||||
(($ $primcall (or 'load-f64 'load-u64) (val))
|
||||
(($ $primcall (or 'load-f64 'load-u64 'load-s64) (val))
|
||||
(intmap-add! out var (intmap-ref out val)))
|
||||
;; Punch through type conversions to allow uadd to specialize
|
||||
;; to uadd/immediate.
|
||||
|
@ -220,6 +220,12 @@ disjoint, an error will be signalled."
|
|||
(<= 0 u64 #xffffFFFFffffFFFF))
|
||||
(intmap-add! out var u64)
|
||||
out)))
|
||||
(($ $primcall 'scm->s64 (val))
|
||||
(let ((s64 (intmap-ref out val (lambda (_) #f))))
|
||||
(if (and s64 (number? s64) (exact-integer? s64)
|
||||
(<= (- #x8000000000000000) u64 #x7fffFFFFffffFFFF))
|
||||
(intmap-add! out var s64)
|
||||
out)))
|
||||
(_ out)))
|
||||
defs
|
||||
(intmap-fold (lambda (var exp out)
|
||||
|
|
|
@ -173,6 +173,9 @@
|
|||
(emit-scm->u64* . emit-scm->u64)
|
||||
emit-load-u64
|
||||
(emit-u64->scm* . emit-u64->scm)
|
||||
(emit-scm->s64* . emit-scm->s64)
|
||||
emit-load-s64
|
||||
(emit-s64->scm* . emit-s64->scm)
|
||||
(emit-bv-length* . emit-bv-length)
|
||||
(emit-bv-u8-ref* . emit-bv-u8-ref)
|
||||
(emit-bv-s8-ref* . emit-bv-s8-ref)
|
||||
|
@ -1919,6 +1922,7 @@ procedure with label @var{rw-init}. @var{rw-init} may be false. If
|
|||
((scm) 0)
|
||||
((f64) 1)
|
||||
((u64) 2)
|
||||
((s64) 3)
|
||||
(else (error "what!" representation)))))
|
||||
(put-uleb128 names-port (logior (ash slot 2) tag)))
|
||||
(lp definitions))))))
|
||||
|
|
|
@ -387,6 +387,7 @@ section of the ELF image. Returns an ELF symbol, or @code{#f}."
|
|||
((0) 'scm)
|
||||
((1) 'f64)
|
||||
((2) 'u64)
|
||||
((3) 's64)
|
||||
(else 'unknown))))
|
||||
(cons (vector name def-offset slot representation)
|
||||
(lp pos names)))))))))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue