Skip to content

Commit

Permalink
VM: a bunch of more methods on the factor_vm class that can be made i…
Browse files Browse the repository at this point in the history
…nto funtions
  • Loading branch information
bjourne committed May 30, 2016
1 parent 00a64c9 commit 3b016bc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 28 deletions.
24 changes: 12 additions & 12 deletions vm/code_blocks.cpp
Expand Up @@ -2,7 +2,7 @@

namespace factor {

cell code_block_owner(code_block* compiled) {
static cell code_block_owner(code_block* compiled) {
cell owner = compiled->owner;

/* Cold generic word call sites point to quotations that call the
Expand All @@ -18,7 +18,7 @@ cell code_block_owner(code_block* compiled) {
return wrap->object;
}

cell compute_entry_point_address(cell obj) {
static cell compute_entry_point_address(cell obj) {
switch (TAG(obj)) {
case WORD_TYPE:
return untag<word>(obj)->entry_point;
Expand All @@ -30,14 +30,22 @@ cell compute_entry_point_address(cell obj) {
}
}

static cell compute_here_address(cell arg, cell offset, code_block* compiled) {
fixnum n = untag_fixnum(arg);
if (n >= 0)
return compiled->entry_point() + offset + n;
return compiled->entry_point() - n;
}

cell code_block::owner_quot() const {
if (!optimized_p() && TAG(owner) == WORD_TYPE)
return untag<word>(owner)->def;
return owner;
}

/* If the code block is an unoptimized quotation, we can calculate the
scan offset. In all other cases -1 is returned. */
scan offset. In all other cases -1 is returned.
Allocates memory (quot_code_offset_to_scan) */
cell code_block::scan(factor_vm* vm, cell addr) const {
if (type() != code_block_unoptimized) {
return tag_fixnum(-1);
Expand Down Expand Up @@ -212,14 +220,6 @@ cell factor_vm::compute_external_address(instruction_operand op) {
return ext_addr;
}

cell factor_vm::compute_here_address(cell arg, cell offset,
code_block* compiled) {
fixnum n = untag_fixnum(arg);
if (n >= 0)
return compiled->entry_point() + offset + n;
return compiled->entry_point() - n;
}

struct initial_code_block_visitor {
factor_vm* parent;
cell literals;
Expand All @@ -243,7 +243,7 @@ struct initial_code_block_visitor {
case RT_ENTRY_POINT_PIC_TAIL:
return parent->compute_entry_point_pic_tail_address(next_literal());
case RT_HERE:
return parent->compute_here_address(
return compute_here_address(
next_literal(), op.rel.offset(), op.compiled);
case RT_UNTAGGED:
return untag_fixnum(next_literal());
Expand Down
2 changes: 1 addition & 1 deletion vm/dispatch.cpp
Expand Up @@ -82,7 +82,7 @@ cell factor_vm::object_class(cell obj) {
return tag_fixnum(tag);
}

cell factor_vm::method_cache_hashcode(cell klass, array* array) {
static cell method_cache_hashcode(cell klass, array* array) {
cell capacity = (array_capacity(array) >> 1) - 1;
return ((klass >> TAG_BITS) & capacity) << 1;
}
Expand Down
13 changes: 4 additions & 9 deletions vm/inline_cache.cpp
Expand Up @@ -16,7 +16,7 @@ void factor_vm::deallocate_inline_cache(cell return_address) {

/* Figure out what kind of type check the PIC needs based on the methods
it contains */
cell factor_vm::determine_inline_cache_type(array* cache_entries) {
static cell determine_inline_cache_type(array* cache_entries) {
for (cell i = 0; i < array_capacity(cache_entries); i += 2) {
/* Is it a tuple layout? */
if (TAG(array_nth(cache_entries, i)) == ARRAY_TYPE) {
Expand Down Expand Up @@ -62,7 +62,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index, cell generic_word_,
data_root<array> cache_entries(cache_entries_, parent);

cell inline_cache_type =
parent->determine_inline_cache_type(cache_entries.untagged());
determine_inline_cache_type(cache_entries.untagged());
parent->update_pic_count(inline_cache_type);

/* Generate machine code to determine the object's class. */
Expand All @@ -72,8 +72,7 @@ void inline_cache_jit::compile_inline_cache(fixnum index, cell generic_word_,

/* Generate machine code to check, in turn, if the class is one of the cached
* entries. */
cell i;
for (i = 0; i < array_capacity(cache_entries.untagged()); i += 2) {
for (cell i = 0; i < array_capacity(cache_entries.untagged()); i += 2) {
/* Class equal? */
cell klass = array_nth(cache_entries.untagged(), i);
emit_check(klass);
Expand Down Expand Up @@ -119,10 +118,6 @@ code_block* factor_vm::compile_inline_cache(fixnum index, cell generic_word_,
return code;
}

cell factor_vm::inline_cache_size(cell cache_entries) {
return array_capacity(untag_check<array>(cache_entries)) / 2;
}

/* Allocates memory */
cell factor_vm::add_inline_cache_entry(cell cache_entries_, cell klass_,
cell method_) {
Expand Down Expand Up @@ -172,7 +167,7 @@ cell factor_vm::inline_cache_miss(cell return_address_) {
data_root<word> generic_word(ctx->pop(), this);
data_root<object> object(((cell*)ctx->datastack)[-index], this);

cell pic_size = inline_cache_size(cache_entries.value());
cell pic_size = array_capacity(cache_entries.untagged()) / 2;

update_pic_transitions(pic_size);

Expand Down
2 changes: 1 addition & 1 deletion vm/quotations.cpp
Expand Up @@ -104,7 +104,7 @@ bool quotation_jit::stack_frame_p() {
return true;
}

bool quotation_jit::trivial_quotation_p(array* elements) {
static bool trivial_quotation_p(array* elements) {
return array_capacity(elements) == 1 &&
TAG(array_nth(elements, 0)) == WORD_TYPE;
}
Expand Down
1 change: 0 additions & 1 deletion vm/quotations.hpp
Expand Up @@ -14,7 +14,6 @@ struct quotation_jit : public jit {
void init_quotation(cell quot);
void emit_mega_cache_lookup(cell methods, fixnum index, cell cache);
bool primitive_call_p(cell i, cell length);
bool trivial_quotation_p(array* elements);
void emit_quotation(cell quot);
void emit_epilog(bool needed);
bool fast_if_p(cell i, cell length);
Expand Down
4 changes: 0 additions & 4 deletions vm/vm.hpp
Expand Up @@ -566,7 +566,6 @@ struct factor_vm {
code_block* compiled,
array* parameters,
cell index);
cell compute_here_address(cell arg, cell offset, code_block* compiled);
void initialize_code_block(code_block* compiled, cell literals);
void initialize_code_block(code_block* compiled);
void fixup_labels(array* labels, code_block* compiled);
Expand Down Expand Up @@ -664,7 +663,6 @@ struct factor_vm {
cell lookup_method(cell obj, cell methods);
void primitive_lookup_method();
cell object_class(cell obj);
cell method_cache_hashcode(cell klass, array* array);
void update_method_cache(cell cache, cell klass, cell method);
void primitive_mega_cache_miss();
void primitive_reset_dispatch_stats();
Expand All @@ -673,12 +671,10 @@ struct factor_vm {
// inline cache
void init_inline_caching(int max_size);
void deallocate_inline_cache(cell return_address);
cell determine_inline_cache_type(array* cache_entries);
void update_pic_count(cell type);
code_block* compile_inline_cache(fixnum index, cell generic_word_,
cell methods_, cell cache_entries_,
bool tail_call_p);
cell inline_cache_size(cell cache_entries);
cell add_inline_cache_entry(cell cache_entries_, cell klass_, cell method_);
void update_pic_transitions(cell pic_size);
cell inline_cache_miss(cell return_address);
Expand Down

0 comments on commit 3b016bc

Please sign in to comment.