3 ms·
"The logic in the inner loop is a silly way to count whether something is below the boundary but it matches what we have to do on the SIMD side" That's somethi
by Someone 11y ago
"The logic in the inner loop is a silly way to count whether something is below the boundary but it matches what we have to do on the SIMD side"
That's something I wouldn't have done; it may be the sole reason the non-SIMD code has a branch in the inner loop.
The SIMD code would still be faster, of course.
It also is a bit unfortunate to have types:
int4 : vector of 4 integers
Int32: 32-bit integer
- xenadu02 11y agoAuthor here; the non-vector loop still has a branch with a less than check if you do it the straightforward way. The whole benchmark is artificial, hence my warning.
- Someone 11y agoThanks. I do not see that when I use what I would think to be the straightforward way to count (using integers), though: var count = Int() for var i in array { i += negBoundary let delta = (i > 0.0) ? 1 : 0 count += delta } (timed using mach_absolute_time(), on my system, that code also seems about twice as fast as the SIMD code) I did not check whether that trigraph gets compiled to a branch (I tried, but I had trouble reading the disassembly that otool gave me; I’m not used to x86, and I found the code surprisingly long)