1 /* Copyright (C) 2001, 2009, 2010, 2011 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));
102 VM_DEFINE_FUNCTION (138, symbolp
, "symbol?", 1)
105 RETURN (scm_from_bool (scm_is_symbol (x
)));
108 VM_DEFINE_FUNCTION (139, vectorp
, "vector?", 1)
111 RETURN (scm_from_bool (SCM_I_IS_VECTOR (x
)));
119 VM_DEFINE_FUNCTION (140, cons
, "cons", 2)
126 #define VM_VALIDATE_CONS(x, proc) \
127 if (SCM_UNLIKELY (!scm_is_pair (x))) \
128 { func_name = proc; \
130 goto vm_error_not_a_pair; \
133 VM_DEFINE_FUNCTION (141, car
, "car", 1)
136 VM_VALIDATE_CONS (x
, "car");
137 RETURN (SCM_CAR (x
));
140 VM_DEFINE_FUNCTION (142, cdr
, "cdr", 1)
143 VM_VALIDATE_CONS (x
, "cdr");
144 RETURN (SCM_CDR (x
));
147 VM_DEFINE_INSTRUCTION (143, set_car
, "set-car!", 0, 2, 0)
151 VM_VALIDATE_CONS (x
, "set-car!");
156 VM_DEFINE_INSTRUCTION (144, set_cdr
, "set-cdr!", 0, 2, 0)
160 VM_VALIDATE_CONS (x
, "set-cdr!");
167 * Numeric relational tests
171 #define REL(crel,srel) \
174 if (SCM_I_INUMP (x) && SCM_I_INUMP (y)) \
175 RETURN (scm_from_bool (((scm_t_signed_bits) SCM_UNPACK (x)) \
176 crel ((scm_t_signed_bits) SCM_UNPACK (y)))); \
178 RETURN (srel (x, y)); \
181 VM_DEFINE_FUNCTION (145, ee
, "ee?", 2)
183 REL (==, scm_num_eq_p
);
186 VM_DEFINE_FUNCTION (146, lt
, "lt?", 2)
191 VM_DEFINE_FUNCTION (147, le
, "le?", 2)
196 VM_DEFINE_FUNCTION (148, gt
, "gt?", 2)
201 VM_DEFINE_FUNCTION (149, ge
, "ge?", 2)
211 /* The maximum/minimum tagged integers. */
214 #define INUM_MAX (INTPTR_MAX - 1)
215 #define INUM_MIN (INTPTR_MIN + scm_tc2_int)
218 #define FUNC2(CFUNC,SFUNC) \
221 if (SCM_I_INUMP (x) && SCM_I_INUMP (y)) \
223 scm_t_int64 n = SCM_I_INUM (x) CFUNC SCM_I_INUM (y);\
224 if (SCM_FIXABLE (n)) \
225 RETURN (SCM_I_MAKINUM (n)); \
228 RETURN (SFUNC (x, y)); \
231 /* Assembly tagged integer arithmetic routines. This code uses the
232 `asm goto' feature introduced in GCC 4.5. */
234 #if defined __x86_64__ && SCM_GNUC_PREREQ (4, 5)
236 /* The macros below check the CPU's overflow flag to improve fixnum
237 arithmetic. The %rcx register is explicitly clobbered because `asm
238 goto' can't have outputs, in which case the `r' constraint could be
239 used to let the register allocator choose a register.
241 TODO: Use `cold' label attribute in GCC 4.6.
242 http://gcc.gnu.org/ml/gcc-patches/2010-10/msg01777.html */
244 # define ASM_ADD(x, y) \
246 asm volatile goto ("mov %1, %%rcx; " \
247 "test %[tag], %%cl; je %l[slow_add]; " \
248 "test %[tag], %0; je %l[slow_add]; " \
249 "add %0, %%rcx; jo %l[slow_add]; " \
250 "sub %[tag], %%rcx; " \
251 "mov %%rcx, (%[vsp])\n" \
253 : "r" (x), "r" (y), \
254 [vsp] "r" (sp), [tag] "i" (scm_tc2_int) \
262 # define ASM_SUB(x, y) \
264 asm volatile goto ("mov %0, %%rcx; " \
265 "test %[tag], %%cl; je %l[slow_sub]; " \
266 "test %[tag], %1; je %l[slow_sub]; " \
267 "sub %1, %%rcx; jo %l[slow_sub]; " \
268 "add %[tag], %%rcx; " \
269 "mov %%rcx, (%[vsp])\n" \
271 : "r" (x), "r" (y), \
272 [vsp] "r" (sp), [tag] "i" (scm_tc2_int) \
283 VM_DEFINE_FUNCTION (150, add
, "add", 2)
291 RETURN (scm_sum (x
, y
));
295 VM_DEFINE_FUNCTION (151, add1
, "add1", 1)
299 /* Check for overflow. */
300 if (SCM_LIKELY ((scm_t_intptr
) SCM_UNPACK (x
) < INUM_MAX
))
304 /* Add the integers without untagging. */
305 result
= SCM_PACK ((scm_t_intptr
) SCM_UNPACK (x
)
306 + (scm_t_intptr
) SCM_UNPACK (SCM_I_MAKINUM (1))
309 if (SCM_LIKELY (SCM_I_INUMP (result
)))
314 RETURN (scm_sum (x
, SCM_I_MAKINUM (1)));
317 VM_DEFINE_FUNCTION (152, sub
, "sub", 2)
320 FUNC2 (-, scm_difference
);
325 RETURN (scm_difference (x
, y
));
329 VM_DEFINE_FUNCTION (153, sub1
, "sub1", 1)
333 /* Check for underflow. */
334 if (SCM_LIKELY ((scm_t_intptr
) SCM_UNPACK (x
) > INUM_MIN
))
338 /* Substract the integers without untagging. */
339 result
= SCM_PACK ((scm_t_intptr
) SCM_UNPACK (x
)
340 - (scm_t_intptr
) SCM_UNPACK (SCM_I_MAKINUM (1))
343 if (SCM_LIKELY (SCM_I_INUMP (result
)))
348 RETURN (scm_difference (x
, SCM_I_MAKINUM (1)));
354 VM_DEFINE_FUNCTION (154, mul
, "mul", 2)
358 RETURN (scm_product (x
, y
));
361 VM_DEFINE_FUNCTION (155, div
, "div", 2)
365 RETURN (scm_divide (x
, y
));
368 VM_DEFINE_FUNCTION (156, quo
, "quo", 2)
372 RETURN (scm_quotient (x
, y
));
375 VM_DEFINE_FUNCTION (157, rem
, "rem", 2)
379 RETURN (scm_remainder (x
, y
));
382 VM_DEFINE_FUNCTION (158, mod
, "mod", 2)
386 RETURN (scm_modulo (x
, y
));
389 VM_DEFINE_FUNCTION (159, ash
, "ash", 2)
392 if (SCM_I_INUMP (x
) && SCM_I_INUMP (y
))
394 if (SCM_I_INUM (y
) < 0)
395 /* Right shift, will be a fixnum. */
396 RETURN (SCM_I_MAKINUM (SCM_I_INUM (x
) >> -SCM_I_INUM (y
)));
398 /* Left shift. See comments in scm_ash. */
400 scm_t_signed_bits nn
, bits_to_shift
;
403 bits_to_shift
= SCM_I_INUM (y
);
405 if (bits_to_shift
< SCM_I_FIXNUM_BIT
-1
407 (SCM_SRS (nn
, (SCM_I_FIXNUM_BIT
-1 - bits_to_shift
)) + 1)
409 RETURN (SCM_I_MAKINUM (nn
<< bits_to_shift
));
415 RETURN (scm_ash (x
, y
));
418 VM_DEFINE_FUNCTION (160, logand
, "logand", 2)
421 if (SCM_I_INUMP (x
) && SCM_I_INUMP (y
))
422 RETURN (SCM_I_MAKINUM (SCM_I_INUM (x
) & SCM_I_INUM (y
)));
424 RETURN (scm_logand (x
, y
));
427 VM_DEFINE_FUNCTION (161, logior
, "logior", 2)
430 if (SCM_I_INUMP (x
) && SCM_I_INUMP (y
))
431 RETURN (SCM_I_MAKINUM (SCM_I_INUM (x
) | SCM_I_INUM (y
)));
433 RETURN (scm_logior (x
, y
));
436 VM_DEFINE_FUNCTION (162, logxor
, "logxor", 2)
439 if (SCM_I_INUMP (x
) && SCM_I_INUMP (y
))
440 RETURN (SCM_I_MAKINUM (SCM_I_INUM (x
) ^ SCM_I_INUM (y
)));
442 RETURN (scm_logxor (x
, y
));
450 VM_DEFINE_FUNCTION (163, string_length
, "string-length", 1)
453 if (SCM_LIKELY (scm_is_string (str
)))
454 RETURN (SCM_I_MAKINUM (scm_i_string_length (str
)));
458 RETURN (scm_string_length (str
));
462 VM_DEFINE_FUNCTION (164, string_ref
, "string-ref", 2)
464 scm_t_signed_bits i
= 0;
466 if (SCM_LIKELY (scm_is_string (str
)
468 && ((i
= SCM_I_INUM (idx
)) >= 0)
469 && i
< scm_i_string_length (str
)))
470 RETURN (SCM_MAKE_CHAR (scm_i_string_ref (str
, i
)));
474 RETURN (scm_string_ref (str
, idx
));
478 /* No string-set! instruction, as there is no good fast path there. */
485 VM_DEFINE_FUNCTION (165, vector_length
, "vector-length", 1)
488 if (SCM_LIKELY (SCM_I_IS_VECTOR (vect
)))
489 RETURN (SCM_I_MAKINUM (SCM_I_VECTOR_LENGTH (vect
)));
493 RETURN (scm_vector_length (vect
));
497 VM_DEFINE_FUNCTION (166, vector_ref
, "vector-ref", 2)
499 scm_t_signed_bits i
= 0;
501 if (SCM_LIKELY (SCM_I_IS_NONWEAK_VECTOR (vect
)
503 && ((i
= SCM_I_INUM (idx
)) >= 0)
504 && i
< SCM_I_VECTOR_LENGTH (vect
)))
505 RETURN (SCM_I_VECTOR_ELTS (vect
)[i
]);
509 RETURN (scm_vector_ref (vect
, idx
));
513 VM_DEFINE_INSTRUCTION (167, vector_set
, "vector-set", 0, 3, 0)
515 scm_t_signed_bits i
= 0;
517 POP3 (val
, idx
, vect
);
518 if (SCM_LIKELY (SCM_I_IS_NONWEAK_VECTOR (vect
)
520 && ((i
= SCM_I_INUM (idx
)) >= 0)
521 && i
< SCM_I_VECTOR_LENGTH (vect
)))
522 SCM_I_VECTOR_WELTS (vect
)[i
] = val
;
526 scm_vector_set_x (vect
, idx
, val
);
531 VM_DEFINE_INSTRUCTION (168, make_array
, "make-array", 3, -1, 1)
537 len
= (len
<< 8) + FETCH ();
538 len
= (len
<< 8) + FETCH ();
541 PRE_CHECK_UNDERFLOW (len
);
542 ret
= scm_from_contiguous_array (shape
, sp
- len
+ 1, len
);
552 #define VM_VALIDATE_STRUCT(obj, proc) \
553 if (SCM_UNLIKELY (!SCM_STRUCTP (obj))) \
556 finish_args = (obj); \
557 goto vm_error_not_a_struct; \
560 VM_DEFINE_FUNCTION (169, struct_p
, "struct?", 1)
563 RETURN (scm_from_bool (SCM_STRUCTP (obj
)));
566 VM_DEFINE_FUNCTION (170, struct_vtable
, "struct-vtable", 1)
569 VM_VALIDATE_STRUCT (obj
, "struct_vtable");
570 RETURN (SCM_STRUCT_VTABLE (obj
));
573 VM_DEFINE_INSTRUCTION (171, make_struct
, "make-struct", 2, -1, 1)
575 unsigned h
= FETCH ();
576 unsigned l
= FETCH ();
577 scm_t_bits n
= ((h
<< 8U) + l
);
578 SCM vtable
= sp
[-(n
- 1)];
579 const SCM
*inits
= sp
- n
+ 2;
584 if (SCM_LIKELY (SCM_STRUCTP (vtable
)
585 && SCM_VTABLE_FLAG_IS_SET (vtable
, SCM_VTABLE_FLAG_SIMPLE
)
586 && (SCM_STRUCT_DATA_REF (vtable
, scm_vtable_index_size
) + 1
588 && !SCM_VTABLE_INSTANCE_FINALIZER (vtable
)))
590 /* Verily, we are making a simple struct with the right number of
591 initializers, and no finalizer. */
592 ret
= scm_words ((scm_t_bits
)SCM_STRUCT_DATA (vtable
) | scm_tc3_struct
,
594 SCM_SET_CELL_WORD_1 (ret
, (scm_t_bits
)SCM_CELL_OBJECT_LOC (ret
, 2));
595 memcpy (SCM_STRUCT_DATA (ret
), inits
, (n
- 1) * sizeof (SCM
));
598 ret
= scm_c_make_structv (vtable
, 0, n
- 1, (scm_t_bits
*) inits
);
606 VM_DEFINE_FUNCTION (172, struct_ref
, "struct-ref", 2)
610 if (SCM_LIKELY (SCM_STRUCTP (obj
)
611 && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj
,
612 SCM_VTABLE_FLAG_SIMPLE
)
613 && SCM_I_INUMP (pos
)))
616 scm_t_bits index
, len
;
618 /* True, an inum is a signed value, but cast to unsigned it will
619 certainly be more than the length, so we will fall through if
620 index is negative. */
621 index
= SCM_I_INUM (pos
);
622 vtable
= SCM_STRUCT_VTABLE (obj
);
623 len
= SCM_STRUCT_DATA_REF (vtable
, scm_vtable_index_size
);
625 if (SCM_LIKELY (index
< len
))
627 scm_t_bits
*data
= SCM_STRUCT_DATA (obj
);
628 RETURN (SCM_PACK (data
[index
]));
633 RETURN (scm_struct_ref (obj
, pos
));
636 VM_DEFINE_FUNCTION (173, struct_set
, "struct-set", 3)
638 ARGS3 (obj
, pos
, val
);
640 if (SCM_LIKELY (SCM_STRUCTP (obj
)
641 && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj
,
642 SCM_VTABLE_FLAG_SIMPLE
)
643 && SCM_STRUCT_VTABLE_FLAG_IS_SET (obj
,
644 SCM_VTABLE_FLAG_SIMPLE_RW
)
645 && SCM_I_INUMP (pos
)))
648 scm_t_bits index
, len
;
650 /* See above regarding index being >= 0. */
651 index
= SCM_I_INUM (pos
);
652 vtable
= SCM_STRUCT_VTABLE (obj
);
653 len
= SCM_STRUCT_DATA_REF (vtable
, scm_vtable_index_size
);
654 if (SCM_LIKELY (index
< len
))
656 scm_t_bits
*data
= SCM_STRUCT_DATA (obj
);
657 data
[index
] = SCM_UNPACK (val
);
663 RETURN (scm_struct_set_x (obj
, pos
, val
));
670 VM_DEFINE_FUNCTION (174, class_of
, "class-of", 1)
673 if (SCM_INSTANCEP (obj
))
674 RETURN (SCM_CLASS_OF (obj
));
676 RETURN (scm_class_of (obj
));
679 /* FIXME: No checking whatsoever. */
680 VM_DEFINE_FUNCTION (175, slot_ref
, "slot-ref", 2)
683 ARGS2 (instance
, idx
);
684 slot
= SCM_I_INUM (idx
);
685 RETURN (SCM_PACK (SCM_STRUCT_DATA (instance
) [slot
]));
688 /* FIXME: No checking whatsoever. */
689 VM_DEFINE_INSTRUCTION (176, slot_set
, "slot-set", 0, 3, 0)
691 SCM instance
, idx
, val
;
693 POP3 (val
, idx
, instance
);
694 slot
= SCM_I_INUM (idx
);
695 SCM_STRUCT_DATA (instance
) [slot
] = SCM_UNPACK (val
);
703 #define VM_VALIDATE_BYTEVECTOR(x, proc) \
706 if (SCM_UNLIKELY (!SCM_BYTEVECTOR_P (x))) \
710 goto vm_error_not_a_bytevector; \
715 #define BV_REF_WITH_ENDIANNESS(stem, fn_stem) \
719 if (scm_is_eq (endianness, scm_i_native_endianness)) \
720 goto VM_LABEL (bv_##stem##_native_ref); \
724 RETURN (scm_bytevector_##fn_stem##_ref (bv, idx, endianness)); \
728 /* Return true (non-zero) if PTR has suitable alignment for TYPE. */
729 #define ALIGNED_P(ptr, type) \
730 ((scm_t_uintptr) (ptr) % alignof (type) == 0)
732 VM_DEFINE_FUNCTION (177, bv_u16_ref
, "bv-u16-ref", 3)
733 BV_REF_WITH_ENDIANNESS (u16
, u16
)
734 VM_DEFINE_FUNCTION (178, bv_s16_ref
, "bv-s16-ref", 3)
735 BV_REF_WITH_ENDIANNESS (s16
, s16
)
736 VM_DEFINE_FUNCTION (179, bv_u32_ref
, "bv-u32-ref", 3)
737 BV_REF_WITH_ENDIANNESS (u32
, u32
)
738 VM_DEFINE_FUNCTION (180, bv_s32_ref
, "bv-s32-ref", 3)
739 BV_REF_WITH_ENDIANNESS (s32
, s32
)
740 VM_DEFINE_FUNCTION (181, bv_u64_ref
, "bv-u64-ref", 3)
741 BV_REF_WITH_ENDIANNESS (u64
, u64
)
742 VM_DEFINE_FUNCTION (182, bv_s64_ref
, "bv-s64-ref", 3)
743 BV_REF_WITH_ENDIANNESS (s64
, s64
)
744 VM_DEFINE_FUNCTION (183, bv_f32_ref
, "bv-f32-ref", 3)
745 BV_REF_WITH_ENDIANNESS (f32
, ieee_single
)
746 VM_DEFINE_FUNCTION (184, bv_f64_ref
, "bv-f64-ref", 3)
747 BV_REF_WITH_ENDIANNESS (f64
, ieee_double
)
749 #undef BV_REF_WITH_ENDIANNESS
751 #define BV_FIXABLE_INT_REF(stem, fn_stem, type, size) \
753 scm_t_signed_bits i; \
754 const scm_t_ ## type *int_ptr; \
757 VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-ref"); \
758 i = SCM_I_INUM (idx); \
759 int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
761 if (SCM_LIKELY (SCM_I_INUMP (idx) \
763 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
764 && (ALIGNED_P (int_ptr, scm_t_ ## type)))) \
765 RETURN (SCM_I_MAKINUM (*int_ptr)); \
769 RETURN (scm_bytevector_ ## fn_stem ## _ref (bv, idx)); \
773 #define BV_INT_REF(stem, type, size) \
775 scm_t_signed_bits i; \
776 const scm_t_ ## type *int_ptr; \
779 VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-ref"); \
780 i = SCM_I_INUM (idx); \
781 int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
783 if (SCM_LIKELY (SCM_I_INUMP (idx) \
785 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
786 && (ALIGNED_P (int_ptr, scm_t_ ## type)))) \
788 scm_t_ ## type x = *int_ptr; \
789 if (SCM_FIXABLE (x)) \
790 RETURN (SCM_I_MAKINUM (x)); \
794 RETURN (scm_from_ ## type (x)); \
800 RETURN (scm_bytevector_ ## stem ## _native_ref (bv, idx)); \
804 #define BV_FLOAT_REF(stem, fn_stem, type, size) \
806 scm_t_signed_bits i; \
807 const type *float_ptr; \
810 VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-ref"); \
811 i = SCM_I_INUM (idx); \
812 float_ptr = (type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
815 if (SCM_LIKELY (SCM_I_INUMP (idx) \
817 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
818 && (ALIGNED_P (float_ptr, type)))) \
819 RETURN (scm_from_double (*float_ptr)); \
821 RETURN (scm_bytevector_ ## fn_stem ## _native_ref (bv, idx)); \
824 VM_DEFINE_FUNCTION (185, bv_u8_ref
, "bv-u8-ref", 2)
825 BV_FIXABLE_INT_REF (u8
, u8
, uint8
, 1)
826 VM_DEFINE_FUNCTION (186, bv_s8_ref
, "bv-s8-ref", 2)
827 BV_FIXABLE_INT_REF (s8
, s8
, int8
, 1)
828 VM_DEFINE_FUNCTION (187, bv_u16_native_ref
, "bv-u16-native-ref", 2)
829 BV_FIXABLE_INT_REF (u16
, u16_native
, uint16
, 2)
830 VM_DEFINE_FUNCTION (188, bv_s16_native_ref
, "bv-s16-native-ref", 2)
831 BV_FIXABLE_INT_REF (s16
, s16_native
, int16
, 2)
832 VM_DEFINE_FUNCTION (189, bv_u32_native_ref
, "bv-u32-native-ref", 2)
833 #if SIZEOF_VOID_P > 4
834 BV_FIXABLE_INT_REF (u32
, u32_native
, uint32
, 4)
836 BV_INT_REF (u32
, uint32
, 4)
838 VM_DEFINE_FUNCTION (190, bv_s32_native_ref
, "bv-s32-native-ref", 2)
839 #if SIZEOF_VOID_P > 4
840 BV_FIXABLE_INT_REF (s32
, s32_native
, int32
, 4)
842 BV_INT_REF (s32
, int32
, 4)
844 VM_DEFINE_FUNCTION (191, bv_u64_native_ref
, "bv-u64-native-ref", 2)
845 BV_INT_REF (u64
, uint64
, 8)
846 VM_DEFINE_FUNCTION (192, bv_s64_native_ref
, "bv-s64-native-ref", 2)
847 BV_INT_REF (s64
, int64
, 8)
848 VM_DEFINE_FUNCTION (193, bv_f32_native_ref
, "bv-f32-native-ref", 2)
849 BV_FLOAT_REF (f32
, ieee_single
, float, 4)
850 VM_DEFINE_FUNCTION (194, bv_f64_native_ref
, "bv-f64-native-ref", 2)
851 BV_FLOAT_REF (f64
, ieee_double
, double, 8)
853 #undef BV_FIXABLE_INT_REF
859 #define BV_SET_WITH_ENDIANNESS(stem, fn_stem) \
863 if (scm_is_eq (endianness, scm_i_native_endianness)) \
864 goto VM_LABEL (bv_##stem##_native_set); \
866 SCM bv, idx, val; POP3 (val, idx, bv); \
868 scm_bytevector_##fn_stem##_set_x (bv, idx, val, endianness); \
873 VM_DEFINE_INSTRUCTION (195, bv_u16_set
, "bv-u16-set", 0, 4, 0)
874 BV_SET_WITH_ENDIANNESS (u16
, u16
)
875 VM_DEFINE_INSTRUCTION (196, bv_s16_set
, "bv-s16-set", 0, 4, 0)
876 BV_SET_WITH_ENDIANNESS (s16
, s16
)
877 VM_DEFINE_INSTRUCTION (197, bv_u32_set
, "bv-u32-set", 0, 4, 0)
878 BV_SET_WITH_ENDIANNESS (u32
, u32
)
879 VM_DEFINE_INSTRUCTION (198, bv_s32_set
, "bv-s32-set", 0, 4, 0)
880 BV_SET_WITH_ENDIANNESS (s32
, s32
)
881 VM_DEFINE_INSTRUCTION (199, bv_u64_set
, "bv-u64-set", 0, 4, 0)
882 BV_SET_WITH_ENDIANNESS (u64
, u64
)
883 VM_DEFINE_INSTRUCTION (200, bv_s64_set
, "bv-s64-set", 0, 4, 0)
884 BV_SET_WITH_ENDIANNESS (s64
, s64
)
885 VM_DEFINE_INSTRUCTION (201, bv_f32_set
, "bv-f32-set", 0, 4, 0)
886 BV_SET_WITH_ENDIANNESS (f32
, ieee_single
)
887 VM_DEFINE_INSTRUCTION (202, bv_f64_set
, "bv-f64-set", 0, 4, 0)
888 BV_SET_WITH_ENDIANNESS (f64
, ieee_double
)
890 #undef BV_SET_WITH_ENDIANNESS
892 #define BV_FIXABLE_INT_SET(stem, fn_stem, type, min, max, size) \
894 scm_t_signed_bits i, j = 0; \
896 scm_t_ ## type *int_ptr; \
898 POP3 (val, idx, bv); \
899 VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-set"); \
900 i = SCM_I_INUM (idx); \
901 int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
903 if (SCM_LIKELY (SCM_I_INUMP (idx) \
905 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
906 && (ALIGNED_P (int_ptr, scm_t_ ## type)) \
907 && (SCM_I_INUMP (val)) \
908 && ((j = SCM_I_INUM (val)) >= min) \
910 *int_ptr = (scm_t_ ## type) j; \
914 scm_bytevector_ ## fn_stem ## _set_x (bv, idx, val); \
919 #define BV_INT_SET(stem, type, size) \
921 scm_t_signed_bits i = 0; \
923 scm_t_ ## type *int_ptr; \
925 POP3 (val, idx, bv); \
926 VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-set"); \
927 i = SCM_I_INUM (idx); \
928 int_ptr = (scm_t_ ## type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
930 if (SCM_LIKELY (SCM_I_INUMP (idx) \
932 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
933 && (ALIGNED_P (int_ptr, scm_t_ ## type)))) \
934 *int_ptr = scm_to_ ## type (val); \
938 scm_bytevector_ ## stem ## _native_set_x (bv, idx, val); \
943 #define BV_FLOAT_SET(stem, fn_stem, type, size) \
945 scm_t_signed_bits i = 0; \
949 POP3 (val, idx, bv); \
950 VM_VALIDATE_BYTEVECTOR (bv, "bv-" #stem "-set"); \
951 i = SCM_I_INUM (idx); \
952 float_ptr = (type *) (SCM_BYTEVECTOR_CONTENTS (bv) + i); \
954 if (SCM_LIKELY (SCM_I_INUMP (idx) \
956 && (i + size <= SCM_BYTEVECTOR_LENGTH (bv)) \
957 && (ALIGNED_P (float_ptr, type)))) \
958 *float_ptr = scm_to_double (val); \
962 scm_bytevector_ ## fn_stem ## _native_set_x (bv, idx, val); \
967 VM_DEFINE_INSTRUCTION (203, bv_u8_set
, "bv-u8-set", 0, 3, 0)
968 BV_FIXABLE_INT_SET (u8
, u8
, uint8
, 0, SCM_T_UINT8_MAX
, 1)
969 VM_DEFINE_INSTRUCTION (204, bv_s8_set
, "bv-s8-set", 0, 3, 0)
970 BV_FIXABLE_INT_SET (s8
, s8
, int8
, SCM_T_INT8_MIN
, SCM_T_INT8_MAX
, 1)
971 VM_DEFINE_INSTRUCTION (205, bv_u16_native_set
, "bv-u16-native-set", 0, 3, 0)
972 BV_FIXABLE_INT_SET (u16
, u16_native
, uint16
, 0, SCM_T_UINT16_MAX
, 2)
973 VM_DEFINE_INSTRUCTION (206, bv_s16_native_set
, "bv-s16-native-set", 0, 3, 0)
974 BV_FIXABLE_INT_SET (s16
, s16_native
, int16
, SCM_T_INT16_MIN
, SCM_T_INT16_MAX
, 2)
975 VM_DEFINE_INSTRUCTION (207, bv_u32_native_set
, "bv-u32-native-set", 0, 3, 0)
976 #if SIZEOF_VOID_P > 4
977 BV_FIXABLE_INT_SET (u32
, u32_native
, uint32
, 0, SCM_T_UINT32_MAX
, 4)
979 BV_INT_SET (u32
, uint32
, 4)
981 VM_DEFINE_INSTRUCTION (208, bv_s32_native_set
, "bv-s32-native-set", 0, 3, 0)
982 #if SIZEOF_VOID_P > 4
983 BV_FIXABLE_INT_SET (s32
, s32_native
, int32
, SCM_T_INT32_MIN
, SCM_T_INT32_MAX
, 4)
985 BV_INT_SET (s32
, int32
, 4)
987 VM_DEFINE_INSTRUCTION (209, bv_u64_native_set
, "bv-u64-native-set", 0, 3, 0)
988 BV_INT_SET (u64
, uint64
, 8)
989 VM_DEFINE_INSTRUCTION (210, bv_s64_native_set
, "bv-s64-native-set", 0, 3, 0)
990 BV_INT_SET (s64
, int64
, 8)
991 VM_DEFINE_INSTRUCTION (211, bv_f32_native_set
, "bv-f32-native-set", 0, 3, 0)
992 BV_FLOAT_SET (f32
, ieee_single
, float, 4)
993 VM_DEFINE_INSTRUCTION (212, bv_f64_native_set
, "bv-f64-native-set", 0, 3, 0)
994 BV_FLOAT_SET (f64
, ieee_double
, double, 8)
996 #undef BV_FIXABLE_INT_SET
1001 (defun renumber-ops ()
1002 "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
1005 (let ((counter 127)) (goto-char (point-min))
1006 (while (re-search-forward "^VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t)
1008 (number-to-string (setq counter (1+ counter)))