diff options
Diffstat (limited to 'src/qcommon/vm_x86_64.c')
-rw-r--r-- | src/qcommon/vm_x86_64.c | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/src/qcommon/vm_x86_64.c b/src/qcommon/vm_x86_64.c index ce9680e5..53239aae 100644 --- a/src/qcommon/vm_x86_64.c +++ b/src/qcommon/vm_x86_64.c @@ -78,7 +78,7 @@ static void VM_Destroy_Compiled(vm_t* self); rsi scratch rdi program frame pointer (programStack) r8 pointer data (vm->dataBase) - r9 opStack data base (opStack) + r9 opStack base (opStack) r10 start of generated code */ @@ -258,10 +258,10 @@ void emit(const char* fmt, ...) #endif #define STACK_PUSH(bytes) \ - emit("addb $0x%x, %%bl", bytes); \ + emit("addb $0x%x, %%bl", bytes >> 2); \ #define STACK_POP(bytes) \ - emit("subb $0x%x, %%bl", bytes); \ + emit("subb $0x%x, %%bl", bytes >> 2); \ #define CHECK_INSTR_REG(reg) \ emit("cmpl $%u, %%"#reg, header->instructionCount); \ @@ -296,7 +296,7 @@ void emit(const char* fmt, ...) got_const = 0; \ vm->instructionPointers[instruction-1] = assembler_get_code_size(); \ STACK_PUSH(4); \ - emit("movl $%d, (%%r9, %%rbx, 1)", const_value); \ + emit("movl $%d, (%%r9, %%rbx, 4)", const_value); \ } #else #define MAYBE_EMIT_CONST() @@ -306,8 +306,8 @@ void emit(const char* fmt, ...) #define IJ(op) \ MAYBE_EMIT_CONST(); \ STACK_POP(8); \ - emit("movl 4(%%r9, %%rbx, 1), %%eax"); \ - emit("cmpl 8(%%r9, %%rbx, 1), %%eax"); \ + emit("movl 4(%%r9, %%rbx, 4), %%eax"); \ + emit("cmpl 8(%%r9, %%rbx, 4), %%eax"); \ emit(op " i_%08x", instruction+1); \ JMPIARG(); \ neednilabel = 1 @@ -316,8 +316,8 @@ void emit(const char* fmt, ...) #define FJ(bits, op) \ MAYBE_EMIT_CONST(); \ STACK_POP(8); \ - emit("flds 4(%%r9, %%rbx, 1)");\ - emit("fcomps 8(%%r9, %%rbx, 1)");\ + emit("flds 4(%%r9, %%rbx, 4)");\ + emit("fcomps 8(%%r9, %%rbx, 4)");\ emit("fnstsw %%ax");\ emit("testb $" #bits ", %%ah");\ emit(op " i_%08x", instruction+1);\ @@ -329,8 +329,8 @@ void emit(const char* fmt, ...) #define XJ(op) \ MAYBE_EMIT_CONST(); \ STACK_POP(8); \ - emit("movss 4(%%r9, %%rbx, 1), %%xmm0");\ - emit("ucomiss 8(%%r9, %%rbx, 1), %%xmm0");\ + emit("movss 4(%%r9, %%rbx, 4), %%xmm0");\ + emit("ucomiss 8(%%r9, %%rbx, 4), %%xmm0");\ emit("jp i_%08x", instruction+1);\ emit(op " i_%08x", instruction+1);\ JMPIARG(); \ @@ -339,35 +339,35 @@ void emit(const char* fmt, ...) #define SIMPLE(op) \ MAYBE_EMIT_CONST(); \ - emit("movl (%%r9, %%rbx, 1), %%eax"); \ + emit("movl (%%r9, %%rbx, 4), %%eax"); \ STACK_POP(4); \ - emit(op " %%eax, (%%r9, %%rbx, 1)") + emit(op " %%eax, (%%r9, %%rbx, 4)") #ifdef USE_X87 #define FSIMPLE(op) \ MAYBE_EMIT_CONST(); \ STACK_POP(4); \ - emit("flds (%%r9, %%rbx, 1)"); \ - emit(op " 4(%%r9, %%rbx, 1)"); \ - emit("fstps (%%r9, %%rbx, 1)") + emit("flds (%%r9, %%rbx, 4)"); \ + emit(op " 4(%%r9, %%rbx, 4)"); \ + emit("fstps (%%r9, %%rbx, 4)") #define XSIMPLE(op) #else #define FSIMPLE(op) #define XSIMPLE(op) \ MAYBE_EMIT_CONST(); \ STACK_POP(4); \ - emit("movss (%%r9, %%rbx, 1), %%xmm0"); \ - emit(op " 4(%%r9, %%rbx, 1), %%xmm0"); \ - emit("movss %%xmm0, (%%r9, %%rbx, 1)") + emit("movss (%%r9, %%rbx, 4), %%xmm0"); \ + emit(op " 4(%%r9, %%rbx, 4), %%xmm0"); \ + emit("movss %%xmm0, (%%r9, %%rbx, 4)") #endif #define SHIFT(op) \ MAYBE_EMIT_CONST(); \ STACK_POP(4); \ - emit("movl 4(%%r9, %%rbx, 1), %%ecx"); \ - emit("movl (%%r9, %%rbx, 1), %%eax"); \ + emit("movl 4(%%r9, %%rbx, 4), %%ecx"); \ + emit("movl (%%r9, %%rbx, 4), %%eax"); \ emit(op " %%cl, %%eax"); \ - emit("movl %%eax, (%%r9, %%rbx, 1)") + emit("movl %%eax, (%%r9, %%rbx, 4)") #ifdef DEBUG_VM #define NOTIMPL(x) \ @@ -565,7 +565,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { else { MAYBE_EMIT_CONST(); - emit("movl (%%r9, %%rbx, 1), %%eax"); // get instr from stack + emit("movl (%%r9, %%rbx, 4), %%eax"); // get instr from stack STACK_POP(4); emit("orl %%eax, %%eax"); @@ -606,7 +606,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { emit("pop %%rdi"); // emit("frstor 4(%%r9, %%rsi, 1)"); STACK_PUSH(4); - emit("movl %%eax, (%%r9, %%rbx, 1)"); // store return value + emit("movl %%eax, (%%r9, %%rbx, 4)"); // store return value neednilabel = 1; break; case OP_PUSH: @@ -624,7 +624,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { const_value = iarg; #else STACK_PUSH(4); - emit("movl $%d, (%%r9, %%rbx, 1)", iarg); + emit("movl $%d, (%%r9, %%rbx, 4)", iarg); #endif break; case OP_LOCAL: @@ -632,7 +632,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { emit("movl %%edi, %%esi"); emit("addl $%d,%%esi", iarg); STACK_PUSH(4); - emit("movl %%esi, (%%r9, %%rbx, 1)"); + emit("movl %%esi, (%%r9, %%rbx, 4)"); break; case OP_JUMP: if(got_const) { @@ -640,7 +640,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { got_const = 0; JMPIARG(); } else { - emit("movl (%%r9, %%rbx, 1), %%eax"); // get instr from stack + emit("movl (%%r9, %%rbx, 4), %%eax"); // get instr from stack STACK_POP(4); PREPARE_JMP(eax); @@ -686,8 +686,8 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { #ifndef USE_X87 MAYBE_EMIT_CONST(); STACK_POP(8); - emit("movss 4(%%r9, %%rbx, 1), %%xmm0"); - emit("ucomiss 8(%%r9, %%rbx, 1), %%xmm0"); + emit("movss 4(%%r9, %%rbx, 4), %%xmm0"); + emit("ucomiss 8(%%r9, %%rbx, 4), %%xmm0"); emit("jp dojump_i_%08x", instruction); emit("jz i_%08x", instruction+1); emit("dojump_i_%08x:", instruction); @@ -713,54 +713,54 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { break; case OP_LOAD1: MAYBE_EMIT_CONST(); - emit("movl (%%r9, %%rbx, 1), %%eax"); // get value from stack + emit("movl (%%r9, %%rbx, 4), %%eax"); // get value from stack RANGECHECK(eax, 1); emit("movb (%%r8, %%rax, 1), %%al"); // deref into eax emit("andq $255, %%rax"); - emit("movl %%eax, (%%r9, %%rbx, 1)"); // store on stack + emit("movl %%eax, (%%r9, %%rbx, 4)"); // store on stack break; case OP_LOAD2: MAYBE_EMIT_CONST(); - emit("movl (%%r9, %%rbx, 1), %%eax"); // get value from stack + emit("movl (%%r9, %%rbx, 4), %%eax"); // get value from stack RANGECHECK(eax, 2); emit("movw (%%r8, %%rax, 1), %%ax"); // deref into eax - emit("movl %%eax, (%%r9, %%rbx, 1)"); // store on stack + emit("movl %%eax, (%%r9, %%rbx, 4)"); // store on stack break; case OP_LOAD4: MAYBE_EMIT_CONST(); - emit("movl (%%r9, %%rbx, 1), %%eax"); // get value from stack + emit("movl (%%r9, %%rbx, 4), %%eax"); // get value from stack RANGECHECK(eax, 4); // not a pointer!? emit("movl (%%r8, %%rax, 1), %%eax"); // deref into eax - emit("movl %%eax, (%%r9, %%rbx, 1)"); // store on stack + emit("movl %%eax, (%%r9, %%rbx, 4)"); // store on stack break; case OP_STORE1: MAYBE_EMIT_CONST(); - emit("movl (%%r9, %%rbx, 1), %%eax"); // get value from stack + emit("movl (%%r9, %%rbx, 4), %%eax"); // get value from stack STACK_POP(8); emit("andq $255, %%rax"); - emit("movl 4(%%r9, %%rbx, 1), %%esi"); // get pointer from stack + emit("movl 4(%%r9, %%rbx, 4), %%esi"); // get pointer from stack RANGECHECK(esi, 1); emit("movb %%al, (%%r8, %%rsi, 1)"); // store in memory break; case OP_STORE2: MAYBE_EMIT_CONST(); - emit("movl (%%r9, %%rbx, 1), %%eax"); // get value from stack + emit("movl (%%r9, %%rbx, 4), %%eax"); // get value from stack STACK_POP(8); - emit("movl 4(%%r9, %%rbx, 1), %%esi"); // get pointer from stack + emit("movl 4(%%r9, %%rbx, 4), %%esi"); // get pointer from stack RANGECHECK(esi, 2); emit("movw %%ax, (%%r8, %%rsi, 1)"); // store in memory break; case OP_STORE4: MAYBE_EMIT_CONST(); - emit("movl (%%r9, %%rbx, 1), %%eax"); // get value from stack + emit("movl (%%r9, %%rbx, 4), %%eax"); // get value from stack STACK_POP(8); - emit("movl 4(%%r9, %%rbx, 1), %%esi"); // get pointer from stack + emit("movl 4(%%r9, %%rbx, 4), %%esi"); // get pointer from stack RANGECHECK(esi, 4); emit("movl %%eax, (%%r8, %%rsi, 1)"); // store in memory break; case OP_ARG: MAYBE_EMIT_CONST(); - emit("movl (%%r9, %%rbx, 1), %%eax"); // get value from stack + emit("movl (%%r9, %%rbx, 4), %%eax"); // get value from stack STACK_POP(4); emit("movl $0x%hx, %%esi", barg); emit("addl %%edi, %%esi"); @@ -780,8 +780,8 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { emit("andq $127, %%rsi"); // | emit("subq %%rsi, %%rsp"); // <-+ emit("push %%rsi"); - emit("movl 4(%%r9, %%rbx, 1), %%edi"); // 1st argument dest - emit("movl 8(%%r9, %%rbx, 1), %%rsi"); // 2nd argument src + emit("movl 4(%%r9, %%rbx, 4), %%edi"); // 1st argument dest + emit("movl 8(%%r9, %%rbx, 4), %%rsi"); // 2nd argument src emit("movl $%d, %%edx", iarg); // 3rd argument count emit("movq $%"PRIu64", %%rax", (intptr_t) block_copy_vm); emit("callq *%%rax"); @@ -795,21 +795,21 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { break; case OP_SEX8: MAYBE_EMIT_CONST(); - emit("movw (%%r9, %%rbx, 1), %%ax"); + emit("movw (%%r9, %%rbx, 4), %%ax"); emit("andq $255, %%rax"); emit("cbw"); emit("cwde"); - emit("movl %%eax, (%%r9, %%rbx, 1)"); + emit("movl %%eax, (%%r9, %%rbx, 4)"); break; case OP_SEX16: MAYBE_EMIT_CONST(); - emit("movw (%%r9, %%rbx, 1), %%ax"); + emit("movw (%%r9, %%rbx, 4), %%ax"); emit("cwde"); - emit("movl %%eax, (%%r9, %%rbx, 1)"); + emit("movl %%eax, (%%r9, %%rbx, 4)"); break; case OP_NEGI: MAYBE_EMIT_CONST(); - emit("negl (%%r9, %%rbx, 1)"); + emit("negl (%%r9, %%rbx, 4)"); break; case OP_ADD: SIMPLE("addl"); @@ -820,49 +820,49 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { case OP_DIVI: MAYBE_EMIT_CONST(); STACK_POP(4); - emit("movl (%%r9, %%rbx, 1), %%eax"); + emit("movl (%%r9, %%rbx, 4), %%eax"); emit("cdq"); - emit("idivl 4(%%r9, %%rbx, 1)"); - emit("movl %%eax, (%%r9, %%rbx, 1)"); + emit("idivl 4(%%r9, %%rbx, 4)"); + emit("movl %%eax, (%%r9, %%rbx, 4)"); break; case OP_DIVU: MAYBE_EMIT_CONST(); STACK_POP(4); - emit("movl (%%r9, %%rbx, 1), %%eax"); + emit("movl (%%r9, %%rbx, 4), %%eax"); emit("xorq %%rdx, %%rdx"); - emit("divl 4(%%r9, %%rbx, 1)"); - emit("movl %%eax, (%%r9, %%rbx, 1)"); + emit("divl 4(%%r9, %%rbx, 4)"); + emit("movl %%eax, (%%r9, %%rbx, 4)"); break; case OP_MODI: MAYBE_EMIT_CONST(); STACK_POP(4); - emit("movl (%%r9, %%rbx, 1), %%eax"); + emit("movl (%%r9, %%rbx, 4), %%eax"); emit("xorl %%edx, %%edx"); emit("cdq"); - emit("idivl 4(%%r9, %%rbx, 1)"); - emit("movl %%edx, (%%r9, %%rbx, 1)"); + emit("idivl 4(%%r9, %%rbx, 4)"); + emit("movl %%edx, (%%r9, %%rbx, 4)"); break; case OP_MODU: MAYBE_EMIT_CONST(); STACK_POP(4); - emit("movl (%%r9, %%rbx, 1), %%eax"); + emit("movl (%%r9, %%rbx, 4), %%eax"); emit("xorl %%edx, %%edx"); - emit("divl 4(%%r9, %%rbx, 1)"); - emit("movl %%edx, (%%r9, %%rbx, 1)"); + emit("divl 4(%%r9, %%rbx, 4)"); + emit("movl %%edx, (%%r9, %%rbx, 4)"); break; case OP_MULI: MAYBE_EMIT_CONST(); STACK_POP(4); - emit("movl (%%r9, %%rbx, 1), %%eax"); - emit("imull 4(%%r9, %%rbx, 1)"); - emit("movl %%eax, (%%r9, %%rbx, 1)"); + emit("movl (%%r9, %%rbx, 4), %%eax"); + emit("imull 4(%%r9, %%rbx, 4)"); + emit("movl %%eax, (%%r9, %%rbx, 4)"); break; case OP_MULU: MAYBE_EMIT_CONST(); STACK_POP(4); - emit("movl (%%r9, %%rbx, 1), %%eax"); - emit("mull 4(%%r9, %%rbx, 1)"); - emit("movl %%eax, (%%r9, %%rbx, 1)"); + emit("movl (%%r9, %%rbx, 4), %%eax"); + emit("mull 4(%%r9, %%rbx, 4)"); + emit("movl %%eax, (%%r9, %%rbx, 4)"); break; case OP_BAND: SIMPLE("andl"); @@ -875,7 +875,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { break; case OP_BCOM: MAYBE_EMIT_CONST(); - emit("notl (%%r9, %%rbx, 1)"); + emit("notl (%%r9, %%rbx, 4)"); break; case OP_LSH: SHIFT("shl"); @@ -889,12 +889,12 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { case OP_NEGF: MAYBE_EMIT_CONST(); #ifdef USE_X87 - emit("flds (%%r9, %%rbx, 1)"); + emit("flds (%%r9, %%rbx, 4)"); emit("fchs"); - emit("fstps (%%r9, %%rbx, 1)"); + emit("fstps (%%r9, %%rbx, 4)"); #else emit("movl $0x80000000, %%eax"); - emit("xorl %%eax, (%%r9, %%rbx, 1)"); + emit("xorl %%eax, (%%r9, %%rbx, 4)"); #endif break; case OP_ADDF: @@ -916,27 +916,27 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) { case OP_CVIF: MAYBE_EMIT_CONST(); #ifdef USE_X87 - emit("filds (%%r9, %%rbx, 1)"); - emit("fstps (%%r9, %%rbx, 1)"); + emit("filds (%%r9, %%rbx, 4)"); + emit("fstps (%%r9, %%rbx, 4)"); #else - emit("movl (%%r9, %%rbx, 1), %%eax"); + emit("movl (%%r9, %%rbx, 4), %%eax"); emit("cvtsi2ss %%eax, %%xmm0"); - emit("movss %%xmm0, (%%r9, %%rbx, 1)"); + emit("movss %%xmm0, (%%r9, %%rbx, 4)"); #endif break; case OP_CVFI: MAYBE_EMIT_CONST(); #ifdef USE_X87 - emit("flds (%%r9, %%rbx, 1)"); - emit("fnstcw 4(%%r9, %%rbx, 1)"); - emit("movw $0x0F7F, 8(%%r9, %%rbx, 1)"); // round toward zero - emit("fldcw 8(%%r9, %%rbx, 1)"); - emit("fistpl (%%r9, %%rbx, 1)"); - emit("fldcw 4(%%r9, %%rbx, 1)"); + emit("flds (%%r9, %%rbx, 4)"); + emit("fnstcw 4(%%r9, %%rbx, 4)"); + emit("movw $0x0F7F, 8(%%r9, %%rbx, 4)"); // round toward zero + emit("fldcw 8(%%r9, %%rbx, 4)"); + emit("fistpl (%%r9, %%rbx, 4)"); + emit("fldcw 4(%%r9, %%rbx, 4)"); #else - emit("movss (%%r9, %%rbx, 1), %%xmm0"); + emit("movss (%%r9, %%rbx, 4), %%xmm0"); emit("cvttss2si %%xmm0, %%eax"); - emit("movl %%eax, (%%r9, %%rbx, 1)"); + emit("movl %%eax, (%%r9, %%rbx, 4)"); #endif break; default: @@ -1095,7 +1095,7 @@ int VM_CallCompiled( vm_t *vm, int *args ) { : "g" (entryPoint), "g" (opStack), "g" (vm->dataBase), "g" (programStack) : "%rsi", "%rdi", "%rax", "%rbx", "%rcx", "%rdx", "%r8", "%r9", "%r10", "%r15", "%xmm0" ); - if(opStackRet != 4 || *opStack != 0xDEADBEEF) + if(opStackRet != 1 || *opStack != 0xDEADBEEF) Com_Error(ERR_DROP, "opStack corrupted in compiled code (offset %ld)", opStackRet); if ( programStack != stackOnEntry - 48 ) { |