diff options
author | 2014-10-20 16:36:47 +0100 | |
---|---|---|
committer | 2014-10-21 13:48:32 +0100 | |
commit | 88cb1755e1d6acaed0f66ce65d7a2a4465053342 (patch) | |
tree | 6ffdd07aa75a38eae9376bd95d0991a789cd624c /test/411-optimizing-arith/src/Main.java | |
parent | 1e642b5e5b2958ffc1653f5f42f2d091bbd8549e (diff) |
Implement int negate instruction in the optimizing compiler.
- Add support for the neg-int (integer two's complement
negate) instruction in the optimizing compiler.
- Add a HNeg node type for control-flow graphs and an
intermediate HUnaryOperation base class.
- Generate ARM, x86 and x86-64 code for integer HNeg nodes.
Change-Id: I72fd3e1e5311a75c38a8cb665a9211a20325a42e
Diffstat (limited to 'test/411-optimizing-arith/src/Main.java')
-rw-r--r-- | test/411-optimizing-arith/src/Main.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/411-optimizing-arith/src/Main.java b/test/411-optimizing-arith/src/Main.java index 74c47a606c..2b3ba33a6a 100644 --- a/test/411-optimizing-arith/src/Main.java +++ b/test/411-optimizing-arith/src/Main.java @@ -33,6 +33,7 @@ public class Main { public static void main(String[] args) { mul(); + neg(); } public static void mul() { @@ -51,6 +52,34 @@ public class Main { expectEquals(36L, $opt$Mul(-12L, -3L)); expectEquals(33L, $opt$Mul(1L, 3L) * 11); expectEquals(240518168583L, $opt$Mul(34359738369L, 7L)); // (2^35 + 1) * 7 + + $opt$InplaceNegOne(1); + } + + public static void neg() { + expectEquals(-1, $opt$Neg(1)); + expectEquals(1, $opt$Neg(-1)); + expectEquals(0, $opt$Neg(0)); + expectEquals(51, $opt$Neg(-51)); + expectEquals(-51, $opt$Neg(51)); + expectEquals(2147483647, $opt$Neg(-2147483647)); // (2^31 - 1) + expectEquals(-2147483647, $opt$Neg(2147483647)); // -(2^31 - 1) + // From the Java 7 SE Edition specification: + // http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.15.4 + // + // For integer values, negation is the same as subtraction from + // zero. The Java programming language uses two's-complement + // representation for integers, and the range of two's-complement + // values is not symmetric, so negation of the maximum negative + // int or long results in that same maximum negative number. + // Overflow occurs in this case, but no exception is thrown. + // For all integer values x, -x equals (~x)+1.'' + expectEquals(-2147483648, $opt$Neg(-2147483648)); // -(2^31) + } + + public static void $opt$InplaceNegOne(int a) { + a = -a; + expectEquals(-1, a); } static int $opt$Mul(int a, int b) { @@ -61,4 +90,7 @@ public class Main { return a * b; } + static int $opt$Neg(int a){ + return -a; + } } |