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 long saturate(long v, Kind kind) { long max = kind.getMaxValue(); if (v > max) { return max; } long min = kind.getMinValue(); if (v < min) { return min; } return v; }