src/optimize.c
static bool is_const(gbz80_inst *inst, int opt_level)
{
    switch (inst->opcode) {
    case NOP:
        return true;
    case LD:
        if (inst->op1 == MEM_HL || inst->op2 == MEM_HL ||
            inst->op1 == MEM_INC_HL || inst->op2 == MEM_INC_HL ||
            inst->op1 == MEM_DEC_HL || inst->op2 == MEM_DEC_HL ||
            inst->op1 == MEM_C || inst->op2 == MEM_C)
            return false;

        if ((inst->op1 == MEM_8 || inst->op2 == MEM_8) &&
            (inst->args[1] < 0x80 || inst->args[1] == 0xff))
            return false;

        return true;
    case AND:
    case CP:
        return inst->op2 == MEM_HL ? false : true;
    default:
        return false;
    }
}
/* The instruction always has the same result deterministically regardless of
 * memory, special registers, etc.
 */
The instruction always has the same result deterministically regardless of
memory, special registers, etc.
The instruction always has the same result deterministically regardless of memory special registers etc .
static bool is_const(gbz80_inst *inst, int opt_level)
{
    switch (inst->opcode) {
    case NOP:
        return true;
    case LD:
        if (inst->op1 == MEM_HL || inst->op2 == MEM_HL ||
            inst->op1 == MEM_INC_HL || inst->op2 == MEM_INC_HL ||
            inst->op1 == MEM_DEC_HL || inst->op2 == MEM_DEC_HL ||
            inst->op1 == MEM_C || inst->op2 == MEM_C)
            return false;
        if ((inst->op1 == MEM_8 || inst->op2 == MEM_8) &&
            (inst->args[1] < 0x80 || inst->args[1] == 0xff))
            return false;
        return true;
    case AND:
    case CP:
        return inst->op2 == MEM_HL ? false : true;
    default:
        return false;
    }
}
static bool is_const ( gbz80_inst * inst , int opt_level ) { switch ( inst -> opcode ) { case NOP : return true ; case LD : if ( inst -> op1 == MEM_HL || inst -> op2 == MEM_HL || inst -> op1 == MEM_INC_HL || inst -> op2 == MEM_INC_HL || inst -> op1 == MEM_DEC_HL || inst -> op2 == MEM_DEC_HL || inst -> op1 == MEM_C || inst -> op2 == MEM_C ) return false ; if ( ( inst -> op1 == MEM_8 || inst -> op2 == MEM_8 ) && ( inst -> args [ 1 ] < 0x80 || inst -> args [ 1 ] == 0xff ) ) return false ; return true ; case AND : case CP : return inst -> op2 == MEM_HL ? false : true ; default : return false ; } }
The instruction always has the same result deterministically regardless of
 memory, special registers, etc.
The instruction always has the same result deterministically regardless of memory special registers etc .