1 /* Copyright (C) 2001, 2009, 2010 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 /* This file is included in vm_engine.c */
26 #define ARGS1(a1) SCM a1 = sp[0];
27 #define ARGS2(a1,a2) SCM a1 = sp[-1], a2 = sp[0]; sp--; NULLSTACK (1);
28 #define ARGS3(a1,a2,a3) SCM a1 = sp[-2], a2 = sp[-1], a3 = sp[0]; sp -= 2; NULLSTACK (2);
30 #define RETURN(x) do { *sp = x; NEXT; } while (0)
32 VM_DEFINE_FUNCTION (128, not, "not", 1)
35 RETURN (scm_from_bool (scm_is_false (x
)));
38 VM_DEFINE_FUNCTION (129, not_not
, "not-not", 1)
41 RETURN (scm_from_bool (!scm_is_false (x
)));
44 VM_DEFINE_FUNCTION (130, eq
, "eq?", 2)
47 RETURN (scm_from_bool (scm_is_eq (x
, y
)));
50 VM_DEFINE_FUNCTION (131, not_eq, "not-eq?", 2)
53 RETURN (scm_from_bool (!scm_is_eq (x
, y
)));
56 VM_DEFINE_FUNCTION (132, nullp
, "null?", 1)
59 RETURN (scm_from_bool (scm_is_null (x
)));
62 VM_DEFINE_FUNCTION (133, not_nullp
, "not-null?", 1)
65 RETURN (scm_from_bool (!scm_is_null (x
)));
68 VM_DEFINE_FUNCTION (134, eqv
, "eqv?", 2)
73 if (SCM_IMP (x
) || SCM_IMP (y
))
76 RETURN (scm_eqv_p (x
, y
));
79 VM_DEFINE_FUNCTION (135, equal
, "equal?", 2)
84 if (SCM_IMP (x
) || SCM_IMP (y
))
87 RETURN (scm_equal_p (x
, y
));
90 VM_DEFINE_FUNCTION (136, pairp
, "pair?", 1)
93 RETURN (scm_from_bool (scm_is_pair (x
)));
96 VM_DEFINE_FUNCTION (137, listp
, "list?", 1)
99 RETURN (scm_from_bool (scm_ilength (x
) >= 0));
107 VM_DEFINE_FUNCTION (138, cons
, "cons", 2)
114 #define VM_VALIDATE_CONS(x) \
115 if (SCM_UNLIKELY (!scm_is_pair (x))) \
117 goto vm_error_not_a_pair; \
120 VM_DEFINE_FUNCTION (139, car
, "car", 1)
123 VM_VALIDATE_CONS (x
);
124 RETURN (SCM_CAR (x
));
127 VM_DEFINE_FUNCTION (140, cdr
, "cdr", 1)
130 VM_VALIDATE_CONS (x
);
131 RETURN (SCM_CDR (x
));
134 VM_DEFINE_INSTRUCTION (141, set_car
, "set-car!", 0, 2, 0)
139 VM_VALIDATE_CONS (x
);
144 VM_DEFINE_INSTRUCTION (142, set_cdr
, "set-cdr!", 0, 2, 0)
149 VM_VALIDATE_CONS (x
);
156 * Numeric relational tests
160 #define REL(crel,srel) \
163 if (SCM_I_INUMP (x) && SCM_I_INUMP (y)) \
164 RETURN (scm_from_bool (SCM_I_INUM (x) crel SCM_I_INUM (y))); \
166 RETURN (srel (x, y)); \
169 VM_DEFINE_FUNCTION (143, ee
, "ee?", 2)
171 REL (==, scm_num_eq_p
);
174 VM_DEFINE_FUNCTION (144, lt
, "lt?", 2)
179 VM_DEFINE_FUNCTION (145, le
, "le?", 2)
184 VM_DEFINE_FUNCTION (146, gt
, "gt?", 2)
189 VM_DEFINE_FUNCTION (147, ge
, "ge?", 2)
200 #define FUNC2(CFUNC,SFUNC) \
203 if (SCM_I_INUMP (x) && SCM_I_INUMP (y)) \
205 scm_t_int64 n = SCM_I_INUM (x) CFUNC SCM_I_INUM (y);\
206 if (SCM_FIXABLE (n)) \
207 RETURN (SCM_I_MAKINUM (n)); \
210 RETURN (SFUNC (x, y)); \
213 VM_DEFINE_FUNCTION (148, add
, "add", 2)
218 VM_DEFINE_FUNCTION (149, add1
, "add1", 1)
223 scm_t_int64 n
= SCM_I_INUM (x
) + 1;
225 RETURN (SCM_I_MAKINUM (n
));
228 RETURN (scm_sum (x
, SCM_I_MAKINUM (1)));
231 VM_DEFINE_FUNCTION (150, sub
, "sub", 2)
233 FUNC2 (-, scm_difference
);
236 VM_DEFINE_FUNCTION (151, sub1
, "sub1", 1)
241 scm_t_int64 n
= SCM_I_INUM (x
) - 1;
243 RETURN (SCM_I_MAKINUM (n
));
246 RETURN (scm_difference (x
, SCM_I_MAKINUM (1)));
249 VM_DEFINE_FUNCTION (152, mul
, "mul", 2)
253 RETURN (scm_product (x
, y
));
256 VM_DEFINE_FUNCTION (153, div
, "div", 2)
260 RETURN (scm_divide (x
, y
));
263 VM_DEFINE_FUNCTION (154, quo
, "quo", 2)
267 RETURN (scm_quotient (x
, y
));
270 VM_DEFINE_FUNCTION (155, rem
, "rem", 2)
274 RETURN (scm_remainder (x
, y
));
277 VM_DEFINE_FUNCTION (156, mod
, "mod", 2)
281 RETURN (scm_modulo (x
, y
));
284 VM_DEFINE_FUNCTION (157, ash
, "ash", 2)
287 if (SCM_I_INUMP (x
) && SCM_I_INUMP (y
))
289 if (SCM_I_INUM (y
) < 0)
290 /* Right shift, will be a fixnum. */
291 RETURN (SCM_I_MAKINUM (SCM_I_INUM (x
) >> -SCM_I_INUM (y
)));
293 /* Left shift. See comments in scm_ash. */
295 long nn
, bits_to_shift
;
298 bits_to_shift
= SCM_I_INUM (y
);
300 if (bits_to_shift
< SCM_I_FIXNUM_BIT
-1
302 (SCM_SRS (nn
, (SCM_I_FIXNUM_BIT
-1 - bits_to_shift
)) + 1)
304 RETURN (SCM_I_MAKINUM (nn
<< bits_to_shift
));
310 RETURN (scm_ash (x
, y
));
313 VM_DEFINE_FUNCTION (158, logand
, "logand", 2)
316 if (SCM_I_INUMP (x
) && SCM_I_INUMP (y
))
317 RETURN (SCM_I_MAKINUM (SCM_I_INUM (x
) & SCM_I_INUM (y
)));
319 RETURN (scm_logand (x
, y
));
322 VM_DEFINE_FUNCTION (159, logior
, "logior", 2)
325 if (SCM_I_INUMP (x
) && SCM_I_INUMP (y
))
326 RETURN (SCM_I_MAKINUM (SCM_I_INUM (x
) | SCM_I_INUM (y
)));
328 RETURN (scm_logior (x
, y
));
331 VM_DEFINE_FUNCTION (160, logxor
, "logxor", 2)
334 if (SCM_I_INUMP (x
) && SCM_I_INUMP (y
))
335 RETURN (SCM_I_MAKINUM (SCM_I_INUM (x
) ^ SCM_I_INUM (y
)));
337 RETURN (scm_logxor (x
, y
));
345 VM_DEFINE_FUNCTION (161, vector_ref
, "vector-ref", 2)
349 if (SCM_LIKELY (SCM_I_IS_NONWEAK_VECTOR (vect
)
351 && ((i
= SCM_I_INUM (idx
)) >= 0)
352 && i
< SCM_I_VECTOR_LENGTH (vect
)))
353 RETURN (SCM_I_VECTOR_ELTS (vect
)[i
]);
357 RETURN (scm_vector_ref (vect
, idx
));
361 VM_DEFINE_INSTRUCTION (162, vector_set
, "vector-set", 0, 3, 0)
365 POP (val
); POP (idx
); POP (vect
);
366 if (SCM_LIKELY (SCM_I_IS_NONWEAK_VECTOR (vect
)
368 && ((i
= SCM_I_INUM (idx
)) >= 0)
369 && i
< SCM_I_VECTOR_LENGTH (vect
)))
370 SCM_I_VECTOR_WELTS (vect
)[i
] = val
;
374 scm_vector_set_x (vect
, idx
, val
);
379 VM_DEFINE_INSTRUCTION (163, make_array
, "make-array", 3, -1, 1)
385 len
= (len
<< 8) + FETCH ();
386 len
= (len
<< 8) + FETCH ();
389 PRE_CHECK_UNDERFLOW (len
);
390 ret
= scm_from_contiguous_array (shape
, sp
- len
+ 1, len
);
400 #define VM_VALIDATE_STRUCT(obj) \
401 if (SCM_UNLIKELY (!SCM_STRUCTP (obj))) \
403 finish_args = (obj); \
404 goto vm_error_not_a_struct; \
407 VM_DEFINE_FUNCTION (164, struct_p
, "struct?", 1)
410 RETURN (scm_from_bool (SCM_STRUCTP (obj
)));
413 VM_DEFINE_FUNCTION (165, struct_vtable
, "struct-vtable", 1)
416 VM_VALIDATE_STRUCT (obj
);
417 RETURN (SCM_STRUCT_VTABLE (obj
));
420 VM_DEFINE_INSTRUCTION (166, make_struct
, "make-struct", 2, -1, 1)
422 unsigned h
= FETCH ();
423 unsigned l
= FETCH ();
424 scm_t_bits n
= ((h
<< 8U) + l
);
425 SCM vtable
= sp
[-(n
- 1)];
426 const SCM
*inits
= sp
- n
+ 2;
431 if (SCM_LIKELY (SCM_STRUCTP (vtable
)
432 && SCM_VTABLE_FLAG_IS_SET (vtable
, SCM_VTABLE_FLAG_SIMPLE
)
433 && (SCM_STRUCT_DATA_REF (vtable
, scm_vtable_index_size
) + 1
435 && !SCM_VTABLE_INSTANCE_FINALIZER (vtable
)))
437 /* Verily, we are making a simple struct with the right number of
438 initializers, and no finalizer. */
439 ret
= scm_words ((scm_t_bits
)SCM_STRUCT_DATA (vtable
) | scm_tc3_struct
,
441 SCM_SET_CELL_WORD_1 (ret
, (scm_t_bits
)SCM_CELL_OBJECT_LOC (ret
, 2));
442 memcpy (SCM_STRUCT_DATA (ret
), inits
, (n
- 1) * sizeof (SCM
));
445 ret
= scm_c_make_structv (vtable
, 0, n
- 1, (scm_t_bits
*) inits
);
453 VM_DEFINE_FUNCTION (167, struct_ref
, "struct-ref", 2)
457 if (SCM_LIKELY (SCM_STRUCTP (obj
)
458 && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj
,
459 SCM_VTABLE_FLAG_SIMPLE
)
460 && SCM_I_INUMP (pos
)))
463 scm_t_bits index
, len
;
465 index
= SCM_I_INUM (pos
);
466 vtable
= SCM_STRUCT_VTABLE (obj
);
467 len
= SCM_STRUCT_DATA_REF (vtable
, scm_vtable_index_size
);
469 if (SCM_LIKELY (index
< len
))
471 scm_t_bits
*data
= SCM_STRUCT_DATA (obj
);
472 RETURN (SCM_PACK (data
[index
]));
477 RETURN (scm_struct_ref (obj
, pos
));
480 VM_DEFINE_FUNCTION (168, struct_set
, "struct-set", 3)
482 ARGS3 (obj
, pos
, val
);
484 if (SCM_LIKELY (SCM_STRUCTP (obj
)
485 && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj
,
486 SCM_VTABLE_FLAG_SIMPLE
)
487 && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj
,
488 SCM_VTABLE_FLAG_SIMPLE_RW
)
489 && SCM_I_INUMP (pos
)))
492 scm_t_bits index
, len
;
494 index
= SCM_I_INUM (pos
);
495 vtable
= SCM_STRUCT_VTABLE (obj
);
496 len
= SCM_STRUCT_DATA_REF (vtable
, scm_vtable_index_size
);
497 if (SCM_LIKELY (index
< len
))
499 scm_t_bits
*data
= SCM_STRUCT_DATA (obj
);
500 data
[index
] = SCM_UNPACK (val
);
506 RETURN (scm_struct_set_x (obj
, pos
, val
));
513 VM_DEFINE_FUNCTION (169, class_of
, "class-of", 1)
516 if (SCM_INSTANCEP (obj
))
517 RETURN (SCM_CLASS_OF (obj
));
519 RETURN (scm_class_of (obj
));
522 VM_DEFINE_FUNCTION (170, slot_ref
, "slot-ref", 2)
525 ARGS2 (instance
, idx
);
526 slot
= SCM_I_INUM (idx
);
527 RETURN (SCM_PACK (SCM_STRUCT_DATA (instance
) [slot
]));
530 VM_DEFINE_INSTRUCTION (171, slot_set
, "slot-set", 0, 3, 0)
532 SCM instance
, idx
, val
;
537 slot
= SCM_I_INUM (idx
);
538 SCM_STRUCT_DATA (instance
) [slot
] = SCM_UNPACK (val
);
546 #define VM_VALIDATE_BYTEVECTOR(x) \
547 if (SCM_UNLIKELY (!SCM_BYTEVECTOR_P (x))) \
549 goto vm_error_not_a_bytevector; \
552 #define BV_REF_WITH_ENDIANNESS(stem, fn_stem) \
556 if (scm_is_eq (endianness, scm_i_native_endianness)) \
557 goto VM_LABEL (bv_##stem##_native_ref); \
561 RETURN (scm_bytevector_##fn_stem##_ref (bv, idx, endianness)); \
565 /* Return true (non-zero) if PTR has suitable alignment for TYPE. */
566 #define ALIGNED_P(ptr, type) \
567 ((scm_t_uintptr) (ptr) % alignof (type) == 0)
569 VM_DEFINE_FUNCTION (172, bv_u16_ref
, "bv-u16-ref", 3)
570 BV_REF_WITH_ENDIANNESS (u16
, u16
)
571 VM_DEFINE_FUNCTION (173, bv_s16_ref
, "bv-s16-ref", 3)
572 BV_REF_WITH_ENDIANNESS (s16
, s16
)
573 VM_DEFINE_FUNCTION (174, bv_u32_ref
, "bv-u32-ref", 3)
574 BV_REF_WITH_ENDIANNESS (u32
, u32
)
575 VM_DEFINE_FUNCTION (175, bv_s32_ref
, "bv-s32-ref", 3)
576 BV_REF_WITH_ENDIANNESS (s32
, s32
)
577 VM_DEFINE_FUNCTION (176, bv_u64_ref
, "bv-u64-ref", 3)
578 BV_REF_WITH_ENDIANNESS (u64
, u64
)
579 VM_DEFINE_FUNCTION (177, bv_s64_ref
, "bv-s64-ref", 3)
580 BV_REF_WITH_ENDIANNESS (s64
, s64
)
581 VM_DEFINE_FUNCTION (178, bv_f32_ref
, "bv-f32-ref", 3)
582 BV_REF_WITH_ENDIANNESS (f32
, ieee_single
)
583 VM_DEFINE_FUNCTION (179, bv_f64_ref
, "bv-f64-ref", 3)
584 BV_REF_WITH_ENDIANNESS (f64
, ieee_double
)
586 #undef BV_REF_WITH_ENDIANNESS
588 #define BV_FIXABLE_INT_REF(stem, fn_stem, type, size) \
591 const scm_t_ ## type *int_ptr; \
594 VM_VALIDATE_BYTEVECTOR (bv); \
595 i = SCM_I_INUM (idx); \
596 int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
598 if (SCM_LIKELY (SCM_I_INUMP (idx) \
600 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
601 && (ALIGNED_P (int_ptr, scm_t_ ## type)))) \
602 RETURN (SCM_I_MAKINUM (*int_ptr)); \
606 RETURN (scm_bytevector_ ## fn_stem ## _ref (bv, idx)); \
610 #define BV_INT_REF(stem, type, size) \
613 const scm_t_ ## type *int_ptr; \
616 VM_VALIDATE_BYTEVECTOR (bv); \
617 i = SCM_I_INUM (idx); \
618 int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
620 if (SCM_LIKELY (SCM_I_INUMP (idx) \
622 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
623 && (ALIGNED_P (int_ptr, scm_t_ ## type)))) \
625 scm_t_ ## type x = *int_ptr; \
626 if (SCM_FIXABLE (x)) \
627 RETURN (SCM_I_MAKINUM (x)); \
631 RETURN (scm_from_ ## type (x)); \
637 RETURN (scm_bytevector_ ## stem ## _native_ref (bv, idx)); \
641 #define BV_FLOAT_REF(stem, fn_stem, type, size) \
644 const type *float_ptr; \
647 VM_VALIDATE_BYTEVECTOR (bv); \
648 i = SCM_I_INUM (idx); \
649 float_ptr = (type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
652 if (SCM_LIKELY (SCM_I_INUMP (idx) \
654 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
655 && (ALIGNED_P (float_ptr, type)))) \
656 RETURN (scm_from_double (*float_ptr)); \
658 RETURN (scm_bytevector_ ## fn_stem ## _native_ref (bv, idx)); \
661 VM_DEFINE_FUNCTION (180, bv_u8_ref
, "bv-u8-ref", 2)
662 BV_FIXABLE_INT_REF (u8
, u8
, uint8
, 1)
663 VM_DEFINE_FUNCTION (181, bv_s8_ref
, "bv-s8-ref", 2)
664 BV_FIXABLE_INT_REF (s8
, s8
, int8
, 1)
665 VM_DEFINE_FUNCTION (182, bv_u16_native_ref
, "bv-u16-native-ref", 2)
666 BV_FIXABLE_INT_REF (u16
, u16_native
, uint16
, 2)
667 VM_DEFINE_FUNCTION (183, bv_s16_native_ref
, "bv-s16-native-ref", 2)
668 BV_FIXABLE_INT_REF (s16
, s16_native
, int16
, 2)
669 VM_DEFINE_FUNCTION (184, bv_u32_native_ref
, "bv-u32-native-ref", 2)
670 #if SIZEOF_VOID_P > 4
671 BV_FIXABLE_INT_REF (u32
, u32_native
, uint32
, 4)
673 BV_INT_REF (u32
, uint32
, 4)
675 VM_DEFINE_FUNCTION (185, bv_s32_native_ref
, "bv-s32-native-ref", 2)
676 #if SIZEOF_VOID_P > 4
677 BV_FIXABLE_INT_REF (s32
, s32_native
, int32
, 4)
679 BV_INT_REF (s32
, int32
, 4)
681 VM_DEFINE_FUNCTION (186, bv_u64_native_ref
, "bv-u64-native-ref", 2)
682 BV_INT_REF (u64
, uint64
, 8)
683 VM_DEFINE_FUNCTION (187, bv_s64_native_ref
, "bv-s64-native-ref", 2)
684 BV_INT_REF (s64
, int64
, 8)
685 VM_DEFINE_FUNCTION (188, bv_f32_native_ref
, "bv-f32-native-ref", 2)
686 BV_FLOAT_REF (f32
, ieee_single
, float, 4)
687 VM_DEFINE_FUNCTION (189, bv_f64_native_ref
, "bv-f64-native-ref", 2)
688 BV_FLOAT_REF (f64
, ieee_double
, double, 8)
690 #undef BV_FIXABLE_INT_REF
696 #define BV_SET_WITH_ENDIANNESS(stem, fn_stem) \
700 if (scm_is_eq (endianness, scm_i_native_endianness)) \
701 goto VM_LABEL (bv_##stem##_native_set); \
703 SCM bv, idx, val; POP (val); POP (idx); POP (bv); \
704 scm_bytevector_##fn_stem##_set_x (bv, idx, val, endianness); \
709 VM_DEFINE_INSTRUCTION (190, bv_u16_set
, "bv-u16-set", 0, 4, 0)
710 BV_SET_WITH_ENDIANNESS (u16
, u16
)
711 VM_DEFINE_INSTRUCTION (191, bv_s16_set
, "bv-s16-set", 0, 4, 0)
712 BV_SET_WITH_ENDIANNESS (s16
, s16
)
713 VM_DEFINE_INSTRUCTION (192, bv_u32_set
, "bv-u32-set", 0, 4, 0)
714 BV_SET_WITH_ENDIANNESS (u32
, u32
)
715 VM_DEFINE_INSTRUCTION (193, bv_s32_set
, "bv-s32-set", 0, 4, 0)
716 BV_SET_WITH_ENDIANNESS (s32
, s32
)
717 VM_DEFINE_INSTRUCTION (194, bv_u64_set
, "bv-u64-set", 0, 4, 0)
718 BV_SET_WITH_ENDIANNESS (u64
, u64
)
719 VM_DEFINE_INSTRUCTION (195, bv_s64_set
, "bv-s64-set", 0, 4, 0)
720 BV_SET_WITH_ENDIANNESS (s64
, s64
)
721 VM_DEFINE_INSTRUCTION (196, bv_f32_set
, "bv-f32-set", 0, 4, 0)
722 BV_SET_WITH_ENDIANNESS (f32
, ieee_single
)
723 VM_DEFINE_INSTRUCTION (197, bv_f64_set
, "bv-f64-set", 0, 4, 0)
724 BV_SET_WITH_ENDIANNESS (f64
, ieee_double
)
726 #undef BV_SET_WITH_ENDIANNESS
728 #define BV_FIXABLE_INT_SET(stem, fn_stem, type, min, max, size) \
732 scm_t_ ## type *int_ptr; \
734 POP (val); POP (idx); POP (bv); \
735 VM_VALIDATE_BYTEVECTOR (bv); \
736 i = SCM_I_INUM (idx); \
737 int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
739 if (SCM_LIKELY (SCM_I_INUMP (idx) \
741 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
742 && (ALIGNED_P (int_ptr, scm_t_ ## type)) \
743 && (SCM_I_INUMP (val)) \
744 && ((j = SCM_I_INUM (val)) >= min) \
746 *int_ptr = (scm_t_ ## type) j; \
748 scm_bytevector_ ## fn_stem ## _set_x (bv, idx, val); \
752 #define BV_INT_SET(stem, type, size) \
756 scm_t_ ## type *int_ptr; \
758 POP (val); POP (idx); POP (bv); \
759 VM_VALIDATE_BYTEVECTOR (bv); \
760 i = SCM_I_INUM (idx); \
761 int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
763 if (SCM_LIKELY (SCM_I_INUMP (idx) \
765 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
766 && (ALIGNED_P (int_ptr, scm_t_ ## type)))) \
767 *int_ptr = scm_to_ ## type (val); \
769 scm_bytevector_ ## stem ## _native_set_x (bv, idx, val); \
773 #define BV_FLOAT_SET(stem, fn_stem, type, size) \
779 POP (val); POP (idx); POP (bv); \
780 VM_VALIDATE_BYTEVECTOR (bv); \
781 i = SCM_I_INUM (idx); \
782 float_ptr = (type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
784 if (SCM_LIKELY (SCM_I_INUMP (idx) \
786 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
787 && (ALIGNED_P (float_ptr, type)))) \
788 *float_ptr = scm_to_double (val); \
790 scm_bytevector_ ## fn_stem ## _native_set_x (bv, idx, val); \
794 VM_DEFINE_INSTRUCTION (198, bv_u8_set
, "bv-u8-set", 0, 3, 0)
795 BV_FIXABLE_INT_SET (u8
, u8
, uint8
, 0, SCM_T_UINT8_MAX
, 1)
796 VM_DEFINE_INSTRUCTION (199, bv_s8_set
, "bv-s8-set", 0, 3, 0)
797 BV_FIXABLE_INT_SET (s8
, s8
, int8
, SCM_T_INT8_MIN
, SCM_T_INT8_MAX
, 1)
798 VM_DEFINE_INSTRUCTION (200, bv_u16_native_set
, "bv-u16-native-set", 0, 3, 0)
799 BV_FIXABLE_INT_SET (u16
, u16_native
, uint16
, 0, SCM_T_UINT16_MAX
, 2)
800 VM_DEFINE_INSTRUCTION (201, bv_s16_native_set
, "bv-s16-native-set", 0, 3, 0)
801 BV_FIXABLE_INT_SET (s16
, s16_native
, int16
, SCM_T_INT16_MIN
, SCM_T_INT16_MAX
, 2)
802 VM_DEFINE_INSTRUCTION (202, bv_u32_native_set
, "bv-u32-native-set", 0, 3, 0)
803 #if SIZEOF_VOID_P > 4
804 BV_FIXABLE_INT_SET (u32
, u32_native
, uint32
, 0, SCM_T_UINT32_MAX
, 4)
806 BV_INT_SET (u32
, uint32
, 4)
808 VM_DEFINE_INSTRUCTION (203, bv_s32_native_set
, "bv-s32-native-set", 0, 3, 0)
809 #if SIZEOF_VOID_P > 4
810 BV_FIXABLE_INT_SET (s32
, s32_native
, int32
, SCM_T_INT32_MIN
, SCM_T_INT32_MAX
, 4)
812 BV_INT_SET (s32
, int32
, 4)
814 VM_DEFINE_INSTRUCTION (204, bv_u64_native_set
, "bv-u64-native-set", 0, 3, 0)
815 BV_INT_SET (u64
, uint64
, 8)
816 VM_DEFINE_INSTRUCTION (205, bv_s64_native_set
, "bv-s64-native-set", 0, 3, 0)
817 BV_INT_SET (s64
, int64
, 8)
818 VM_DEFINE_INSTRUCTION (206, bv_f32_native_set
, "bv-f32-native-set", 0, 3, 0)
819 BV_FLOAT_SET (f32
, ieee_single
, float, 4)
820 VM_DEFINE_INSTRUCTION (207, bv_f64_native_set
, "bv-f64-native-set", 0, 3, 0)
821 BV_FLOAT_SET (f64
, ieee_double
, double, 8)
823 #undef BV_FIXABLE_INT_SET
828 (defun renumber-ops ()
829 "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
832 (let ((counter 127)) (goto-char (point-min))
833 (while (re-search-forward "^VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t)
835 (number-to-string (setq counter (1+ counter)))