[vector] binary operations with a scalar
Paul Sandoz
paul.sandoz at oracle.com
Fri Feb 16 23:51:30 UTC 2018
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