Many architectures support autonomous absolute value operation. If not, it can be modeled by multiplying or shifting the shifted sign value and believing in a specific behavior that depends on the implementation.
It is also quite possible that in Intel and ARM architectures the operation can be done without a wind
((x0<x) && (x<x1))&((y0<y) && (y<y1))
The reason is that range checking is often optimized for consistency:
mov ebx, 1 // not needed on arm sub eax, imm0 sub eax, imm1 // this will cause a carry only when both conditions are met cmovc eax, ebx // movcs reg,
Bitwise and between (x) and (y) expressions are also not common.
EDIT Original idea:
This test range: a <= x <= b, first determine the midpoint. Then both sides can be tested with | (x-mid) | <A; multiplying with factor B that A has the strength of two ... (x-mid) * B <2 ^ n and squaring ((x-mid) * B) ^ 2 <2 ^ 2n
This value has only bits specified with the least significant 2n bits (if the condition is met). Do the same for the y and OR range. In this case, factor C should be chosen so that (y-midy) ^ 2 scales to the same 2 ^ 2n.
return (((x-mid)*B)*(((x-mid)*B) | ((y-mid)*C)*((y-mid)*C))) >> (n*2);
The return value is 0 for x, y inside AABB and nonzero for x, y outside. (Here the operation is or, since you are interested in the complement (a & b) and (c & d), which is (! (A & b)) | (! (C & dd));
source share