ruby-changes:52864
From: k0kubun <ko1@a...>
Date: Sun, 14 Oct 2018 22:25:28 +0900 (JST)
Subject: [ruby-changes:52864] k0kubun:r65076 (trunk): _mjit_compile_ivar.erb: optimize setivar as well
k0kubun 2018-10-14 22:25:21 +0900 (Sun, 14 Oct 2018) New Revision: 65076 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65076 Log: _mjit_compile_ivar.erb: optimize setivar as well mjit_compile.inc.erb: ditto common.mk: update dependency for the rename from getivar.erb === Optcarrot benchmark === ``` $ benchmark-driver benchmark.yml --rbenv '2.0.0::2.0.0-p648 --disable-gems;before::before --disable-gems;before+JIT::before --disable-gems --jit;after::after --disable-gems;after+JIT::after --disable-gems --jit' -v --repeat-count 24 2.0.0: ruby 2.0.0p648 (2015-12-16 revision 53162) [x86_64-linux] before: ruby 2.6.0dev (2018-10-14 trunk 65074) [x86_64-linux] before+JIT: ruby 2.6.0dev (2018-10-14 trunk 65074) +JIT [x86_64-linux] after: ruby 2.6.0dev (2018-10-14 trunk 65074) [x86_64-linux] after+JIT: ruby 2.6.0dev (2018-10-14 trunk 65074) +JIT [x86_64-linux] Calculating ------------------------------------- 2.0.0 before before+JIT after after+JIT Optcarrot Lan_Master.nes 34.434 53.125 84.782 53.321 86.812 fps Comparison: Optcarrot Lan_Master.nes after+JIT: 86.8 fps before+JIT: 84.8 fps - 1.02x slower after: 53.3 fps - 1.63x slower before: 53.1 fps - 1.63x slower 2.0.0: 34.4 fps - 2.52x slower ``` Added files: trunk/tool/ruby_vm/views/_mjit_compile_ivar.erb Removed files: trunk/tool/ruby_vm/views/_mjit_compile_getivar.erb Modified files: trunk/common.mk trunk/tool/ruby_vm/views/mjit_compile.inc.erb Index: tool/ruby_vm/views/_mjit_compile_getivar.erb =================================================================== --- tool/ruby_vm/views/_mjit_compile_getivar.erb (revision 65075) +++ tool/ruby_vm/views/_mjit_compile_getivar.erb (nonexistent) @@ -1,44 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_getivar.erb#L0 -% # -*- mode:c; style:ruby; coding: utf-8; indent-tabs-mode: nil -*- -% # Copyright (c) 2018 Takashi Kokubun. All rights reserved. -% # -% # This file is a part of the programming language Ruby. Permission is hereby -% # granted, to either redistribute and/or modify this file, provided that the -% # conditions mentioned in the file COPYING are met. Consult the file for -% # details. -% -% # Optimized case of get_instancevariable instruction. -#if OPT_IC_FOR_IVAR -{ -% # compiler: Prepare operands which may be used by `insn.call_attribute` -% insn.opes.each_with_index do |ope, i| - MAYBE_UNUSED(<%= ope.fetch(:decl) %>) = (<%= ope.fetch(:type) %>)operands[<%= i %>]; -% end -% -% # compiler: Consider cfp->self as T_OBJECT if ic->ic_serial is set - if (ic->ic_serial) { -% # JIT: optimize away motion of sp and pc. This path does not call rb_warning() and so it's always leaf and not `handles_sp`. -% # <%= render 'mjit_compile_pc_and_sp', locals: { insn: insn } -%> -% -% # JIT: prepare vm_getivar's arguments and variables - fprintf(f, "{\n"); - fprintf(f, " VALUE obj = GET_SELF();\n"); - fprintf(f, " const rb_serial_t ic_serial = (rb_serial_t)%"PRI_SERIALT_PREFIX"u;\n", ic->ic_serial); - fprintf(f, " const st_index_t index = %lu;\n", ic->ic_value.index); -% -% # JIT: cache hit path of vm_getivar, or cancel JIT. - fprintf(f, " if (LIKELY(RB_TYPE_P(obj, T_OBJECT) && ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass) && index < ROBJECT_NUMIV(obj))) {\n"); - fprintf(f, " stack[%d] = ROBJECT_IVPTR(obj)[index];\n", b->stack_size); - fprintf(f, " }\n"); - fprintf(f, " else {\n"); - fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", pos); - fprintf(f, " reg_cfp->sp = (VALUE *)reg_cfp->bp + %d;\n", b->stack_size + 1); - fprintf(f, " goto cancel;\n"); - fprintf(f, " }\n"); - -% # compiler: Move JIT compiler's internal stack pointer - b->stack_size += <%= insn.call_attribute('sp_inc') %>; - fprintf(f, "}\n"); - break; - } -} -#endif /* OPT_IC_FOR_IVAR */ Index: tool/ruby_vm/views/mjit_compile.inc.erb =================================================================== --- tool/ruby_vm/views/mjit_compile.inc.erb (revision 65075) +++ tool/ruby_vm/views/mjit_compile.inc.erb (revision 65076) @@ -52,8 +52,8 @@ switch (insn) { https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/mjit_compile.inc.erb#L52 <%= render 'mjit_compile_send', locals: { insn: insn } -%> % when 'opt_aref' # experimental. TODO: increase insns and make the list automatically by finding DISPATCH_ORIGINAL_INSN <%= render 'mjit_compile_send', locals: { insn: opt_send_without_block } -%> -% when 'getinstancevariable' -<%= render 'mjit_compile_getivar', locals: { insn: insn } -%> +% when 'getinstancevariable', 'setinstancevariable' +<%= render 'mjit_compile_ivar', locals: { insn: insn } -%> % when 'leave' if (b->stack_size != 1) { if (mjit_opts.warnings || mjit_opts.verbose) Index: tool/ruby_vm/views/_mjit_compile_ivar.erb =================================================================== --- tool/ruby_vm/views/_mjit_compile_ivar.erb (nonexistent) +++ tool/ruby_vm/views/_mjit_compile_ivar.erb (revision 65076) @@ -0,0 +1,52 @@ https://github.com/ruby/ruby/blob/trunk/tool/ruby_vm/views/_mjit_compile_ivar.erb#L1 +% # -*- mode:c; style:ruby; coding: utf-8; indent-tabs-mode: nil -*- +% # Copyright (c) 2018 Takashi Kokubun. All rights reserved. +% # +% # This file is a part of the programming language Ruby. Permission is hereby +% # granted, to either redistribute and/or modify this file, provided that the +% # conditions mentioned in the file COPYING are met. Consult the file for +% # details. +% +% # Optimized case of get_instancevariable instruction. +#if OPT_IC_FOR_IVAR +{ +% # compiler: Prepare operands which may be used by `insn.call_attribute` +% insn.opes.each_with_index do |ope, i| + MAYBE_UNUSED(<%= ope.fetch(:decl) %>) = (<%= ope.fetch(:type) %>)operands[<%= i %>]; +% end +% +% # compiler: Consider cfp->self as T_OBJECT if ic->ic_serial is set + if (ic->ic_serial) { +% # JIT: optimize away motion of sp and pc. This path does not call rb_warning() and so it's always leaf and not `handles_sp`. +% # <%= render 'mjit_compile_pc_and_sp', locals: { insn: insn } -%> +% +% # JIT: prepare vm_getivar's arguments and variables + fprintf(f, "{\n"); + fprintf(f, " VALUE obj = GET_SELF();\n"); + fprintf(f, " const rb_serial_t ic_serial = (rb_serial_t)%"PRI_SERIALT_PREFIX"u;\n", ic->ic_serial); + fprintf(f, " const st_index_t index = %lu;\n", ic->ic_value.index); +% if insn.name == 'setinstancevariable' + fprintf(f, " VALUE val = stack[%d];\n", b->stack_size - 1); +% end +% +% # JIT: cache hit path of vm_getivar, or cancel JIT. + fprintf(f, " if (LIKELY(RB_TYPE_P(obj, T_OBJECT) && ic_serial == RCLASS_SERIAL(RBASIC(obj)->klass) && index < ROBJECT_NUMIV(obj))) {\n"); +% if insn.name == 'setinstancevariable' + fprintf(f, " VALUE *ptr = ROBJECT_IVPTR(obj);\n"); + fprintf(f, " RB_OBJ_WRITE(obj, &ptr[index], val);\n"); +% else + fprintf(f, " stack[%d] = ROBJECT_IVPTR(obj)[index];\n", b->stack_size); +% end + fprintf(f, " }\n"); + fprintf(f, " else {\n"); + fprintf(f, " reg_cfp->pc = original_body_iseq + %d;\n", pos); + fprintf(f, " reg_cfp->sp = (VALUE *)reg_cfp->bp + %d;\n", b->stack_size + 1); + fprintf(f, " goto cancel;\n"); + fprintf(f, " }\n"); + +% # compiler: Move JIT compiler's internal stack pointer + b->stack_size += <%= insn.call_attribute('sp_inc') %>; + fprintf(f, "}\n"); + break; + } +} +#endif /* OPT_IC_FOR_IVAR */ Index: common.mk =================================================================== --- common.mk (revision 65075) +++ common.mk (revision 65076) @@ -938,7 +938,7 @@ $(srcs_vpath)vm.inc: $(srcdir)/tool/ruby https://github.com/ruby/ruby/blob/trunk/common.mk#L938 $(srcdir)/tool/ruby_vm/views/_insn_entry.erb $(srcdir)/tool/ruby_vm/views/_trace_instruction.erb $(srcs_vpath)mjit_compile.inc: $(srcdir)/tool/ruby_vm/views/mjit_compile.inc.erb $(inc_common_headers) \ $(srcdir)/tool/ruby_vm/views/_mjit_compile_insn.erb $(srcdir)/tool/ruby_vm/views/_mjit_compile_send.erb \ - $(srcdir)/tool/ruby_vm/views/_mjit_compile_send_guard.erb $(srcdir)/tool/ruby_vm/views/_mjit_compile_getivar.erb \ + $(srcdir)/tool/ruby_vm/views/_mjit_compile_send_guard.erb $(srcdir)/tool/ruby_vm/views/_mjit_compile_ivar.erb \ $(srcdir)/tool/ruby_vm/views/_mjit_compile_insn_body.erb $(srcdir)/tool/ruby_vm/views/_mjit_compile_pc_and_sp.erb common-srcs: $(srcs_vpath)parse.c $(srcs_vpath)lex.c $(srcs_vpath)enc/trans/newline.c $(srcs_vpath)id.c \ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/