From a1293f402a25801d03a58312b06b65c33702c726 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Tue, 31 May 2016 11:30:56 +0000 Subject: builtins.c (java_builtins): Use popcount* and bswap* builtins to implement bitCount() and reverseBytes()... 2016-05-31 Roger Sayle gcc/java: * builtins.c (java_builtins): Use popcount* and bswap* builtins to implement bitCount() and reverseBytes() methods in java.lang.Integer and friends. (initialize_builtins): Annotate math builtins with ECF_LEAF. Call define_builtin for the new popcount* and bswap* builtins. libjava: * testsuite/libjava.lang/BuiltinBitCount.java: New test case. * testsuite/libjava.lang/BuiltinReverseBytes.java: Likewise. From-SVN: r236919 --- .../testsuite/libjava.lang/BuiltinBitCount.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 libjava/testsuite/libjava.lang/BuiltinBitCount.java (limited to 'libjava/testsuite/libjava.lang/BuiltinBitCount.java') diff --git a/libjava/testsuite/libjava.lang/BuiltinBitCount.java b/libjava/testsuite/libjava.lang/BuiltinBitCount.java new file mode 100644 index 0000000..bcafd31 --- /dev/null +++ b/libjava/testsuite/libjava.lang/BuiltinBitCount.java @@ -0,0 +1,51 @@ +class BuiltinBitCount +{ + public static int popcount(int x) + { + return Integer.bitCount(x); + } + + public static int popcountl(long x) + { + return Long.bitCount(x); + } + + public static void main(String[] args) + { + if (Integer.bitCount(0) != 0) + throw new Error(); + if (Integer.bitCount(8) != 1) + throw new Error(); + if (Integer.bitCount(123456) != 6) + throw new Error(); + if (Integer.bitCount(-1) != 32) + throw new Error(); + + if (Long.bitCount(0) != 0) + throw new Error(); + if (Long.bitCount(8) != 1) + throw new Error(); + if (Long.bitCount(123456) != 6) + throw new Error(); + if (Long.bitCount(-1) != 64) + throw new Error(); + + if (popcount(0) != 0) + throw new Error(); + if (popcount(8) != 1) + throw new Error(); + if (popcount(123456) != 6) + throw new Error(); + if (popcount(-1) != 32) + throw new Error(); + + if (popcountl(0) != 0) + throw new Error(); + if (popcountl(8) != 1) + throw new Error(); + if (popcountl(123456) != 6) + throw new Error(); + if (popcountl(-1) != 64) + throw new Error(); + } +} -- cgit v1.1