RFR: 8256431: [PPC64] Implement Base64 encodeBlock() for Power64-LE [v4]
Martin Doerr
mdoerr at openjdk.java.net
Thu Dec 10 10:05:44 UTC 2020
On Wed, 9 Dec 2020 22:54:50 GMT, Corey Ashford <github.com+51754783+CoreyAshford at openjdk.org> wrote:
>> Add a vector-based implementation of the Base64 encodeBlock intrinsic for Power9 and Power10, little-endian Linux only.
>>
>> This implementation is based upon a paper (linked in comments) describing an Intel SSE vector-based implementation of Base64 encoding. Although the Intel SSE instruction set and the Power VMX/VSX instruction sets are different, the method used in the paper is adaptable to Power. In addition there are a few places in the algorithm where it's possible to gain some performance by using more optimal instruction sequences for VMX/VSX, and some additional benefit is gained from the ISA 3.1 additions available in Power10.
>>
>> There is one controversial method I used in this implementation: I defined a macro to emit the instruction sequence for encoding 12 bytes in a vector to 16 bytes, because this sequence is needed in three places. Turning it into a function would have been possible, but I would have needed to pass quite a few register numbers into the function. I would have liked to have used a nested function, to give the function visibility to the register numbers declared in the outer scope, but alas nested functions are not possible in C++.
>>
>> The overall performance advantage on Power9 is about 4.0X, based on the main/java/org/openjdk/micro/bench/java/util/Base64VarLenEncode.java benchmark. This benchmark covers random buffer lengths from 8 to 20007 bytes. Buffers that are short won't perform as well, approaching the performance of the pure Java code (or slightly worse for very short buffers), Buffers that are consistently long will perform a little better than 4.0X.
>
> Corey Ashford has updated the pull request incrementally with one additional commit since the last revision:
>
> stubGenerator_ppc.cpp: Improve performance of the the main loop of encode
>
> The original code used the saturated subtract algorithm, but because Power
> has a vperm instruction which can handle a 32-byte lookup, we can utilize
> it to do a 64-byte lookup in four instructions, saving two instructions
> from the original six. This yields a 15% performance improvement for large
> buffers.
Thanks for the improvements. The algorithm looks good to me, but I'll have to go over it a 2nd time and run tests.
src/hotspot/cpu/ppc/stubGenerator_ppc.cpp line 4129:
> 4127: // available in assembler_ppc.*
> 4128:
> 4129: #define ENCODE_CORE \
Thanks for improving it. I'd prefer a function over a macro. But I can live with it.
src/hotspot/cpu/ppc/stubGenerator_ppc.cpp line 4185:
> 4183: 0b00111111, 0b00111100, 0b00110000, 0b00000000 ) };
> 4184:
> 4185: static const __vector unsigned char base64_00_15 = {
I don't really like so many individual arrays of constants. They could get put into one larger block of memory and accessed by lvx with offset.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1245
More information about the hotspot-compiler-dev
mailing list