x86 Machine Code (with SSE2), 36 bytes
; bool CirclesOverlap(double x1, double y1, double r1,
; double x2, double y2, double r2);
F2 0F 5C C3 subsd xmm0, xmm3 ; x1 - x2
F2 0F 5C CC subsd xmm1, xmm4 ; y1 - y2
F2 0F 58 D5 addsd xmm2, xmm5 ; r1 + r2
F2 0F 59 C0 mulsd xmm0, xmm0 ; (x1 - x2)^2
F2 0F 59 C9 mulsd xmm1, xmm1 ; (y1 - y2)^2
F2 0F 59 D2 mulsd xmm2, xmm2 ; (r1 + r2)^2
F2 0F 58 C1 addsd xmm0, xmm1 ; (x1 - x2)^2 + (y1 - y2)^2
66 0F 2F D0 comisd xmm2, xmm0
0F 97 C0 seta al ; ((r1 + r2)^2) > ((x1 - x2)^2 + (y1 - y2)^2)
C3 ret
The above function accepts descriptions of two circles (x- and y-coordinates of center point and a radius), and returns a Boolean value indicating whether or not they intersect.
It uses a vector calling convention, where the parameters are passed in SIMD registers. On x86-32 and 64-bit Windows, this is the __vectorcall
calling convention. On 64-bit Unix/Linux/Gnu, this is the standard System V AMD64 calling convention.
The return value is left in the low byte of EAX
, as is standard with all x86 calling conventions.
This code works equally well on 32-bit and 64-bit x86 processors, as long as they support the SSE2 instruction set (which would be Intel Pentium 4 and later, or AMD Athlon 64 and later).
AVX version, still 36 bytes
If you were targeting AVX, you would probably want to add a VEX prefix to the instructions. This does not change the byte count; just the actual bytes used to encode the instructions:
; bool CirclesOverlap(double x1, double y1, double r1,
; double x2, double y2, double r2);
C5 FB 5C C3 vsubsd xmm0, xmm0, xmm3 ; x1 - x2
C5 F3 5C CC vsubsd xmm1, xmm1, xmm4 ; y1 - y2
C5 EB 58 D5 vaddsd xmm2, xmm2, xmm5 ; r1 + r2
C5 FB 59 C0 vmulsd xmm0, xmm0, xmm0 ; (x1 - x2)^2
C5 F3 59 C9 vmulsd xmm1, xmm1, xmm1 ; (y1 - y2)^2
C5 EB 59 D2 vmulsd xmm2, xmm2, xmm2 ; (r1 + r2)^2
C5 FB 58 C1 vaddsd xmm0, xmm0, xmm1 ; (x1 - x2)^2 + (y1 - y2)^2
C5 F9 2F D0 vcomisd xmm2, xmm0
0F 97 C0 seta al ; ((r1 + r2)^2) > ((x1 - x2)^2 + (y1 - y2)^2)
C3 ret
AVX instructions have the advantage of taking three operands, allowing you to do non-destructive operations, but that doesn't really help us to compact the code any here. However, mixing instructions with and without VEX prefixes can result in sub-optimal code, so you generally want to stick with all AVX instructions if you're targeting AVX, and in this case, it doesn't even hurt your byte count.