[vectorIntrinsics] what about div?

John Rose john.r.rose at oracle.com
Fri May 31 07:34:53 UTC 2019


The top-level vector class doesn't have a divide operation,
for what I think are a pair of reasons:

1. It isn't total.  It could run into 1/0 and need to throw
an exception.

2. Intel hardware does not support it directly.

On the other hand, supporting add/sub/mul and not div
seems overly surprising to me.

I propose that we move div up into the top level class,
and make it (for now) a partial operation which throws
UOE.  Later we can fill it in.  I note that SVE seems to
support it (though it may well be slow).  And for Intel
we can use some of the ideas here:

https://stackoverflow.com/questions/16822757/sse-integer-division

I think we can treat the 1/0 problem as similar to the
range check problem (with toArray masked).  Basically,
we need to do `v.equal(broadcast(0)).anyTrue()` before
a div and uncommon-trap to scalar code if it happens.

ARM SVE defines zero as the result of x/0, but I don't think
we need to do that.

For efficient integer division up to 32 bits we can use
64-bit floats.  For 64-bit integer division we can
eventually optimize with something tricky; see the
link above.

— John


More information about the panama-dev mailing list