[vector] reshape/cast using species
John Rose
john.r.rose at oracle.com
Wed Feb 28 04:47:35 UTC 2018
On Feb 27, 2018, at 5:03 PM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>
> Hi,
>
> I think it makes more sense to move the reshape and cast functionality from Vector to species, and then to preserve the fluent nature of the API add methods to Vector that accept a species and defer to the species method. Same applies to Mask and Shuffle.
>
> http://cr.openjdk.java.net/~psandoz/panama/species-reshape-cast/webrev/index.html <http://cr.openjdk.java.net/~psandoz/panama/species-reshape-cast/webrev/index.html>
This looks good. You are removing dynamic calls to the factory/registry method
Vector.speciesInstance, and rooting the computation in constant species.
Eventually we might have a way to express constant expressions sort of like
C++ constexpr, and that might make us add more places where species
constants can be written, and even dynamically derived. But putting them
on static finals is a known-good way to make them available to the user
and scrutable to the JIT.
A couple more observations:
The newly placed Species.cast operation has a decision chain on the
target lane type (byte, long, float, etc.). Maybe this can be refactored
at some point to a dispatch on a species subtype, which "knows"
which loop to execute?
I see there are ByteBuffer.allocate calls floating around. I guess these
get intrinsified away, so it's not an issue, but I have to ask: Is there
a more direct way to do it, of working with plain Java arrays? (Had
to ask.)
Good work!
— John
>
>
> I left some commented out methods that are intrinsic as a reminder this needs to be looked at:
>
> 139 // //Costless vector cast. Bit-wise contents preserved
> 140 // @HotSpotIntrinsicCandidate
> 141 // default <F> Vector<F, S> rebracket(Class<F> type) { return reshape(type, shape());}
> 142
>
> 468 //#if[float]
> 469 // @HotSpotIntrinsicCandidate
> 470 //#end[float]
> 471 // @Override
> 472 // public <F> Vector<F,S> cast(Class<F> type) {
> 473 // return cast(type, shape());
> 474 // }
>
> I’ll need some guidance with respect preserving hotspot intrinsic behavior for the newly added methods on species.
>
> I’ll add some combo test later.
>
> Thanks,
> Paul.
More information about the panama-dev
mailing list