Search in sources :

Example 36 with Word

use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.

the class Simplifier method refXor.

private static DefUseEffect refXor(Instruction s, OptOptions opts) {
    if (opts.SIMPLIFY_REF_OPS) {
        canonicalizeCommutativeOperator(s);
        Operand op1 = Binary.getVal1(s);
        Operand op2 = Binary.getVal2(s);
        if (op1.similar(op2)) {
            // THE SAME OPERAND: x ^ x == 0
            Move.mutate(s, REF_MOVE, Binary.getClearResult(s), IC(0));
            return DefUseEffect.MOVE_FOLDED;
        }
        if (op2.isConstant() && !op2.isMovableObjectConstant()) {
            Word val2 = getAddressValue(op2).toWord();
            if (op1.isConstant() && !op1.isMovableObjectConstant()) {
                // BOTH CONSTANTS: FOLD
                Word val1 = getAddressValue(op1).toWord();
                Move.mutate(s, REF_MOVE, Binary.getClearResult(s), AC(val1.xor(val2).toAddress()));
                return DefUseEffect.MOVE_FOLDED;
            } else {
                // ONLY OP2 IS CONSTANT: ATTEMPT TO APPLY AXIOMS
                if (val2.isMax()) {
                    // x ^ -1 == x ^ 0xffffffff = ~x
                    Unary.mutate(s, REF_NOT, Binary.getClearResult(s), Binary.getClearVal1(s));
                    return DefUseEffect.REDUCED;
                }
                if (val2.isZero()) {
                    // x ^ 0 == x
                    Move.mutate(s, REF_MOVE, Binary.getClearResult(s), Binary.getClearVal1(s));
                    return DefUseEffect.MOVE_REDUCED;
                }
            }
        }
    }
    return DefUseEffect.UNCHANGED;
}
Also used : Word(org.vmmagic.unboxed.Word) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) CodeConstantOperand(org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)

Example 37 with Word

use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.

the class Simplifier method refAnd.

private static DefUseEffect refAnd(Instruction s, OptOptions opts) {
    if (opts.SIMPLIFY_REF_OPS) {
        canonicalizeCommutativeOperator(s);
        Operand op1 = Binary.getVal1(s);
        Operand op2 = Binary.getVal2(s);
        if (op1.similar(op2)) {
            // THE SAME OPERAND: x & x == x
            Move.mutate(s, REF_MOVE, Binary.getClearResult(s), Binary.getClearVal1(s));
            return op1.isConstant() ? DefUseEffect.MOVE_FOLDED : DefUseEffect.MOVE_REDUCED;
        }
        if (op2.isConstant() && !op2.isMovableObjectConstant()) {
            Word val2 = getAddressValue(op2).toWord();
            if (op1.isConstant() && !op1.isMovableObjectConstant()) {
                // BOTH CONSTANTS: FOLD
                Word val1 = getAddressValue(op1).toWord();
                Move.mutate(s, REF_MOVE, Binary.getClearResult(s), AC(val1.and(val2).toAddress()));
                return DefUseEffect.MOVE_FOLDED;
            } else {
                // ONLY OP2 IS CONSTANT: ATTEMPT TO APPLY AXIOMS
                if (val2.isZero()) {
                    // x & 0 == 0
                    Move.mutate(s, REF_MOVE, Binary.getClearResult(s), AC(Address.zero()));
                    return DefUseEffect.MOVE_FOLDED;
                }
                if (val2.isMax()) {
                    // x & -1 == x & 0xffffffff == x
                    Move.mutate(s, REF_MOVE, Binary.getClearResult(s), Binary.getClearVal1(s));
                    return DefUseEffect.MOVE_REDUCED;
                }
            }
        }
    }
    return DefUseEffect.UNCHANGED;
}
Also used : Word(org.vmmagic.unboxed.Word) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) CodeConstantOperand(org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)

Example 38 with Word

use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.

the class Simplifier method refOr.

private static DefUseEffect refOr(Instruction s, OptOptions opts) {
    if (opts.SIMPLIFY_REF_OPS) {
        canonicalizeCommutativeOperator(s);
        Operand op1 = Binary.getVal1(s);
        Operand op2 = Binary.getVal2(s);
        if (op1.similar(op2)) {
            // THE SAME OPERAND: x | x == x
            Move.mutate(s, REF_MOVE, Binary.getClearResult(s), Binary.getClearVal1(s));
            return op1.isConstant() ? DefUseEffect.MOVE_FOLDED : DefUseEffect.MOVE_REDUCED;
        }
        if (op2.isConstant() && !op2.isMovableObjectConstant()) {
            Word val2 = getAddressValue(op2).toWord();
            if (op1.isAddressConstant()) {
                // BOTH CONSTANTS: FOLD
                Word val1 = getAddressValue(op1).toWord();
                Move.mutate(s, REF_MOVE, Binary.getClearResult(s), AC(val1.or(val2).toAddress()));
                return DefUseEffect.MOVE_FOLDED;
            } else {
                // ONLY OP2 IS CONSTANT: ATTEMPT TO APPLY AXIOMS
                if (val2.isMax()) {
                    // x | -1 == x | 0xffffffff == 0xffffffff == -1
                    Move.mutate(s, REF_MOVE, Binary.getClearResult(s), AC(Address.max()));
                    return DefUseEffect.MOVE_FOLDED;
                }
                if (val2.isZero()) {
                    // x | 0 == x
                    Move.mutate(s, REF_MOVE, Binary.getClearResult(s), Binary.getClearVal1(s));
                    return DefUseEffect.MOVE_REDUCED;
                }
            }
        }
    }
    return DefUseEffect.UNCHANGED;
}
Also used : Word(org.vmmagic.unboxed.Word) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) CodeConstantOperand(org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)

Example 39 with Word

use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.

the class TestNullChecks_Resolved method readVolatileWordField.

private static Word readVolatileWordField(ClassWithVolatileWordField c) {
    try {
        Word readVolatile = c.w;
        System.out.println("Read value " + readVolatile.toLong() + " from field");
        return readVolatile;
    } catch (NullPointerException npe) {
        System.out.println("Caught NPE when reading Word field");
        return NPE_WORD;
    }
}
Also used : Word(org.vmmagic.unboxed.Word)

Example 40 with Word

use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.

the class TestNullChecks_Unresolved_ReadFromNonNullObject method readWordField.

private static Word readWordField(ClassWithWordField c) {
    try {
        Word read = c.w;
        System.out.println("Read value " + read.toLong() + " from field");
        return read;
    } catch (NullPointerException npe) {
        System.out.println("Caught NPE when reading Word field");
        return NPE_WORD;
    }
}
Also used : Word(org.vmmagic.unboxed.Word)

Aggregations

Word (org.vmmagic.unboxed.Word)62 Inline (org.vmmagic.pragma.Inline)15 Address (org.vmmagic.unboxed.Address)14 NoInline (org.vmmagic.pragma.NoInline)11 Offset (org.vmmagic.unboxed.Offset)10 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)8 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)8 CodeConstantOperand (org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand)8 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)8 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)8 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)8 LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)8 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)8 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)8 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)8 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)8 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)8 TIBConstantOperand (org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand)8 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)8 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)8