ruby-changes:54917
From: ko1 <ko1@a...>
Date: Fri, 22 Feb 2019 16:26:02 +0900 (JST)
Subject: [ruby-changes:54917] ko1:r67122 (trunk): change `cfunc->invoker` type for opt.
ko1 2019-02-22 16:25:51 +0900 (Fri, 22 Feb 2019) New Revision: 67122 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67122 Log: change `cfunc->invoker` type for opt. * vm_insnhelper.c: change `call_cfunc_*` parameters order and specify a function type for the passed func ptr. This fix reduce the number of asm instructions, such as: # before this patch 0000000000000110 <call_cfunc_0>: 110: 48 89 fa mov %rdi,%rdx 113: 31 c0 xor %eax,%eax 115: 48 89 f7 mov %rsi,%rdi 118: ff e2 jmpq *%rdx 11a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1) # after this patch 0000000000000110 <call_cfunc_0>: 110: ff e1 jmpq *%rcx However, this kind of instruction reduction doesn't affect any performance because of great CPU architectures :p Modified files: trunk/method.h trunk/vm_eval.c trunk/vm_insnhelper.c trunk/vm_method.c Index: method.h =================================================================== --- method.h (revision 67121) +++ method.h (revision 67122) @@ -129,7 +129,7 @@ typedef struct rb_method_iseq_struct { https://github.com/ruby/ruby/blob/trunk/method.h#L129 typedef struct rb_method_cfunc_struct { VALUE (*func)(ANYARGS); - VALUE (*invoker)(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv); + VALUE (*invoker)(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)); int argc; } rb_method_cfunc_t; Index: vm_eval.c =================================================================== --- vm_eval.c (revision 67121) +++ vm_eval.c (revision 67122) @@ -83,7 +83,7 @@ vm_call0_cfunc_with_frame(rb_execution_c https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L83 if (len >= 0) rb_check_arity(argc, len, len); - val = (*cfunc->invoker)(cfunc->func, recv, argc, argv); + val = (*cfunc->invoker)(recv, argc, argv, cfunc->func); CHECK_CFP_CONSISTENCY("vm_call0_cfunc_with_frame"); rb_vm_pop_frame(ec); Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 67121) +++ vm_insnhelper.c (revision 67122) @@ -1829,111 +1829,112 @@ vm_call_iseq_setup_tailcall(rb_execution https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1829 } static VALUE -call_cfunc_m2(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_m2(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { return (*func)(recv, rb_ary_new4(argc, argv)); } static VALUE -call_cfunc_m1(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_m1(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { return (*func)(argc, argv, recv); } static VALUE -call_cfunc_0(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_0(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv); + VALUE(*f)(VALUE) = (VALUE(*)(VALUE))func; + return (*f)(recv); } - static VALUE -call_cfunc_1(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_1(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0]); + VALUE(*f)(VALUE, VALUE) = (VALUE(*)(VALUE, VALUE))func; + return (*f)(recv, argv[0]); } - static VALUE -call_cfunc_2(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_2(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1]); + VALUE(*f)(VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1]); } - static VALUE -call_cfunc_3(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_3(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2]); } - static VALUE -call_cfunc_4(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_4(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3]); } - static VALUE -call_cfunc_5(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_5(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4]); } - static VALUE -call_cfunc_6(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_6(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); } - static VALUE -call_cfunc_7(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_7(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); } - static VALUE -call_cfunc_8(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_8(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]); } - static VALUE -call_cfunc_9(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_9(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); } - static VALUE -call_cfunc_10(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_10(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); } - static VALUE -call_cfunc_11(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_11(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]); } - static VALUE -call_cfunc_12(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_12(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11]); } - static VALUE -call_cfunc_13(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_13(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12]); } - static VALUE -call_cfunc_14(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_14(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]); } - static VALUE -call_cfunc_15(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv) +call_cfunc_15(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS)) { - return (*func)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14]); + VALUE(*f)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE) = (VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE))func; + return (*f)(recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14]); } static inline int @@ -2002,7 +2003,7 @@ vm_call_cfunc_with_frame(rb_execution_co https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2003 if (len >= 0) rb_check_arity(argc, len, len); reg_cfp->sp -= argc + 1; - val = (*cfunc->invoker)(cfunc->func, recv, argc, reg_cfp->sp + 1); + val = (*cfunc->invoker)(recv, argc, reg_cfp->sp + 1, cfunc->func); CHECK_CFP_CONSISTENCY("vm_call_cfunc"); Index: vm_method.c =================================================================== --- vm_method.c (revision 67121) +++ vm_method.c (revision 67122) @@ -191,7 +191,7 @@ lookup_method_table(VALUE klass, ID id) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L191 } static VALUE -(*call_cfunc_invoker_func(int argc))(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *) +(*call_cfunc_invoker_func(int argc))(VALUE recv, int argc, const VALUE *, VALUE (*func)(ANYARGS)) { switch (argc) { case -2: return &call_cfunc_m2; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/