|
1 /* |
|
2 * Copyright (c) 2018, 2019, 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 |
|
24 |
|
25 package org.graalvm.compiler.nodes.util; |
|
26 |
|
27 import org.graalvm.compiler.core.common.type.IntegerStamp; |
|
28 import org.graalvm.compiler.nodes.LogicNode; |
|
29 import org.graalvm.compiler.nodes.NodeView; |
|
30 import org.graalvm.compiler.nodes.ValueNode; |
|
31 |
|
32 public abstract class IntegerHelper { |
|
33 protected final int bits; |
|
34 |
|
35 protected IntegerHelper(int bits) { |
|
36 this.bits = bits; |
|
37 } |
|
38 |
|
39 public abstract long upperBound(IntegerStamp stamp); |
|
40 |
|
41 public abstract long lowerBound(IntegerStamp stamp); |
|
42 |
|
43 public int compare(long a, long b) { |
|
44 return rawCompare(cast(a), cast(b)); |
|
45 } |
|
46 |
|
47 public boolean isGreater(long a, long b) { |
|
48 return compare(a, b) > 0; |
|
49 } |
|
50 |
|
51 public boolean isSmaller(long a, long b) { |
|
52 return compare(a, b) < 0; |
|
53 } |
|
54 |
|
55 public boolean isGreaterEqual(long a, long b) { |
|
56 return compare(a, b) >= 0; |
|
57 } |
|
58 |
|
59 public boolean isSmallerEqual(long a, long b) { |
|
60 return compare(a, b) <= 0; |
|
61 } |
|
62 |
|
63 public long min(long a, long b) { |
|
64 return rawMin(cast(a), cast(b)); |
|
65 } |
|
66 |
|
67 public long max(long a, long b) { |
|
68 return rawMax(cast(a), cast(b)); |
|
69 } |
|
70 |
|
71 public abstract long cast(long a); |
|
72 |
|
73 public abstract long minValue(); |
|
74 |
|
75 public abstract long maxValue(); |
|
76 |
|
77 public abstract IntegerStamp stamp(long min, long max); |
|
78 |
|
79 public abstract LogicNode createCompareNode(ValueNode x, ValueNode y, NodeView view); |
|
80 |
|
81 protected abstract int rawCompare(long a, long b); |
|
82 |
|
83 protected abstract long rawMin(long a, long b); |
|
84 |
|
85 protected abstract long rawMax(long a, long b); |
|
86 } |