[JAVA PATCH] Builtin support for popcount* and bswap* functions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[JAVA PATCH] Builtin support for popcount* and bswap* functions

Roger Sayle-2

The following patch provides builtin support for byte swapping and bit counting.
On suitable hardware, these generate the x86 popcount instructions, as also
generated by the SUN HotSpot JIT/JVM for these method calls.

java.lang.Integer.bitCount -> __builtin_popcount
java.lang.Long.bitCount -> __builtin_popcountl

java.lang.Short.reverseBytes -> __builtin_bswap16
java.lang.Integer.reverseBytes -> __builtin_bswap32
java.lang.Long.reverseBytes -> __builtin_bswap64

New test cases have been added to libjava to double check nothing breaks.
Whist I was there I noticed that the math builtins (many of which I added support for
back in 2003/2004) weren't marked as ECF_LEAF, indicating that they don't/can't
invoke any user specified functions.   This has also been fixed in the patch below.

The following patch has been tested on x86_64-pc-linux-gnu with a full make bootstrap
and make check with no new failures/regressions.

Ok for stage1 once it reopens?

Cheers,

Roger
--
Roger Sayle, Ph.D.
CEO and founder
NextMove Software Limited
Registered in England No. 07588305
Registered Office: Innovation Centre (Unit 23), Cambridge Science Park, Cambridge CB4 0EY

2016-02-21  Roger Sayle  <[hidden email]>

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.

 




patch7b.txt (4K) Download Attachment
BuiltinBitCount.java (1K) Download Attachment
BuiltinReverseBytes.java (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [JAVA PATCH] Builtin support for popcount* and bswap* functions

Andrew Haley
On 02/22/2016 06:13 PM, [hidden email] wrote:
> Ok for stage1 once it reopens?

Yes, thanks.

Andrew.

Reply | Threaded
Open this post in threaded view
|

Re: [JAVA PATCH] Builtin support for popcount* and bswap* functions

Jeff Law
In reply to this post by Roger Sayle-2
On 02/22/2016 11:13 AM, [hidden email] wrote:

>
> The following patch provides builtin support for byte swapping and bit counting.
> On suitable hardware, these generate the x86 popcount instructions, as also
> generated by the SUN HotSpot JIT/JVM for these method calls.
>
> java.lang.Integer.bitCount -> __builtin_popcount
> java.lang.Long.bitCount -> __builtin_popcountl
>
> java.lang.Short.reverseBytes -> __builtin_bswap16
> java.lang.Integer.reverseBytes -> __builtin_bswap32
> java.lang.Long.reverseBytes -> __builtin_bswap64
>
> New test cases have been added to libjava to double check nothing breaks.
> Whist I was there I noticed that the math builtins (many of which I added support for
> back in 2003/2004) weren't marked as ECF_LEAF, indicating that they don't/can't
> invoke any user specified functions.   This has also been fixed in the patch below.
>
> The following patch has been tested on x86_64-pc-linux-gnu with a full make bootstrap
> and make check with no new failures/regressions.
>
> Ok for stage1 once it reopens?
>
> Cheers,
>
> Roger
> --
> Roger Sayle, Ph.D.
> CEO and founder
> NextMove Software Limited
> Registered in England No. 07588305
> Registered Office: Innovation Centre (Unit 23), Cambridge Science Park, Cambridge CB4 0EY
>
> 2016-02-21  Roger Sayle  <[hidden email]>
>
> 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.
OK for the trunk.

Thanks,
Jeff