aboutsummaryrefslogtreecommitdiff
path: root/py/asmx86.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-10-13 13:59:19 +1100
committerDamien George <damien.p.george@gmail.com>2018-10-13 15:16:33 +1100
commit355eb8eafb1a0b0e096cd452d1107ab45bbf72c4 (patch)
treeb79f788c6347514d43c78f91e21ebdd7e31365f4 /py/asmx86.c
parentb7c6f859d06a3a4270f98561827ba5ae360fee74 (diff)
py/asmx86: Change indirect calls to load fun ptr from the native table.
Instead of storing the function pointer directly in the assembly code. This makes the generated code more independent of the runtime (so easier to relocate the code), and reduces the generated code size.
Diffstat (limited to 'py/asmx86.c')
-rw-r--r--py/asmx86.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/py/asmx86.c b/py/asmx86.c
index 81ff1d00d..60917fdeb 100644
--- a/py/asmx86.c
+++ b/py/asmx86.c
@@ -494,7 +494,7 @@ void asm_x86_push_local_addr(asm_x86_t *as, int local_num, int temp_r32)
}
#endif
-void asm_x86_call_ind(asm_x86_t *as, void *ptr, mp_uint_t n_args, int temp_r32) {
+void asm_x86_call_ind(asm_x86_t *as, size_t fun_id, mp_uint_t n_args, int temp_r32) {
// TODO align stack on 16-byte boundary before the call
assert(n_args <= 5);
if (n_args > 4) {
@@ -512,20 +512,10 @@ void asm_x86_call_ind(asm_x86_t *as, void *ptr, mp_uint_t n_args, int temp_r32)
if (n_args > 0) {
asm_x86_push_r32(as, ASM_X86_REG_ARG_1);
}
-#ifdef __LP64__
- // We wouldn't run x86 code on an x64 machine. This is here to enable
- // testing of the x86 emitter only.
- asm_x86_mov_i32_to_r32(as, (int32_t)(int64_t)ptr, temp_r32);
-#else
- // If we get here, sizeof(int) == sizeof(void*).
- asm_x86_mov_i32_to_r32(as, (int32_t)ptr, temp_r32);
-#endif
+
+ // Load the pointer to the function and make the call
+ asm_x86_mov_mem32_to_r32(as, ASM_X86_REG_EBP, fun_id * WORD_SIZE, temp_r32);
asm_x86_write_byte_2(as, OPCODE_CALL_RM32, MODRM_R32(2) | MODRM_RM_REG | MODRM_RM_R32(temp_r32));
- // this reduces code size by 2 bytes per call, but doesn't seem to speed it up at all
- /*
- asm_x86_write_byte_1(as, OPCODE_CALL_REL32);
- asm_x86_write_word32(as, ptr - (void*)(as->code_base + as->base.code_offset + 4));
- */
// the caller must clean up the stack
if (n_args > 0) {