ruby-changes:49421
From: mame <ko1@a...>
Date: Mon, 1 Jan 2018 22:19:00 +0900 (JST)
Subject: [ruby-changes:49421] mame:r61537 (trunk): vm_core.h: make the algorithm of get_insn_info selectable
mame 2018-01-01 22:18:55 +0900 (Mon, 01 Jan 2018) New Revision: 61537 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61537 Log: vm_core.h: make the algorithm of get_insn_info selectable Currently, VM_INSN_INFO_TABLE_IMPL == 0 means linear search, and VM_INSN_INFO_TABLE_IMPL == 1 means binary search. I plan to add succinct bitvector algorithm later. Modified files: trunk/iseq.c trunk/vm_core.h Index: vm_core.h =================================================================== --- vm_core.h (revision 61536) +++ vm_core.h (revision 61537) @@ -56,6 +56,13 @@ https://github.com/ruby/ruby/blob/trunk/vm_core.h#L56 #define RUBY_VM_THREAD_MODEL 2 +/* + * implementation selector of get_insn_info algorithm + * 0: linear search + * 1: binary search + */ +#define VM_INSN_INFO_TABLE_IMPL 1 + #include "ruby/ruby.h" #include "ruby/st.h" Index: iseq.c =================================================================== --- iseq.c (revision 61536) +++ iseq.c (revision 61537) @@ -346,7 +346,7 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L346 return Qtrue; } -#if VM_CHECK_MODE > 0 +#if VM_CHECK_MODE > 0 && VM_INSN_INFO_TABLE_IMPL > 0 static void validate_get_insn_info(rb_iseq_t *iseq); #endif @@ -358,7 +358,7 @@ finish_iseq_build(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L358 ISEQ_COMPILE_DATA_CLEAR(iseq); compile_data_free(data); -#if VM_CHECK_MODE > 0 +#if VM_CHECK_MODE > 0 && VM_INSN_INFO_TABLE_IMPL > 0 validate_get_insn_info(iseq); #endif @@ -1252,6 +1252,7 @@ iseqw_to_a(VALUE self) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1252 return iseq_data_to_ary(iseq); } +#if VM_INSN_INFO_TABLE_IMPL == 1 /* binary search */ static const struct iseq_insn_info_entry * get_insn_info_binary_search(const rb_iseq_t *iseq, size_t pos) { @@ -1296,7 +1297,14 @@ get_insn_info_binary_search(const rb_ise https://github.com/ruby/ruby/blob/trunk/iseq.c#L1297 } } -#if VM_CHECK_MODE > 0 +static const struct iseq_insn_info_entry * +get_insn_info(const rb_iseq_t *iseq, size_t pos) +{ + return get_insn_info_binary_search(iseq, pos); +} +#endif + +#if VM_CHECK_MODE > 0 || VM_INSN_INFO_TABLE_IMPL == 0 static const struct iseq_insn_info_entry * get_insn_info_linear_search(const rb_iseq_t *iseq, size_t pos) { @@ -1332,14 +1340,24 @@ get_insn_info_linear_search(const rb_ise https://github.com/ruby/ruby/blob/trunk/iseq.c#L1340 } return &insns_info[i-1]; } +#endif + +#if VM_INSN_INFO_TABLE_IMPL == 0 /* linear search */ +static const struct iseq_insn_info_entry * +get_insn_info(const rb_iseq_t *iseq, size_t pos) +{ + return get_insn_info_linear_search(iseq, pos); +} +#endif +#if VM_CHECK_MODE > 0 && VM_INSN_INFO_TABLE_IMPL > 0 static void validate_get_insn_info(rb_iseq_t *iseq) { size_t i; for (i = 0; i < iseq->body->iseq_size; i++) { - if (get_insn_info_linear_search(iseq, i) != get_insn_info_binary_search(iseq, i)) { - rb_bug("validate_get_insn_info: get_insn_info_linear_search(iseq, %"PRIuSIZE") != get_insn_info_binary_search(iseq, %"PRIuSIZE")", i, i); + if (get_insn_info_linear_search(iseq, i) != get_insn_info(iseq, i)) { + rb_bug("validate_get_insn_info: get_insn_info_linear_search(iseq, %"PRIuSIZE") != get_insn_info(iseq, %"PRIuSIZE")", i, i); } } } @@ -1348,7 +1366,7 @@ validate_get_insn_info(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1366 unsigned int rb_iseq_line_no(const rb_iseq_t *iseq, size_t pos) { - const struct iseq_insn_info_entry *entry = get_insn_info_binary_search(iseq, pos); + const struct iseq_insn_info_entry *entry = get_insn_info(iseq, pos); if (entry) { return entry->line_no; @@ -1361,7 +1379,7 @@ rb_iseq_line_no(const rb_iseq_t *iseq, s https://github.com/ruby/ruby/blob/trunk/iseq.c#L1379 rb_event_flag_t rb_iseq_event_flags(const rb_iseq_t *iseq, size_t pos) { - const struct iseq_insn_info_entry *entry = get_insn_info_binary_search(iseq, pos); + const struct iseq_insn_info_entry *entry = get_insn_info(iseq, pos); if (entry) { return entry->events; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/