cc_t compute_cc(alu_t op, word_t argA, word_t argB) { word_t val = compute_alu(op, argA, argB); bool_t zero = (val == 0); bool_t sign = ((int)val < 0); bool_t ovf; switch(op) { case A_ADD: ovf = (((int)argA < 0) == ((int)argB < 0)) && (((int)val < 0) != ((int)argA < 0)); break; case A_SUB: ovf = (((int)argA > 0) == ((int)argB < 0)) && (((int)val < 0) != ((int)argB < 0)); break; /* JB inutile case A_AND: case A_XOR: ovf = FALSE; break; */ default: ovf = FALSE; } return PACK_CC(zero,sign,ovf); }
/* * compute_cc: modify condition codes according to operations * args * op: operations (A_ADD, A_SUB, A_AND, A_XOR) * argA: the first argument * argB: the second argument * val: the result of operation on argA and argB * * return * PACK_CC: the final condition codes */ cc_t compute_cc(alu_t op, long_t argA, long_t argB, long_t val) { bool_t zero = (val == 0); bool_t sign = (val < 0); bool_t ovf = FALSE; switch (op) { case 0: ovf = (argA<0 == argB<0) && (val<0 != argB<0); break; case 1: ovf = (argA>0 == argB<0) && (val<0 != argB<0); break; } return PACK_CC(zero,sign,ovf); }
/* * compute_cc: modify condition codes according to operations * args * op: operations (A_ADD, A_SUB, A_AND, A_XOR) * argA: the first argument * argB: the second argument * val: the result of operation on argA and argB * * return * PACK_CC: the final condition codes */ cc_t compute_cc(alu_t op, long_t argA, long_t argB, long_t val) { bool_t zero = (val == 0); bool_t ovf = FALSE; bool_t sign = (val < 0); if(op == A_ADD){ ovf = ((argA > 0) == (argB > 0))&& ((argA > 0) != (val > 0)); }else if(op == A_SUB){ ovf = ((argA > 0) == (argB < 0))&& ((argA > 0) != (val < 0)); } return PACK_CC(zero,sign,ovf); }
/* * compute_cc: modify condition codes according to operations * args * op: operations (A_ADD, A_SUB, A_AND, A_XOR) * argA: the first argument * argB: the second argument * val: the result of operation on argA and argB * * return * PACK_CC: the final condition codes */ cc_t compute_cc(alu_t op, long_t argA, long_t argB, long_t val) { bool_t zero = FALSE; bool_t sign = FALSE; bool_t ovf = FALSE; if (val==0) zero = TRUE; if (val<0) sign = TRUE; if (op==A_ADD) if (((argA<0) == (argB<0)) && ((val<0) != (argA<0))) ovf = TRUE; if (op==A_SUB) if (((argA<0)&&(argB>0)&&(val<0))||((argA>0)&&(argB<0)&&(val>0))) ovf = TRUE; if ((op==A_XOR)||(op==A_AND)) ovf = FALSE; return PACK_CC(zero,sign,ovf); }