[vector] binary operations with a scalar
Viswanathan, Sandhya
sandhya.viswanathan at intel.com
Sat Feb 17 01:30:35 UTC 2018
Thanks for adding these. The "species" field access would result in boxing, so generalized intrinsic will have to be at v.add(int) level, possibly leading to expansion to two IR nodes: broadcast followed by operation. By doing expansion at IR level, the broadcast will then be moved out of loop by existing compiler optimizations.
It will be very interesting to get Vladimir's thought on this.
Best Regards,
Sandhya
-----Original Message-----
From: panama-dev [mailto:panama-dev-bounces at openjdk.java.net] On Behalf Of Paul Sandoz
Sent: Friday, February 16, 2018 3:52 PM
To: panama-dev at openjdk.java.net
Subject: [vector] binary operations with a scalar
Hi,
Based on feedback and usages it would be advantageous to provide additional binary operations that accept a scalar rather than a vector e.g.:
102 public IntVector<S> add(int o) {
103 return bOp(o, (i, a, b) -> (int) (a + b));
104 }
112 public IntVector<S> add(int o, Mask<Integer, S> m) {
113 return bOp(o, m, (i, a, b) -> (int) (a + b));
114 }
v.add(1) is equivalent to v.add(v.species().broadcast(1))
(Perhaps the mask variant is not as important and could be dropped?)
Although this can be achieved using the existing operations with broadcast, such code has been found harder to read, and possibly harder to optimize.
Here is an initial step towards this focusing on the add operation for IntVector:
http://cr.openjdk.java.net/~psandoz/panama/bin-op-with-scalar/webrev/
I don’t wanna proceed further until we agree on the direction/optimization strategy.
If we want to elide explicit broadcasts (hidden in the implementation) we would need to push this down into the intrinsics. This would require 6 additional intrinsic methods on VectorIntrinsics.
The current approach may not be optimal performance-wise leveraging existing intrinsics and is not optimal from the pure Java perspective either.
Thanks,
Paul.
More information about the panama-dev
mailing list