- use local variable for load_ptr,store_ptr, now that they exist.

- add BLUR_DYNAMIC_TRANSLATE1, a simple code generator that writes to
  translate1.c
- add BLUR_DYNAMIC_TRANSLATE1_TEST that is (statically) linked with
  translate1.c
This commit is contained in:
Bryce Denney 2002-04-17 04:18:34 +00:00
parent 2a3524e2d2
commit ac8a29fb3d

View File

@ -1,6 +1,6 @@
/*
*
* $Id: blur-opcode.c,v 1.1 2002-04-17 02:31:36 bdenney Exp $
* $Id: blur-opcode.c,v 1.2 2002-04-17 04:18:34 bdenney Exp $
*
*/
@ -414,8 +414,8 @@ void blur_opcode_translated2 ()
#define BEFORE_EXEC() do { \
/* set up state */ \
accum = 0xfab28342; /* start with trash in accum */ \
state->load_ptr = &array[x][y]; \
state->store_ptr = &array2[x][y]; \
load_ptr = &array[x][y]; \
store_ptr = &array2[x][y]; \
} while (0)
#define AFTER_EXEC() do { \
@ -444,65 +444,65 @@ void blur_instructions_translated3 (State *state)
// OP_MOVE_REL, -1, -1,
x += -1;
y += -1;
state->load_ptr = &array[x][y];
load_ptr = &array[x][y];
// OP_SET_ACCUM, 0,
accum = 0;
// OP_ADD_DATA,
accum += *state->load_ptr++;
accum += *load_ptr++;
// OP_MOVE_REL, 0, 1,
x += 0;
y += 1;
state->load_ptr = &array[x][y];
load_ptr = &array[x][y];
// OP_ADD_DATA,
accum += *state->load_ptr++;
accum += *load_ptr++;
// OP_MOVE_REL, 0, 1,
x += 0;
y += 1;
state->load_ptr = &array[x][y];
load_ptr = &array[x][y];
// OP_ADD_DATA,
accum += *state->load_ptr++;
accum += *load_ptr++;
// OP_MOVE_REL, 1, -2,
x += 1;
y += -2;
state->load_ptr = &array[x][y];
load_ptr = &array[x][y];
// OP_ADD_DATA,
accum += *state->load_ptr++;
accum += *load_ptr++;
// OP_MOVE_REL, 0, 1,
x += 0;
y += 1;
state->load_ptr = &array[x][y];
load_ptr = &array[x][y];
// OP_ADD_DATA,
accum += *state->load_ptr++;
accum += *load_ptr++;
// OP_MOVE_REL, 0, 1,
x += 0;
y += 1;
state->load_ptr = &array[x][y];
load_ptr = &array[x][y];
// OP_ADD_DATA,
accum += *state->load_ptr++;
accum += *load_ptr++;
// OP_MOVE_REL, 1, -2,
x += 1;
y += -2;
state->load_ptr = &array[x][y];
load_ptr = &array[x][y];
// OP_ADD_DATA,
accum += *state->load_ptr++;
accum += *load_ptr++;
// OP_MOVE_REL, 0, 1,
x += 0;
y += 1;
state->load_ptr = &array[x][y];
load_ptr = &array[x][y];
// OP_ADD_DATA,
accum += *state->load_ptr++;
accum += *load_ptr++;
// OP_MOVE_REL, 0, 1,
x += 0;
y += 1;
state->load_ptr = &array[x][y];
load_ptr = &array[x][y];
// OP_ADD_DATA,
accum += *state->load_ptr++;
accum += *load_ptr++;
// OP_STORE_DATA,
*(state->store_ptr++) = accum;
*(store_ptr++) = accum;
// OP_MOVE_REL, -1, -1
x += -1;
y += -1;
state->load_ptr = &array[state->x][y];
load_ptr = &array[state->x][y];
// OP_END
AFTER_EXEC();
}
@ -523,6 +523,82 @@ void blur_opcode_translated3 ()
#endif // ifdef BLUR_TRANSLATED3
#ifdef BLUR_DYNAMIC_TRANSLATE1
static int unique_fn_id = 283473;
void blur_dynamic_translate1 ()
{
// csrc is the main text file containing the translated code.
FILE *csrc = fopen ("translate1.c", "w");
State state;
int done = 0;
int *pc;
assert (csrc!=NULL);
fprintf (csrc, "// code generated by blur-opcode.c, blur_dynamic_translate1()\n");
fprintf (csrc, "#include \"translate1-defs.h\"\n");
fprintf (csrc, "void translate%d (State *state) {\n", unique_fn_id);
fprintf (csrc, "TOP_OF_TRANSLATED_FUNCTION();\n");
pc = &blur_instructions[0];
while (!done) {
switch (*pc++) {
case OP_MOVE_REL:
fprintf (csrc, "DO_MOVE_REL(%d,%d);\n", *pc++, *pc++);
break;
case OP_SET_ACCUM:
fprintf (csrc, "DO_SET_ACCUM(%d);\n", *pc++);
break;
case OP_ADD_DATA:
fprintf (csrc, "DO_ADD_DATA();\n");
break;
case OP_SUBTRACT_DATA:
fprintf (csrc, "DO_SUBTRACT_DATA();\n");
break;
case OP_MULTIPLY_DATA:
fprintf (csrc, "DO_MULTIPLY_DATA();\n");
break;
case OP_STORE_DATA:
fprintf (csrc, "DO_STORE_DATA();\n");
break;
case OP_END:
done = 1;
break;
default:
assert (0);
}
}
fprintf (csrc, "BOTTOM_OF_TRANSLATED_FUNCTION();\n");
fprintf (csrc, "} // end of translate%d\n", unique_fn_id);
unique_fn_id++;
fclose (csrc);
}
#endif
#ifdef BLUR_DYNAMIC_TRANSLATE1_TEST
extern void translate284472 (State *state);
void blur_dynamic_translate1_test ()
{
int sum;
int x,y,x2,y2;
State state;
for (x=1; x<MAX-1; x++)
for (y=1; y<MAX-1; y++)
{
int *pc;
int done = 0;
sum = 0;
// set up state
state.x = x;
state.y = y;
state.accum = 0xfab28342; // start with trash in accum
state.load_ptr = &array[x][y];
state.store_ptr = &array2[x][y];
// call translated function
translate284472 (&state);
}
}
#endif
void fill_array()
{
@ -583,6 +659,10 @@ int main (int argc, char *argv[])
blur_opcode_translated2();
#elif defined BLUR_TRANSLATED3
blur_opcode_translated3();
#elif defined BLUR_DYNAMIC_TRANSLATE1
blur_dynamic_translate1 ();
#elif defined BLUR_DYNAMIC_TRANSLATE1_TEST
blur_dynamic_translate1_test ();
#else
blur_simple();
#endif