Fix script interpreter stack for x86_64

Alot of stack and event variables are pointers. Align the size of
all script and event variable types to sizeof(intptr_t) so that
the CPU needs only one fetch insn on 64bit archs.

Tested on x86 and x86_64 and found no different script behaviours
compared to the binary from id.
Savegames on x86_64 do work, but are not compatible to x86 and vice
versa (among other issues, the stack is written to file as-is).
x86 builds can still load savegames from the official binary and
vice versa.
This commit is contained in:
dhewg 2011-12-01 21:30:02 +01:00 committed by Daniel Gibson
parent dc86a8a02c
commit f8efcf5e90
12 changed files with 240 additions and 110 deletions

View file

@ -30,7 +30,7 @@ If you have questions concerning this license or the applicable additional terms
#define __SCRIPT_INTERPRETER_H__
#define MAX_STACK_DEPTH 64
#define LOCALSTACK_SIZE 6144
#define LOCALSTACK_SIZE (6144 * 2)
typedef struct prstack_s {
int s;
@ -60,7 +60,8 @@ private:
void PopParms( int numParms );
void PushString( const char *string );
void Push( int value );
void PushVector( const idVec3 &vector );
void Push( intptr_t value );
const char *FloatToString( float value );
void AppendString( idVarDef *def, const char *from );
void SetString( idVarDef *def, const char *from );
@ -135,12 +136,25 @@ ID_INLINE void idInterpreter::PopParms( int numParms ) {
idInterpreter::Push
====================
*/
ID_INLINE void idInterpreter::Push( int value ) {
if ( localstackUsed + sizeof( int ) > LOCALSTACK_SIZE ) {
ID_INLINE void idInterpreter::Push( intptr_t value ) {
if ( localstackUsed + sizeof( intptr_t ) > LOCALSTACK_SIZE ) {
Error( "Push: locals stack overflow\n" );
}
*( int * )&localstack[ localstackUsed ] = value;
localstackUsed += sizeof( int );
*( intptr_t * )&localstack[ localstackUsed ] = value;
localstackUsed += sizeof( intptr_t );
}
/*
====================
idInterpreter::PushVector
====================
*/
ID_INLINE void idInterpreter::PushVector( const idVec3 &vector ) {
if ( localstackUsed + E_EVENT_SIZEOF_VEC > LOCALSTACK_SIZE ) {
Error( "Push: locals stack overflow\n" );
}
*( idVec3 * )&localstack[ localstackUsed ] = vector;
localstackUsed += E_EVENT_SIZEOF_VEC;
}
/*