Using the fact that a negative 64-bit integer is also a negative 32-bit integer when truncated, you could use 2x SSE2 32-bit comparison. - one for [v0 , v1] - [vlow, vlow] compared to [0, 0] (result should be >= 0, signed comparison) - one for [v0 , v1] - [vhigh, vhigh] compared to [0, 0] (result should be < 0, signed comparison)

Then apply logical and on the masks.
This doesn't work if vhigh - vlow spans a too large area.

On Monday, 8 December 2014 at 16:32:50 UTC, Martin Nowak wrote:
I want to do bounds checking of 2 (4 on avx) ulongs (64-bit) at a time.

ulong2 vval = [v0, v1];
ulong2 vlow = [low, low];
ulong2 vhigh = [high, high];

int res = PMOVMSKB(vval >= vlow & vval < vhigh);

I figured out sort of a solution, but it seems way too complicated, because there is only signed comparison.

Usually (scalar) I'd use this, which makes use of unsigned wrap to safe one conditional

immutable size = cast(ulong)(vhigh - vlow);
if (cast(ulong)(v0 - vlow) < size) {}
if (cast(ulong)(v1 - vlow) < size) {}

over

if (v0 >= vlow && v0 < vhigh) {}

Maybe this can be used on SIMD too (saturated sub or so)?

-Martin

Reply via email to