diff --git a/benchmark/mjit_integer.yml b/benchmark/mjit_integer.yml index edc3556479..a6b5c9ee16 100644 --- a/benchmark/mjit_integer.yml +++ b/benchmark/mjit_integer.yml @@ -8,6 +8,7 @@ prelude: | def mjit_magnitude(int) int.magnitude end def mjit_odd?(int) int.odd? end def mjit_ord(int) int.ord end + def mjit_size(int) int.size end def mjit_to_i(int) int.to_i end def mjit_to_int(int) int.to_int end def mjit_uminus(int) -int end @@ -22,6 +23,7 @@ benchmark: - mjit_magnitude(-1) - mjit_odd?(1) - mjit_ord(1) + - mjit_size(1) - mjit_to_i(1) - mjit_to_int(1) - mjit_uminus(1) diff --git a/mjit_compile.c b/mjit_compile.c index afa5e626fa..d68d440ca3 100644 --- a/mjit_compile.c +++ b/mjit_compile.c @@ -515,7 +515,7 @@ precompile_inlinable_iseqs(FILE *f, const rb_iseq_t *iseq, struct compile_status unsigned int pos = 0; while (pos < body->iseq_size) { int insn = rb_vm_insn_decode(body->iseq_encoded[pos]); - if (insn == BIN(opt_send_without_block)) { // `compile_inlined_cancel_handler` supports only `opt_send_without_block` + if (insn == BIN(opt_send_without_block) || insn == BIN(opt_size)) { // `compile_inlined_cancel_handler` supports only `opt_send_without_block` CALL_DATA cd = (CALL_DATA)body->iseq_encoded[pos + 1]; const struct rb_callinfo *ci = cd->ci; const struct rb_callcache *cc = captured_cc_entries(status)[call_data_index(cd, body)]; // use copy to avoid race condition diff --git a/mjit_worker.c b/mjit_worker.c index 2e87b1c97c..bfcf8c0f69 100644 --- a/mjit_worker.c +++ b/mjit_worker.c @@ -735,7 +735,7 @@ set_compiling_iseqs(const rb_iseq_t *iseq) unsigned int pos = 0; while (pos < iseq->body->iseq_size) { int insn = rb_vm_insn_decode(iseq->body->iseq_encoded[pos]); - if (insn == BIN(opt_send_without_block)) { + if (insn == BIN(opt_send_without_block) || insn == BIN(opt_size)) { CALL_DATA cd = (CALL_DATA)iseq->body->iseq_encoded[pos + 1]; extern const rb_iseq_t *rb_mjit_inlinable_iseq(const struct rb_callinfo *ci, const struct rb_callcache *cc); const rb_iseq_t *iseq = rb_mjit_inlinable_iseq(cd->ci, cd->cc); diff --git a/numeric.c b/numeric.c index d0538ca126..b1425cad02 100644 --- a/numeric.c +++ b/numeric.c @@ -4715,30 +4715,14 @@ rb_int_abs(VALUE num) return Qnil; } -/* - * Document-method: Integer#size - * call-seq: - * int.size -> int - * - * Returns the number of bytes in the machine representation of +int+ - * (machine dependent). - * - * 1.size #=> 8 - * -1.size #=> 8 - * 2147483647.size #=> 8 - * (256**10 - 1).size #=> 10 - * (256**20 - 1).size #=> 20 - * (256**40 - 1).size #=> 40 - */ - static VALUE fix_size(VALUE fix) { return INT2FIX(sizeof(long)); } -static VALUE -int_size(VALUE num) +MJIT_FUNC_EXPORTED VALUE +rb_int_size(VALUE num) { if (FIXNUM_P(num)) { return fix_size(num); @@ -5458,7 +5442,6 @@ Init_Numeric(void) rb_define_method(rb_cInteger, "<<", rb_int_lshift, 1); rb_define_method(rb_cInteger, ">>", rb_int_rshift, 1); - rb_define_method(rb_cInteger, "size", int_size, 0); rb_define_method(rb_cInteger, "digits", rb_int_digits, -1); /* An obsolete class, use Integer */ diff --git a/numeric.rb b/numeric.rb index be33c5b436..c892cbe6ef 100644 --- a/numeric.rb +++ b/numeric.rb @@ -167,6 +167,26 @@ class Integer return self end + # + # Document-method: Integer#size + # call-seq: + # int.size -> int + # + # Returns the number of bytes in the machine representation of +int+ + # (machine dependent). + # + # 1.size #=> 8 + # -1.size #=> 8 + # 2147483647.size #=> 8 + # (256**10 - 1).size #=> 10 + # (256**20 - 1).size #=> 20 + # (256**40 - 1).size #=> 40 + # + def size + Primitive.attr! 'inline' + Primitive.cexpr! 'rb_int_size(self)' + end + # call-seq: # int.to_i -> integer #