From 691b05e83c41d089c4f6c7a8bbac9dd63f36a144 Mon Sep 17 00:00:00 2001 From: mame Date: Mon, 1 Jan 2018 13:18:55 +0000 Subject: 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- iseq.c | 32 +++++++++++++++++++++++++------- vm_core.h | 7 +++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/iseq.c b/iseq.c index 4470424357..28a9eca53a 100644 --- a/iseq.c +++ b/iseq.c @@ -346,7 +346,7 @@ prepare_iseq_build(rb_iseq_t *iseq, 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) 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) 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_iseq_t *iseq, size_t pos) } } -#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_iseq_t *iseq, size_t pos) } 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) 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, size_t pos) 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; } diff --git a/vm_core.h b/vm_core.h index 0d08875afd..16ee74b28e 100644 --- a/vm_core.h +++ b/vm_core.h @@ -56,6 +56,13 @@ #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" -- cgit v1.2.3