// File: mlugo2[P]SunshineGPU/src/gpu.cpp
// Function: gpu::mul_instr(unsigned long long)
void gpu::mul_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.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;
	}

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

}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x14ac0
leaq 0x70(%rsp), %rdi
callq 0x14ac0
movq 0x8(%rsp), %rdi
movq 0x98(%rsp), %rsi
callq 0x13c50
movq 0x8(%rsp), %rdi
movb %al, 0x6f(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13c90
movq 0x8(%rsp), %rdi
movb %al, 0x6e(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13cd0
movq 0x8(%rsp), %rdi
movb %al, 0x6d(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13d10
movq 0x8(%rsp), %rdi
movb %al, 0x6c(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13d50
movq 0x8(%rsp), %rdi
movb %al, 0x6b(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13d90
movq 0x8(%rsp), %rdi
movb %al, 0x6a(%rsp)
movq 0x98(%rsp), %rsi
xorl %edx, %edx
movl %edx, (%rsp)
callq 0x13e30
movl (%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x69(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13e90
movl (%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x68(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13ef0
movl (%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x67(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13f50
movl (%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x66(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13fb0
movl (%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x65(%rsp)
movq 0x98(%rsp), %rsi
callq 0x14010
movq 0x8(%rsp), %rdi
movb %al, 0x64(%rsp)
movq 0x98(%rsp), %rsi
movl $0x1, %edx
movl %edx, 0x4(%rsp)
callq 0x13e30
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x63(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13e90
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x62(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13ef0
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x61(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13f50
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x60(%rsp)
movq 0x98(%rsp), %rsi
callq 0x13fb0
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x5f(%rsp)
movq 0x98(%rsp), %rsi
callq 0x14010
movq 0x8(%rsp), %rdi
movb %al, 0x5e(%rsp)
movzbl 0x69(%rsp), %eax
shll $0x8, %eax
leaq 0x7d6c0(%rdi,%rax), %rcx
movzbl 0x68(%rsp), %eax
shll $0x4, %eax
movups (%rax,%rcx), %xmm0
movaps %xmm0, 0x30(%rsp)
movzbl 0x67(%rsp), %esi
movzbl 0x66(%rsp), %edx
movzbl 0x65(%rsp), %ecx
movzbl 0x64(%rsp), %r8d
movsd 0x30(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
callq 0x14840
movq 0x8(%rsp), %rdi
movlpd %xmm0, 0x4c(%rsp)
movlpd %xmm1, 0x54(%rsp)
movups 0x4c(%rsp), %xmm0
movaps %xmm0, 0x80(%rsp)
movzbl 0x63(%rsp), %eax
shll $0x8, %eax
leaq 0x7d6c0(%rdi,%rax), %rcx
movzbl 0x62(%rsp), %eax
shll $0x4, %eax
movups (%rax,%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movzbl 0x61(%rsp), %esi
movzbl 0x60(%rsp), %edx
movzbl 0x5f(%rsp), %ecx
movzbl 0x5e(%rsp), %r8d
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
callq 0x14840
movq 0x8(%rsp), %rdi
movlpd %xmm0, 0x20(%rsp)
movlpd %xmm1, 0x28(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x98(%rsp), %rsi
xorl %edx, %edx
callq 0x13dd0
cmpb $0x0, %al
je 0xdc7d
movss 0x8c(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x8c(%rsp)
movss 0x88(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x88(%rsp)
movss 0x84(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x84(%rsp)
movss 0x80(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x80(%rsp)
movq 0x8(%rsp), %rdi
movq 0x98(%rsp), %rsi
movl $0x1, %edx
callq 0x13dd0
cmpb $0x0, %al
je 0xdcfc
movss 0x7c(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x7c(%rsp)
movss 0x78(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x78(%rsp)
movss 0x74(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x74(%rsp)
movss 0x70(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x70(%rsp)
movzbl 0x6f(%rsp), %eax
cmpl $0x0, %eax
jne 0xde06
cmpb $0x0, 0x6d(%rsp)
je 0xdd47
movq 0x8(%rsp), %rax
movss 0x80(%rsp), %xmm0
mulss 0x70(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x6f(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x6e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, (%rax)
cmpb $0x0, 0x6c(%rsp)
je 0xdd85
movq 0x8(%rsp), %rax
movss 0x84(%rsp), %xmm0
mulss 0x74(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x6f(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x6e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
cmpb $0x0, 0x6b(%rsp)
je 0xddc3
movq 0x8(%rsp), %rax
movss 0x88(%rsp), %xmm0
mulss 0x78(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x6f(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x6e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
cmpb $0x0, 0x6a(%rsp)
je 0xde01
movq 0x8(%rsp), %rax
movss 0x8c(%rsp), %xmm0
mulss 0x7c(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x6f(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x6e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
jmp 0xdecf
cmpb $0x0, 0x6d(%rsp)
je 0xde37
movq 0x8(%rsp), %rax
movss 0x80(%rsp), %xmm0
mulss 0x70(%rsp), %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x6e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, (%rax)
cmpb $0x0, 0x6c(%rsp)
je 0xde69
movq 0x8(%rsp), %rax
movss 0x84(%rsp), %xmm0
mulss 0x74(%rsp), %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x6e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
cmpb $0x0, 0x6b(%rsp)
je 0xde9b
movq 0x8(%rsp), %rax
movss 0x88(%rsp), %xmm0
mulss 0x78(%rsp), %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x6e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
cmpb $0x0, 0x6a(%rsp)
je 0xdecd
movq 0x8(%rsp), %rax
movss 0x8c(%rsp), %xmm0
mulss 0x7c(%rsp), %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x6e(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
jmp 0xdecf
addq $0xa8, %rsp
retq
nopw (%rax,%rax)