diff options
author | Roland Levillain <rpl@google.com> | 2014-10-24 16:20:17 +0100 |
---|---|---|
committer | Roland Levillain <rpl@google.com> | 2014-10-27 17:33:47 +0000 |
commit | 705664321a5cc1418255172f92d7d7195cf60a7b (patch) | |
tree | bdb7a60edff3e13c9bb6658d9ba20d3541a9c50d /test/416-optimizing-arith-not/src/Main.java | |
parent | 2deace28b16d3161ccd6a85a2c577e83f4b25364 (diff) | |
download | android_art-705664321a5cc1418255172f92d7d7195cf60a7b.tar.gz android_art-705664321a5cc1418255172f92d7d7195cf60a7b.tar.bz2 android_art-705664321a5cc1418255172f92d7d7195cf60a7b.zip |
Add long bitwise not instruction in the optimizing compiler.
- Add support for the not-long (long integer one's
complement negation) instruction in the optimizing
compiler.
- Add a 64-bit NOT instruction (notq) to the x86-64
assembler.
- Generate ARM, x86 and x86-64 code for long HNot nodes.
- Gather not-related tests in test/416-optimizing-arith-not.
Change-Id: I2d5b75e9875664d6032d04f8401b2bbb84506948
Diffstat (limited to 'test/416-optimizing-arith-not/src/Main.java')
-rw-r--r-- | test/416-optimizing-arith-not/src/Main.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/416-optimizing-arith-not/src/Main.java b/test/416-optimizing-arith-not/src/Main.java new file mode 100644 index 0000000000..26e206c94d --- /dev/null +++ b/test/416-optimizing-arith-not/src/Main.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.lang.reflect.Method; + +public class Main { + + public static void expectEquals(int expected, int result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + + public static void expectEquals(long expected, long result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + + public static void main(String[] args) throws Exception { + notInt(); + notLong(); + } + + private static void notInt() throws Exception { + expectEquals(1, smaliNotInt(-2)); + expectEquals(0, smaliNotInt(-1)); + expectEquals(-1, smaliNotInt(0)); + expectEquals(-2, smaliNotInt(1)); + expectEquals(2147483647, smaliNotInt(-2147483648)); // (2^31) - 1 + expectEquals(2147483646, smaliNotInt(-2147483647)); // (2^31) - 2 + expectEquals(-2147483647, smaliNotInt(2147483646)); // -(2^31) - 1 + expectEquals(-2147483648, smaliNotInt(2147483647)); // -(2^31) + } + + private static void notLong() throws Exception { + expectEquals(1L, smaliNotLong(-2L)); + expectEquals(0L, smaliNotLong(-1L)); + expectEquals(-1L, smaliNotLong(0L)); + expectEquals(-2L, smaliNotLong(1L)); + expectEquals(2147483647L, smaliNotLong(-2147483648L)); // (2^31) - 1 + expectEquals(2147483646L, smaliNotLong(-2147483647L)); // (2^31) - 2 + expectEquals(-2147483647L, smaliNotLong(2147483646L)); // -(2^31) - 1 + expectEquals(-2147483648L, smaliNotLong(2147483647L)); // -(2^31) + expectEquals(9223372036854775807L, smaliNotLong(-9223372036854775808L)); // (2^63) - 1 + expectEquals(9223372036854775806L, smaliNotLong(-9223372036854775807L)); // (2^63) - 2 + expectEquals(-9223372036854775807L, smaliNotLong(9223372036854775806L)); // -(2^63) - 1 + expectEquals(-9223372036854775808L, smaliNotLong(9223372036854775807L)); // -(2^63) + } + + // Wrappers around methods located in file not.smali. + + private static int smaliNotInt(int a) throws Exception { + Class<?> c = Class.forName("TestNot"); + Method m = c.getMethod("$opt$NotInt", int.class); + int result = (Integer)m.invoke(null, a); + return result; + } + + private static long smaliNotLong(long a) throws Exception { + Class<?> c = Class.forName("TestNot"); + Method m = c.getMethod("$opt$NotLong", long.class); + long result = (Long)m.invoke(null, a); + return result; + } +} |