[vector] binary operations with a scalar
Paul Sandoz
paul.sandoz at oracle.com
Mon Feb 26 17:32:13 UTC 2018
Hi Rahul,
Thanks for checking.
BTW i held off adding unit tests for the scalar cases. I was gonna wait for future updates from Jp w.r.t data providers.
Paul.
> On Feb 23, 2018, at 12:00 PM, Kandu, Rahul <rahul.kandu at intel.com> wrote:
>
> 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