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

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

	if (temp.w < -(128.0-(1.0/256.0))) temp.w = -(128.0 - (1.0/256.0));
	else if ( temp.w > 128-(1.0/256.0)) temp.w = 128.0 - (1.0/256.0);
	if (temp.x < 0.0) temp.x = 0.0;
	if (temp.y < 0.0) temp.y = 0.0;

	// Bop it..
	if ( dest == TEMP_REG )
	{
		if (destW) main_mem[dest][destIndex].w = 1.0;
		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 = 1.0;
		if (destZ) VOB[destIndex].z = (temp.x > 0.0) ? pow(2, temp.w*(log(temp.y)/log(2))) : 0.0;
		if (destY) VOB[destIndex].y = temp.x;
		if (destX) VOB[destIndex].x = 1.0;
	}

}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x14ac0
movq 0x28(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x13c50
movq 0x28(%rsp), %rdi
movb %al, 0x67(%rsp)
movq 0x78(%rsp), %rsi
callq 0x13c90
movq 0x28(%rsp), %rdi
movb %al, 0x66(%rsp)
movq 0x78(%rsp), %rsi
callq 0x13cd0
movq 0x28(%rsp), %rdi
movb %al, 0x65(%rsp)
movq 0x78(%rsp), %rsi
callq 0x13d10
movq 0x28(%rsp), %rdi
movb %al, 0x64(%rsp)
movq 0x78(%rsp), %rsi
callq 0x13d50
movq 0x28(%rsp), %rdi
movb %al, 0x63(%rsp)
movq 0x78(%rsp), %rsi
callq 0x13d90
movq 0x28(%rsp), %rdi
movb %al, 0x62(%rsp)
movq 0x78(%rsp), %rsi
xorl %edx, %edx
movl %edx, 0x24(%rsp)
callq 0x13e30
movl 0x24(%rsp), %edx
movq 0x28(%rsp), %rdi
movb %al, 0x61(%rsp)
movq 0x78(%rsp), %rsi
callq 0x13e90
movl 0x24(%rsp), %edx
movq 0x28(%rsp), %rdi
movb %al, 0x60(%rsp)
movq 0x78(%rsp), %rsi
callq 0x13ef0
movl 0x24(%rsp), %edx
movq 0x28(%rsp), %rdi
movb %al, 0x5f(%rsp)
movq 0x78(%rsp), %rsi
callq 0x13f50
movl 0x24(%rsp), %edx
movq 0x28(%rsp), %rdi
movb %al, 0x5e(%rsp)
movq 0x78(%rsp), %rsi
callq 0x13fb0
movl 0x24(%rsp), %edx
movq 0x28(%rsp), %rdi
movb %al, 0x5d(%rsp)
movq 0x78(%rsp), %rsi
callq 0x14010
movq 0x28(%rsp), %rdi
movb %al, 0x5c(%rsp)
movzbl 0x61(%rsp), %eax
shll $0x8, %eax
movq %rdi, %rcx
addq %rax, %rcx
movzbl 0x60(%rsp), %eax
shll $0x4, %eax
movups 0x7d6c0(%rax,%rcx), %xmm0
movaps %xmm0, 0x30(%rsp)
movzbl 0x5f(%rsp), %esi
movzbl 0x5e(%rsp), %edx
movzbl 0x5d(%rsp), %ecx
movzbl 0x5c(%rsp), %r8d
movsd 0x30(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
callq 0x14840
movq 0x28(%rsp), %rdi
movlpd %xmm0, 0x4c(%rsp)
movlpd %xmm1, 0x54(%rsp)
movq 0x4c(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x54(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x78(%rsp), %rsi
xorl %edx, %edx
callq 0x13dd0
cmpb $0x0, %al
je 0x12f65
movss 0x74(%rsp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x74(%rsp)
movss 0x68(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x23c1(%rip), %xmm0     # 0x15338
ucomisd %xmm1, %xmm0
jbe 0x12f8d
movss 0x238f(%rip), %xmm0     # 0x15314
movss %xmm0, 0x68(%rsp)
jmp 0x12fb5
movss 0x68(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x23a1(%rip), %xmm1     # 0x15340
ucomisd %xmm1, %xmm0
jbe 0x12fb3
movss 0x2363(%rip), %xmm0     # 0x15310
movss %xmm0, 0x68(%rsp)
jmp 0x12fb5
movss 0x74(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x12fd1
xorps %xmm0, %xmm0
movss %xmm0, 0x74(%rsp)
movss 0x70(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x12fed
xorps %xmm0, %xmm0
movss %xmm0, 0x70(%rsp)
movzbl 0x67(%rsp), %eax
cmpl $0x0, %eax
jne 0x130d5
cmpb $0x0, 0x65(%rsp)
je 0x13031
movq 0x28(%rsp), %rax
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x67(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x66(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss 0x22db(%rip), %xmm0     # 0x15308
movss %xmm0, (%rax)
cmpb $0x0, 0x64(%rsp)
je 0x13066
movq 0x28(%rsp), %rax
movss 0x74(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x67(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x66(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
cmpb $0x0, 0x63(%rsp)
je 0x1309b
movq 0x28(%rsp), %rax
movss 0x74(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x67(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x66(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
cmpb $0x0, 0x62(%rsp)
je 0x130d0
movq 0x28(%rsp), %rax
movss 0x74(%rsp), %xmm0
addq $0x7d6c0, %rax          # imm = 0x7D6C0
movzbl 0x67(%rsp), %ecx
shlq $0x8, %rcx
addq %rcx, %rax
movzbl 0x66(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0xc(%rax)
jmp 0x131fc
cmpb $0x0, 0x65(%rsp)
je 0x130ff
movq 0x28(%rsp), %rax
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x66(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss 0x220d(%rip), %xmm0     # 0x15308
movss %xmm0, (%rax)
cmpb $0x0, 0x64(%rsp)
je 0x131a6
movss 0x74(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x13175
movss 0x68(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movss 0x70(%rsp), %xmm0
callq 0x14bd0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movl $0x2, %edi
callq 0x14bf0
movsd 0x8(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x10(%rsp), %xmm0
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movl $0x2, %edi
callq 0x14c30
movsd %xmm0, 0x18(%rsp)
jmp 0x13180
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
jmp 0x13180
movq 0x28(%rsp), %rax
movsd 0x18(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x66(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x4(%rax)
cmpb $0x0, 0x63(%rsp)
je 0x131cf
movq 0x28(%rsp), %rax
movss 0x74(%rsp), %xmm0
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x66(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss %xmm0, 0x8(%rax)
cmpb $0x0, 0x62(%rsp)
je 0x131fa
movq 0x28(%rsp), %rax
addq $0x7dec0, %rax          # imm = 0x7DEC0
movzbl 0x66(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movss 0x2113(%rip), %xmm0     # 0x15308
movss %xmm0, 0xc(%rax)
jmp 0x131fc
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)