Permalink
Browse files

Shuffle methods by usage

  • Loading branch information...
tadeuzagallo committed May 12, 2016
1 parent c4e9a3e commit df387375010af7b2e834c5bfc04b0dc8e168892a
Showing with 96 additions and 103 deletions.
  1. +96 −103 compiler/interpreter.S
@@ -67,6 +67,17 @@ _execute:
mov %rdx, %VM
mov %rcx, %BCBASE
mov %r8, %LOOKUP
jmp _loop
_op_exit:
mov %rbp, %rsp
pop %LOOKUP
pop %BCBASE
pop %VM
pop %STRINGS
pop %BYTECODE
pop %rbp
ret
_loop:
xor %rax, %rax
@@ -91,21 +102,6 @@ _loop_op_addresses:
op_address release_lex_scope
op_address put_to_scope
_op_exit:
mov %rbp, %rsp
pop %LOOKUP
pop %BCBASE
pop %VM
pop %STRINGS
pop %BYTECODE
pop %rbp
ret
_op_push:
read 1, %edi
push %rdi
skip 1
_op_lookup:
_op_lookup_fast_path:
read 2, %edi
@@ -115,59 +111,31 @@ _op_lookup_fast_path:
push %rsi
skip 2
_op_lookup_slow_path:
read 1, %esi // string ID
mov (%VM), %r9 // VM::m_scope *
mov (%STRINGS, %rsi, 8), %rsi // actual char *
_op_lookup_load:
mov (%r9), %rax // Scope::table *
test %rax, %rax
jz _op_lookup_check_parent
mov 0x18(%r9), %edx // Scope::tableHash
mov %esi, %ecx // index
and %edx, %ecx // index &= hash
mov %ecx, %r8d // begin
_op_push:
read 1, %edi
push %rdi
skip 1
_op_lookup_begin:
mov %ecx, %edi
shl $1, %edi
mov (%rax, %rdi, 0x8), %r11 // Entry::key
cmp %rsi, %r11
jne slow_path
mov 0x8(%rax, %rdi, 0x8), %rax // Entry::value
_op_push_arg:
read 1, %edi
get_arg %rdi, %rax
push %rax
skip 1
slow_path:
cmp %rsi, %r11
jz _op_lookup_found
test %r11,%r11
jz _op_lookup_check_parent
inc %ecx
and %edx, %ecx
cmp %ecx, %r8d
jnz _op_lookup_begin
_op_lookup_check_parent:
mov 0x8(%r9), %r9 // Scope::parent
test %r9, %r9
jnz _op_lookup_load
_op_lookup_not_found:
mov %rsi, %rdi
ccall _symbolNotFound
_op_lookup_found:
mov 0x8(%rax, %rdi, 0x8), %rax // Entry::value
read 2, %edx
test %edx, %edx
jz _op_lookup_done
mov %rax, (%LOOKUP, %rdx, 8) // cache value
_op_jz:
pop %rdi
test %edi, %edi
jz _jz
skip 1
_jz:
read 1, %edi
add %rdi, %BYTECODE
jmp _loop
_op_lookup_done:
push %rax
skip 2
_op_jmp:
read 1, %edi
add %rdi, %BYTECODE
jmp _loop
_op_call:
// pop the callee from the stack
@@ -181,9 +149,9 @@ _op_call:
// check tag
rol $8, %rcx
test $CLOSURE_TAG, %cl
jnz call_closure
jnz _op_call_closure
call_builtin:
_op_call_builtin:
shr $8, %rcx
push %rdi
ccall *%rcx
@@ -192,7 +160,7 @@ call_builtin:
push %rax
skip 1
call_closure:
_op_call_closure:
shr $8, %rcx
push %BYTECODE
push %rdi
@@ -203,21 +171,6 @@ call_closure:
lea (%BCBASE, %rax, 1), %BYTECODE
jmp _loop
_op_ret:
pop %rax
mov %rbp, %rsp
pop %rbp
pop %rsi
pop %rdi
pop %BYTECODE
lea (%rsp, %rdi, 8), %rsp
push %rax
restore_scope:
mov %VM, %rdi // VM::m_scope : Scope
// %rsi is the Closure *
ccall _finishClosure
skip 1
_op_load_string:
read 1, %edi
mov (%STRINGS, %rdi, 8), %rdi
@@ -246,28 +199,6 @@ _op_bind:
ccall _setScope
skip 0
_op_jz:
pop %rdi
test %edi, %edi
jz _jz
skip 1
_jz:
read 1, %edi
add %rdi, %BYTECODE
jmp _loop
_op_jmp:
read 1, %edi
add %rdi, %BYTECODE
jmp _loop
_op_push_arg:
read 1, %edi
get_arg %rdi, %rax
push %rax
skip 1
_op_create_lex_scope:
mov %VM, %rdi
ccall _pushScope
@@ -288,3 +219,65 @@ _op_put_to_scope:
ccall _setScope
skip 2
_op_ret:
pop %rax
mov %rbp, %rsp
pop %rbp
pop %rsi
pop %rdi
pop %BYTECODE
lea (%rsp, %rdi, 8), %rsp
push %rax
restore_scope:
mov %VM, %rdi // VM::m_scope : Scope
// %rsi is the Closure *
ccall _finishClosure
skip 1
_op_lookup_slow_path:
read 1, %esi // string ID
mov (%VM), %r9 // VM::m_scope *
mov (%STRINGS, %rsi, 8), %rsi // actual char *
_op_lookup_load:
mov (%r9), %rax // Scope::table *
test %rax, %rax
jz _op_lookup_check_parent
mov 0x18(%r9), %edx // Scope::tableHash
mov %esi, %ecx // index
and %edx, %ecx // index &= hash
mov %ecx, %r8d // begin
_op_lookup_begin:
mov %ecx, %edi
shl $1, %edi
mov (%rax, %rdi, 0x8), %r11 // Entry::key
test %r11,%r11
jz _op_lookup_check_parent
cmp %rsi, %r11
jz _op_lookup_found
inc %ecx
and %edx, %ecx
cmp %ecx, %r8d
jnz _op_lookup_begin
_op_lookup_check_parent:
mov 0x8(%r9), %r9 // Scope::parent
test %r9, %r9
jnz _op_lookup_load
_op_lookup_not_found:
mov %rsi, %rdi
ccall _symbolNotFound
_op_lookup_found:
mov 0x8(%rax, %rdi, 0x8), %rax // Entry::value
read 2, %edx
test %edx, %edx
jz _op_lookup_done
mov %rax, (%LOOKUP, %rdx, 8) // cache value
_op_lookup_done:
push %rax
skip 2

0 comments on commit df38737

Please sign in to comment.