// File: mlugo2[P]SunshineGPU/src/gpu.cpp
// Function: gpu::rcp_instr(unsigned long long)
void gpu::rcp_instr(u64 instr)
{
	u128 temp;

	// 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 src = get_srcN_type(instr, 0);
	u8 srcIndex = get_srcN_index(instr, 0);
	u8 srcW = get_srcN_w(instr, 0);
	u8 srcZ = get_srcN_z(instr, 0);
	u8 srcY = get_srcN_y(instr, 0);
	u8 srcX = get_srcN_x(instr, 0);

	// Swizzle it
	temp = swizzle(main_mem[src][srcIndex], srcW, srcZ, srcY, srcX);

	if (get_srcN_neg(instr, 0))
	{
		temp.x = -temp.x;
	}

	if ( temp.x == 1.0 )
		temp.x = 1;
	else {
		temp.x = 1.0 / temp.x;
	}

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

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x14ac0
movq 0x8(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x13c50
movq 0x8(%rsp), %rdi
movb %al, 0x47(%rsp)
movq 0x58(%rsp), %rsi
callq 0x13c90
movq 0x8(%rsp), %rdi
movb %al, 0x46(%rsp)
movq 0x58(%rsp), %rsi
callq 0x13cd0
movq 0x8(%rsp), %rdi
movb %al, 0x45(%rsp)
movq 0x58(%rsp), %rsi
callq 0x13d10
movq 0x8(%rsp), %rdi
movb %al, 0x44(%rsp)
movq 0x58(%rsp), %rsi
callq 0x13d50
movq 0x8(%rsp), %rdi
movb %al, 0x43(%rsp)
movq 0x58(%rsp), %rsi
callq 0x13d90
movq 0x8(%rsp), %rdi
movb %al, 0x42(%rsp)
movq 0x58(%rsp), %rsi
xorl %edx, %edx
movl %edx, 0x4(%rsp)
callq 0x13e30
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x41(%rsp)
movq 0x58(%rsp), %rsi
callq 0x13e90
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x40(%rsp)
movq 0x58(%rsp), %rsi
callq 0x13ef0
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x3f(%rsp)
movq 0x58(%rsp), %rsi
callq 0x13f50
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x3e(%rsp)
movq 0x58(%rsp), %rsi
callq 0x13fb0
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movb %al, 0x3d(%rsp)
movq 0x58(%rsp), %rsi
callq 0x14010
movq 0x8(%rsp), %rdi
movb %al, 0x3c(%rsp)
movzbl 0x41(%rsp), %eax
shll $0x8, %eax
movq %rdi, %rcx
addq %rax, %rcx
movzbl 0x40(%rsp), %eax
shll $0x4, %eax
movups 0x7d6c0(%rax,%rcx), %xmm0
movaps %xmm0, 0x10(%rsp)
movzbl 0x3f(%rsp), %esi
movzbl 0x3e(%rsp), %edx
movzbl 0x3d(%rsp), %ecx
movzbl 0x3c(%rsp), %r8d
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
callq 0x14840
movq 0x8(%rsp), %rdi
movlpd %xmm0, 0x2c(%rsp)
movlpd %xmm1, 0x34(%rsp)
movq 0x2c(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x34(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rsi
xorl %edx, %edx
callq 0x13dd0
cmpb $0x0, %al
je 0x115ac
movss 0x54(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x54(%rsp)
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3d72(%rip), %xmm1     # 0x15330
ucomisd %xmm1, %xmm0
jne 0x115d6
jp 0x115d6
movss 0x3d3a(%rip), %xmm0     # 0x15308
movss %xmm0, 0x54(%rsp)
jmp 0x115f6
movss 0x54(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x3d48(%rip), %xmm0     # 0x15330
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x54(%rsp)
movzbl 0x47(%rsp), %eax
cmpl $0x0, %eax
jne 0x116dc
cmpb $0x0, 0x45(%rsp)
je 0x11638
movq 0x8(%rsp), %rax
movss 0x54(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x47(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x46(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, (%rax)
cmpb $0x0, 0x44(%rsp)
je 0x1166d
movq 0x8(%rsp), %rax
movss 0x54(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x47(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x46(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
cmpb $0x0, 0x43(%rsp)
je 0x116a2
movq 0x8(%rsp), %rax
movss 0x54(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x47(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x46(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
cmpb $0x0, 0x42(%rsp)
je 0x116d7
movq 0x8(%rsp), %rax
movss 0x54(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x47(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x46(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
jmp 0x11781
cmpb $0x0, 0x45(%rsp)
je 0x11704
movq 0x8(%rsp), %rax
movss 0x54(%rsp), %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x46(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, (%rax)
cmpb $0x0, 0x44(%rsp)
je 0x1172d
movq 0x8(%rsp), %rax
movss 0x54(%rsp), %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x46(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
cmpb $0x0, 0x43(%rsp)
je 0x11756
movq 0x8(%rsp), %rax
movss 0x54(%rsp), %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x46(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
cmpb $0x0, 0x42(%rsp)
je 0x1177f
movq 0x8(%rsp), %rax
movss 0x54(%rsp), %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x46(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
jmp 0x11781
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)