// File: /workspace/github_c_makefile_star2_O1/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:
vmovdqa 0x1b60(%rdi), %xmm0
vmovdqa 0x1b70(%rdi), %xmm1
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
vpxor %xmm0, %xmm0, %xmm0
vmovdqa %ymm0, 0x1b60(%rdi)
movsbl 0x51(%rdi), %esi
movsbl 0x52(%rdi), %ecx
movq 0x680(%rdi), %rax
movsbq 0x2(%rax), %rdx
leaq (%rdx,%rdx,2), %r8
shlq $0x4, %r8
movzbl 0x240(%rdi,%r8), %r9d
movl $0xaaaaaaab, %edx       # imm = 0xAAAAAAAB
movq %rsi, %r10
imulq %rdx, %r10
shrq $0x22, %r10
leal (%r10,%r10), %r11d
leal (%r11,%r11,2), %r11d
subl %r11d, %esi
leaq 0x2263c(%rip), %r11     # 0x36b00
movsbl (%r11,%rsi,4), %esi
imull %r9d, %esi
shlxl %r10d, %esi, %esi
vpbroadcastd %esi, %xmm0
movzbl 0x250(%rdi,%r8), %esi
imulq %rcx, %rdx
shrq $0x22, %rdx
leal (%rdx,%rdx), %r8d
leal (%r8,%r8,2), %r8d
subl %r8d, %ecx
movsbl (%r11,%rcx,4), %ecx
imull %esi, %ecx
shlxl %edx, %ecx, %ecx
vpbroadcastd %ecx, %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(%rax)
je 0x14546
vmovdqa %xmm0, 0x1ba0(%rdi)
vmovdqa %xmm1, 0x1bb0(%rdi)
vzeroupper
retq
cmpw $0xff, 0x180(%rdi)
jne 0x146dc
movzwl 0x36(%rdi), %eax
movl %eax, %ecx
shrl %ecx
movq 0x670(%rdi), %rdi
vpbroadcastd 0x22cb7(%rip), %xmm2 # 0x37224
vpaddd %xmm2, %xmm1, %xmm1
vmovdqa 0x1f227(%rip), %xmm3    # 0x337a0
vpsrad $0x6, %xmm1, %xmm1
vpaddd %xmm2, %xmm0, %xmm0
vpsrad $0x6, %xmm0, %xmm0
vmovdqa 0x1f221(%rip), %xmm2    # 0x337b0
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)
vzeroupper
retq