From a1293f402a25801d03a58312b06b65c33702c726 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Tue, 31 May 2016 11:30:56 +0000 Subject: [PATCH] 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 --- gcc/java/ChangeLog | 8 +++ gcc/java/builtins.c | 65 +++++++++++++----- libjava/ChangeLog | 5 ++ .../libjava.lang/BuiltinBitCount.jar | Bin 0 -> 1033 bytes .../libjava.lang/BuiltinBitCount.java | 51 ++++++++++++++ .../libjava.lang/BuiltinBitCount.out | 0 .../libjava.lang/BuiltinReverseBytes.jar | Bin 0 -> 1126 bytes .../libjava.lang/BuiltinReverseBytes.java | 62 +++++++++++++++++ .../libjava.lang/BuiltinReverseBytes.out | 0 9 files changed, 175 insertions(+), 16 deletions(-) create mode 100644 libjava/testsuite/libjava.lang/BuiltinBitCount.jar create mode 100644 libjava/testsuite/libjava.lang/BuiltinBitCount.java create mode 100644 libjava/testsuite/libjava.lang/BuiltinBitCount.out create mode 100644 libjava/testsuite/libjava.lang/BuiltinReverseBytes.jar create mode 100644 libjava/testsuite/libjava.lang/BuiltinReverseBytes.java create mode 100644 libjava/testsuite/libjava.lang/BuiltinReverseBytes.out diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 8aa55ab7a40..58e40a6c133 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,11 @@ +2016-05-31 Roger Sayle + + * 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. + 2016-04-28 Rainer Orth PR java/70839 diff --git a/gcc/java/builtins.c b/gcc/java/builtins.c index 033e086dc4b..f27831d51c2 100644 --- a/gcc/java/builtins.c +++ b/gcc/java/builtins.c @@ -98,6 +98,11 @@ static GTY(()) struct builtin_record java_builtins[] = { { "java.lang.Math" }, { "sin" }, NULL, BUILT_IN_SIN }, { { "java.lang.Math" }, { "sqrt" }, NULL, BUILT_IN_SQRT }, { { "java.lang.Math" }, { "tan" }, NULL, BUILT_IN_TAN }, + { { "java.lang.Integer" }, { "bitCount" }, NULL, BUILT_IN_POPCOUNT }, + { { "java.lang.Integer" }, { "reverseBytes" }, NULL, BUILT_IN_BSWAP32 }, + { { "java.lang.Long" }, { "bitCount" }, NULL, BUILT_IN_POPCOUNTL }, + { { "java.lang.Long" }, { "reverseBytes" }, NULL, BUILT_IN_BSWAP64 }, + { { "java.lang.Short" }, { "reverseBytes" }, NULL, BUILT_IN_BSWAP16 }, { { "java.lang.Float" }, { "intBitsToFloat" }, convert_real, (enum built_in_function) 0 }, { { "java.lang.Double" }, { "longBitsToDouble" }, convert_real, @@ -483,6 +488,7 @@ initialize_builtins (void) tree double_ftype_double, double_ftype_double_double; tree float_ftype_float_float; tree boolean_ftype_boolean_boolean; + tree int_ftype_int; int i; for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i) @@ -507,50 +513,77 @@ initialize_builtins (void) double_type_node, double_type_node, NULL_TREE); define_builtin (BUILT_IN_FMOD, "__builtin_fmod", - double_ftype_double_double, "fmod", ECF_CONST); + double_ftype_double_double, "fmod", ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_FMODF, "__builtin_fmodf", - float_ftype_float_float, "fmodf", ECF_CONST); + float_ftype_float_float, "fmodf", ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_ACOS, "__builtin_acos", double_ftype_double, "_ZN4java4lang4Math4acosEJdd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_ASIN, "__builtin_asin", double_ftype_double, "_ZN4java4lang4Math4asinEJdd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_ATAN, "__builtin_atan", double_ftype_double, "_ZN4java4lang4Math4atanEJdd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_ATAN2, "__builtin_atan2", double_ftype_double_double, "_ZN4java4lang4Math5atan2EJddd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_CEIL, "__builtin_ceil", double_ftype_double, "_ZN4java4lang4Math4ceilEJdd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_COS, "__builtin_cos", double_ftype_double, "_ZN4java4lang4Math3cosEJdd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_EXP, "__builtin_exp", double_ftype_double, "_ZN4java4lang4Math3expEJdd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_FLOOR, "__builtin_floor", double_ftype_double, "_ZN4java4lang4Math5floorEJdd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_LOG, "__builtin_log", double_ftype_double, "_ZN4java4lang4Math3logEJdd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_POW, "__builtin_pow", double_ftype_double_double, "_ZN4java4lang4Math3powEJddd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_SIN, "__builtin_sin", double_ftype_double, "_ZN4java4lang4Math3sinEJdd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_SQRT, "__builtin_sqrt", double_ftype_double, "_ZN4java4lang4Math4sqrtEJdd", - ECF_CONST); + ECF_CONST | ECF_LEAF); define_builtin (BUILT_IN_TAN, "__builtin_tan", double_ftype_double, "_ZN4java4lang4Math3tanEJdd", - ECF_CONST); - + ECF_CONST | ECF_LEAF); + + int_ftype_int = build_function_type_list (int_type_node, + int_type_node, NULL_TREE); + + define_builtin (BUILT_IN_POPCOUNT, "__builtin_popcount", int_ftype_int, + "_ZN4java4lang7Integer8bitCountEJii", + ECF_CONST | ECF_LEAF | ECF_NOTHROW); + define_builtin (BUILT_IN_BSWAP32, "__builtin_bswap32", int_ftype_int, + "_ZN4java4lang7Integer12reverseBytesEJii", + ECF_CONST | ECF_LEAF | ECF_NOTHROW); + + define_builtin (BUILT_IN_POPCOUNTL, "__builtin_popcountl", + build_function_type_list (int_type_node, + long_type_node, NULL_TREE), + "_ZN4java4lang4Long8bitCountEJix", + ECF_CONST | ECF_LEAF | ECF_NOTHROW); + define_builtin (BUILT_IN_BSWAP64, "__builtin_bswap64", + build_function_type_list (long_type_node, + long_type_node, NULL_TREE), + "_ZN4java4lang4Long12reverseBytesEJxx", + ECF_CONST | ECF_LEAF | ECF_NOTHROW); + + define_builtin (BUILT_IN_BSWAP16, "__builtin_bswap16", + build_function_type_list (short_type_node, + short_type_node, NULL_TREE), + "_ZN4java4lang5Short12reverseBytesEJss", + ECF_CONST | ECF_LEAF | ECF_NOTHROW); + boolean_ftype_boolean_boolean = build_function_type_list (boolean_type_node, boolean_type_node, boolean_type_node, diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 596fc0529ed..0a2830555d3 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,8 @@ +2016-05-31 Roger Sayle + + * testsuite/libjava.lang/BuiltinBitCount.java: New test case. + * testsuite/libjava.lang/BuiltinReverseBytes.java: Likewise. + 2016-04-30 Oleg Endo * classpath/config.guess: Revert r235676. diff --git a/libjava/testsuite/libjava.lang/BuiltinBitCount.jar b/libjava/testsuite/libjava.lang/BuiltinBitCount.jar new file mode 100644 index 0000000000000000000000000000000000000000..0f6591c1e27bbf1e37f53cc917ca4de610d1b5f0 GIT binary patch literal 1033 zcmWIWW@Zs#;Nak3IF+#9g8>O}GO#fCx`sIFdiuHP|2xINz|0Wf&CUT*!30$nfK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T3eZ{uV2cov$>6%*iE^=z& zzMdY7b6qng7# zBv|<8ZswO%x>Fi(YiIL?-wh@{K~>v>mpBDzP26&Ox{Q}|$>c5N?7s3$L9I*n?kLdU z4OF#EHD@*YAf`KCux>~1v-PXe1Oj+-S08h7aVjn55`5)kGV$51na3Cw+9^1dDXo9y z^yq;`-!!)yuMS_U^4K|Lf$h^4Th#=8sSV=1x4PNhtW^W>;7xYEX?IUmUjpG*kl9}vZO#acS`DamR{ow=hF^Np;j3lo|$Xt(&L2ZH2?r_n+^6|IZG}POYKl*3H2DG?4|Ak{Ovq7*KN~EUSTX zBPxJrFHqh@*NU7$KzR`XY=KO;R-~MXYyv1FAv+9|kr3bzkcl%}1$eWvfs`@>;SnI+ I!wlj90OSUn1poj5 literal 0 HcmV?d00001 diff --git a/libjava/testsuite/libjava.lang/BuiltinReverseBytes.java b/libjava/testsuite/libjava.lang/BuiltinReverseBytes.java new file mode 100644 index 00000000000..0d2e332081d --- /dev/null +++ b/libjava/testsuite/libjava.lang/BuiltinReverseBytes.java @@ -0,0 +1,62 @@ +class BuiltinReverseBytes +{ + public static short bswap16(short x) + { + return Short.reverseBytes(x); + } + + public static int bswap32(int x) + { + return Integer.reverseBytes(x); + } + + public static long bswap64(long x) + { + return Long.reverseBytes(x); + } + + public static void main(String[] args) + { + if (Short.reverseBytes((short)0) != (short)0) + throw new Error(); + if (Short.reverseBytes((short)0x1234) != (short)0x3412) + throw new Error(); + if (Short.reverseBytes((short)-1) != (short)-1) + throw new Error(); + + if (Integer.reverseBytes(0) != 0) + throw new Error(); + if (Integer.reverseBytes(0x12345678) != 0x78563412) + throw new Error(); + if (Integer.reverseBytes(-1) != -1) + throw new Error(); + + if (Long.reverseBytes(0L) != 0L) + throw new Error(); + if (Long.reverseBytes(0x123456789abcde0fL) != 0x0fdebc9a78563412L) + throw new Error(); + if (Long.reverseBytes(-1L) != -1L) + throw new Error(); + + if (bswap16((short)0) != (short)0) + throw new Error(); + if (bswap16((short)0x1234) != (short)0x3412) + throw new Error(); + if (bswap16((short)-1) != (short)-1) + throw new Error(); + + if (bswap32(0) != 0) + throw new Error(); + if (bswap32(0x12345678) != 0x78563412) + throw new Error(); + if (bswap32(-1) != -1) + throw new Error(); + + if (bswap64(0L) != 0L) + throw new Error(); + if (bswap64(0x123456789abcde0fL) != 0x0fdebc9a78563412L) + throw new Error(); + if (bswap64(-1L) != -1L) + throw new Error(); + } +} diff --git a/libjava/testsuite/libjava.lang/BuiltinReverseBytes.out b/libjava/testsuite/libjava.lang/BuiltinReverseBytes.out new file mode 100644 index 00000000000..e69de29bb2d -- 2.30.2