// File: /workspace/github_cpp_makefile_star2_O3/mlugo2[P]SunshineGPU/src/gpu.cpp
// Function: gpu::dst_instr(unsigned long long)
void gpu::dst_instr(u64 instr)
{
	u128 temp0, temp1;

	// Determine destination and source paths
	u8 dest = get_dest_type(instr);
	u8 destIndex = get_dest_index(instr);
	u8 destW = get_dest_w(instr);
	u8 destZ = get_dest_z(instr);
	u8 destY = get_dest_y(instr);
	u8 destX = get_dest_x(instr);

	u8 src0 = get_srcN_type(instr, 0);
	u8 src0Index = get_srcN_index(instr, 0);
	u8 src0W = get_srcN_w(instr, 0);
	u8 src0Z = get_srcN_z(instr, 0);
	u8 src0Y = get_srcN_y(instr, 0);
	u8 src0X = get_srcN_x(instr, 0);

	u8 src1 = get_srcN_type(instr, 1);
	u8 src1Index = get_srcN_index(instr, 1);
	u8 src1W = get_srcN_w(instr, 1);
	u8 src1Z = get_srcN_z(instr, 1);
	u8 src1Y = get_srcN_y(instr, 1);
	u8 src1X = get_srcN_x(instr, 1);

	// Swizzle it
	temp0 = swizzle(main_mem[src0][src0Index], src0W, src0Z, src0Y, src0X);

	temp1 = swizzle(main_mem[src1][src1Index], src1W, src1Z, src1Y, src1X);

	// Negate it
	if (get_srcN_neg(instr, 0))
	{
		temp0.y = -temp0.y;
		temp0.z = -temp0.z;
	}

	if (get_srcN_neg(instr, 1))
	{
		temp1.y = -temp1.y;
		temp1.w = -temp1.w;
	}

	// Bop it..
	if ( dest == TEMP_REG )
	{
		if (destW) main_mem[dest][destIndex].w = temp1.w;
		if (destZ) main_mem[dest][destIndex].z = temp0.z;
		if (destY) main_mem[dest][destIndex].y = temp0.y * temp1.y;
		if (destX) main_mem[dest][destIndex].x = 1.0;
	}
	else
	{
		if (destW) VOB[destIndex].w = temp1.w;
		if (destZ) VOB[destIndex].z = temp0.z;
		if (destY) VOB[destIndex].y = temp0.y * temp1.y;
		if (destX) VOB[destIndex].x = 1.0;
	}	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rax
shrq $0x34, %rax
movq %rax, (%rsp)
movq %rsi, %rax
shrq $0x2d, %rax
andl $0x3, %eax
movq %rsi, %rdi
shrq $0x29, %rdi
andl $0xf, %edi
shrq $0x27, %rsi
movq %r14, %rdx
shrq $0x25, %rdx
movq %r14, %rcx
shrq $0x23, %rcx
movq %r14, %r8
shrq $0x21, %r8
movl %r14d, %ebp
shrl $0x18, %ebp
movl %r14d, %r15d
shrl $0x16, %r15d
movl %r14d, %r12d
shrl $0x14, %r12d
movl %r14d, %r13d
shrl $0x12, %r13d
shll $0x8, %eax
addq %rbx, %rax
addq $0x7d6c0, %rax          # imm = 0x7D6C0
shll $0x4, %edi
movsd (%rdi,%rax), %xmm0
movsd 0x8(%rdi,%rax), %xmm1
andl $0x3, %esi
andl $0x3, %edx
andl $0x3, %ecx
andl $0x3, %r8d
callq 0x8342
movaps %xmm0, 0x10(%rsp)
movaps %xmm1, 0x20(%rsp)
movl %r15d, %eax
andl $0x300, %eax            # imm = 0x300
movq %rbx, 0x8(%rsp)
addq %rbx, %rax
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movl %r15d, %ecx
andl $0xf0, %ecx
movsd (%rcx,%rax), %xmm0
movsd 0x8(%rcx,%rax), %xmm1
andl $0x3, %ebp
andl $0x3, %r15d
andl $0x3, %r12d
andl $0x3, %r13d
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
movl %r13d, %r8d
callq 0x8342
btq $0x2f, %r14
jb 0x5c0b
movaps 0x20(%rsp), %xmm4
movaps 0x10(%rsp), %xmm5
jmp 0x5c38
movaps 0x364e(%rip), %xmm2     # 0x9260
movaps 0x20(%rsp), %xmm4
movaps %xmm4, %xmm3
xorps %xmm2, %xmm3
shufps $0x1, %xmm3, %xmm4      # xmm4 = xmm4[1,0],xmm3[0,0]
shufps $0xe2, %xmm3, %xmm4     # xmm4 = xmm4[2,0],xmm3[2,3]
movaps 0x10(%rsp), %xmm3
xorps %xmm3, %xmm2
shufps $0x1, %xmm3, %xmm2      # xmm2 = xmm2[1,0],xmm3[0,0]
shufps $0xe2, %xmm3, %xmm2     # xmm2 = xmm2[2,0],xmm3[2,3]
movaps %xmm2, %xmm5
movq (%rsp), %r8
andl $0xf, %r8d
movq %r14, %rdx
shrq $0x32, %rdx
movq %r14, %rcx
shrq $0x31, %rcx
movq %r14, %rax
shrq $0x30, %rax
btq $0x20, %r14
movq 0x8(%rsp), %rdi
jae 0x5c81
movaps 0x35f8(%rip), %xmm2     # 0x9260
movaps %xmm1, %xmm3
xorps %xmm2, %xmm3
shufps $0x1, %xmm3, %xmm1      # xmm1 = xmm1[1,0],xmm3[0,0]
shufps $0xe2, %xmm3, %xmm1     # xmm1 = xmm1[2,0],xmm3[2,3]
xorps %xmm0, %xmm2
shufps $0x1, %xmm2, %xmm0      # xmm0 = xmm0[1,0],xmm2[0,0]
shufps $0xe2, %xmm2, %xmm0     # xmm0 = xmm0[2,0],xmm2[2,3]
btq $0x38, %r14
jb 0x5cdd
addq $0x7d6c0, %rdi          # imm = 0x7D6C0
btq $0x33, %r14
jae 0x5ca1
movl %r8d, %esi
shll $0x4, %esi
movss %xmm0, (%rdi,%rsi)
testb $0x1, %dl
je 0x5cb6
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
movl %r8d, %edx
shll $0x4, %edx
movss %xmm5, 0x4(%rdi,%rdx)
testb $0x1, %cl
je 0x5ccb
mulss %xmm1, %xmm4
movl %r8d, %ecx
shll $0x4, %ecx
movss %xmm4, 0x8(%rdi,%rcx)
testb $0x1, %al
je 0x5d3b
shll $0x4, %r8d
leaq (%rdi,%r8), %rax
addq $0xc, %rax
jmp 0x5d35
btq $0x33, %r14
jae 0x5cf3
movl %r8d, %esi
shll $0x4, %esi
movss %xmm0, 0x7dec0(%rdi,%rsi)
testb $0x1, %dl
je 0x5d0b
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
movl %r8d, %edx
shll $0x4, %edx
movss %xmm5, 0x7dec4(%rdi,%rdx)
testb $0x1, %cl
je 0x5d23
mulss %xmm1, %xmm4
movl %r8d, %ecx
shll $0x4, %ecx
movss %xmm4, 0x7dec8(%rdi,%rcx)
testb $0x1, %al
je 0x5d3b
shll $0x4, %r8d
leaq (%rdi,%r8), %rax
addq $0x7decc, %rax          # imm = 0x7DECC
movl $0x3f800000, (%rax)     # imm = 0x3F800000
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq