Permalink
Browse files

Add get scope fastpath in asm

  • Loading branch information...
1 parent 0c7d2ea commit 055e3f7cbd890b847dc640fedb44969f4279d2fd @tadeuzagallo committed May 6, 2016
Showing with 42 additions and 12 deletions.
  1. +30 −1 compiler/interpreter.S
  2. +4 −7 compiler/scope.h
  3. +6 −3 compiler/vm.cc
  4. +2 −1 compiler/vm.h
@@ -116,10 +116,39 @@ _op_push:
skip 1
_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
read 1, %esi
mov (%STRINGS, %rsi, 8), %rsi
ccall _getScope
+ jmp done
+
+found:
+ mov 0x8(%rax, %rdi, 0x8), %rax // Entry::value
+
+done:
push %rax
skip 1
@@ -172,7 +201,7 @@ _op_ret:
_op_load_string:
read 1, %edi
mov (%STRINGS, %rdi, 8), %rdi
- rol $8, %rdi
+ rol $8, %rdi
mov $STRING_TAG, %dil
ror $8, %rdi
push %rdi
View
@@ -31,13 +31,10 @@ namespace ceos {
void resize(unsigned size) {
//assert(size > 0);
- unsigned i = tableSize;
tableSize = size;
tableHash = size - 1;
table = (Entry *)realloc(table, sizeof(Entry) * size);
- while (i < size) {
- table[i++].key = NULL;
- }
+ memset(table, 0, sizeof(Entry) * size);
}
Scope *inc() {
@@ -135,15 +132,15 @@ namespace ceos {
Value value;
};
- Scope *parent;
- private:
Entry *table;
+ unsigned tableHash;
+ Scope *parent;
+ private:
Scope *previous;
unsigned refCount;
unsigned length;
unsigned tableSize;
- unsigned tableHash;
static Scope **s_scopePool;
static unsigned s_scopePoolIndex;
View
@@ -15,16 +15,19 @@ extern "C" void execute(
extern "C" 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()) {
std::cerr << "Symbol not found: " << name.str() << "\n";
throw;
}
return value.encode();
}
-extern "C" void setScope(VM *vm, String name, Value closure);
-void setScope(VM *vm, String name, Value closure) {
+extern "C" void setScope(VM *vm, const char *name, Value closure);
+void setScope(VM *vm, const char *name, Value closure) {
vm->m_scope->set(name, closure);
}
View
@@ -51,13 +51,14 @@ namespace ceos {
return String(v);
}
+ Scope *m_scope; // first thing, easy to access from asm
+
unsigned pc;
size_t length;
size_t heapSize;
size_t heapLimit;
std::vector<std::pair<size_t, void *>> blocks;
- Scope *m_scope;
std::vector<String> m_stringTable;
std::vector<Function> m_userFunctions;

0 comments on commit 055e3f7

Please sign in to comment.