1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 19:50:24 +02:00

Add make-vector opcode

* libguile/vm-engine.c (make-vector): New opcode.
* module/language/cps/compile-bytecode.scm (compile-fun):
* module/system/vm/assembler.scm (system): Support the new opcode.
  (*bytecode-minor-version*): Bump.

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* test-suite/tests/compiler.test ("limits"): Add vector test.
This commit is contained in:
Andy Wingo 2014-04-21 21:48:39 +02:00
parent d4b3a36d42
commit d38ca16e2c
5 changed files with 61 additions and 37 deletions

View file

@ -268,7 +268,7 @@ void scm_ia64_longjmp (scm_i_jmp_buf *, int);
/* Major and minor versions must be single characters. */ /* Major and minor versions must be single characters. */
#define SCM_OBJCODE_MAJOR_VERSION 3 #define SCM_OBJCODE_MAJOR_VERSION 3
#define SCM_OBJCODE_MINOR_VERSION 5 #define SCM_OBJCODE_MINOR_VERSION 6
#define SCM_OBJCODE_MAJOR_VERSION_STRING \ #define SCM_OBJCODE_MAJOR_VERSION_STRING \
SCM_CPP_STRINGIFY(SCM_OBJCODE_MAJOR_VERSION) SCM_CPP_STRINGIFY(SCM_OBJCODE_MAJOR_VERSION)
#define SCM_OBJCODE_MINOR_VERSION_STRING \ #define SCM_OBJCODE_MINOR_VERSION_STRING \

View file

@ -2527,13 +2527,29 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
RETURN_EXP (scm_logxor (x, y)); RETURN_EXP (scm_logxor (x, y));
} }
/* make-vector dst:8 length:8 init:8
*
* Make a vector and write it to DST. The vector will have space for
* LENGTH slots. They will be filled with the value in slot INIT.
*/
VM_DEFINE_OP (94, make_vector, "make-vector", OP1 (U8_U8_U8_U8) | OP_DST)
{
scm_t_uint8 dst, init, length;
UNPACK_8_8_8 (op, dst, length, init);
LOCAL_SET (dst, scm_make_vector (LOCAL_REF (length), LOCAL_REF (init)));
NEXT (1);
}
/* make-vector/immediate dst:8 length:8 init:8 /* make-vector/immediate dst:8 length:8 init:8
* *
* Make a short vector of known size and write it to DST. The vector * Make a short vector of known size and write it to DST. The vector
* will have space for LENGTH slots, an immediate value. They will be * will have space for LENGTH slots, an immediate value. They will be
* filled with the value in slot INIT. * filled with the value in slot INIT.
*/ */
VM_DEFINE_OP (94, make_vector_immediate, "make-vector/immediate", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (95, make_vector_immediate, "make-vector/immediate", OP1 (U8_U8_U8_U8) | OP_DST)
{ {
scm_t_uint8 dst, init; scm_t_uint8 dst, init;
scm_t_int32 length, n; scm_t_int32 length, n;
@ -2554,7 +2570,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* *
* Store the length of the vector in SRC in DST. * Store the length of the vector in SRC in DST.
*/ */
VM_DEFINE_OP (95, vector_length, "vector-length", OP1 (U8_U12_U12) | OP_DST) VM_DEFINE_OP (96, vector_length, "vector-length", OP1 (U8_U12_U12) | OP_DST)
{ {
ARGS1 (vect); ARGS1 (vect);
VM_ASSERT (SCM_I_IS_VECTOR (vect), VM_ASSERT (SCM_I_IS_VECTOR (vect),
@ -2567,7 +2583,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* Fetch the item at position IDX in the vector in SRC, and store it * Fetch the item at position IDX in the vector in SRC, and store it
* in DST. * in DST.
*/ */
VM_DEFINE_OP (96, vector_ref, "vector-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (97, vector_ref, "vector-ref", OP1 (U8_U8_U8_U8) | OP_DST)
{ {
scm_t_signed_bits i = 0; scm_t_signed_bits i = 0;
ARGS2 (vect, idx); ARGS2 (vect, idx);
@ -2585,7 +2601,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* Fill DST with the item IDX elements into the vector at SRC. Useful * Fill DST with the item IDX elements into the vector at SRC. Useful
* for building data types using vectors. * for building data types using vectors.
*/ */
VM_DEFINE_OP (97, vector_ref_immediate, "vector-ref/immediate", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (98, vector_ref_immediate, "vector-ref/immediate", OP1 (U8_U8_U8_U8) | OP_DST)
{ {
scm_t_uint8 dst, src, idx; scm_t_uint8 dst, src, idx;
SCM v; SCM v;
@ -2604,7 +2620,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* *
* Store SRC into the vector DST at index IDX. * Store SRC into the vector DST at index IDX.
*/ */
VM_DEFINE_OP (98, vector_set, "vector-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (99, vector_set, "vector-set!", OP1 (U8_U8_U8_U8))
{ {
scm_t_uint8 dst, idx_var, src; scm_t_uint8 dst, idx_var, src;
SCM vect, idx, val; SCM vect, idx, val;
@ -2630,7 +2646,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* Store SRC into the vector DST at index IDX. Here IDX is an * Store SRC into the vector DST at index IDX. Here IDX is an
* immediate value. * immediate value.
*/ */
VM_DEFINE_OP (99, vector_set_immediate, "vector-set!/immediate", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (100, vector_set_immediate, "vector-set!/immediate", OP1 (U8_U8_U8_U8))
{ {
scm_t_uint8 dst, idx, src; scm_t_uint8 dst, idx, src;
SCM vect, val; SCM vect, val;
@ -2658,7 +2674,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* *
* Store the vtable of SRC into DST. * Store the vtable of SRC into DST.
*/ */
VM_DEFINE_OP (100, struct_vtable, "struct-vtable", OP1 (U8_U12_U12) | OP_DST) VM_DEFINE_OP (101, struct_vtable, "struct-vtable", OP1 (U8_U12_U12) | OP_DST)
{ {
ARGS1 (obj); ARGS1 (obj);
VM_VALIDATE_STRUCT (obj, "struct_vtable"); VM_VALIDATE_STRUCT (obj, "struct_vtable");
@ -2671,7 +2687,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* will be constructed with space for NFIELDS fields, which should * will be constructed with space for NFIELDS fields, which should
* correspond to the field count of the VTABLE. * correspond to the field count of the VTABLE.
*/ */
VM_DEFINE_OP (101, allocate_struct_immediate, "allocate-struct/immediate", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (102, allocate_struct_immediate, "allocate-struct/immediate", OP1 (U8_U8_U8_U8) | OP_DST)
{ {
scm_t_uint8 dst, vtable, nfields; scm_t_uint8 dst, vtable, nfields;
SCM ret; SCM ret;
@ -2690,7 +2706,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* Fetch the item at slot IDX in the struct in SRC, and store it * Fetch the item at slot IDX in the struct in SRC, and store it
* in DST. IDX is an immediate unsigned 8-bit value. * in DST. IDX is an immediate unsigned 8-bit value.
*/ */
VM_DEFINE_OP (102, struct_ref_immediate, "struct-ref/immediate", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (103, struct_ref_immediate, "struct-ref/immediate", OP1 (U8_U8_U8_U8) | OP_DST)
{ {
scm_t_uint8 dst, src, idx; scm_t_uint8 dst, src, idx;
SCM obj; SCM obj;
@ -2715,7 +2731,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* Store SRC into the struct DST at slot IDX. IDX is an immediate * Store SRC into the struct DST at slot IDX. IDX is an immediate
* unsigned 8-bit value. * unsigned 8-bit value.
*/ */
VM_DEFINE_OP (103, struct_set_immediate, "struct-set!/immediate", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (104, struct_set_immediate, "struct-set!/immediate", OP1 (U8_U8_U8_U8))
{ {
scm_t_uint8 dst, idx, src; scm_t_uint8 dst, idx, src;
SCM obj, val; SCM obj, val;
@ -2746,7 +2762,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* *
* Store the vtable of SRC into DST. * Store the vtable of SRC into DST.
*/ */
VM_DEFINE_OP (104, class_of, "class-of", OP1 (U8_U12_U12) | OP_DST) VM_DEFINE_OP (105, class_of, "class-of", OP1 (U8_U12_U12) | OP_DST)
{ {
ARGS1 (obj); ARGS1 (obj);
if (SCM_INSTANCEP (obj)) if (SCM_INSTANCEP (obj))
@ -2767,7 +2783,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* from the instruction pointer, and store into DST. LEN is a byte * from the instruction pointer, and store into DST. LEN is a byte
* length. OFFSET is signed. * length. OFFSET is signed.
*/ */
VM_DEFINE_OP (105, load_typed_array, "load-typed-array", OP3 (U8_U8_U8_U8, N32, U32) | OP_DST) VM_DEFINE_OP (106, load_typed_array, "load-typed-array", OP3 (U8_U8_U8_U8, N32, U32) | OP_DST)
{ {
scm_t_uint8 dst, type, shape; scm_t_uint8 dst, type, shape;
scm_t_int32 offset; scm_t_int32 offset;
@ -2787,7 +2803,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
* *
* Make a new array with TYPE, FILL, and BOUNDS, storing it in DST. * Make a new array with TYPE, FILL, and BOUNDS, storing it in DST.
*/ */
VM_DEFINE_OP (106, make_array, "make-array", OP2 (U8_U8_U8_U8, X8_U24) | OP_DST) VM_DEFINE_OP (107, make_array, "make-array", OP2 (U8_U8_U8_U8, X8_U24) | OP_DST)
{ {
scm_t_uint8 dst, type, fill, bounds; scm_t_uint8 dst, type, fill, bounds;
UNPACK_8_8_8 (op, dst, type, fill); UNPACK_8_8_8 (op, dst, type, fill);
@ -2885,42 +2901,42 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
RETURN (scm_bytevector_ ## fn_stem ## _native_ref (bv, idx)); \ RETURN (scm_bytevector_ ## fn_stem ## _native_ref (bv, idx)); \
} while (0) } while (0)
VM_DEFINE_OP (107, bv_u8_ref, "bv-u8-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (108, bv_u8_ref, "bv-u8-ref", OP1 (U8_U8_U8_U8) | OP_DST)
BV_FIXABLE_INT_REF (u8, u8, uint8, 1); BV_FIXABLE_INT_REF (u8, u8, uint8, 1);
VM_DEFINE_OP (108, bv_s8_ref, "bv-s8-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (109, bv_s8_ref, "bv-s8-ref", OP1 (U8_U8_U8_U8) | OP_DST)
BV_FIXABLE_INT_REF (s8, s8, int8, 1); BV_FIXABLE_INT_REF (s8, s8, int8, 1);
VM_DEFINE_OP (109, bv_u16_ref, "bv-u16-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (110, bv_u16_ref, "bv-u16-ref", OP1 (U8_U8_U8_U8) | OP_DST)
BV_FIXABLE_INT_REF (u16, u16_native, uint16, 2); BV_FIXABLE_INT_REF (u16, u16_native, uint16, 2);
VM_DEFINE_OP (110, bv_s16_ref, "bv-s16-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (111, bv_s16_ref, "bv-s16-ref", OP1 (U8_U8_U8_U8) | OP_DST)
BV_FIXABLE_INT_REF (s16, s16_native, int16, 2); BV_FIXABLE_INT_REF (s16, s16_native, int16, 2);
VM_DEFINE_OP (111, bv_u32_ref, "bv-u32-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (112, bv_u32_ref, "bv-u32-ref", OP1 (U8_U8_U8_U8) | OP_DST)
#if SIZEOF_VOID_P > 4 #if SIZEOF_VOID_P > 4
BV_FIXABLE_INT_REF (u32, u32_native, uint32, 4); BV_FIXABLE_INT_REF (u32, u32_native, uint32, 4);
#else #else
BV_INT_REF (u32, uint32, 4); BV_INT_REF (u32, uint32, 4);
#endif #endif
VM_DEFINE_OP (112, bv_s32_ref, "bv-s32-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (113, bv_s32_ref, "bv-s32-ref", OP1 (U8_U8_U8_U8) | OP_DST)
#if SIZEOF_VOID_P > 4 #if SIZEOF_VOID_P > 4
BV_FIXABLE_INT_REF (s32, s32_native, int32, 4); BV_FIXABLE_INT_REF (s32, s32_native, int32, 4);
#else #else
BV_INT_REF (s32, int32, 4); BV_INT_REF (s32, int32, 4);
#endif #endif
VM_DEFINE_OP (113, bv_u64_ref, "bv-u64-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (114, bv_u64_ref, "bv-u64-ref", OP1 (U8_U8_U8_U8) | OP_DST)
BV_INT_REF (u64, uint64, 8); BV_INT_REF (u64, uint64, 8);
VM_DEFINE_OP (114, bv_s64_ref, "bv-s64-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (115, bv_s64_ref, "bv-s64-ref", OP1 (U8_U8_U8_U8) | OP_DST)
BV_INT_REF (s64, int64, 8); BV_INT_REF (s64, int64, 8);
VM_DEFINE_OP (115, bv_f32_ref, "bv-f32-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (116, bv_f32_ref, "bv-f32-ref", OP1 (U8_U8_U8_U8) | OP_DST)
BV_FLOAT_REF (f32, ieee_single, float, 4); BV_FLOAT_REF (f32, ieee_single, float, 4);
VM_DEFINE_OP (116, bv_f64_ref, "bv-f64-ref", OP1 (U8_U8_U8_U8) | OP_DST) VM_DEFINE_OP (117, bv_f64_ref, "bv-f64-ref", OP1 (U8_U8_U8_U8) | OP_DST)
BV_FLOAT_REF (f64, ieee_double, double, 8); BV_FLOAT_REF (f64, ieee_double, double, 8);
/* bv-u8-set! dst:8 idx:8 src:8 /* bv-u8-set! dst:8 idx:8 src:8
@ -3024,45 +3040,44 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
NEXT (1); \ NEXT (1); \
} while (0) } while (0)
VM_DEFINE_OP (117, bv_u8_set, "bv-u8-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (118, bv_u8_set, "bv-u8-set!", OP1 (U8_U8_U8_U8))
BV_FIXABLE_INT_SET (u8, u8, uint8, 0, SCM_T_UINT8_MAX, 1); BV_FIXABLE_INT_SET (u8, u8, uint8, 0, SCM_T_UINT8_MAX, 1);
VM_DEFINE_OP (118, bv_s8_set, "bv-s8-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (119, bv_s8_set, "bv-s8-set!", OP1 (U8_U8_U8_U8))
BV_FIXABLE_INT_SET (s8, s8, int8, SCM_T_INT8_MIN, SCM_T_INT8_MAX, 1); BV_FIXABLE_INT_SET (s8, s8, int8, SCM_T_INT8_MIN, SCM_T_INT8_MAX, 1);
VM_DEFINE_OP (119, bv_u16_set, "bv-u16-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (120, bv_u16_set, "bv-u16-set!", OP1 (U8_U8_U8_U8))
BV_FIXABLE_INT_SET (u16, u16_native, uint16, 0, SCM_T_UINT16_MAX, 2); BV_FIXABLE_INT_SET (u16, u16_native, uint16, 0, SCM_T_UINT16_MAX, 2);
VM_DEFINE_OP (120, bv_s16_set, "bv-s16-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (121, bv_s16_set, "bv-s16-set!", OP1 (U8_U8_U8_U8))
BV_FIXABLE_INT_SET (s16, s16_native, int16, SCM_T_INT16_MIN, SCM_T_INT16_MAX, 2); BV_FIXABLE_INT_SET (s16, s16_native, int16, SCM_T_INT16_MIN, SCM_T_INT16_MAX, 2);
VM_DEFINE_OP (121, bv_u32_set, "bv-u32-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (122, bv_u32_set, "bv-u32-set!", OP1 (U8_U8_U8_U8))
#if SIZEOF_VOID_P > 4 #if SIZEOF_VOID_P > 4
BV_FIXABLE_INT_SET (u32, u32_native, uint32, 0, SCM_T_UINT32_MAX, 4); BV_FIXABLE_INT_SET (u32, u32_native, uint32, 0, SCM_T_UINT32_MAX, 4);
#else #else
BV_INT_SET (u32, uint32, 4); BV_INT_SET (u32, uint32, 4);
#endif #endif
VM_DEFINE_OP (122, bv_s32_set, "bv-s32-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (123, bv_s32_set, "bv-s32-set!", OP1 (U8_U8_U8_U8))
#if SIZEOF_VOID_P > 4 #if SIZEOF_VOID_P > 4
BV_FIXABLE_INT_SET (s32, s32_native, int32, SCM_T_INT32_MIN, SCM_T_INT32_MAX, 4); BV_FIXABLE_INT_SET (s32, s32_native, int32, SCM_T_INT32_MIN, SCM_T_INT32_MAX, 4);
#else #else
BV_INT_SET (s32, int32, 4); BV_INT_SET (s32, int32, 4);
#endif #endif
VM_DEFINE_OP (123, bv_u64_set, "bv-u64-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (124, bv_u64_set, "bv-u64-set!", OP1 (U8_U8_U8_U8))
BV_INT_SET (u64, uint64, 8); BV_INT_SET (u64, uint64, 8);
VM_DEFINE_OP (124, bv_s64_set, "bv-s64-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (125, bv_s64_set, "bv-s64-set!", OP1 (U8_U8_U8_U8))
BV_INT_SET (s64, int64, 8); BV_INT_SET (s64, int64, 8);
VM_DEFINE_OP (125, bv_f32_set, "bv-f32-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (126, bv_f32_set, "bv-f32-set!", OP1 (U8_U8_U8_U8))
BV_FLOAT_SET (f32, ieee_single, float, 4); BV_FLOAT_SET (f32, ieee_single, float, 4);
VM_DEFINE_OP (126, bv_f64_set, "bv-f64-set!", OP1 (U8_U8_U8_U8)) VM_DEFINE_OP (127, bv_f64_set, "bv-f64-set!", OP1 (U8_U8_U8_U8))
BV_FLOAT_SET (f64, ieee_double, double, 8); BV_FLOAT_SET (f64, ieee_double, double, 8);
VM_DEFINE_OP (127, unused_127, NULL, NOP)
VM_DEFINE_OP (128, unused_128, NULL, NOP) VM_DEFINE_OP (128, unused_128, NULL, NOP)
VM_DEFINE_OP (129, unused_129, NULL, NOP) VM_DEFINE_OP (129, unused_129, NULL, NOP)
VM_DEFINE_OP (130, unused_130, NULL, NOP) VM_DEFINE_OP (130, unused_130, NULL, NOP)

View file

@ -268,6 +268,8 @@
(emit-free-ref asm dst (slot closure) (constant idx))) (emit-free-ref asm dst (slot closure) (constant idx)))
(($ $primcall 'vector-ref (vector index)) (($ $primcall 'vector-ref (vector index))
(emit-vector-ref asm dst (slot vector) (slot index))) (emit-vector-ref asm dst (slot vector) (slot index)))
(($ $primcall 'make-vector (length init))
(emit-make-vector asm dst (slot length) (slot init)))
(($ $primcall 'make-vector/immediate (length init)) (($ $primcall 'make-vector/immediate (length init))
(emit-make-vector/immediate asm dst (constant length) (slot init))) (emit-make-vector/immediate asm dst (constant length) (slot init)))
(($ $primcall 'vector-ref/immediate (vector index)) (($ $primcall 'vector-ref/immediate (vector index))

View file

@ -137,6 +137,7 @@
(emit-logand* . emit-logand) (emit-logand* . emit-logand)
(emit-logior* . emit-logior) (emit-logior* . emit-logior)
(emit-logxor* . emit-logxor) (emit-logxor* . emit-logxor)
(emit-make-vector* . emit-make-vector)
(emit-make-vector/immediate* . emit-make-vector/immediate) (emit-make-vector/immediate* . emit-make-vector/immediate)
(emit-vector-length* . emit-vector-length) (emit-vector-length* . emit-vector-length)
(emit-vector-ref* . emit-vector-ref) (emit-vector-ref* . emit-vector-ref)
@ -1586,7 +1587,7 @@ needed."
;; FIXME: Define these somewhere central, shared with C. ;; FIXME: Define these somewhere central, shared with C.
(define *bytecode-major-version* #x0202) (define *bytecode-major-version* #x0202)
(define *bytecode-minor-version* 5) (define *bytecode-minor-version* 6)
(define (link-dynamic-section asm text rw rw-init frame-maps) (define (link-dynamic-section asm text rw rw-init frame-maps)
"Link the dynamic section for an ELF image with bytecode @var{text}, "Link the dynamic section for an ELF image with bytecode @var{text},

View file

@ -195,4 +195,10 @@
(equal? ((compile `(lambda () (equal? ((compile `(lambda ()
(list ,@(map (lambda (n) `(identity ,n)) (list ,@(map (lambda (n) `(identity ,n))
(iota 300)))))) (iota 300))))))
(iota 300)))) (iota 300)))
(pass-if "0 arguments with vector of 300 elements"
(equal? ((compile `(lambda ()
(vector ,@(map (lambda (n) `(identity ,n))
(iota 300))))))
(list->vector (iota 300)))))