Skip to content

Commit

Permalink
Add get scope fastpath in asm
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeuzagallo committed May 6, 2016
1 parent 0c7d2ea commit 055e3f7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
31 changes: 30 additions & 1 deletion compiler/interpreter.S
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -116,10 +116,39 @@ _op_push:
skip 1 skip 1


_op_lookup: _op_lookup:
read 1, %esi
mov (%STRINGS, %rsi, 8), %rsi
mov (%VM), %rdi
mov (%rdi), %rax // scope table
mov 0x8(%rdi), %edx // table hash
mov %esi, %ecx // index
and %edx, %ecx // index &= hash
mov %ecx, %r8d // begin

begin:
mov %ecx, %edi
shl $1, %edi
mov (%rax, %rdi, 0x8), %r9 // Entry::key
test %r9,%r9
jz slow_path
xor %r9, %rsi
jz found
inc %ecx
and %edx, %ecx
xor %ecx, %r8d
jnz begin

slow_path:
mov %VM, %rdi mov %VM, %rdi
read 1, %esi read 1, %esi
mov (%STRINGS, %rsi, 8), %rsi mov (%STRINGS, %rsi, 8), %rsi
ccall _getScope ccall _getScope
jmp done

found:
mov 0x8(%rax, %rdi, 0x8), %rax // Entry::value

done:
push %rax push %rax
skip 1 skip 1


Expand Down Expand Up @@ -172,7 +201,7 @@ _op_ret:
_op_load_string: _op_load_string:
read 1, %edi read 1, %edi
mov (%STRINGS, %rdi, 8), %rdi mov (%STRINGS, %rdi, 8), %rdi
rol $8, %rdi rol $8, %rdi
mov $STRING_TAG, %dil mov $STRING_TAG, %dil
ror $8, %rdi ror $8, %rdi
push %rdi push %rdi
Expand Down
11 changes: 4 additions & 7 deletions compiler/scope.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ namespace ceos {


void resize(unsigned size) { void resize(unsigned size) {
//assert(size > 0); //assert(size > 0);
unsigned i = tableSize;
tableSize = size; tableSize = size;
tableHash = size - 1; tableHash = size - 1;
table = (Entry *)realloc(table, sizeof(Entry) * size); table = (Entry *)realloc(table, sizeof(Entry) * size);
while (i < size) { memset(table, 0, sizeof(Entry) * size);
table[i++].key = NULL;
}
} }


Scope *inc() { Scope *inc() {
Expand Down Expand Up @@ -135,15 +132,15 @@ namespace ceos {
Value value; Value value;
}; };


Scope *parent;


private:
Entry *table; Entry *table;
unsigned tableHash;
Scope *parent;
private:
Scope *previous; Scope *previous;
unsigned refCount; unsigned refCount;
unsigned length; unsigned length;
unsigned tableSize; unsigned tableSize;
unsigned tableHash;


static Scope **s_scopePool; static Scope **s_scopePool;
static unsigned s_scopePoolIndex; static unsigned s_scopePoolIndex;
Expand Down
9 changes: 6 additions & 3 deletions compiler/vm.cc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ extern "C" void execute(


extern "C" uint64_t getScope(VM *vm, String name); extern "C" uint64_t getScope(VM *vm, String name);
uint64_t getScope(VM *vm, String name) { uint64_t getScope(VM *vm, String name) {
auto value = vm->m_scope->get(name); Value value;
if (vm->m_scope->parent) {
value = vm->m_scope->parent->get(name);
}
if (value.isUndefined()) { if (value.isUndefined()) {
std::cerr << "Symbol not found: " << name.str() << "\n"; std::cerr << "Symbol not found: " << name.str() << "\n";
throw; throw;
} }
return value.encode(); return value.encode();
} }


extern "C" void setScope(VM *vm, String name, Value closure); extern "C" void setScope(VM *vm, const char *name, Value closure);
void setScope(VM *vm, String name, Value closure) { void setScope(VM *vm, const char *name, Value closure) {
vm->m_scope->set(name, closure); vm->m_scope->set(name, closure);
} }


Expand Down
3 changes: 2 additions & 1 deletion compiler/vm.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ namespace ceos {
return String(v); return String(v);
} }


Scope *m_scope; // first thing, easy to access from asm

unsigned pc; unsigned pc;
size_t length; size_t length;
size_t heapSize; size_t heapSize;
size_t heapLimit; size_t heapLimit;
std::vector<std::pair<size_t, void *>> blocks; std::vector<std::pair<size_t, void *>> blocks;


Scope *m_scope;
std::vector<String> m_stringTable; std::vector<String> m_stringTable;
std::vector<Function> m_userFunctions; std::vector<Function> m_userFunctions;


Expand Down

0 comments on commit 055e3f7

Please sign in to comment.