JIT memory code is properly aligned now to 16 bytes
authorBorja Ferrer <faluco@alliedmods.net>
Wed May 23 23:42:04 2007 +0000 (2007-05-23)
changeset 8530bca7912df0e
parent 852 9a7a93363979
child 854 ffeae23d84b3
JIT memory code is properly aligned now to 16 bytes
sourcepawn/jit/x86/jit_x86.cpp
sourcepawn/jit/x86/opcode_helpers.cpp
sourcepawn/jit/x86/opcode_helpers.h
     1.1 --- a/sourcepawn/jit/x86/jit_x86.cpp	Wed May 23 22:08:05 2007 +0000
     1.2 +++ b/sourcepawn/jit/x86/jit_x86.cpp	Wed May 23 23:42:04 2007 +0000
     1.3 @@ -242,17 +242,18 @@
     1.4  
     1.5  inline void WriteOp_Proc(JitWriter *jit)
     1.6  {
     1.7 -	/* align this to four byte boundaries!
     1.8 -	 * This is a decent optimization - x86 likes calls to be properly aligned, otherwise there's an alignment exception
     1.9 -	 * Since all calls are jumped to by relocation, the nops/garbage will never be hit by the runtime process.
    1.10 -	 * Just in case, we guard this memory with INT3 to break into the debugger.
    1.11 -	 */
    1.12 +	CompData *co = (CompData *)jit->data;
    1.13 +
    1.14 +	/* Specialized code to align this taking in account the function magic number */
    1.15  	jitoffs_t cur_offs = jit->get_outputpos();
    1.16 -	CompData *co = (CompData *)jit->data;
    1.17 -	if (cur_offs % 4)
    1.18 +	jitoffs_t offset = ((cur_offs & 0xFFFFFFF8) + 8) - cur_offs;
    1.19 +	if (!((offset + cur_offs) & 8))
    1.20  	{
    1.21 -		cur_offs = 4 - (cur_offs % 4);
    1.22 -		for (unsigned int i=0; i<cur_offs; i++)
    1.23 +		offset += 8;
    1.24 +	}
    1.25 +	if (offset)
    1.26 +	{
    1.27 +		for (jit_uint32_t i=0; i<offset; i++)
    1.28  		{
    1.29  			jit->write_ubyte(IA32_INT3);
    1.30  		}
    1.31 @@ -1301,6 +1302,8 @@
    1.32  
    1.33  inline void WriteOp_Halt(JitWriter *jit)
    1.34  {
    1.35 +	AlignMe(jit);
    1.36 +
    1.37  	//mov ecx, [esi+ret]
    1.38  	//mov [ecx], eax
    1.39  	IA32_Mov_Reg_Rm_Disp8(jit, AMX_REG_TMP, AMX_REG_INFO, AMX_INFO_RETVAL);
    1.40 @@ -2195,6 +2198,8 @@
    1.41  
    1.42  void WriteErrorRoutines(CompData *data, JitWriter *jit)
    1.43  {
    1.44 +	AlignMe(jit);
    1.45 +
    1.46  	data->jit_error_divzero = jit->get_outputpos();
    1.47  	Write_SetError(jit, SP_ERROR_DIVIDE_BY_ZERO);
    1.48  
    1.49 @@ -2267,6 +2272,7 @@
    1.50  	/* Write the SYSREQ.N opcode if we need to */
    1.51  	if (!(data->inline_level & JIT_INLINE_NATIVES))
    1.52  	{
    1.53 +		AlignMe(jit);
    1.54  		data->jit_sysreq_n = jit->get_outputpos();
    1.55  		WriteOp_Sysreq_N_Function(jit);
    1.56  	}
    1.57 @@ -2274,23 +2280,28 @@
    1.58  	/* Write the debug section if we need it */
    1.59  	if (data->debug == true)
    1.60  	{
    1.61 +		AlignMe(jit);
    1.62  		data->jit_break = jit->get_outputpos();
    1.63  		Write_BreakDebug(jit);
    1.64  	}
    1.65  
    1.66  	/* Plugins compiled with -O0 will need this! */
    1.67 +	AlignMe(jit);
    1.68  	data->jit_sysreq_c = jit->get_outputpos();
    1.69  	WriteOp_Sysreq_C_Function(jit);
    1.70  
    1.71 +	AlignMe(jit);
    1.72  	data->jit_genarray = jit->get_outputpos();
    1.73  	WriteIntrinsic_GenArray(jit);
    1.74  
    1.75  	/* Write error checking routines that are called to */
    1.76  	if (!(data->inline_level & JIT_INLINE_ERRORCHECKS))
    1.77  	{
    1.78 +		AlignMe(jit);
    1.79  		data->jit_verify_addr_eax = jit->get_outputpos();
    1.80  		Write_Check_VerifyAddr(jit, REG_EAX);
    1.81  	
    1.82 +		AlignMe(jit);
    1.83  		data->jit_verify_addr_edx = jit->get_outputpos();
    1.84  		Write_Check_VerifyAddr(jit, REG_EDX);
    1.85  	}
    1.86 @@ -2648,7 +2659,7 @@
    1.87  		} else if (!strcmp(name, "RoundToFloor")) {
    1.88  			data->jit_float_table[i].found = true;
    1.89  			data->jit_float_table[i].index = OP_RND_TO_FLOOR;
    1.90 -		} else if (!strcmp(name, "RountToNearest")) {
    1.91 +		} else if (!strcmp(name, "RoundToNearest")) {
    1.92  			data->jit_float_table[i].found = true;
    1.93  			data->jit_float_table[i].index = OP_RND_TO_NEAREST;
    1.94  		}
    1.95 @@ -2768,5 +2779,5 @@
    1.96  
    1.97  const char *JITX86::GetCPUOptimizations()
    1.98  {
    1.99 -	return "Generic 80486";
   1.100 +	return "Generic i686";
   1.101  }
     2.1 --- a/sourcepawn/jit/x86/opcode_helpers.cpp	Wed May 23 22:08:05 2007 +0000
     2.2 +++ b/sourcepawn/jit/x86/opcode_helpers.cpp	Wed May 23 23:42:04 2007 +0000
     2.3 @@ -806,3 +806,17 @@
     2.4  	jit->write_int32(0);
     2.5  	jit->write_int32(1);
     2.6  }
     2.7 +
     2.8 +void AlignMe(JitWriter *jit)
     2.9 +{
    2.10 +	jitoffs_t cur_offs = jit->get_outputpos();
    2.11 +	jitoffs_t offset = ((cur_offs & 0xFFFFFFF0) + 16) - cur_offs;
    2.12 +
    2.13 +	if (offset)
    2.14 +	{
    2.15 +		for (jit_uint32_t i=0; i<offset; i++)
    2.16 +		{
    2.17 +			jit->write_ubyte(IA32_INT3);
    2.18 +		}
    2.19 +	}
    2.20 +}
     3.1 --- a/sourcepawn/jit/x86/opcode_helpers.h	Wed May 23 22:08:05 2007 +0000
     3.2 +++ b/sourcepawn/jit/x86/opcode_helpers.h	Wed May 23 23:42:04 2007 +0000
     3.3 @@ -96,6 +96,11 @@
     3.4  */
     3.5  void Write_RoundingTable(JitWriter *jit);
     3.6  
     3.7 +/** 
     3.8 +* Aligns the current code position to 16 bytes.
     3.9 +*/
    3.10 +void AlignMe(JitWriter *jit);
    3.11 +
    3.12  /**
    3.13   * Legend for Statuses:
    3.14   * ****** *** ********