// File: /workspace/github_cpp_makefile_star2_O2/kylegranger[P]ImageScaling/filter16.cpp
// Function: Downfilter(color_t*, color_t*, color_t*, color_t*)
void Downfilter(color_t *src1, color_t *src2, color_t *src3, color_t *dst)
{
	// we mix 16 source pixels into one destination pixel
	int r = (src1[0].r + src1[3].r)     + 3 * (src1[1].r + src1[2].r);
	r    += (src2[0].r + src2[3].r) * 3 + 9 * (src2[1].r + src2[2].r);
	r    += (src3[0].r + src3[3].r) * 3 + 9 * (src3[1].r + src3[2].r);
	dst->r = ((r+28)/56);
	int g = (src1[0].g + src1[3].g)     + 3 * (src1[1].g + src1[2].g);
	g    += (src2[0].g + src2[3].g) * 3 + 9 * (src2[1].g + src2[2].g);
	g    += (src3[0].g + src3[3].g) * 3 + 9 * (src3[1].g + src3[2].g);
	dst->g = ((g+28)/56);
	int b = (src1[0].b + src1[3].b)     + 3 * (src1[1].b + src1[2].b);
	b    += (src2[0].b + src2[3].b) * 3 + 9 * (src2[1].b + src2[2].b);
	b    += (src3[0].b + src3[3].b) * 3 + 9 * (src3[1].b + src3[2].b);
	dst->b = ((b+28)/56);
	int a = (src1[0].a + src1[3].a)     + 3 * (src1[1].a + src1[2].a);
	a    += (src2[0].a + src2[3].a) * 3 + 9 * (src2[1].a + src2[2].a);
	a    += (src3[0].a + src3[3].a) * 3 + 9 * (src3[1].a + src3[2].a);
	dst->a = ((a+28)/56);
}

// Assembly:
movq (%rdi), %xmm2
pxor %xmm1, %xmm1
punpcklwd %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3]
movq 0x18(%rdi), %xmm0
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
paddd %xmm2, %xmm0
movq 0x8(%rdi), %xmm2
punpcklwd %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3]
movq 0x10(%rdi), %xmm3
punpcklwd %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1],xmm3[2],xmm1[2],xmm3[3],xmm1[3]
paddd %xmm2, %xmm3
movq (%rsi), %xmm2
punpcklwd %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3]
movq 0x18(%rsi), %xmm4
punpcklwd %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1],xmm4[2],xmm1[2],xmm4[3],xmm1[3]
paddd %xmm2, %xmm4
paddd %xmm3, %xmm4
movq 0x8(%rsi), %xmm2
punpcklwd %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3]
movq 0x10(%rsi), %xmm3
punpcklwd %xmm1, %xmm3    # xmm3 = xmm3[0],xmm1[0],xmm3[1],xmm1[1],xmm3[2],xmm1[2],xmm3[3],xmm1[3]
paddd %xmm2, %xmm3
movq (%rdx), %xmm2
punpcklwd %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3]
movq 0x18(%rdx), %xmm5
punpcklwd %xmm1, %xmm5    # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1],xmm5[2],xmm1[2],xmm5[3],xmm1[3]
paddd %xmm2, %xmm5
paddd %xmm4, %xmm5
movq 0x8(%rdx), %xmm2
punpcklwd %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1],xmm2[2],xmm1[2],xmm2[3],xmm1[3]
movq 0x10(%rdx), %xmm4
punpcklwd %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1],xmm4[2],xmm1[2],xmm4[3],xmm1[3]
paddd %xmm2, %xmm4
paddd %xmm3, %xmm4
movdqa %xmm5, %xmm2
paddd %xmm5, %xmm2
paddd %xmm5, %xmm2
movdqa %xmm4, %xmm1
pslld $0x3, %xmm1
paddd %xmm4, %xmm1
paddd %xmm0, %xmm1
paddd %xmm2, %xmm1
paddd 0x189c6(%rip), %xmm1    # 0x1e1e0
pshufd $0xff, %xmm1, %xmm0     # xmm0 = xmm1[3,3,3,3]
movd %xmm0, %eax
pushq $0x38
popq %rsi
xorl %edx, %edx
divl %esi
movd %eax, %xmm0
pshufd $0xee, %xmm1, %xmm2     # xmm2 = xmm1[2,3,2,3]
movd %xmm2, %eax
xorl %edx, %edx
divl %esi
movd %eax, %xmm2
punpckldq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
movd %xmm1, %eax
xorl %edx, %edx
divl %esi
movd %eax, %xmm0
pshufd $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
movd %xmm1, %eax
xorl %edx, %edx
divl %esi
movd %eax, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
punpcklqdq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0]
pshuflw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3,4,5,6,7]
pshufhw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,1,2,3,4,6,6,7]
pshufd $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3]
movq %xmm0, (%rcx)
retq