* Improve perfomance for Integer#size method [Feature #17135] * re-run ci * Let MJIT frame skip work for Integer#size Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
This commit is contained in:
parent
033e76e760
commit
3208a5df2d
Notes:
git
2021-06-05 13:57:41 +09:00
Merged-By: k0kubun <takashikkbn@gmail.com>
@ -8,6 +8,7 @@ prelude: |
|
|||||||
def mjit_magnitude(int) int.magnitude end
|
def mjit_magnitude(int) int.magnitude end
|
||||||
def mjit_odd?(int) int.odd? end
|
def mjit_odd?(int) int.odd? end
|
||||||
def mjit_ord(int) int.ord 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_i(int) int.to_i end
|
||||||
def mjit_to_int(int) int.to_int end
|
def mjit_to_int(int) int.to_int end
|
||||||
def mjit_uminus(int) -int end
|
def mjit_uminus(int) -int end
|
||||||
@ -22,6 +23,7 @@ benchmark:
|
|||||||
- mjit_magnitude(-1)
|
- mjit_magnitude(-1)
|
||||||
- mjit_odd?(1)
|
- mjit_odd?(1)
|
||||||
- mjit_ord(1)
|
- mjit_ord(1)
|
||||||
|
- mjit_size(1)
|
||||||
- mjit_to_i(1)
|
- mjit_to_i(1)
|
||||||
- mjit_to_int(1)
|
- mjit_to_int(1)
|
||||||
- mjit_uminus(1)
|
- mjit_uminus(1)
|
||||||
|
@ -515,7 +515,7 @@ precompile_inlinable_iseqs(FILE *f, const rb_iseq_t *iseq, struct compile_status
|
|||||||
unsigned int pos = 0;
|
unsigned int pos = 0;
|
||||||
while (pos < body->iseq_size) {
|
while (pos < body->iseq_size) {
|
||||||
int insn = rb_vm_insn_decode(body->iseq_encoded[pos]);
|
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];
|
CALL_DATA cd = (CALL_DATA)body->iseq_encoded[pos + 1];
|
||||||
const struct rb_callinfo *ci = cd->ci;
|
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
|
const struct rb_callcache *cc = captured_cc_entries(status)[call_data_index(cd, body)]; // use copy to avoid race condition
|
||||||
|
@ -735,7 +735,7 @@ set_compiling_iseqs(const rb_iseq_t *iseq)
|
|||||||
unsigned int pos = 0;
|
unsigned int pos = 0;
|
||||||
while (pos < iseq->body->iseq_size) {
|
while (pos < iseq->body->iseq_size) {
|
||||||
int insn = rb_vm_insn_decode(iseq->body->iseq_encoded[pos]);
|
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];
|
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);
|
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);
|
const rb_iseq_t *iseq = rb_mjit_inlinable_iseq(cd->ci, cd->cc);
|
||||||
|
21
numeric.c
21
numeric.c
@ -4715,30 +4715,14 @@ rb_int_abs(VALUE num)
|
|||||||
return Qnil;
|
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
|
static VALUE
|
||||||
fix_size(VALUE fix)
|
fix_size(VALUE fix)
|
||||||
{
|
{
|
||||||
return INT2FIX(sizeof(long));
|
return INT2FIX(sizeof(long));
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
MJIT_FUNC_EXPORTED VALUE
|
||||||
int_size(VALUE num)
|
rb_int_size(VALUE num)
|
||||||
{
|
{
|
||||||
if (FIXNUM_P(num)) {
|
if (FIXNUM_P(num)) {
|
||||||
return fix_size(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_lshift, 1);
|
||||||
rb_define_method(rb_cInteger, ">>", rb_int_rshift, 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);
|
rb_define_method(rb_cInteger, "digits", rb_int_digits, -1);
|
||||||
|
|
||||||
/* An obsolete class, use Integer */
|
/* An obsolete class, use Integer */
|
||||||
|
20
numeric.rb
20
numeric.rb
@ -167,6 +167,26 @@ class Integer
|
|||||||
return self
|
return self
|
||||||
end
|
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:
|
# call-seq:
|
||||||
# int.to_i -> integer
|
# int.to_i -> integer
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user