Esempio n. 1
0
 public static Stamp div(IntegerStamp stamp1, IntegerStamp stamp2) {
   Kind kind = stamp1.kind();
   if (stamp2.isStrictlyPositive()) {
     long lowerBound = stamp1.lowerBound() / stamp2.lowerBound();
     long upperBound = stamp1.upperBound() / stamp2.lowerBound();
     return StampFactory.forInteger(
         kind, lowerBound, upperBound, IntegerStamp.maskFor(kind, lowerBound, upperBound));
   }
   return StampFactory.forKind(kind);
 }
Esempio n. 2
0
  public static Stamp add(IntegerStamp stamp1, IntegerStamp stamp2) {
    Kind kind = stamp1.kind();
    assert kind == stamp2.kind();
    if (addOverflow(stamp1.lowerBound(), stamp2.lowerBound(), kind)) {
      return StampFactory.forKind(kind);
    }
    if (addOverflow(stamp1.upperBound(), stamp2.upperBound(), kind)) {
      return StampFactory.forKind(kind);
    }
    long lowerBound = stamp1.lowerBound() + stamp2.lowerBound();
    long upperBound = stamp1.upperBound() + stamp2.upperBound();
    long mask = IntegerStamp.maskFor(kind, lowerBound, upperBound);

    return StampFactory.forInteger(kind, lowerBound, upperBound, mask);
  }
Esempio n. 3
0
 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);
 }