[vector] binary operations with a scalar
Kandu, Rahul
rahul.kandu at intel.com
Fri Feb 23 20:00:15 UTC 2018
Hi Paul, John
I just checked that performance-wise there is no major concern with the binary ops accepting scalar values http://hg.openjdk.java.net/panama/dev/rev/3c6eb79d5312
I took simple binary ops- Add, Mul and Sub for floats. Performance is same (ops/sec)- in both cases a) with broadcasting a scalar (outside the loop) vs. b) calling the scalar version of the method. Consider these simple loops for example.
static void AddTestWithScalar(float[] data1f, float data, float[] data3f) {
for (int i = 0; i < data1f.length; i += SPECIES.length()) {
FloatVector<Shapes.S256Bit> av = SPECIES.fromArray(data1f, i);
// FloatVector<Shapes.S256Bit> bv = SPECIES.fromArray(data2f, i);
av.add(data).intoArray(data3f, i);
}
}
static void AddTestWithVectorHoisted(float[] data1f, float data, float[] data3f) {
FloatVector<Shapes.S256Bit> bv = SPECIES.broadcast(data);
for (int i = 0; i < data1f.length; i += SPECIES.length()) {
FloatVector<Shapes.S256Bit> av = SPECIES.fromArray(data1f, i);
av.add(bv).intoArray(data3f, i);
}
}
Rahul
-----Original Message-----
From: panama-dev [mailto:panama-dev-bounces at openjdk.java.net] On Behalf Of John Rose
Sent: Tuesday, February 20, 2018 1:16 PM
To: Paul Sandoz <paul.sandoz at oracle.com>
Cc: panama-dev at openjdk.java.net
Subject: Re: [vector] binary operations with a scalar
> On Feb 20, 2018, at 9:19 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>
> I like this but suggest we keep the code marginally simpler and revisit if we have performance concerns. If we don’t make intrinsic the broadcast+op combination i think something like this is probably ok for now:
>
> @Override
> @ForceInline
> public Int256Vector add(int o) {
> return add(Int256Species.broadcastImpl(o));
> }
That seems like the simplest way, and good to start with, maybe even end with. We could do decisively better with templates but we dint have them yet.
More information about the panama-dev
mailing list