optimise is/2 as a binary predicate.

This commit is contained in:
Vitor Santos Costa 2009-02-09 22:21:58 +00:00
parent 8a3978e3e1
commit 89635fb1f6
2 changed files with 19 additions and 17 deletions

View File

@ -1598,29 +1598,31 @@ static COUNT
compile_cmp_flags(char *s)
{
if (strcmp(s,"=<") == 0)
return(EQ_OK_IN_CMP|LT_OK_IN_CMP);
return EQ_OK_IN_CMP|LT_OK_IN_CMP;
if (strcmp(s,"is") == 0)
return EQ_OK_IN_CMP;
if (strcmp(s,"@=<") == 0)
return(EQ_OK_IN_CMP|LT_OK_IN_CMP);
return EQ_OK_IN_CMP|LT_OK_IN_CMP;
if (strcmp(s,"<") == 0)
return(LT_OK_IN_CMP);
return LT_OK_IN_CMP;
if (strcmp(s,"@<") == 0)
return(LT_OK_IN_CMP);
return LT_OK_IN_CMP;
if (strcmp(s,">=") == 0)
return(EQ_OK_IN_CMP|GT_OK_IN_CMP);
return EQ_OK_IN_CMP|GT_OK_IN_CMP;
if (strcmp(s,"@>=") == 0)
return(EQ_OK_IN_CMP|GT_OK_IN_CMP);
return EQ_OK_IN_CMP|GT_OK_IN_CMP;
if (strcmp(s,">") == 0)
return(GT_OK_IN_CMP);
return GT_OK_IN_CMP;
if (strcmp(s,"@>") == 0)
return(GT_OK_IN_CMP);
return GT_OK_IN_CMP;
if (strcmp(s,"=:=") == 0)
return(EQ_OK_IN_CMP);
return EQ_OK_IN_CMP;
if (strcmp(s,"=\\=") == 0)
return(GT_OK_IN_CMP|LT_OK_IN_CMP);
return GT_OK_IN_CMP|LT_OK_IN_CMP;
if (strcmp(s,"\\==") == 0)
return(GT_OK_IN_CMP|LT_OK_IN_CMP);
Yap_Error(INTERNAL_COMPILER_ERROR, TermNil, "internal assembler error, %s is not recognised", s);
return(0);
return GT_OK_IN_CMP|LT_OK_IN_CMP;
Yap_Error(INTERNAL_COMPILER_ERROR, TermNil, "internal assembler error, %s/2 not recognised as binary op", s);
return 0;
}
COUNT

View File

@ -131,16 +131,16 @@ BEAM_is(void)
#endif
static Int
p_is(void)
p_is(CELL result, CELL in)
{ /* X is Y */
Term out;
out = Eval(Deref(ARG2));
out = Eval(Deref(in));
if (out == 0L) {
Yap_Error(EVALUATION_ERROR_INT_OVERFLOW, ARG2, "is/2");
return FALSE;
}
return Yap_unify_constant(ARG1,out);
return Yap_unify_constant(result,out);
}
void
@ -150,6 +150,6 @@ Yap_InitEval(void)
Yap_InitConstExps();
Yap_InitUnaryExps();
Yap_InitBinaryExps();
Yap_InitCPred("is", 2, p_is, TestPredFlag | SafePredFlag);
Yap_InitCmpPred("is", 2, p_is, BinaryPredFlag | TestPredFlag | SafePredFlag);
}