Search in sources :

Example 26 with Word

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

the class Simplifier method refShl.

private static DefUseEffect refShl(Instruction s, OptOptions opts) {
    if (opts.SIMPLIFY_REF_OPS) {
        Operand op2 = Binary.getVal2(s);
        Operand op1 = Binary.getVal1(s);
        if (op2.isIntConstant()) {
            int val2 = op2.asIntConstant().value;
            if (op1.isConstant() && !op1.isMovableObjectConstant()) {
                // BOTH CONSTANTS: FOLD
                Word val1 = getAddressValue(op1).toWord();
                Move.mutate(s, REF_MOVE, Binary.getClearResult(s), AC(val1.lsh(val2).toAddress()));
                return DefUseEffect.MOVE_FOLDED;
            } else {
                // ONLY OP2 IS CONSTANT: ATTEMPT TO APPLY AXIOMS
                if (val2 == 0) {
                    // x << 0 == x
                    Move.mutate(s, REF_MOVE, Binary.getClearResult(s), Binary.getClearVal1(s));
                    return DefUseEffect.MOVE_REDUCED;
                }
                if ((val2 >= BITS_IN_ADDRESS) || (val2 < 0)) {
                    // x << 32 == 0
                    Move.mutate(s, REF_MOVE, Binary.getClearResult(s), IC(0));
                    return DefUseEffect.MOVE_FOLDED;
                }
            }
        } else if (op1.isConstant() && !op1.isMovableObjectConstant()) {
            Word val1 = getAddressValue(op1).toWord();
            // ONLY OP1 IS CONSTANT: ATTEMPT TO APPLY AXIOMS
            if (val1.isZero()) {
                // 0 << x == 0
                Move.mutate(s, REF_MOVE, Binary.getClearResult(s), AC(Address.zero()));
                return DefUseEffect.MOVE_FOLDED;
            }
        }
    }
    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 27 with Word

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

the class Simplifier method refNeg.

private static DefUseEffect refNeg(Instruction s, OptOptions opts) {
    if (opts.SIMPLIFY_REF_OPS) {
        Operand op = Unary.getVal(s);
        if (op.isConstant() && !op.isMovableObjectConstant()) {
            // CONSTANT: FOLD
            Word val = getAddressValue(op).toWord();
            Word negVal = Word.zero().minus(val);
            Move.mutate(s, REF_MOVE, Unary.getClearResult(s), AC(negVal.toAddress()));
            return DefUseEffect.MOVE_FOLDED;
        }
    }
    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 28 with Word

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

the class Simplifier method refShr.

private static DefUseEffect refShr(Instruction s, OptOptions opts) {
    if (opts.SIMPLIFY_REF_OPS) {
        Operand op1 = Binary.getVal1(s);
        Operand op2 = Binary.getVal2(s);
        if (op2.isIntConstant()) {
            int val2 = op2.asIntConstant().value;
            if (op1.isConstant() && !op1.isMovableObjectConstant()) {
                // BOTH CONSTANTS: FOLD
                Word val1 = getAddressValue(op1).toWord();
                Move.mutate(s, REF_MOVE, Binary.getClearResult(s), AC(val1.rsha(val2).toAddress()));
                return DefUseEffect.MOVE_FOLDED;
            } else {
                // ONLY OP2 IS CONSTANT: ATTEMPT TO APPLY AXIOMS
                if (val2 == 0) {
                    // x >> 0 == x
                    Move.mutate(s, REF_MOVE, Binary.getClearResult(s), Binary.getClearVal1(s));
                    return DefUseEffect.MOVE_REDUCED;
                }
                if ((val2 >= BITS_IN_ADDRESS) || (val2 < 0)) {
                    // x >> 32 == x >> 31
                    Binary.setVal2(s, IC(BITS_IN_ADDRESS - 1));
                    return DefUseEffect.UNCHANGED;
                }
            }
        } else if (op1.isConstant() && !op1.isMovableObjectConstant()) {
            Word val1 = getAddressValue(op1).toWord();
            // -1 >> x == -1, 0 >> x == 0
            if (val1.EQ(Word.zero()) || val1.EQ(Word.zero().minus(Word.one()))) {
                Move.mutate(s, REF_MOVE, Binary.getClearResult(s), op1);
                return DefUseEffect.MOVE_FOLDED;
            }
        }
    }
    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 29 with Word

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

the class TestNullChecks_Resolved 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)

Example 30 with Word

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

the class TestNullChecks_Unresolved_ReadFromNonNullObject 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)

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