Optimizing byte reverse code for int value
Hiroshi H Horii
HORII at jp.ibm.com
Fri Apr 7 17:51:09 UTC 2017
> I suggest replacing the use of loadI by endianness specific code
> (which could possibly use lwbrx on big endian).
I believe that lwbrx is necessary for BE.
> Surely the source code needs fixing. It could be:
>
> public float readFloat(InputStream in) throws IOException {
> readFully(in, aByteBuffer, 0, 4);
> int val = aByteBuffer.getInt(0);
>
> return Float.intBitsToFloat(val);
> }
In my understanding, ByteBuffer.getInt() does the similar thing. I guess
that application does not use ByteBuffer only for calling getInt().
Heap-X-Buffer.java.template
public int getInt() {
return Bits.getInt(this, ix(nextGetIndex(4)), bigEndian);
}
Bits.java
static int getInt(ByteBuffer bb, int bi, boolean bigEndian) {
return bigEndian ? getIntB(bb, bi) : getIntL(bb, bi) ;
}
static int getIntL(ByteBuffer bb, int bi) {
return makeInt(bb._get(bi + 3),
bb._get(bi + 2),
bb._get(bi + 1),
bb._get(bi ));
}
static private int makeInt(byte b3, byte b2, byte b1, byte b0) {
return (((b3 ) << 24) |
((b2 & 0xff) << 16) |
((b1 & 0xff) << 8) |
((b0 & 0xff) ));
}
Heap-X-Buffer.java.template
byte _get(int i) { // package-private
return hb[i];
}
Direct-X-Buffer.java.template
byte _get(int i) { // package-private
return unsafe.getByte(address + i);
}
Regards,
Hiroshi
Andrew Haley <aph at redhat.com> wrote on 2017/04/07 17:36:13:
> From: Andrew Haley <aph at redhat.com>
> To: Michihiro Horie/Japan/IBM at IBMJP, ppc-aix-port-
> dev at openjdk.java.net, hotspot-dev at openjdk.java.net
> Cc: Hiroshi H Horii/Japan/IBM at IBMJP, volker.simonis at sap.com
> Date: 2017/04/07 17:37
> Subject: Re: Optimizing byte reverse code for int value
>
> On 07/04/17 06:49, Michihiro Horie wrote:
> >
> > Would you please review our change for JDK10 on ppc64?
> > Issue: https://bugs.openjdk.java.net/browse/JDK-8178294
> > Webrev: http://cr.openjdk.java.net/~horii/8178294/webrev.00/
> >
> > This change adds two conversion rules of reversing contiguous 4 bytes
for
> > int value.
> > The first conversion rule finds a pattern below and emits a lwz
instruction
> > instead.
>
> Surely the source code needs fixing. It could be:
>
> public float readFloat(InputStream in) throws IOException {
> readFully(in, aByteBuffer, 0, 4);
> int val = aByteBuffer.getInt(0);
>
> return Float.intBitsToFloat(val);
> }
>
> Then there would be no need for a special ppc64 pattern.
>
> Andrew.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/ppc-aix-port-dev/attachments/20170408/68b77c34/attachment.html>
More information about the ppc-aix-port-dev
mailing list