// File: /workspace/github_c_makefile_star2_O2/tvlabs[P]edge264/./edge264_residual.c
// Function: transform_dc2x2
static void transform_dc2x2(Edge264Context *ctx)
{
	// load both matrices interlaced+transposed and multiply right
	i32x4 d0 = ctx->c_v[0] + ctx->c_v[1];
	i32x4 d1 = ctx->c_v[0] - ctx->c_v[1];
	ctx->c_v[0] = ctx->c_v[1] = (i8x16){};
	
	// transpose and multiply left
	i32x4 e0 = ziplo64(d0, d1);
	i32x4 e1 = ziphi64(d0, d1);
	i32x4 f0 = e0 + e1;
	i32x4 f1 = e0 - e1;
	
	// deinterlace and scale
	unsigned qPb = ctx->t.QP[1];
	unsigned qPr = ctx->t.QP[2];
	i32x4 LSb = set32((ctx->t.pps.weightScale4x4[1 + mb->mbIsInterFlag * 3][0] * normAdjust4x4[qPb % 6][0]) << (qPb / 6));
	i32x4 LSr = set32((ctx->t.pps.weightScale4x4[2 + mb->mbIsInterFlag * 3][0] * normAdjust4x4[qPr % 6][0]) << (qPr / 6));
	i32x4 dcCb = ((i32x4)unziplo32(f0, f1) * LSb) >> 5;
	i32x4 dcCr = ((i32x4)unziphi32(f0, f1) * LSr) >> 5;
	
	// store if needed later ...
	if (mb->f.CodedBlockPatternChromaAC) {
		ctx->c_v[4] = dcCb;
		ctx->c_v[5] = dcCr;
		
	// ... or prepare for storage in place
	} else {
		i32x4 s32 = set32(32); // for SSE
		i32x4 rb = shrrs32(dcCb, 6, s32);
		i32x4 rr = shrrs32(dcCr, 6, s32);
		#if defined(__SSE2__)
			i16x8 lob = shuffle32(shufflelo(rb, 0, 0, 2, 2), 0, 0, 1, 1);
			i16x8 lor = shuffle32(shufflelo(rr, 0, 0, 2, 2), 0, 0, 1, 1);
			i16x8 hib = shuffle32(shufflehi(rb, 0, 0, 2, 2), 2, 2, 3, 3);
			i16x8 hir = shuffle32(shufflehi(rr, 0, 0, 2, 2), 2, 2, 3, 3);
		#elif defined(__ARM_NEON)
			i16x8 vb = vtrn1q_s16(rb, rb);
			i16x8 vr = vtrn1q_s16(rr, rr);
			i16x8 lob = ziplo32(vb, vb);
			i16x8 lor = ziplo32(vr, vr);
			i16x8 hib = ziphi32(vb, vb);
			i16x8 hir = ziphi32(vr, vr);
		#endif
		
		// add to predicted samples
		uint8_t *p = ctx->samples_mb[1];
		size_t stride = ctx->t.stride[1] >> 1;
		if (ctx->t.samples_clip[1][0] == 255) {
			i16x8 b0 = addlou8s16(load64(p             ), lob);
			i16x8 r0 = addlou8s16(load64(p + stride    ), lor);
			i16x8 b1 = addlou8s16(load64(p + stride * 2), lob);
			i16x8 r1 = addlou8s16(load64(p + stride * 3), lor);
			i64x2 b8 = packus16(b0, b1);
			i64x2 r8 = packus16(r0, r1);
			*(int64_t *)(p             ) = b8[0];
			*(int64_t *)(p + stride    ) = r8[0];
			*(int64_t *)(p + stride * 2) = b8[1];
			*(int64_t *)(p + stride * 3) = r8[1];
			i16x8 b2 = addlou8s16(load64(p += stride * 4), lob);
			i16x8 r2 = addlou8s16(load64(p + stride    ), lor);
			i16x8 b3 = addlou8s16(load64(p + stride * 2), lob);
			i16x8 r3 = addlou8s16(load64(p + stride * 3), lor);
			i64x2 b9 = packus16(b2, b3);
			i64x2 r9 = packus16(r2, r3);
			*(int64_t *)(p             ) = b9[0];
			*(int64_t *)(p + stride    ) = r9[0];
			*(int64_t *)(p + stride * 2) = b9[1];
			*(int64_t *)(p + stride * 3) = r9[1];
			i16x8 b4 = addlou8s16(load64(p += stride * 4), hib);
			i16x8 r4 = addlou8s16(load64(p + stride    ), hir);
			i16x8 b5 = addlou8s16(load64(p + stride * 2), hib);
			i16x8 r5 = addlou8s16(load64(p + stride * 3), hir);
			i64x2 bA = packus16(b4, b5);
			i64x2 rA = packus16(r4, r5);
			*(int64_t *)(p             ) = bA[0];
			*(int64_t *)(p + stride    ) = rA[0];
			*(int64_t *)(p + stride * 2) = bA[1];
			*(int64_t *)(p + stride * 3) = rA[1];
			i16x8 b6 = addlou8s16(load64(p += stride * 4), hib);
			i16x8 r6 = addlou8s16(load64(p + stride    ), hir);
			i16x8 b7 = addlou8s16(load64(p + stride * 2), hib);
			i16x8 r7 = addlou8s16(load64(p + stride * 3), hir);
			i64x2 bB = packus16(b6, b7);
			i64x2 rB = packus16(r6, r7);
			*(int64_t *)(p             ) = bB[0];
			*(int64_t *)(p + stride    ) = rB[0];
			*(int64_t *)(p + stride * 2) = bB[1];
			*(int64_t *)(p + stride * 3) = rB[1];
		}
	}
}

// Assembly:
pushq %rbp
pushq %rbx
vmovdqa 0x1b60(%rdi), %xmm0
vmovdqa 0x1b70(%rdi), %xmm1
vxorps %xmm2, %xmm2, %xmm2
vmovaps %ymm2, 0x1b60(%rdi)
movsbl 0x51(%rdi), %eax
movsbl 0x52(%rdi), %ecx
movq 0x680(%rdi), %r8
movsbq 0x2(%r8), %rdx
imulq $0x30, %rdx, %r10
movzbl 0x240(%rdi,%r10), %r9d
movl $0x6, %r11d
xorl %edx, %edx
divl %r11d
movl %eax, %esi
leaq 0x1f3cc(%rip), %rbx     # 0x30b20
movsbl (%rbx,%rdx,4), %ebp
movzbl 0x250(%rdi,%r10), %r10d
movl %ecx, %eax
xorl %edx, %edx
divl %r11d
vpaddd %xmm0, %xmm1, %xmm2
vpsubd %xmm1, %xmm0, %xmm0
vpunpcklqdq %xmm0, %xmm2, %xmm1 # xmm1 = xmm2[0],xmm0[0]
vpunpckhqdq %xmm0, %xmm2, %xmm0 # xmm0 = xmm2[1],xmm0[1]
vpaddd %xmm0, %xmm1, %xmm2
vpsubd %xmm0, %xmm1, %xmm1
imull %r9d, %ebp
shlxl %esi, %ebp, %ecx
vpbroadcastd %ecx, %xmm0
movsbl (%rbx,%rdx,4), %ecx
imull %r10d, %ecx
shlxl %eax, %ecx, %eax
vpbroadcastd %eax, %xmm3
vinserti128 $0x1, %xmm1, %ymm2, %ymm4
vpmovqd %ymm4, %xmm4
vpmulld %xmm4, %xmm0, %xmm0
vpsrad $0x5, %xmm0, %xmm0
vshufps $0xdd, %xmm1, %xmm2, %xmm1 # xmm1 = xmm2[1,3],xmm1[1,3]
vpmulld %xmm1, %xmm3, %xmm1
vpsrad $0x5, %xmm1, %xmm1
cmpb $0x0, 0x27(%r8)
je 0x117e3
vmovdqa %xmm0, 0x1ba0(%rdi)
vmovdqa %xmm1, 0x1bb0(%rdi)
jmp 0x11979
cmpw $0xff, 0x180(%rdi)
jne 0x11979
movzwl 0x36(%rdi), %eax
movl %eax, %ecx
shrl %ecx
movq 0x670(%rdi), %rdi
vpbroadcastd 0x1fa8a(%rip), %xmm2 # 0x31294
vpaddd %xmm2, %xmm1, %xmm1
vmovdqa 0x1bf9a(%rip), %xmm3    # 0x2d7b0
vpsrad $0x6, %xmm1, %xmm1
vpaddd %xmm2, %xmm0, %xmm0
vpsrad $0x6, %xmm0, %xmm0
vmovdqa 0x1bf94(%rip), %xmm2    # 0x2d7c0
vpshufb %xmm2, %xmm1, %xmm4
vpshufb %xmm2, %xmm0, %xmm2
vpmovzxbw (%rdi), %xmm5
vpaddw %xmm5, %xmm2, %xmm5
vpmovzxbw (%rdi,%rcx), %xmm6
vpaddw %xmm6, %xmm4, %xmm6
andl $-0x2, %eax
vpmovzxbw (%rdi,%rax), %xmm7
vpaddw %xmm7, %xmm2, %xmm7
vpackuswb %xmm7, %xmm5, %xmm5
leaq (%rcx,%rcx,2), %rdx
vpmovzxbw (%rdi,%rdx), %xmm7
vpaddw %xmm7, %xmm4, %xmm7
vmovq %xmm5, (%rdi)
vpackuswb %xmm7, %xmm6, %xmm6
vmovq %xmm6, (%rdi,%rcx)
vpextrq $0x1, %xmm5, (%rdi,%rax)
vpextrq $0x1, %xmm6, (%rdi,%rdx)
movl %ecx, %esi
shll $0x2, %esi
leaq (%rdi,%rsi), %r8
vpmovzxbw (%rdi,%rsi), %xmm5
vpaddw %xmm5, %xmm2, %xmm5
vpmovzxbw (%rax,%r8), %xmm6
vpaddw %xmm6, %xmm2, %xmm2
vpmovzxbw (%rcx,%r8), %xmm6
vpaddw %xmm6, %xmm4, %xmm6
vpackuswb %xmm2, %xmm5, %xmm2
vpmovzxbw (%r8,%rdx), %xmm5
vpaddw %xmm5, %xmm4, %xmm4
vpackuswb %xmm4, %xmm6, %xmm4
vmovq %xmm2, (%rdi,%rsi)
vmovq %xmm4, (%rcx,%r8)
vpextrq $0x1, %xmm2, (%rax,%r8)
vpextrq $0x1, %xmm4, (%r8,%rdx)
vpshufb %xmm3, %xmm1, %xmm1
vpshufb %xmm3, %xmm0, %xmm0
leaq (%r8,%rsi), %rdi
vpmovzxbw (%rsi,%r8), %xmm2
vpaddw %xmm2, %xmm0, %xmm2
vpmovzxbw (%rcx,%rdi), %xmm3
vpaddw %xmm3, %xmm1, %xmm3
vpmovzxbw (%rax,%rdi), %xmm4
vpaddw %xmm4, %xmm0, %xmm4
vpackuswb %xmm4, %xmm2, %xmm2
vpmovzxbw (%rdi,%rdx), %xmm4
vpaddw %xmm4, %xmm1, %xmm4
vmovq %xmm2, (%rsi,%r8)
vpackuswb %xmm4, %xmm3, %xmm3
vmovq %xmm3, (%rcx,%rdi)
vpextrq $0x1, %xmm2, (%rax,%rdi)
vpextrq $0x1, %xmm3, (%rdi,%rdx)
leaq (%rdi,%rsi), %r8
vpmovzxbw (%rsi,%rdi), %xmm2
vpaddw %xmm2, %xmm0, %xmm2
vpmovzxbw (%rcx,%r8), %xmm3
vpaddw %xmm3, %xmm1, %xmm3
vpmovzxbw (%rax,%r8), %xmm4
vpaddw %xmm4, %xmm0, %xmm0
vpackuswb %xmm0, %xmm2, %xmm0
vpmovzxbw (%r8,%rdx), %xmm2
vpaddw %xmm2, %xmm1, %xmm1
vpackuswb %xmm1, %xmm3, %xmm1
vmovq %xmm0, (%rsi,%rdi)
vmovq %xmm1, (%rcx,%r8)
vpextrq $0x1, %xmm0, (%rax,%r8)
vpextrq $0x1, %xmm1, (%r8,%rdx)
popq %rbx
popq %rbp
vzeroupper
retq