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

	// 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);

	u8 src2 = get_srcN_type(instr, 2);
	u8 src2Index = get_srcN_index(instr, 2);
	u8 src2W = get_srcN_w(instr, 2);
	u8 src2Z = get_srcN_z(instr, 2);
	u8 src2Y = get_srcN_y(instr, 2);
	u8 src2X = get_srcN_x(instr, 2);

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

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

	temp2 = swizzle(main_mem[src2][src2Index], src2W, src2Z, src2Y, src2X);

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

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

	if (get_srcN_neg(instr, 2))
	{
		temp2.x = -temp2.x;
		temp2.y = -temp2.y;
		temp2.z = -temp2.z;
		temp2.w = -temp2.w;
	}

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

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x14ac0
leaq 0xb0(%rsp), %rdi
callq 0x14ac0
leaq 0xa0(%rsp), %rdi
callq 0x14ac0
movq 0x18(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x13c50
movq 0x18(%rsp), %rdi
movb %al, 0x9f(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13c90
movq 0x18(%rsp), %rdi
movb %al, 0x9e(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13cd0
movq 0x18(%rsp), %rdi
movb %al, 0x9d(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13d10
movq 0x18(%rsp), %rdi
movb %al, 0x9c(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13d50
movq 0x18(%rsp), %rdi
movb %al, 0x9b(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13d90
movq 0x18(%rsp), %rdi
movb %al, 0x9a(%rsp)
movq 0xd8(%rsp), %rsi
xorl %edx, %edx
movl %edx, 0xc(%rsp)
callq 0x13e30
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x99(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13e90
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x98(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13ef0
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x97(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13f50
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x96(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13fb0
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x95(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x14010
movq 0x18(%rsp), %rdi
movb %al, 0x94(%rsp)
movq 0xd8(%rsp), %rsi
movl $0x1, %edx
movl %edx, 0x10(%rsp)
callq 0x13e30
movl 0x10(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x93(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13e90
movl 0x10(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x92(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13ef0
movl 0x10(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x91(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13f50
movl 0x10(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x90(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13fb0
movl 0x10(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x8f(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x14010
movq 0x18(%rsp), %rdi
movb %al, 0x8e(%rsp)
movq 0xd8(%rsp), %rsi
movl $0x2, %edx
movl %edx, 0x14(%rsp)
callq 0x13e30
movl 0x14(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x8d(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13e90
movl 0x14(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x8c(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13ef0
movl 0x14(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x8b(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13f50
movl 0x14(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x8a(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x13fb0
movl 0x14(%rsp), %edx
movq 0x18(%rsp), %rdi
movb %al, 0x89(%rsp)
movq 0xd8(%rsp), %rsi
callq 0x14010
movq 0x18(%rsp), %rdi
movb %al, 0x88(%rsp)
movzbl 0x99(%rsp), %eax
shll $0x8, %eax
leaq 0x7d6c0(%rdi,%rax), %rcx
movzbl 0x98(%rsp), %eax
shll $0x4, %eax
movups (%rax,%rcx), %xmm0
movaps %xmm0, 0x60(%rsp)
movzbl 0x97(%rsp), %esi
movzbl 0x96(%rsp), %edx
movzbl 0x95(%rsp), %ecx
movzbl 0x94(%rsp), %r8d
movsd 0x60(%rsp), %xmm0
movsd 0x68(%rsp), %xmm1
callq 0x14840
movq 0x18(%rsp), %rdi
movlpd %xmm0, 0x78(%rsp)
movlpd %xmm1, 0x80(%rsp)
movups 0x78(%rsp), %xmm0
movaps %xmm0, 0xc0(%rsp)
movzbl 0x93(%rsp), %eax
shll $0x8, %eax
leaq 0x7d6c0(%rdi,%rax), %rcx
movzbl 0x92(%rsp), %eax
shll $0x4, %eax
movups (%rax,%rcx), %xmm0
movaps %xmm0, 0x40(%rsp)
movzbl 0x91(%rsp), %esi
movzbl 0x90(%rsp), %edx
movzbl 0x8f(%rsp), %ecx
movzbl 0x8e(%rsp), %r8d
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
callq 0x14840
movq 0x18(%rsp), %rdi
movlpd %xmm0, 0x50(%rsp)
movlpd %xmm1, 0x58(%rsp)
movups 0x50(%rsp), %xmm0
movaps %xmm0, 0xb0(%rsp)
movzbl 0x8d(%rsp), %eax
shll $0x8, %eax
leaq 0x7d6c0(%rdi,%rax), %rcx
movzbl 0x8c(%rsp), %eax
shll $0x4, %eax
movups (%rax,%rcx), %xmm0
movaps %xmm0, 0x20(%rsp)
movzbl 0x8b(%rsp), %esi
movzbl 0x8a(%rsp), %edx
movzbl 0x89(%rsp), %ecx
movzbl 0x88(%rsp), %r8d
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x14840
movq 0x18(%rsp), %rdi
movlpd %xmm0, 0x30(%rsp)
movlpd %xmm1, 0x38(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0xd8(%rsp), %rsi
xorl %edx, %edx
callq 0x13dd0
cmpb $0x0, %al
je 0xe9a0
movss 0xcc(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xcc(%rsp)
movss 0xc8(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xc8(%rsp)
movss 0xc4(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xc4(%rsp)
movss 0xc0(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xc0(%rsp)
movq 0x18(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movl $0x1, %edx
callq 0x13dd0
cmpb $0x0, %al
je 0xea37
movss 0xbc(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xbc(%rsp)
movss 0xb8(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xb8(%rsp)
movss 0xb4(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xb4(%rsp)
movss 0xb0(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xb0(%rsp)
movq 0x18(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movl $0x2, %edx
callq 0x13dd0
cmpb $0x0, %al
je 0xeace
movss 0xac(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xac(%rsp)
movss 0xa8(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xa8(%rsp)
movss 0xa4(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xa4(%rsp)
movss 0xa0(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0xa0(%rsp)
movzbl 0x9f(%rsp), %eax
cmpl $0x0, %eax
jne 0xec4f
cmpb $0x0, 0x9d(%rsp)
je 0xeb39
movq 0x18(%rsp), %rax
movss 0xc0(%rsp), %xmm0
movss 0xb0(%rsp), %xmm2
movss 0xa0(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x9f(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x9e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, (%rax)
cmpb $0x0, 0x9c(%rsp)
je 0xeb94
movq 0x18(%rsp), %rax
movss 0xc4(%rsp), %xmm0
movss 0xb4(%rsp), %xmm2
movss 0xa4(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x9f(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x9e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
cmpb $0x0, 0x9b(%rsp)
je 0xebef
movq 0x18(%rsp), %rax
movss 0xc8(%rsp), %xmm0
movss 0xb8(%rsp), %xmm2
movss 0xa8(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x9f(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x9e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
cmpb $0x0, 0x9a(%rsp)
je 0xec4a
movq 0x18(%rsp), %rax
movss 0xcc(%rsp), %xmm0
movss 0xbc(%rsp), %xmm2
movss 0xac(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x9f(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x9e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
jmp 0xed80
cmpb $0x0, 0x9d(%rsp)
je 0xec9a
movq 0x18(%rsp), %rax
movss 0xc0(%rsp), %xmm0
movss 0xb0(%rsp), %xmm2
movss 0xa0(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x9e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, (%rax)
cmpb $0x0, 0x9c(%rsp)
je 0xece6
movq 0x18(%rsp), %rax
movss 0xc4(%rsp), %xmm0
movss 0xb4(%rsp), %xmm2
movss 0xa4(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x9e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
cmpb $0x0, 0x9b(%rsp)
je 0xed32
movq 0x18(%rsp), %rax
movss 0xc8(%rsp), %xmm0
movss 0xb8(%rsp), %xmm2
movss 0xa8(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x9e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
cmpb $0x0, 0x9a(%rsp)
je 0xed7e
movq 0x18(%rsp), %rax
movss 0xcc(%rsp), %xmm0
movss 0xbc(%rsp), %xmm2
movss 0xac(%rsp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x9e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
jmp 0xed80
addq $0xe8, %rsp
retq
nopl (%rax,%rax)