public static Stamp intToLong(IntegerStamp intStamp) { long mask; if (intStamp.isPositive()) { mask = intStamp.mask(); } else { mask = 0xffffffff00000000L | intStamp.mask(); } return StampFactory.forInteger(Kind.Long, intStamp.lowerBound(), intStamp.upperBound(), mask); }
public static Stamp or(IntegerStamp stamp1, IntegerStamp stamp2) { Kind kind = stamp1.kind(); long mask = stamp1.mask() | stamp2.mask(); if (stamp1.lowerBound() >= 0 && stamp2.lowerBound() >= 0) { return stampForMask(kind, mask, stamp1.lowerBound() | stamp2.lowerBound()); } else { return stampForMask(kind, mask); } }
public static Stamp negate(Stamp stamp) { Kind kind = stamp.kind(); if (stamp instanceof IntegerStamp) { IntegerStamp integerStamp = (IntegerStamp) stamp; if (integerStamp.lowerBound() != kind.getMinValue()) { // TODO(ls) check if the mask calculation is correct... return new IntegerStamp( kind, -integerStamp.upperBound(), -integerStamp.lowerBound(), IntegerStamp.defaultMask(kind) & (integerStamp.mask() | -integerStamp.mask())); } } return StampFactory.forKind(kind); }
private static Stamp narrowingKindConvertion(IntegerStamp fromStamp, Kind toKind) { long mask = fromStamp.mask() & IntegerStamp.defaultMask(toKind); long lowerBound = saturate(fromStamp.lowerBound(), toKind); long upperBound = saturate(fromStamp.upperBound(), toKind); if (fromStamp.lowerBound() < toKind.getMinValue()) { upperBound = toKind.getMaxValue(); } if (fromStamp.upperBound() > toKind.getMaxValue()) { lowerBound = toKind.getMinValue(); } return StampFactory.forInteger(toKind.getStackKind(), lowerBound, upperBound, mask); }
public static Stamp leftShift(IntegerStamp value, IntegerStamp shift) { Kind kind = value.kind(); int shiftBits = kind == Kind.Int ? 5 : 6; long shiftMask = kind == Kind.Int ? 0x1FL : 0x3FL; if ((shift.lowerBound() >>> shiftBits) == (shift.upperBound() >>> shiftBits)) { long mask = 0; for (long i = shift.lowerBound() & shiftMask; i <= (shift.upperBound() & shiftMask); i++) { mask |= value.mask() << i; } mask &= IntegerStamp.defaultMask(kind); return stampForMask(kind, mask); } return StampFactory.forKind(kind); }
public static Stamp unsignedRightShift(IntegerStamp value, IntegerStamp shift) { Kind kind = value.kind(); if (shift.lowerBound() == shift.upperBound()) { long shiftMask = kind == Kind.Int ? 0x1FL : 0x3FL; long shiftCount = shift.lowerBound() & shiftMask; if (shiftCount != 0) { long lowerBound; long upperBound; if (value.lowerBound() < 0) { lowerBound = 0; upperBound = IntegerStamp.defaultMask(kind) >>> shiftCount; } else { lowerBound = value.lowerBound() >>> shiftCount; upperBound = value.upperBound() >>> shiftCount; } long mask = value.mask() >>> shiftCount; return StampFactory.forInteger(kind, lowerBound, upperBound, mask); } } long mask = IntegerStamp.maskFor(kind, value.lowerBound(), value.upperBound()); return stampForMask(kind, mask); }
public static Stamp xor(IntegerStamp stamp1, IntegerStamp stamp2) { Kind kind = stamp1.kind(); long mask = stamp1.mask() | stamp2.mask(); return stampForMask(kind, mask); }