1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
mame 2018-01-01 13:18:55 +00:00
parent 295838e6eb
commit 691b05e83c
2 changed files with 32 additions and 7 deletions

32
iseq.c
View file

@ -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;
}

View file

@ -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"