[quake3-commits] r1995 - trunk/code/qcommon

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue May 17 20:17:02 EDT 2011


Author: thilo
Date: 2011-05-17 20:17:02 -0400 (Tue, 17 May 2011)
New Revision: 1995

Modified:
   trunk/code/qcommon/vm_local.h
   trunk/code/qcommon/vm_x86_64.c
Log:
Use scaled indexing mode n=4 for addressing opStack, this way we can use the 8 bit offset value in %%bl to address an OPSTACK_SIZE of 1024 which was the old value.


Modified: trunk/code/qcommon/vm_local.h
===================================================================
--- trunk/code/qcommon/vm_local.h	2011-05-17 12:07:56 UTC (rev 1994)
+++ trunk/code/qcommon/vm_local.h	2011-05-18 00:17:02 UTC (rev 1995)
@@ -24,7 +24,7 @@
 
 // don't change, this is hardcoded into x86 VMs, opStack protection relies
 // on this
-#define	OPSTACK_SIZE	256
+#define	OPSTACK_SIZE	1024
 #define	OPSTACK_MASK	(OPSTACK_SIZE-1)
 
 // don't change

Modified: trunk/code/qcommon/vm_x86_64.c
===================================================================
--- trunk/code/qcommon/vm_x86_64.c	2011-05-17 12:07:56 UTC (rev 1994)
+++ trunk/code/qcommon/vm_x86_64.c	2011-05-18 00:17:02 UTC (rev 1995)
@@ -77,7 +77,7 @@
   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
 */
 
@@ -257,10 +257,10 @@
 #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); \
@@ -295,7 +295,7 @@
 		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()
@@ -305,8 +305,8 @@
 #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
@@ -315,8 +315,8 @@
 #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);\
@@ -328,8 +328,8 @@
 #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(); \
@@ -338,35 +338,35 @@
 
 #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) \
@@ -564,7 +564,7 @@
 				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");
@@ -605,7 +605,7 @@
 				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:
@@ -623,7 +623,7 @@
 				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:
@@ -631,7 +631,7 @@
 				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) {
@@ -639,7 +639,7 @@
 					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);
@@ -685,8 +685,8 @@
 #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);
@@ -712,54 +712,54 @@
 				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");
@@ -779,8 +779,8 @@
 				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");
@@ -794,21 +794,21 @@
 				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");
@@ -819,49 +819,49 @@
 			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");
@@ -874,7 +874,7 @@
 				break;
 			case OP_BCOM:
 				MAYBE_EMIT_CONST();
-				emit("notl (%%r9, %%rbx, 1)");
+				emit("notl (%%r9, %%rbx, 4)");
 				break;
 			case OP_LSH:
 				SHIFT("shl");
@@ -888,12 +888,12 @@
 			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:
@@ -915,27 +915,27 @@
 			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:
@@ -1094,7 +1094,7 @@
 		: "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 ) {



More information about the quake3-commits mailing list