first cut at Anderson's JIT code.

This commit is contained in:
Vitor Santos Costa 2009-04-07 23:55:16 +01:00
parent f97bc596b9
commit b2ad3bd000
9 changed files with 73 additions and 1 deletions

View File

@ -8931,6 +8931,28 @@ Yap_absmi(int inp)
/************************************************************************\
* Native Code Execution *
\************************************************************************/
/* native_me */
BOp(native_me, aFlp);
if (PREG->u.aFlp.n)
EXEC_NATIVE(PREG->u.aFlp.n);
else {
PREG->u.aFlp.n++;
if (PREG->u.aFlp.n == MAX_INVOCATION)
PREG->u.aFlp.n = Yapc_Compile(PREG->u.aFlp.p);
}
PREG = NEXTOP(PREG, aFlp);
GONext();
ENDBOp();
/************************************************************************\
* Basic Primitive Predicates *
\************************************************************************/
@ -11271,7 +11293,7 @@ Yap_absmi(int inp)
d0 = (CELL) (f) (d0,d1);
setregs();
}
if (!d0 || PREG == FAILCODE) {
if (!d0) {
if (PREG != FAILCODE)
PREG = PREG->u.plxxs.f;
JMPNext();

View File

@ -1606,6 +1606,21 @@ a_empty_call(clause_info *clinfo, yamop *code_p, int pass_no, struct intermedia
return code_p;
}
static yamop *
a_cnp(op_numbers opcode, yamop *code_p, int pass_no, struct intermediates *cip)
{
if (pass_no) {
code_p->opc = emit_op(opcode);
code_p->u.aFlp.n = 0;
code_p->u.aFlp.native = NULL;
code_p->u.aFlp.native_next = 0;
code_p->u.aFlp.p = cip->CurrentPred;
}
GONEXT(aFlp);
return code_p;
}
static yamop *
a_pl(op_numbers opcode, PredEntry *pred, yamop *code_p, int pass_no)
{
@ -3376,6 +3391,9 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp
case cut_op:
code_p = a_cut(&clinfo, code_p, pass_no, cip);
break;
case native_op:
code_p = a_cnp(_native_me, code_p, pass_no, cip);
break;
case cutexit_op:
code_p = a_cut(&clinfo, code_p, pass_no, cip);
if (cip->CurrentPred->PredFlags & LogUpdatePredFlag &&

View File

@ -637,6 +637,7 @@ static char *opformat[] =
"unify_last_dbterm\t%w",
"unify_last_longint\t%w",
"unify_last_bigint\t%l",
"native_code"
"function_to_var\t%v,%B",
"function_to_val\t%v,%B",
"function_to_0\t%B",

View File

@ -235,6 +235,7 @@
OPCODE(index_dbref ,e),
OPCODE(index_blob ,e),
OPCODE(index_long ,e),
OPCODE(native_me ,aFlp),
OPCODE(p_atom_x ,xl),
OPCODE(p_atom_y ,yl),
OPCODE(p_atomic_x ,xl),

View File

@ -20,6 +20,14 @@ static char SccsId[] = "%W% %G%";
#endif /* SCCS */
#if NATIVE_EXECUTION
/* just a stub */
#else
#define EXEC_NATIVE(X)
#define MAX_INVOCATION 1024
#define Yapc_Compile(P) 0
#endif
/***************************************************************
* Macros for register manipulation *
***************************************************************/

View File

@ -330,6 +330,15 @@ typedef struct yami {
struct yami *d;
CELL next;
} Otapl;
struct {
COUNT n; /* call counter */
CPredicate native; /* native code pointer */
struct yami *native_next; /* next instruction to execute
after native code
if the predicate was not fully compiled */
struct pred_entry *p; /* Pointer to pred */
CELL next;
} aFlp;
/* The next two instructions are twin: they both correspond to the old ldd. */
/* The first one, aLl, handles try_logical and retry_logical, */
/* Ill handles trust_logical. */

View File

@ -77,6 +77,7 @@ typedef enum compiler_op {
unify_last_dbterm_op,
unify_last_longint_op,
unify_last_bigint_op,
native_op,
f_var_op,
f_val_op,
f_0_op,

View File

@ -124,6 +124,14 @@ restore_opcodes(yamop *pc)
pc->u.Otapl.d = PtoOpAdjust(pc->u.Otapl.d);
pc = NEXTOP(pc,Otapl);
break;
/* instructions type aFlp */
case _native_me:
pc->u.aFlp.n = ArityAdjust(pc->u.aFlp.n);
pc->u.aFlp.native = ExternalFunctionAdjust(pc->u.aFlp.native);
pc->u.aFlp.native_next = PtoOpAdjust(pc->u.aFlp.native_next);
pc->u.aFlp.native = PtoPredAdjust(pc->u.aFlp.native);
pc = NEXTOP(pc,aFlp);
break;
/* instructions type c */
case _write_atom:
pc->u.c.c = ConstantTermAdjust(pc->u.c.c);

View File

@ -90,6 +90,10 @@
pp = pc->u.Otapl.p;
pc = NEXTOP(pc,Otapl);
break;
/* instructions type aFlp */
case _native_me:
pc = NEXTOP(pc,aFlp);
break;
/* instructions type c */
case _write_atom:
pc = NEXTOP(pc,c);