43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.compiler.core.common.type;
|
|
24 |
|
|
25 |
import static org.graalvm.compiler.core.common.calc.FloatConvert.I2D;
|
|
26 |
import static org.graalvm.compiler.core.common.calc.FloatConvert.I2F;
|
|
27 |
import static org.graalvm.compiler.core.common.calc.FloatConvert.L2D;
|
|
28 |
import static org.graalvm.compiler.core.common.calc.FloatConvert.L2F;
|
|
29 |
|
|
30 |
import java.nio.ByteBuffer;
|
|
31 |
import java.util.Formatter;
|
|
32 |
|
|
33 |
import org.graalvm.compiler.core.common.LIRKind;
|
46344
|
34 |
import org.graalvm.compiler.core.common.NumUtil;
|
43972
|
35 |
import org.graalvm.compiler.core.common.spi.LIRKindTool;
|
|
36 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp;
|
|
37 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable.FloatConvertOp;
|
|
38 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable.IntegerConvertOp;
|
|
39 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable.ShiftOp;
|
|
40 |
import org.graalvm.compiler.core.common.type.ArithmeticOpTable.UnaryOp;
|
|
41 |
import org.graalvm.compiler.debug.GraalError;
|
|
42 |
|
|
43 |
import jdk.vm.ci.code.CodeUtil;
|
|
44 |
import jdk.vm.ci.meta.Constant;
|
|
45 |
import jdk.vm.ci.meta.JavaConstant;
|
|
46 |
import jdk.vm.ci.meta.JavaKind;
|
|
47 |
import jdk.vm.ci.meta.MetaAccessProvider;
|
|
48 |
import jdk.vm.ci.meta.PrimitiveConstant;
|
|
49 |
import jdk.vm.ci.meta.ResolvedJavaType;
|
|
50 |
import jdk.vm.ci.meta.SerializableConstant;
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Describes the possible values of a node that produces an int or long result.
|
|
54 |
*
|
|
55 |
* The description consists of (inclusive) lower and upper bounds and up (may be set) and down
|
|
56 |
* (always set) bit-masks.
|
|
57 |
*/
|
46344
|
58 |
public final class IntegerStamp extends PrimitiveStamp {
|
43972
|
59 |
|
|
60 |
private final long lowerBound;
|
|
61 |
private final long upperBound;
|
|
62 |
private final long downMask;
|
|
63 |
private final long upMask;
|
|
64 |
|
46344
|
65 |
private IntegerStamp(int bits, long lowerBound, long upperBound, long downMask, long upMask) {
|
43972
|
66 |
super(bits, OPS);
|
46344
|
67 |
|
43972
|
68 |
this.lowerBound = lowerBound;
|
|
69 |
this.upperBound = upperBound;
|
|
70 |
this.downMask = downMask;
|
|
71 |
this.upMask = upMask;
|
46344
|
72 |
|
43972
|
73 |
assert lowerBound >= CodeUtil.minValue(bits) : this;
|
|
74 |
assert upperBound <= CodeUtil.maxValue(bits) : this;
|
|
75 |
assert (downMask & CodeUtil.mask(bits)) == downMask : this;
|
|
76 |
assert (upMask & CodeUtil.mask(bits)) == upMask : this;
|
|
77 |
}
|
|
78 |
|
46344
|
79 |
public static IntegerStamp create(int bits, long lowerBoundInput, long upperBoundInput) {
|
|
80 |
return create(bits, lowerBoundInput, upperBoundInput, 0, CodeUtil.mask(bits));
|
|
81 |
}
|
|
82 |
|
|
83 |
public static IntegerStamp create(int bits, long lowerBoundInput, long upperBoundInput, long downMask, long upMask) {
|
|
84 |
assert (downMask & ~upMask) == 0 : String.format("\u21ca: %016x \u21c8: %016x", downMask, upMask);
|
|
85 |
|
|
86 |
// Set lower bound, use masks to make it more precise
|
|
87 |
long minValue = minValueForMasks(bits, downMask, upMask);
|
|
88 |
long lowerBoundTmp = Math.max(lowerBoundInput, minValue);
|
|
89 |
|
|
90 |
// Set upper bound, use masks to make it more precise
|
|
91 |
long maxValue = maxValueForMasks(bits, downMask, upMask);
|
|
92 |
long upperBoundTmp = Math.min(upperBoundInput, maxValue);
|
|
93 |
|
|
94 |
// Assign masks now with the bounds in mind.
|
|
95 |
final long boundedDownMask;
|
|
96 |
final long boundedUpMask;
|
|
97 |
long defaultMask = CodeUtil.mask(bits);
|
|
98 |
if (lowerBoundTmp == upperBoundTmp) {
|
|
99 |
boundedDownMask = lowerBoundTmp;
|
|
100 |
boundedUpMask = lowerBoundTmp;
|
|
101 |
} else if (lowerBoundTmp >= 0) {
|
|
102 |
int upperBoundLeadingZeros = Long.numberOfLeadingZeros(upperBoundTmp);
|
|
103 |
long differentBits = lowerBoundTmp ^ upperBoundTmp;
|
|
104 |
int sameBitCount = Long.numberOfLeadingZeros(differentBits << upperBoundLeadingZeros);
|
|
105 |
|
|
106 |
boundedUpMask = upperBoundTmp | -1L >>> (upperBoundLeadingZeros + sameBitCount);
|
|
107 |
boundedDownMask = upperBoundTmp & ~(-1L >>> (upperBoundLeadingZeros + sameBitCount));
|
|
108 |
} else {
|
|
109 |
if (upperBoundTmp >= 0) {
|
|
110 |
boundedUpMask = defaultMask;
|
|
111 |
boundedDownMask = 0;
|
|
112 |
} else {
|
|
113 |
int lowerBoundLeadingOnes = Long.numberOfLeadingZeros(~lowerBoundTmp);
|
|
114 |
long differentBits = lowerBoundTmp ^ upperBoundTmp;
|
|
115 |
int sameBitCount = Long.numberOfLeadingZeros(differentBits << lowerBoundLeadingOnes);
|
|
116 |
|
|
117 |
boundedUpMask = lowerBoundTmp | -1L >>> (lowerBoundLeadingOnes + sameBitCount) | ~(-1L >>> lowerBoundLeadingOnes);
|
|
118 |
boundedDownMask = lowerBoundTmp & ~(-1L >>> (lowerBoundLeadingOnes + sameBitCount)) | ~(-1L >>> lowerBoundLeadingOnes);
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
return new IntegerStamp(bits, lowerBoundTmp, upperBoundTmp, defaultMask & (downMask | boundedDownMask), defaultMask & upMask & boundedUpMask);
|
|
123 |
}
|
|
124 |
|
|
125 |
static long significantBit(long bits, long value) {
|
|
126 |
return (value >>> (bits - 1)) & 1;
|
|
127 |
}
|
|
128 |
|
|
129 |
static long minValueForMasks(int bits, long downMask, long upMask) {
|
|
130 |
if (significantBit(bits, upMask) == 0) {
|
|
131 |
// Value is always positive. Minimum value always positive.
|
|
132 |
assert significantBit(bits, downMask) == 0;
|
|
133 |
return downMask;
|
|
134 |
} else {
|
|
135 |
// Value can be positive or negative. Minimum value always negative.
|
|
136 |
return downMask | (-1L << (bits - 1));
|
|
137 |
}
|
|
138 |
}
|
|
139 |
|
|
140 |
static long maxValueForMasks(int bits, long downMask, long upMask) {
|
|
141 |
if (significantBit(bits, downMask) == 1) {
|
|
142 |
// Value is always negative. Maximum value always negative.
|
|
143 |
assert significantBit(bits, upMask) == 1;
|
|
144 |
return CodeUtil.signExtend(upMask, bits);
|
|
145 |
} else {
|
|
146 |
// Value can be positive or negative. Maximum value always positive.
|
|
147 |
return upMask & (CodeUtil.mask(bits) >>> 1);
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
43972
|
151 |
public static IntegerStamp stampForMask(int bits, long downMask, long upMask) {
|
46344
|
152 |
return new IntegerStamp(bits, minValueForMasks(bits, downMask, upMask), maxValueForMasks(bits, downMask, upMask), downMask, upMask);
|
43972
|
153 |
}
|
|
154 |
|
|
155 |
@Override
|
|
156 |
public IntegerStamp unrestricted() {
|
|
157 |
return new IntegerStamp(getBits(), CodeUtil.minValue(getBits()), CodeUtil.maxValue(getBits()), 0, CodeUtil.mask(getBits()));
|
|
158 |
}
|
|
159 |
|
|
160 |
@Override
|
46344
|
161 |
public IntegerStamp empty() {
|
43972
|
162 |
return new IntegerStamp(getBits(), CodeUtil.maxValue(getBits()), CodeUtil.minValue(getBits()), CodeUtil.mask(getBits()), 0);
|
|
163 |
}
|
|
164 |
|
|
165 |
@Override
|
|
166 |
public Stamp constant(Constant c, MetaAccessProvider meta) {
|
|
167 |
if (c instanceof PrimitiveConstant) {
|
|
168 |
long value = ((PrimitiveConstant) c).asLong();
|
|
169 |
return StampFactory.forInteger(getBits(), value, value);
|
|
170 |
}
|
|
171 |
return this;
|
|
172 |
}
|
|
173 |
|
|
174 |
@Override
|
|
175 |
public SerializableConstant deserialize(ByteBuffer buffer) {
|
|
176 |
switch (getBits()) {
|
|
177 |
case 1:
|
|
178 |
return JavaConstant.forBoolean(buffer.get() != 0);
|
|
179 |
case 8:
|
|
180 |
return JavaConstant.forByte(buffer.get());
|
|
181 |
case 16:
|
|
182 |
return JavaConstant.forShort(buffer.getShort());
|
|
183 |
case 32:
|
|
184 |
return JavaConstant.forInt(buffer.getInt());
|
|
185 |
case 64:
|
|
186 |
return JavaConstant.forLong(buffer.getLong());
|
|
187 |
default:
|
|
188 |
throw GraalError.shouldNotReachHere();
|
|
189 |
}
|
|
190 |
}
|
|
191 |
|
|
192 |
@Override
|
|
193 |
public boolean hasValues() {
|
|
194 |
return lowerBound <= upperBound;
|
|
195 |
}
|
|
196 |
|
|
197 |
@Override
|
|
198 |
public JavaKind getStackKind() {
|
|
199 |
if (getBits() > 32) {
|
|
200 |
return JavaKind.Long;
|
|
201 |
} else {
|
|
202 |
return JavaKind.Int;
|
|
203 |
}
|
|
204 |
}
|
|
205 |
|
|
206 |
@Override
|
|
207 |
public LIRKind getLIRKind(LIRKindTool tool) {
|
|
208 |
return tool.getIntegerKind(getBits());
|
|
209 |
}
|
|
210 |
|
|
211 |
@Override
|
|
212 |
public ResolvedJavaType javaType(MetaAccessProvider metaAccess) {
|
|
213 |
switch (getBits()) {
|
|
214 |
case 1:
|
|
215 |
return metaAccess.lookupJavaType(Boolean.TYPE);
|
|
216 |
case 8:
|
|
217 |
return metaAccess.lookupJavaType(Byte.TYPE);
|
|
218 |
case 16:
|
|
219 |
return metaAccess.lookupJavaType(Short.TYPE);
|
|
220 |
case 32:
|
|
221 |
return metaAccess.lookupJavaType(Integer.TYPE);
|
|
222 |
case 64:
|
|
223 |
return metaAccess.lookupJavaType(Long.TYPE);
|
|
224 |
default:
|
|
225 |
throw GraalError.shouldNotReachHere();
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
/**
|
|
230 |
* The signed inclusive lower bound on the value described by this stamp.
|
|
231 |
*/
|
|
232 |
public long lowerBound() {
|
|
233 |
return lowerBound;
|
|
234 |
}
|
|
235 |
|
|
236 |
/**
|
|
237 |
* The signed inclusive upper bound on the value described by this stamp.
|
|
238 |
*/
|
|
239 |
public long upperBound() {
|
|
240 |
return upperBound;
|
|
241 |
}
|
|
242 |
|
|
243 |
/**
|
|
244 |
* This bit-mask describes the bits that are always set in the value described by this stamp.
|
|
245 |
*/
|
|
246 |
public long downMask() {
|
|
247 |
return downMask;
|
|
248 |
}
|
|
249 |
|
|
250 |
/**
|
|
251 |
* This bit-mask describes the bits that can be set in the value described by this stamp.
|
|
252 |
*/
|
|
253 |
public long upMask() {
|
|
254 |
return upMask;
|
|
255 |
}
|
|
256 |
|
46371
|
257 |
@Override
|
43972
|
258 |
public boolean isUnrestricted() {
|
|
259 |
return lowerBound == CodeUtil.minValue(getBits()) && upperBound == CodeUtil.maxValue(getBits()) && downMask == 0 && upMask == CodeUtil.mask(getBits());
|
|
260 |
}
|
|
261 |
|
|
262 |
public boolean contains(long value) {
|
|
263 |
return value >= lowerBound && value <= upperBound && (value & downMask) == downMask && (value & upMask) == (value & CodeUtil.mask(getBits()));
|
|
264 |
}
|
|
265 |
|
|
266 |
public boolean isPositive() {
|
|
267 |
return lowerBound() >= 0;
|
|
268 |
}
|
|
269 |
|
|
270 |
public boolean isNegative() {
|
|
271 |
return upperBound() <= 0;
|
|
272 |
}
|
|
273 |
|
|
274 |
public boolean isStrictlyPositive() {
|
|
275 |
return lowerBound() > 0;
|
|
276 |
}
|
|
277 |
|
|
278 |
public boolean isStrictlyNegative() {
|
|
279 |
return upperBound() < 0;
|
|
280 |
}
|
|
281 |
|
|
282 |
public boolean canBePositive() {
|
|
283 |
return upperBound() > 0;
|
|
284 |
}
|
|
285 |
|
|
286 |
public boolean canBeNegative() {
|
|
287 |
return lowerBound() < 0;
|
|
288 |
}
|
|
289 |
|
|
290 |
@Override
|
|
291 |
public String toString() {
|
|
292 |
StringBuilder str = new StringBuilder();
|
|
293 |
str.append('i');
|
|
294 |
str.append(getBits());
|
46344
|
295 |
if (hasValues()) {
|
|
296 |
if (lowerBound == upperBound) {
|
|
297 |
str.append(" [").append(lowerBound).append(']');
|
|
298 |
} else if (lowerBound != CodeUtil.minValue(getBits()) || upperBound != CodeUtil.maxValue(getBits())) {
|
|
299 |
str.append(" [").append(lowerBound).append(" - ").append(upperBound).append(']');
|
|
300 |
}
|
|
301 |
if (downMask != 0) {
|
|
302 |
str.append(" \u21ca");
|
|
303 |
new Formatter(str).format("%016x", downMask);
|
|
304 |
}
|
|
305 |
if (upMask != CodeUtil.mask(getBits())) {
|
|
306 |
str.append(" \u21c8");
|
|
307 |
new Formatter(str).format("%016x", upMask);
|
|
308 |
}
|
|
309 |
} else {
|
|
310 |
str.append("<empty>");
|
43972
|
311 |
}
|
|
312 |
return str.toString();
|
|
313 |
}
|
|
314 |
|
46344
|
315 |
private IntegerStamp createStamp(IntegerStamp other, long newUpperBound, long newLowerBound, long newDownMask, long newUpMask) {
|
43972
|
316 |
assert getBits() == other.getBits();
|
|
317 |
if (newLowerBound > newUpperBound || (newDownMask & (~newUpMask)) != 0 || (newUpMask == 0 && (newLowerBound > 0 || newUpperBound < 0))) {
|
|
318 |
return empty();
|
|
319 |
} else if (newLowerBound == lowerBound && newUpperBound == upperBound && newDownMask == downMask && newUpMask == upMask) {
|
|
320 |
return this;
|
|
321 |
} else if (newLowerBound == other.lowerBound && newUpperBound == other.upperBound && newDownMask == other.downMask && newUpMask == other.upMask) {
|
|
322 |
return other;
|
|
323 |
} else {
|
46344
|
324 |
return IntegerStamp.create(getBits(), newLowerBound, newUpperBound, newDownMask, newUpMask);
|
43972
|
325 |
}
|
|
326 |
}
|
|
327 |
|
|
328 |
@Override
|
|
329 |
public Stamp meet(Stamp otherStamp) {
|
|
330 |
if (otherStamp == this) {
|
|
331 |
return this;
|
|
332 |
}
|
|
333 |
IntegerStamp other = (IntegerStamp) otherStamp;
|
|
334 |
return createStamp(other, Math.max(upperBound, other.upperBound), Math.min(lowerBound, other.lowerBound), downMask & other.downMask, upMask | other.upMask);
|
|
335 |
}
|
|
336 |
|
|
337 |
@Override
|
46344
|
338 |
public IntegerStamp join(Stamp otherStamp) {
|
43972
|
339 |
if (otherStamp == this) {
|
|
340 |
return this;
|
|
341 |
}
|
|
342 |
IntegerStamp other = (IntegerStamp) otherStamp;
|
|
343 |
long newDownMask = downMask | other.downMask;
|
46344
|
344 |
long newLowerBound = Math.max(lowerBound, other.lowerBound);
|
43972
|
345 |
long newUpperBound = Math.min(upperBound, other.upperBound);
|
|
346 |
long newUpMask = upMask & other.upMask;
|
46344
|
347 |
return createStamp(other, newUpperBound, newLowerBound, newDownMask, newUpMask);
|
43972
|
348 |
}
|
|
349 |
|
|
350 |
@Override
|
|
351 |
public boolean isCompatible(Stamp stamp) {
|
|
352 |
if (this == stamp) {
|
|
353 |
return true;
|
|
354 |
}
|
|
355 |
if (stamp instanceof IntegerStamp) {
|
|
356 |
IntegerStamp other = (IntegerStamp) stamp;
|
|
357 |
return getBits() == other.getBits();
|
|
358 |
}
|
|
359 |
return false;
|
|
360 |
}
|
|
361 |
|
|
362 |
@Override
|
|
363 |
public boolean isCompatible(Constant constant) {
|
|
364 |
if (constant instanceof PrimitiveConstant) {
|
|
365 |
PrimitiveConstant prim = (PrimitiveConstant) constant;
|
|
366 |
return prim.getJavaKind().isNumericInteger();
|
|
367 |
}
|
|
368 |
return false;
|
|
369 |
}
|
|
370 |
|
46344
|
371 |
public long unsignedUpperBound() {
|
|
372 |
if (sameSignBounds()) {
|
|
373 |
return CodeUtil.zeroExtend(upperBound(), getBits());
|
|
374 |
}
|
|
375 |
return NumUtil.maxValueUnsigned(getBits());
|
|
376 |
}
|
|
377 |
|
|
378 |
public long unsignedLowerBound() {
|
|
379 |
if (sameSignBounds()) {
|
|
380 |
return CodeUtil.zeroExtend(lowerBound(), getBits());
|
|
381 |
}
|
|
382 |
return 0;
|
|
383 |
}
|
|
384 |
|
|
385 |
private boolean sameSignBounds() {
|
|
386 |
return NumUtil.sameSign(lowerBound, upperBound);
|
|
387 |
}
|
|
388 |
|
43972
|
389 |
@Override
|
|
390 |
public int hashCode() {
|
|
391 |
final int prime = 31;
|
|
392 |
int result = 1;
|
|
393 |
result = prime * result + super.hashCode();
|
|
394 |
result = prime * result + (int) (lowerBound ^ (lowerBound >>> 32));
|
|
395 |
result = prime * result + (int) (upperBound ^ (upperBound >>> 32));
|
|
396 |
result = prime * result + (int) (downMask ^ (downMask >>> 32));
|
|
397 |
result = prime * result + (int) (upMask ^ (upMask >>> 32));
|
|
398 |
return result;
|
|
399 |
}
|
|
400 |
|
|
401 |
@Override
|
|
402 |
public boolean equals(Object obj) {
|
|
403 |
if (this == obj) {
|
|
404 |
return true;
|
|
405 |
}
|
|
406 |
if (obj == null || getClass() != obj.getClass() || !super.equals(obj)) {
|
|
407 |
return false;
|
|
408 |
}
|
|
409 |
IntegerStamp other = (IntegerStamp) obj;
|
|
410 |
if (lowerBound != other.lowerBound || upperBound != other.upperBound || downMask != other.downMask || upMask != other.upMask) {
|
|
411 |
return false;
|
|
412 |
}
|
|
413 |
return super.equals(other);
|
|
414 |
}
|
|
415 |
|
|
416 |
public static long upMaskFor(int bits, long lowerBound, long upperBound) {
|
|
417 |
long mask = lowerBound | upperBound;
|
|
418 |
if (mask == 0) {
|
|
419 |
return 0;
|
|
420 |
} else {
|
|
421 |
return ((-1L) >>> Long.numberOfLeadingZeros(mask)) & CodeUtil.mask(bits);
|
|
422 |
}
|
|
423 |
}
|
|
424 |
|
|
425 |
/**
|
|
426 |
* Checks if the 2 stamps represent values of the same sign. Returns true if the two stamps are
|
|
427 |
* both positive of null or if they are both strictly negative
|
|
428 |
*
|
|
429 |
* @return true if the two stamps are both positive of null or if they are both strictly
|
|
430 |
* negative
|
|
431 |
*/
|
|
432 |
public static boolean sameSign(IntegerStamp s1, IntegerStamp s2) {
|
|
433 |
return s1.isPositive() && s2.isPositive() || s1.isStrictlyNegative() && s2.isStrictlyNegative();
|
|
434 |
}
|
|
435 |
|
|
436 |
@Override
|
|
437 |
public JavaConstant asConstant() {
|
|
438 |
if (lowerBound == upperBound) {
|
|
439 |
switch (getBits()) {
|
|
440 |
case 1:
|
|
441 |
return JavaConstant.forBoolean(lowerBound != 0);
|
|
442 |
case 8:
|
|
443 |
return JavaConstant.forByte((byte) lowerBound);
|
|
444 |
case 16:
|
|
445 |
return JavaConstant.forShort((short) lowerBound);
|
|
446 |
case 32:
|
|
447 |
return JavaConstant.forInt((int) lowerBound);
|
|
448 |
case 64:
|
|
449 |
return JavaConstant.forLong(lowerBound);
|
|
450 |
}
|
|
451 |
}
|
|
452 |
return null;
|
|
453 |
}
|
|
454 |
|
46344
|
455 |
public static boolean addCanOverflow(IntegerStamp a, IntegerStamp b) {
|
|
456 |
assert a.getBits() == b.getBits();
|
|
457 |
return addOverflowsPositively(a.upperBound(), b.upperBound(), a.getBits()) ||
|
|
458 |
addOverflowsNegatively(a.lowerBound(), b.lowerBound(), a.getBits());
|
|
459 |
|
|
460 |
}
|
|
461 |
|
43972
|
462 |
public static boolean addOverflowsPositively(long x, long y, int bits) {
|
|
463 |
long result = x + y;
|
|
464 |
if (bits == 64) {
|
|
465 |
return (~x & ~y & result) < 0;
|
|
466 |
} else {
|
|
467 |
return result > CodeUtil.maxValue(bits);
|
|
468 |
}
|
|
469 |
}
|
|
470 |
|
|
471 |
public static boolean addOverflowsNegatively(long x, long y, int bits) {
|
|
472 |
long result = x + y;
|
|
473 |
if (bits == 64) {
|
|
474 |
return (x & y & ~result) < 0;
|
|
475 |
} else {
|
|
476 |
return result < CodeUtil.minValue(bits);
|
|
477 |
}
|
|
478 |
}
|
|
479 |
|
|
480 |
public static long carryBits(long x, long y) {
|
|
481 |
return (x + y) ^ x ^ y;
|
|
482 |
}
|
|
483 |
|
|
484 |
private static long saturate(long v, int bits) {
|
|
485 |
if (bits < 64) {
|
|
486 |
long max = CodeUtil.maxValue(bits);
|
|
487 |
if (v > max) {
|
|
488 |
return max;
|
|
489 |
}
|
|
490 |
long min = CodeUtil.minValue(bits);
|
|
491 |
if (v < min) {
|
|
492 |
return min;
|
|
493 |
}
|
|
494 |
}
|
|
495 |
return v;
|
|
496 |
}
|
|
497 |
|
|
498 |
public static boolean multiplicationOverflows(long a, long b, int bits) {
|
|
499 |
assert bits <= 64 && bits >= 0;
|
|
500 |
long result = a * b;
|
|
501 |
// result is positive if the sign is the same
|
|
502 |
boolean positive = (a >= 0 && b >= 0) || (a < 0 && b < 0);
|
|
503 |
if (bits == 64) {
|
|
504 |
if (a > 0 && b > 0) {
|
|
505 |
return a > 0x7FFFFFFF_FFFFFFFFL / b;
|
|
506 |
} else if (a > 0 && b <= 0) {
|
|
507 |
return b < 0x80000000_00000000L / a;
|
|
508 |
} else if (a <= 0 && b > 0) {
|
|
509 |
return a < 0x80000000_00000000L / b;
|
|
510 |
} else {
|
|
511 |
// a<=0 && b <=0
|
|
512 |
return a != 0 && b < 0x7FFFFFFF_FFFFFFFFL / a;
|
|
513 |
}
|
|
514 |
} else {
|
|
515 |
if (positive) {
|
|
516 |
return result > CodeUtil.maxValue(bits);
|
|
517 |
} else {
|
|
518 |
return result < CodeUtil.minValue(bits);
|
|
519 |
}
|
|
520 |
}
|
|
521 |
}
|
|
522 |
|
46344
|
523 |
public static boolean multiplicationCanOverflow(IntegerStamp a, IntegerStamp b) {
|
|
524 |
// see IntegerStamp#foldStamp for details
|
|
525 |
assert a.getBits() == b.getBits();
|
|
526 |
if (a.upMask() == 0) {
|
|
527 |
return false;
|
|
528 |
} else if (b.upMask() == 0) {
|
|
529 |
return false;
|
|
530 |
}
|
|
531 |
if (a.isUnrestricted()) {
|
|
532 |
return true;
|
|
533 |
}
|
|
534 |
if (b.isUnrestricted()) {
|
|
535 |
return true;
|
|
536 |
}
|
|
537 |
int bits = a.getBits();
|
|
538 |
long minNegA = a.lowerBound();
|
|
539 |
long maxNegA = Math.min(0, a.upperBound());
|
|
540 |
long minPosA = Math.max(0, a.lowerBound());
|
|
541 |
long maxPosA = a.upperBound();
|
|
542 |
|
|
543 |
long minNegB = b.lowerBound();
|
|
544 |
long maxNegB = Math.min(0, b.upperBound());
|
|
545 |
long minPosB = Math.max(0, b.lowerBound());
|
|
546 |
long maxPosB = b.upperBound();
|
|
547 |
|
|
548 |
boolean mayOverflow = false;
|
|
549 |
if (a.canBePositive()) {
|
|
550 |
if (b.canBePositive()) {
|
|
551 |
mayOverflow |= IntegerStamp.multiplicationOverflows(maxPosA, maxPosB, bits);
|
|
552 |
mayOverflow |= IntegerStamp.multiplicationOverflows(minPosA, minPosB, bits);
|
|
553 |
}
|
|
554 |
if (b.canBeNegative()) {
|
|
555 |
mayOverflow |= IntegerStamp.multiplicationOverflows(minPosA, maxNegB, bits);
|
|
556 |
mayOverflow |= IntegerStamp.multiplicationOverflows(maxPosA, minNegB, bits);
|
|
557 |
|
|
558 |
}
|
|
559 |
}
|
|
560 |
if (a.canBeNegative()) {
|
|
561 |
if (b.canBePositive()) {
|
|
562 |
mayOverflow |= IntegerStamp.multiplicationOverflows(maxNegA, minPosB, bits);
|
|
563 |
mayOverflow |= IntegerStamp.multiplicationOverflows(minNegA, maxPosB, bits);
|
|
564 |
}
|
|
565 |
if (b.canBeNegative()) {
|
|
566 |
mayOverflow |= IntegerStamp.multiplicationOverflows(minNegA, minNegB, bits);
|
|
567 |
mayOverflow |= IntegerStamp.multiplicationOverflows(maxNegA, maxNegB, bits);
|
|
568 |
}
|
|
569 |
}
|
|
570 |
return mayOverflow;
|
|
571 |
}
|
|
572 |
|
43972
|
573 |
public static boolean subtractionCanOverflow(IntegerStamp x, IntegerStamp y) {
|
|
574 |
assert x.getBits() == y.getBits();
|
46344
|
575 |
return subtractionOverflows(x.lowerBound(), y.upperBound(), x.getBits()) || subtractionOverflows(x.upperBound(), y.lowerBound(), x.getBits());
|
43972
|
576 |
}
|
|
577 |
|
|
578 |
public static boolean subtractionOverflows(long x, long y, int bits) {
|
|
579 |
long result = x - y;
|
|
580 |
if (bits == 64) {
|
|
581 |
return (((x ^ y) & (x ^ result)) < 0);
|
|
582 |
}
|
|
583 |
return result < CodeUtil.minValue(bits) || result > CodeUtil.maxValue(bits);
|
|
584 |
}
|
|
585 |
|
|
586 |
public static final ArithmeticOpTable OPS = new ArithmeticOpTable(
|
|
587 |
|
|
588 |
new UnaryOp.Neg() {
|
|
589 |
|
|
590 |
@Override
|
|
591 |
public Constant foldConstant(Constant value) {
|
|
592 |
PrimitiveConstant c = (PrimitiveConstant) value;
|
|
593 |
return JavaConstant.forIntegerKind(c.getJavaKind(), -c.asLong());
|
|
594 |
}
|
|
595 |
|
|
596 |
@Override
|
|
597 |
public Stamp foldStamp(Stamp s) {
|
|
598 |
IntegerStamp stamp = (IntegerStamp) s;
|
|
599 |
int bits = stamp.getBits();
|
|
600 |
if (stamp.lowerBound() != CodeUtil.minValue(bits)) {
|
|
601 |
// TODO(ls) check if the mask calculation is correct...
|
|
602 |
return StampFactory.forInteger(bits, -stamp.upperBound(), -stamp.lowerBound());
|
|
603 |
} else {
|
|
604 |
return stamp.unrestricted();
|
|
605 |
}
|
|
606 |
}
|
|
607 |
},
|
|
608 |
|
|
609 |
new BinaryOp.Add(true, true) {
|
|
610 |
|
|
611 |
@Override
|
|
612 |
public Constant foldConstant(Constant const1, Constant const2) {
|
|
613 |
PrimitiveConstant a = (PrimitiveConstant) const1;
|
|
614 |
PrimitiveConstant b = (PrimitiveConstant) const2;
|
|
615 |
assert a.getJavaKind() == b.getJavaKind();
|
|
616 |
return JavaConstant.forIntegerKind(a.getJavaKind(), a.asLong() + b.asLong());
|
|
617 |
}
|
|
618 |
|
|
619 |
@Override
|
|
620 |
public Stamp foldStamp(Stamp stamp1, Stamp stamp2) {
|
|
621 |
IntegerStamp a = (IntegerStamp) stamp1;
|
|
622 |
IntegerStamp b = (IntegerStamp) stamp2;
|
|
623 |
|
|
624 |
int bits = a.getBits();
|
|
625 |
assert bits == b.getBits();
|
|
626 |
|
|
627 |
if (a.isUnrestricted()) {
|
|
628 |
return a;
|
|
629 |
} else if (b.isUnrestricted()) {
|
|
630 |
return b;
|
|
631 |
}
|
|
632 |
long defaultMask = CodeUtil.mask(bits);
|
|
633 |
long variableBits = (a.downMask() ^ a.upMask()) | (b.downMask() ^ b.upMask());
|
|
634 |
long variableBitsWithCarry = variableBits | (carryBits(a.downMask(), b.downMask()) ^ carryBits(a.upMask(), b.upMask()));
|
|
635 |
long newDownMask = (a.downMask() + b.downMask()) & ~variableBitsWithCarry;
|
|
636 |
long newUpMask = (a.downMask() + b.downMask()) | variableBitsWithCarry;
|
|
637 |
|
|
638 |
newDownMask &= defaultMask;
|
|
639 |
newUpMask &= defaultMask;
|
|
640 |
|
|
641 |
long newLowerBound;
|
|
642 |
long newUpperBound;
|
|
643 |
boolean lowerOverflowsPositively = addOverflowsPositively(a.lowerBound(), b.lowerBound(), bits);
|
|
644 |
boolean upperOverflowsPositively = addOverflowsPositively(a.upperBound(), b.upperBound(), bits);
|
|
645 |
boolean lowerOverflowsNegatively = addOverflowsNegatively(a.lowerBound(), b.lowerBound(), bits);
|
|
646 |
boolean upperOverflowsNegatively = addOverflowsNegatively(a.upperBound(), b.upperBound(), bits);
|
|
647 |
if ((lowerOverflowsNegatively && !upperOverflowsNegatively) || (!lowerOverflowsPositively && upperOverflowsPositively)) {
|
|
648 |
newLowerBound = CodeUtil.minValue(bits);
|
|
649 |
newUpperBound = CodeUtil.maxValue(bits);
|
|
650 |
} else {
|
|
651 |
newLowerBound = CodeUtil.signExtend((a.lowerBound() + b.lowerBound()) & defaultMask, bits);
|
|
652 |
newUpperBound = CodeUtil.signExtend((a.upperBound() + b.upperBound()) & defaultMask, bits);
|
|
653 |
}
|
|
654 |
IntegerStamp limit = StampFactory.forInteger(bits, newLowerBound, newUpperBound);
|
|
655 |
newUpMask &= limit.upMask();
|
|
656 |
newUpperBound = CodeUtil.signExtend(newUpperBound & newUpMask, bits);
|
|
657 |
newDownMask |= limit.downMask();
|
|
658 |
newLowerBound |= newDownMask;
|
|
659 |
return new IntegerStamp(bits, newLowerBound, newUpperBound, newDownMask, newUpMask);
|
|
660 |
}
|
|
661 |
|
|
662 |
@Override
|
|
663 |
public boolean isNeutral(Constant value) {
|
|
664 |
PrimitiveConstant n = (PrimitiveConstant) value;
|
|
665 |
return n.asLong() == 0;
|
|
666 |
}
|
|
667 |
},
|
|
668 |
|
|
669 |
new BinaryOp.Sub(true, false) {
|
|
670 |
|
|
671 |
@Override
|
|
672 |
public Constant foldConstant(Constant const1, Constant const2) {
|
|
673 |
PrimitiveConstant a = (PrimitiveConstant) const1;
|
|
674 |
PrimitiveConstant b = (PrimitiveConstant) const2;
|
|
675 |
assert a.getJavaKind() == b.getJavaKind();
|
|
676 |
return JavaConstant.forIntegerKind(a.getJavaKind(), a.asLong() - b.asLong());
|
|
677 |
}
|
|
678 |
|
|
679 |
@Override
|
|
680 |
public Stamp foldStamp(Stamp a, Stamp b) {
|
|
681 |
return OPS.getAdd().foldStamp(a, OPS.getNeg().foldStamp(b));
|
|
682 |
}
|
|
683 |
|
|
684 |
@Override
|
|
685 |
public boolean isNeutral(Constant value) {
|
|
686 |
PrimitiveConstant n = (PrimitiveConstant) value;
|
|
687 |
return n.asLong() == 0;
|
|
688 |
}
|
|
689 |
|
|
690 |
@Override
|
|
691 |
public Constant getZero(Stamp s) {
|
|
692 |
IntegerStamp stamp = (IntegerStamp) s;
|
|
693 |
return JavaConstant.forPrimitiveInt(stamp.getBits(), 0);
|
|
694 |
}
|
|
695 |
},
|
|
696 |
|
|
697 |
new BinaryOp.Mul(true, true) {
|
|
698 |
|
|
699 |
@Override
|
|
700 |
public Constant foldConstant(Constant const1, Constant const2) {
|
|
701 |
PrimitiveConstant a = (PrimitiveConstant) const1;
|
|
702 |
PrimitiveConstant b = (PrimitiveConstant) const2;
|
|
703 |
assert a.getJavaKind() == b.getJavaKind();
|
|
704 |
return JavaConstant.forIntegerKind(a.getJavaKind(), a.asLong() * b.asLong());
|
|
705 |
}
|
|
706 |
|
|
707 |
@Override
|
|
708 |
public Stamp foldStamp(Stamp stamp1, Stamp stamp2) {
|
|
709 |
IntegerStamp a = (IntegerStamp) stamp1;
|
|
710 |
IntegerStamp b = (IntegerStamp) stamp2;
|
|
711 |
|
|
712 |
int bits = a.getBits();
|
|
713 |
assert bits == b.getBits();
|
|
714 |
// if a==0 or b==0 result of a*b is always 0
|
|
715 |
if (a.upMask() == 0) {
|
|
716 |
return a;
|
|
717 |
} else if (b.upMask() == 0) {
|
|
718 |
return b;
|
|
719 |
} else {
|
|
720 |
// if a has the full range or b, the result will also have it
|
|
721 |
if (a.isUnrestricted()) {
|
|
722 |
return a;
|
|
723 |
} else if (b.isUnrestricted()) {
|
|
724 |
return b;
|
|
725 |
}
|
|
726 |
// a!=0 && b !=0 holds
|
|
727 |
long newLowerBound = Long.MAX_VALUE;
|
|
728 |
long newUpperBound = Long.MIN_VALUE;
|
|
729 |
/*
|
|
730 |
* Based on the signs of the incoming stamps lower and upper bound
|
|
731 |
* of the result of the multiplication may be swapped. LowerBound
|
|
732 |
* can become upper bound if both signs are negative, and so on. To
|
|
733 |
* determine the new values for lower and upper bound we need to
|
|
734 |
* look at the max and min of the cases blow:
|
|
735 |
*
|
|
736 |
* @formatter:off
|
|
737 |
*
|
|
738 |
* a.lowerBound * b.lowerBound
|
|
739 |
* a.lowerBound * b.upperBound
|
|
740 |
* a.upperBound * b.lowerBound
|
|
741 |
* a.upperBound * b.upperBound
|
|
742 |
*
|
|
743 |
* @formatter:on
|
|
744 |
*
|
|
745 |
* We are only interested in those cases that are relevant due to
|
|
746 |
* the sign of the involved stamps (whether a stamp includes
|
|
747 |
* negative and / or positive values). Based on the signs, the maximum
|
|
748 |
* or minimum of the above multiplications form the new lower and
|
|
749 |
* upper bounds.
|
|
750 |
*
|
|
751 |
* The table below contains the interesting candidates for lower and
|
|
752 |
* upper bound after multiplication.
|
|
753 |
*
|
|
754 |
* For example if we consider two stamps a & b that both contain
|
46344
|
755 |
* negative and positive values, the product of minNegA * minNegB
|
43972
|
756 |
* (both the smallest negative value for each stamp) can only be the
|
|
757 |
* highest positive number. The other candidates can be computed in
|
|
758 |
* a similar fashion. Some of them can never be a new minimum or
|
|
759 |
* maximum and are therefore excluded.
|
|
760 |
*
|
|
761 |
*
|
|
762 |
* @formatter:off
|
|
763 |
*
|
46344
|
764 |
* [x................0................y]
|
|
765 |
* -------------------------------------
|
|
766 |
* [minNeg maxNeg minPos maxPos]
|
|
767 |
*
|
|
768 |
* where maxNeg = min(0,y) && minPos = max(0,x)
|
43972
|
769 |
*
|
|
770 |
*
|
46344
|
771 |
* |minNegA maxNegA minPosA maxPosA
|
|
772 |
* _______ |____________________________________
|
|
773 |
* minNegB | MAX / : / MIN
|
|
774 |
* maxNegB | / MIN : MAX /
|
|
775 |
* |------------------+-----------------
|
|
776 |
* minPosB | / MAX : MIN /
|
|
777 |
* maxPosB | MIN / : / MAX
|
43972
|
778 |
*
|
|
779 |
* @formatter:on
|
|
780 |
*/
|
|
781 |
// We materialize all factors here. If they are needed, the signs of
|
|
782 |
// the stamp will ensure the correct value is used.
|
46344
|
783 |
long minNegA = a.lowerBound();
|
|
784 |
long maxNegA = Math.min(0, a.upperBound());
|
|
785 |
long minPosA = Math.max(0, a.lowerBound());
|
|
786 |
long maxPosA = a.upperBound();
|
43972
|
787 |
|
46344
|
788 |
long minNegB = b.lowerBound();
|
|
789 |
long maxNegB = Math.min(0, b.upperBound());
|
|
790 |
long minPosB = Math.max(0, b.lowerBound());
|
|
791 |
long maxPosB = b.upperBound();
|
43972
|
792 |
|
|
793 |
// multiplication has shift semantics
|
|
794 |
long newUpMask = ~CodeUtil.mask(Long.numberOfTrailingZeros(a.upMask) + Long.numberOfTrailingZeros(b.upMask)) & CodeUtil.mask(bits);
|
|
795 |
|
|
796 |
if (a.canBePositive()) {
|
|
797 |
if (b.canBePositive()) {
|
46344
|
798 |
if (multiplicationOverflows(maxPosA, maxPosB, bits)) {
|
43972
|
799 |
return a.unrestricted();
|
|
800 |
}
|
46344
|
801 |
long maxCandidate = maxPosA * maxPosB;
|
|
802 |
if (multiplicationOverflows(minPosA, minPosB, bits)) {
|
43972
|
803 |
return a.unrestricted();
|
|
804 |
}
|
46344
|
805 |
long minCandidate = minPosA * minPosB;
|
43972
|
806 |
newLowerBound = Math.min(newLowerBound, minCandidate);
|
|
807 |
newUpperBound = Math.max(newUpperBound, maxCandidate);
|
|
808 |
}
|
|
809 |
if (b.canBeNegative()) {
|
46344
|
810 |
if (multiplicationOverflows(minPosA, maxNegB, bits)) {
|
43972
|
811 |
return a.unrestricted();
|
|
812 |
}
|
46344
|
813 |
long maxCandidate = minPosA * maxNegB;
|
|
814 |
if (multiplicationOverflows(maxPosA, minNegB, bits)) {
|
43972
|
815 |
return a.unrestricted();
|
|
816 |
}
|
46344
|
817 |
long minCandidate = maxPosA * minNegB;
|
43972
|
818 |
newLowerBound = Math.min(newLowerBound, minCandidate);
|
|
819 |
newUpperBound = Math.max(newUpperBound, maxCandidate);
|
|
820 |
}
|
|
821 |
}
|
|
822 |
if (a.canBeNegative()) {
|
|
823 |
if (b.canBePositive()) {
|
46344
|
824 |
if (multiplicationOverflows(maxNegA, minPosB, bits)) {
|
43972
|
825 |
return a.unrestricted();
|
|
826 |
}
|
46344
|
827 |
long maxCandidate = maxNegA * minPosB;
|
|
828 |
if (multiplicationOverflows(minNegA, maxPosB, bits)) {
|
43972
|
829 |
return a.unrestricted();
|
|
830 |
}
|
46344
|
831 |
long minCandidate = minNegA * maxPosB;
|
43972
|
832 |
newLowerBound = Math.min(newLowerBound, minCandidate);
|
|
833 |
newUpperBound = Math.max(newUpperBound, maxCandidate);
|
|
834 |
}
|
|
835 |
if (b.canBeNegative()) {
|
46344
|
836 |
if (multiplicationOverflows(minNegA, minNegB, bits)) {
|
43972
|
837 |
return a.unrestricted();
|
|
838 |
}
|
46344
|
839 |
long maxCandidate = minNegA * minNegB;
|
|
840 |
if (multiplicationOverflows(maxNegA, maxNegB, bits)) {
|
43972
|
841 |
return a.unrestricted();
|
|
842 |
}
|
46344
|
843 |
long minCandidate = maxNegA * maxNegB;
|
43972
|
844 |
newLowerBound = Math.min(newLowerBound, minCandidate);
|
|
845 |
newUpperBound = Math.max(newUpperBound, maxCandidate);
|
|
846 |
}
|
|
847 |
}
|
|
848 |
|
|
849 |
assert newLowerBound <= newUpperBound;
|
|
850 |
return StampFactory.forIntegerWithMask(bits, newLowerBound, newUpperBound, 0, newUpMask);
|
|
851 |
}
|
|
852 |
}
|
|
853 |
|
|
854 |
@Override
|
|
855 |
public boolean isNeutral(Constant value) {
|
|
856 |
PrimitiveConstant n = (PrimitiveConstant) value;
|
|
857 |
return n.asLong() == 1;
|
|
858 |
}
|
|
859 |
},
|
|
860 |
|
|
861 |
new BinaryOp.Div(true, false) {
|
|
862 |
|
|
863 |
@Override
|
|
864 |
public Constant foldConstant(Constant const1, Constant const2) {
|
|
865 |
PrimitiveConstant a = (PrimitiveConstant) const1;
|
|
866 |
PrimitiveConstant b = (PrimitiveConstant) const2;
|
|
867 |
assert a.getJavaKind() == b.getJavaKind();
|
|
868 |
return JavaConstant.forIntegerKind(a.getJavaKind(), a.asLong() / b.asLong());
|
|
869 |
}
|
|
870 |
|
|
871 |
@Override
|
|
872 |
public Stamp foldStamp(Stamp stamp1, Stamp stamp2) {
|
|
873 |
IntegerStamp a = (IntegerStamp) stamp1;
|
|
874 |
IntegerStamp b = (IntegerStamp) stamp2;
|
|
875 |
assert a.getBits() == b.getBits();
|
|
876 |
if (b.isStrictlyPositive()) {
|
|
877 |
long newLowerBound = a.lowerBound() / b.upperBound();
|
|
878 |
long newUpperBound = a.upperBound() / b.lowerBound();
|
|
879 |
return StampFactory.forInteger(a.getBits(), newLowerBound, newUpperBound);
|
|
880 |
} else {
|
|
881 |
return a.unrestricted();
|
|
882 |
}
|
|
883 |
}
|
|
884 |
|
|
885 |
@Override
|
|
886 |
public boolean isNeutral(Constant value) {
|
|
887 |
PrimitiveConstant n = (PrimitiveConstant) value;
|
|
888 |
return n.asLong() == 1;
|
|
889 |
}
|
|
890 |
},
|
|
891 |
|
|
892 |
new BinaryOp.Rem(false, false) {
|
|
893 |
|
|
894 |
@Override
|
|
895 |
public Constant foldConstant(Constant const1, Constant const2) {
|
|
896 |
PrimitiveConstant a = (PrimitiveConstant) const1;
|
|
897 |
PrimitiveConstant b = (PrimitiveConstant) const2;
|
|
898 |
assert a.getJavaKind() == b.getJavaKind();
|
|
899 |
return JavaConstant.forIntegerKind(a.getJavaKind(), a.asLong() % b.asLong());
|
|
900 |
}
|
|
901 |
|
|
902 |
@Override
|
|
903 |
public Stamp foldStamp(Stamp stamp1, Stamp stamp2) {
|
|
904 |
IntegerStamp a = (IntegerStamp) stamp1;
|
|
905 |
IntegerStamp b = (IntegerStamp) stamp2;
|
|
906 |
assert a.getBits() == b.getBits();
|
|
907 |
// zero is always possible
|
|
908 |
long newLowerBound = Math.min(a.lowerBound(), 0);
|
|
909 |
long newUpperBound = Math.max(a.upperBound(), 0);
|
|
910 |
|
|
911 |
/* the maximum absolute value of the result, derived from b */
|
|
912 |
long magnitude;
|
|
913 |
if (b.lowerBound() == CodeUtil.minValue(b.getBits())) {
|
|
914 |
// Math.abs(...) - 1 does not work in a case
|
|
915 |
magnitude = CodeUtil.maxValue(b.getBits());
|
|
916 |
} else {
|
|
917 |
magnitude = Math.max(Math.abs(b.lowerBound()), Math.abs(b.upperBound())) - 1;
|
|
918 |
}
|
|
919 |
newLowerBound = Math.max(newLowerBound, -magnitude);
|
|
920 |
newUpperBound = Math.min(newUpperBound, magnitude);
|
|
921 |
|
|
922 |
return StampFactory.forInteger(a.getBits(), newLowerBound, newUpperBound);
|
|
923 |
}
|
|
924 |
},
|
|
925 |
|
|
926 |
new UnaryOp.Not() {
|
|
927 |
|
|
928 |
@Override
|
|
929 |
public Constant foldConstant(Constant c) {
|
|
930 |
PrimitiveConstant value = (PrimitiveConstant) c;
|
|
931 |
return JavaConstant.forIntegerKind(value.getJavaKind(), ~value.asLong());
|
|
932 |
}
|
|
933 |
|
|
934 |
@Override
|
|
935 |
public Stamp foldStamp(Stamp stamp) {
|
|
936 |
IntegerStamp integerStamp = (IntegerStamp) stamp;
|
|
937 |
int bits = integerStamp.getBits();
|
|
938 |
long defaultMask = CodeUtil.mask(bits);
|
|
939 |
return new IntegerStamp(bits, ~integerStamp.upperBound(), ~integerStamp.lowerBound(), (~integerStamp.upMask()) & defaultMask, (~integerStamp.downMask()) & defaultMask);
|
|
940 |
}
|
|
941 |
},
|
|
942 |
|
|
943 |
new BinaryOp.And(true, true) {
|
|
944 |
|
|
945 |
@Override
|
|
946 |
public Constant foldConstant(Constant const1, Constant const2) {
|
|
947 |
PrimitiveConstant a = (PrimitiveConstant) const1;
|
|
948 |
PrimitiveConstant b = (PrimitiveConstant) const2;
|
|
949 |
assert a.getJavaKind() == b.getJavaKind();
|
|
950 |
return JavaConstant.forIntegerKind(a.getJavaKind(), a.asLong() & b.asLong());
|
|
951 |
}
|
|
952 |
|
|
953 |
@Override
|
|
954 |
public Stamp foldStamp(Stamp stamp1, Stamp stamp2) {
|
|
955 |
IntegerStamp a = (IntegerStamp) stamp1;
|
|
956 |
IntegerStamp b = (IntegerStamp) stamp2;
|
|
957 |
assert a.getBits() == b.getBits();
|
|
958 |
return stampForMask(a.getBits(), a.downMask() & b.downMask(), a.upMask() & b.upMask());
|
|
959 |
}
|
|
960 |
|
|
961 |
@Override
|
|
962 |
public boolean isNeutral(Constant value) {
|
|
963 |
PrimitiveConstant n = (PrimitiveConstant) value;
|
|
964 |
int bits = n.getJavaKind().getBitCount();
|
|
965 |
long mask = CodeUtil.mask(bits);
|
|
966 |
return (n.asLong() & mask) == mask;
|
|
967 |
}
|
|
968 |
},
|
|
969 |
|
|
970 |
new BinaryOp.Or(true, true) {
|
|
971 |
|
|
972 |
@Override
|
|
973 |
public Constant foldConstant(Constant const1, Constant const2) {
|
|
974 |
PrimitiveConstant a = (PrimitiveConstant) const1;
|
|
975 |
PrimitiveConstant b = (PrimitiveConstant) const2;
|
|
976 |
assert a.getJavaKind() == b.getJavaKind();
|
|
977 |
return JavaConstant.forIntegerKind(a.getJavaKind(), a.asLong() | b.asLong());
|
|
978 |
}
|
|
979 |
|
|
980 |
@Override
|
|
981 |
public Stamp foldStamp(Stamp stamp1, Stamp stamp2) {
|
|
982 |
IntegerStamp a = (IntegerStamp) stamp1;
|
|
983 |
IntegerStamp b = (IntegerStamp) stamp2;
|
|
984 |
assert a.getBits() == b.getBits();
|
|
985 |
return stampForMask(a.getBits(), a.downMask() | b.downMask(), a.upMask() | b.upMask());
|
|
986 |
}
|
|
987 |
|
|
988 |
@Override
|
|
989 |
public boolean isNeutral(Constant value) {
|
|
990 |
PrimitiveConstant n = (PrimitiveConstant) value;
|
|
991 |
return n.asLong() == 0;
|
|
992 |
}
|
|
993 |
},
|
|
994 |
|
|
995 |
new BinaryOp.Xor(true, true) {
|
|
996 |
|
|
997 |
@Override
|
|
998 |
public Constant foldConstant(Constant const1, Constant const2) {
|
|
999 |
PrimitiveConstant a = (PrimitiveConstant) const1;
|
|
1000 |
PrimitiveConstant b = (PrimitiveConstant) const2;
|
|
1001 |
assert a.getJavaKind() == b.getJavaKind();
|
|
1002 |
return JavaConstant.forIntegerKind(a.getJavaKind(), a.asLong() ^ b.asLong());
|
|
1003 |
}
|
|
1004 |
|
|
1005 |
@Override
|
|
1006 |
public Stamp foldStamp(Stamp stamp1, Stamp stamp2) {
|
|
1007 |
IntegerStamp a = (IntegerStamp) stamp1;
|
|
1008 |
IntegerStamp b = (IntegerStamp) stamp2;
|
|
1009 |
assert a.getBits() == b.getBits();
|
|
1010 |
|
|
1011 |
long variableBits = (a.downMask() ^ a.upMask()) | (b.downMask() ^ b.upMask());
|
|
1012 |
long newDownMask = (a.downMask() ^ b.downMask()) & ~variableBits;
|
|
1013 |
long newUpMask = (a.downMask() ^ b.downMask()) | variableBits;
|
|
1014 |
return stampForMask(a.getBits(), newDownMask, newUpMask);
|
|
1015 |
}
|
|
1016 |
|
|
1017 |
@Override
|
|
1018 |
public boolean isNeutral(Constant value) {
|
|
1019 |
PrimitiveConstant n = (PrimitiveConstant) value;
|
|
1020 |
return n.asLong() == 0;
|
|
1021 |
}
|
|
1022 |
|
|
1023 |
@Override
|
|
1024 |
public Constant getZero(Stamp s) {
|
|
1025 |
IntegerStamp stamp = (IntegerStamp) s;
|
|
1026 |
return JavaConstant.forPrimitiveInt(stamp.getBits(), 0);
|
|
1027 |
}
|
|
1028 |
},
|
|
1029 |
|
|
1030 |
new ShiftOp.Shl() {
|
|
1031 |
|
|
1032 |
@Override
|
|
1033 |
public Constant foldConstant(Constant value, int amount) {
|
|
1034 |
PrimitiveConstant c = (PrimitiveConstant) value;
|
|
1035 |
switch (c.getJavaKind()) {
|
|
1036 |
case Int:
|
|
1037 |
return JavaConstant.forInt(c.asInt() << amount);
|
|
1038 |
case Long:
|
|
1039 |
return JavaConstant.forLong(c.asLong() << amount);
|
|
1040 |
default:
|
|
1041 |
throw GraalError.shouldNotReachHere();
|
|
1042 |
}
|
|
1043 |
}
|
|
1044 |
|
|
1045 |
@Override
|
|
1046 |
public Stamp foldStamp(Stamp stamp, IntegerStamp shift) {
|
|
1047 |
IntegerStamp value = (IntegerStamp) stamp;
|
|
1048 |
int bits = value.getBits();
|
|
1049 |
long defaultMask = CodeUtil.mask(bits);
|
|
1050 |
if (value.upMask() == 0) {
|
|
1051 |
return value;
|
|
1052 |
}
|
|
1053 |
int shiftMask = getShiftAmountMask(stamp);
|
|
1054 |
int shiftBits = Integer.bitCount(shiftMask);
|
|
1055 |
if (shift.lowerBound() == shift.upperBound()) {
|
|
1056 |
int shiftAmount = (int) (shift.lowerBound() & shiftMask);
|
|
1057 |
if (shiftAmount == 0) {
|
|
1058 |
return value;
|
|
1059 |
}
|
|
1060 |
// the mask of bits that will be lost or shifted into the sign bit
|
|
1061 |
long removedBits = -1L << (bits - shiftAmount - 1);
|
|
1062 |
if ((value.lowerBound() & removedBits) == 0 && (value.upperBound() & removedBits) == 0) {
|
|
1063 |
/*
|
|
1064 |
* use a better stamp if neither lower nor upper bound can lose
|
|
1065 |
* bits
|
|
1066 |
*/
|
|
1067 |
return new IntegerStamp(bits, value.lowerBound() << shiftAmount, value.upperBound() << shiftAmount, value.downMask() << shiftAmount, value.upMask() << shiftAmount);
|
|
1068 |
}
|
|
1069 |
}
|
|
1070 |
if ((shift.lowerBound() >>> shiftBits) == (shift.upperBound() >>> shiftBits)) {
|
|
1071 |
long downMask = defaultMask;
|
|
1072 |
long upMask = 0;
|
|
1073 |
for (long i = shift.lowerBound(); i <= shift.upperBound(); i++) {
|
|
1074 |
if (shift.contains(i)) {
|
|
1075 |
downMask &= value.downMask() << (i & shiftMask);
|
|
1076 |
upMask |= value.upMask() << (i & shiftMask);
|
|
1077 |
}
|
|
1078 |
}
|
|
1079 |
Stamp result = IntegerStamp.stampForMask(bits, downMask, upMask & defaultMask);
|
|
1080 |
return result;
|
|
1081 |
}
|
|
1082 |
return value.unrestricted();
|
|
1083 |
}
|
|
1084 |
|
|
1085 |
@Override
|
|
1086 |
public int getShiftAmountMask(Stamp s) {
|
|
1087 |
IntegerStamp stamp = (IntegerStamp) s;
|
|
1088 |
assert CodeUtil.isPowerOf2(stamp.getBits());
|
|
1089 |
return stamp.getBits() - 1;
|
|
1090 |
}
|
|
1091 |
},
|
|
1092 |
|
|
1093 |
new ShiftOp.Shr() {
|
|
1094 |
|
|
1095 |
@Override
|
|
1096 |
public Constant foldConstant(Constant value, int amount) {
|
|
1097 |
PrimitiveConstant c = (PrimitiveConstant) value;
|
|
1098 |
switch (c.getJavaKind()) {
|
|
1099 |
case Int:
|
|
1100 |
return JavaConstant.forInt(c.asInt() >> amount);
|
|
1101 |
case Long:
|
|
1102 |
return JavaConstant.forLong(c.asLong() >> amount);
|
|
1103 |
default:
|
|
1104 |
throw GraalError.shouldNotReachHere();
|
|
1105 |
}
|
|
1106 |
}
|
|
1107 |
|
|
1108 |
@Override
|
|
1109 |
public Stamp foldStamp(Stamp stamp, IntegerStamp shift) {
|
|
1110 |
IntegerStamp value = (IntegerStamp) stamp;
|
|
1111 |
int bits = value.getBits();
|
|
1112 |
if (shift.lowerBound() == shift.upperBound()) {
|
|
1113 |
long shiftCount = shift.lowerBound() & getShiftAmountMask(stamp);
|
|
1114 |
if (shiftCount == 0) {
|
|
1115 |
return stamp;
|
|
1116 |
}
|
|
1117 |
|
|
1118 |
int extraBits = 64 - bits;
|
|
1119 |
long defaultMask = CodeUtil.mask(bits);
|
|
1120 |
// shifting back and forth performs sign extension
|
|
1121 |
long downMask = (value.downMask() << extraBits) >> (shiftCount + extraBits) & defaultMask;
|
|
1122 |
long upMask = (value.upMask() << extraBits) >> (shiftCount + extraBits) & defaultMask;
|
|
1123 |
return new IntegerStamp(bits, value.lowerBound() >> shiftCount, value.upperBound() >> shiftCount, downMask, upMask);
|
|
1124 |
}
|
|
1125 |
long mask = IntegerStamp.upMaskFor(bits, value.lowerBound(), value.upperBound());
|
|
1126 |
return IntegerStamp.stampForMask(bits, 0, mask);
|
|
1127 |
}
|
|
1128 |
|
|
1129 |
@Override
|
|
1130 |
public int getShiftAmountMask(Stamp s) {
|
|
1131 |
IntegerStamp stamp = (IntegerStamp) s;
|
|
1132 |
assert CodeUtil.isPowerOf2(stamp.getBits());
|
|
1133 |
return stamp.getBits() - 1;
|
|
1134 |
}
|
|
1135 |
},
|
|
1136 |
|
|
1137 |
new ShiftOp.UShr() {
|
|
1138 |
|
|
1139 |
@Override
|
|
1140 |
public Constant foldConstant(Constant value, int amount) {
|
|
1141 |
PrimitiveConstant c = (PrimitiveConstant) value;
|
|
1142 |
switch (c.getJavaKind()) {
|
|
1143 |
case Int:
|
|
1144 |
return JavaConstant.forInt(c.asInt() >>> amount);
|
|
1145 |
case Long:
|
|
1146 |
return JavaConstant.forLong(c.asLong() >>> amount);
|
|
1147 |
default:
|
|
1148 |
throw GraalError.shouldNotReachHere();
|
|
1149 |
}
|
|
1150 |
}
|
|
1151 |
|
|
1152 |
@Override
|
|
1153 |
public Stamp foldStamp(Stamp stamp, IntegerStamp shift) {
|
|
1154 |
IntegerStamp value = (IntegerStamp) stamp;
|
|
1155 |
int bits = value.getBits();
|
|
1156 |
if (shift.lowerBound() == shift.upperBound()) {
|
|
1157 |
long shiftCount = shift.lowerBound() & getShiftAmountMask(stamp);
|
|
1158 |
if (shiftCount == 0) {
|
|
1159 |
return stamp;
|
|
1160 |
}
|
|
1161 |
|
|
1162 |
long downMask = value.downMask() >>> shiftCount;
|
|
1163 |
long upMask = value.upMask() >>> shiftCount;
|
|
1164 |
if (value.lowerBound() < 0) {
|
|
1165 |
return new IntegerStamp(bits, downMask, upMask, downMask, upMask);
|
|
1166 |
} else {
|
|
1167 |
return new IntegerStamp(bits, value.lowerBound() >>> shiftCount, value.upperBound() >>> shiftCount, downMask, upMask);
|
|
1168 |
}
|
|
1169 |
}
|
|
1170 |
long mask = IntegerStamp.upMaskFor(bits, value.lowerBound(), value.upperBound());
|
|
1171 |
return IntegerStamp.stampForMask(bits, 0, mask);
|
|
1172 |
}
|
|
1173 |
|
|
1174 |
@Override
|
|
1175 |
public int getShiftAmountMask(Stamp s) {
|
|
1176 |
IntegerStamp stamp = (IntegerStamp) s;
|
|
1177 |
assert CodeUtil.isPowerOf2(stamp.getBits());
|
|
1178 |
return stamp.getBits() - 1;
|
|
1179 |
}
|
|
1180 |
},
|
|
1181 |
|
|
1182 |
new UnaryOp.Abs() {
|
|
1183 |
|
|
1184 |
@Override
|
|
1185 |
public Constant foldConstant(Constant value) {
|
|
1186 |
PrimitiveConstant c = (PrimitiveConstant) value;
|
|
1187 |
return JavaConstant.forIntegerKind(c.getJavaKind(), Math.abs(c.asLong()));
|
|
1188 |
}
|
|
1189 |
|
|
1190 |
@Override
|
|
1191 |
public Stamp foldStamp(Stamp input) {
|
|
1192 |
IntegerStamp stamp = (IntegerStamp) input;
|
|
1193 |
int bits = stamp.getBits();
|
|
1194 |
if (stamp.lowerBound() == CodeUtil.minValue(bits)) {
|
|
1195 |
return input.unrestricted();
|
|
1196 |
} else {
|
|
1197 |
long limit = Math.max(-stamp.lowerBound(), stamp.upperBound());
|
|
1198 |
return StampFactory.forInteger(bits, 0, limit);
|
|
1199 |
}
|
|
1200 |
}
|
|
1201 |
},
|
|
1202 |
|
|
1203 |
null,
|
|
1204 |
|
|
1205 |
new IntegerConvertOp.ZeroExtend() {
|
|
1206 |
|
|
1207 |
@Override
|
|
1208 |
public Constant foldConstant(int inputBits, int resultBits, Constant c) {
|
|
1209 |
PrimitiveConstant value = (PrimitiveConstant) c;
|
|
1210 |
return JavaConstant.forPrimitiveInt(resultBits, CodeUtil.zeroExtend(value.asLong(), inputBits));
|
|
1211 |
}
|
|
1212 |
|
|
1213 |
@Override
|
|
1214 |
public Stamp foldStamp(int inputBits, int resultBits, Stamp input) {
|
|
1215 |
IntegerStamp stamp = (IntegerStamp) input;
|
|
1216 |
assert inputBits == stamp.getBits();
|
|
1217 |
assert inputBits <= resultBits;
|
|
1218 |
|
46344
|
1219 |
if (inputBits == resultBits) {
|
|
1220 |
return input;
|
|
1221 |
}
|
|
1222 |
|
|
1223 |
if (input.isEmpty()) {
|
|
1224 |
return StampFactory.forInteger(resultBits).empty();
|
|
1225 |
}
|
|
1226 |
|
43972
|
1227 |
long downMask = CodeUtil.zeroExtend(stamp.downMask(), inputBits);
|
|
1228 |
long upMask = CodeUtil.zeroExtend(stamp.upMask(), inputBits);
|
46344
|
1229 |
long lowerBound = stamp.unsignedLowerBound();
|
|
1230 |
long upperBound = stamp.unsignedUpperBound();
|
|
1231 |
return IntegerStamp.create(resultBits, lowerBound, upperBound, downMask, upMask);
|
|
1232 |
}
|
43972
|
1233 |
|
46344
|
1234 |
@Override
|
|
1235 |
public Stamp invertStamp(int inputBits, int resultBits, Stamp outStamp) {
|
|
1236 |
IntegerStamp stamp = (IntegerStamp) outStamp;
|
|
1237 |
if (stamp.isEmpty()) {
|
|
1238 |
return StampFactory.forInteger(inputBits).empty();
|
43972
|
1239 |
}
|
46344
|
1240 |
return StampFactory.forUnsignedInteger(inputBits, stamp.lowerBound(), stamp.upperBound(), stamp.downMask(), stamp.upMask());
|
43972
|
1241 |
}
|
|
1242 |
},
|
|
1243 |
|
|
1244 |
new IntegerConvertOp.SignExtend() {
|
|
1245 |
|
|
1246 |
@Override
|
|
1247 |
public Constant foldConstant(int inputBits, int resultBits, Constant c) {
|
|
1248 |
PrimitiveConstant value = (PrimitiveConstant) c;
|
|
1249 |
return JavaConstant.forPrimitiveInt(resultBits, CodeUtil.signExtend(value.asLong(), inputBits));
|
|
1250 |
}
|
|
1251 |
|
|
1252 |
@Override
|
|
1253 |
public Stamp foldStamp(int inputBits, int resultBits, Stamp input) {
|
|
1254 |
IntegerStamp stamp = (IntegerStamp) input;
|
|
1255 |
assert inputBits == stamp.getBits();
|
|
1256 |
assert inputBits <= resultBits;
|
|
1257 |
|
|
1258 |
long defaultMask = CodeUtil.mask(resultBits);
|
|
1259 |
long downMask = CodeUtil.signExtend(stamp.downMask(), inputBits) & defaultMask;
|
|
1260 |
long upMask = CodeUtil.signExtend(stamp.upMask(), inputBits) & defaultMask;
|
|
1261 |
|
|
1262 |
return new IntegerStamp(resultBits, stamp.lowerBound(), stamp.upperBound(), downMask, upMask);
|
|
1263 |
}
|
46344
|
1264 |
|
|
1265 |
@Override
|
|
1266 |
public Stamp invertStamp(int inputBits, int resultBits, Stamp outStamp) {
|
|
1267 |
IntegerStamp stamp = (IntegerStamp) outStamp;
|
|
1268 |
long mask = CodeUtil.mask(inputBits);
|
|
1269 |
return StampFactory.forIntegerWithMask(inputBits, stamp.lowerBound(), stamp.upperBound(), stamp.downMask() & mask, stamp.upMask() & mask);
|
|
1270 |
}
|
43972
|
1271 |
},
|
|
1272 |
|
|
1273 |
new IntegerConvertOp.Narrow() {
|
|
1274 |
|
|
1275 |
@Override
|
|
1276 |
public Constant foldConstant(int inputBits, int resultBits, Constant c) {
|
|
1277 |
PrimitiveConstant value = (PrimitiveConstant) c;
|
|
1278 |
return JavaConstant.forPrimitiveInt(resultBits, CodeUtil.narrow(value.asLong(), resultBits));
|
|
1279 |
}
|
|
1280 |
|
|
1281 |
@Override
|
|
1282 |
public Stamp foldStamp(int inputBits, int resultBits, Stamp input) {
|
|
1283 |
IntegerStamp stamp = (IntegerStamp) input;
|
|
1284 |
assert inputBits == stamp.getBits();
|
|
1285 |
assert resultBits <= inputBits;
|
|
1286 |
if (resultBits == inputBits) {
|
|
1287 |
return stamp;
|
|
1288 |
}
|
|
1289 |
|
|
1290 |
final long upperBound;
|
|
1291 |
if (stamp.lowerBound() < CodeUtil.minValue(resultBits)) {
|
|
1292 |
upperBound = CodeUtil.maxValue(resultBits);
|
|
1293 |
} else {
|
|
1294 |
upperBound = saturate(stamp.upperBound(), resultBits);
|
|
1295 |
}
|
|
1296 |
final long lowerBound;
|
|
1297 |
if (stamp.upperBound() > CodeUtil.maxValue(resultBits)) {
|
|
1298 |
lowerBound = CodeUtil.minValue(resultBits);
|
|
1299 |
} else {
|
|
1300 |
lowerBound = saturate(stamp.lowerBound(), resultBits);
|
|
1301 |
}
|
|
1302 |
|
|
1303 |
long defaultMask = CodeUtil.mask(resultBits);
|
|
1304 |
long newDownMask = stamp.downMask() & defaultMask;
|
|
1305 |
long newUpMask = stamp.upMask() & defaultMask;
|
|
1306 |
long newLowerBound = CodeUtil.signExtend((lowerBound | newDownMask) & newUpMask, resultBits);
|
|
1307 |
long newUpperBound = CodeUtil.signExtend((upperBound | newDownMask) & newUpMask, resultBits);
|
|
1308 |
return new IntegerStamp(resultBits, newLowerBound, newUpperBound, newDownMask, newUpMask);
|
|
1309 |
}
|
|
1310 |
},
|
|
1311 |
|
|
1312 |
new FloatConvertOp(I2F) {
|
|
1313 |
|
|
1314 |
@Override
|
|
1315 |
public Constant foldConstant(Constant c) {
|
|
1316 |
PrimitiveConstant value = (PrimitiveConstant) c;
|
|
1317 |
return JavaConstant.forFloat(value.asInt());
|
|
1318 |
}
|
|
1319 |
|
|
1320 |
@Override
|
|
1321 |
public Stamp foldStamp(Stamp input) {
|
|
1322 |
IntegerStamp stamp = (IntegerStamp) input;
|
|
1323 |
assert stamp.getBits() == 32;
|
|
1324 |
float lowerBound = stamp.lowerBound();
|
|
1325 |
float upperBound = stamp.upperBound();
|
|
1326 |
return StampFactory.forFloat(JavaKind.Float, lowerBound, upperBound, true);
|
|
1327 |
}
|
|
1328 |
},
|
|
1329 |
|
|
1330 |
new FloatConvertOp(L2F) {
|
|
1331 |
|
|
1332 |
@Override
|
|
1333 |
public Constant foldConstant(Constant c) {
|
|
1334 |
PrimitiveConstant value = (PrimitiveConstant) c;
|
|
1335 |
return JavaConstant.forFloat(value.asLong());
|
|
1336 |
}
|
|
1337 |
|
|
1338 |
@Override
|
|
1339 |
public Stamp foldStamp(Stamp input) {
|
|
1340 |
IntegerStamp stamp = (IntegerStamp) input;
|
|
1341 |
assert stamp.getBits() == 64;
|
|
1342 |
float lowerBound = stamp.lowerBound();
|
|
1343 |
float upperBound = stamp.upperBound();
|
|
1344 |
return StampFactory.forFloat(JavaKind.Float, lowerBound, upperBound, true);
|
|
1345 |
}
|
|
1346 |
},
|
|
1347 |
|
|
1348 |
new FloatConvertOp(I2D) {
|
|
1349 |
|
|
1350 |
@Override
|
|
1351 |
public Constant foldConstant(Constant c) {
|
|
1352 |
PrimitiveConstant value = (PrimitiveConstant) c;
|
|
1353 |
return JavaConstant.forDouble(value.asInt());
|
|
1354 |
}
|
|
1355 |
|
|
1356 |
@Override
|
|
1357 |
public Stamp foldStamp(Stamp input) {
|
|
1358 |
IntegerStamp stamp = (IntegerStamp) input;
|
|
1359 |
assert stamp.getBits() == 32;
|
|
1360 |
double lowerBound = stamp.lowerBound();
|
|
1361 |
double upperBound = stamp.upperBound();
|
|
1362 |
return StampFactory.forFloat(JavaKind.Double, lowerBound, upperBound, true);
|
|
1363 |
}
|
|
1364 |
},
|
|
1365 |
|
|
1366 |
new FloatConvertOp(L2D) {
|
|
1367 |
|
|
1368 |
@Override
|
|
1369 |
public Constant foldConstant(Constant c) {
|
|
1370 |
PrimitiveConstant value = (PrimitiveConstant) c;
|
|
1371 |
return JavaConstant.forDouble(value.asLong());
|
|
1372 |
}
|
|
1373 |
|
|
1374 |
@Override
|
|
1375 |
public Stamp foldStamp(Stamp input) {
|
|
1376 |
IntegerStamp stamp = (IntegerStamp) input;
|
|
1377 |
assert stamp.getBits() == 64;
|
|
1378 |
double lowerBound = stamp.lowerBound();
|
|
1379 |
double upperBound = stamp.upperBound();
|
|
1380 |
return StampFactory.forFloat(JavaKind.Double, lowerBound, upperBound, true);
|
|
1381 |
}
|
|
1382 |
});
|
|
1383 |
}
|