5 ms·
> I have no idea if HotSpot optimises the specific loop Gil posted, I'm actually curious to see what the output assembly of LLVM is for that loop, because JDK8
by gopalv 9y ago
> I have no idea if HotSpot optimises the specific loop Gil posted,
I'm actually curious to see what the output assembly of LLVM is for that loop, because JDK8 does not optimize a branch in a loop.
But the JVM does do a pretty decent job using ymm<n> registers if you write the loops without branches.
But you end up with really obscure java code like
"(((a - b) ^ (b - a)) >>> 63) ^ 1"
To convert a branch into an integer.
- flamedoge 9y agoyou certainly can vectorize branch in a loop. Unroll loop, compute conditions in parallel, use result as a mask for conditional computation.
- barrkel 9y agoThe parent's point was that the JVM didn't vectorize, not that it wasn't possible.
- giltene 9y agoI had actually posted an annotated assembly output for one of this example vector tests (the doAddArraysIfEven one) here: https://groups.google.com/d/msg/mechanical-sympathy/EMIBqjX4uzk/OYw6d1sIEwAJ https://groups.google.com/d/msg/mechanical-sympathy/EMIBqjX4... Enjoy!
- raphlinus 9y agoPretty sure that code gives the wrong answer for a = 0, b = 1 << 63 (assuming the goal is equality represented as 0 or 1).
- mike_hearn 9y agoIf you're testing with JDK8 you're missing the last two years of work on the optimiser. I'd be interested to see what Java 9 does, as it's (supposedly) coming out in a few months.
- opportun1st 9y agoJDK9 has the capability to vectorize a loop with branch inside. I tried JDK9 early release with a simple testing case myself.