// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %r14
movq %rdi, %rbx
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
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, %xmm2
btq $0x2f, %r14
movaps %xmm1, %xmm3
jae 0x7233
movaps 0x2030(%rip), %xmm3     # 0x9260
xorps %xmm1, %xmm3
movq %r14, %r15
shrq $0x34, %r15
movaps %xmm3, %xmm0
shufps $0x1, %xmm1, %xmm0      # xmm0 = xmm0[1,0],xmm1[0,0]
movss 0x20ab(%rip), %xmm4     # 0x92f4
ucomiss %xmm2, %xmm4
jbe 0x725b
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps 0x2037(%rip), %xmm4     # 0x9290
jmp 0x726f
ucomiss 0x2096(%rip), %xmm2     # 0x92f8
jbe 0x7275
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movaps 0x2011(%rip), %xmm4     # 0x9280
unpcklps %xmm2, %xmm4            # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1]
movaps %xmm4, %xmm2
shufps $0xe2, %xmm1, %xmm0     # xmm0 = xmm0[2,0],xmm1[2,3]
shufps $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
xorps %xmm1, %xmm1
ucomiss %xmm3, %xmm1
jbe 0x7292
xorps %xmm3, %xmm3
movlhps %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
shufps $0xe2, %xmm0, %xmm3     # xmm3 = xmm3[2,0],xmm0[2,3]
movaps %xmm3, %xmm0
andl $0xf, %r15d
movq %r14, %rax
shrq $0x32, %rax
movq %r14, %r13
shrq $0x31, %r13
movq %r14, %r12
shrq $0x30, %r12
ucomiss %xmm0, %xmm1
jbe 0x72b4
movss %xmm1, %xmm0            # xmm0 = xmm1[0],xmm0[1,2,3]
btq $0x38, %r14
jb 0x7324
addq $0x7d6c0, %rbx          # imm = 0x7D6C0
btq $0x33, %r14
jae 0x72d6
movl %r15d, %ecx
shll $0x4, %ecx
movl $0x3f800000, (%rbx,%rcx) # imm = 0x3F800000
testb $0x1, %al
je 0x72ed
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
movl %r15d, %eax
shll $0x4, %eax
movss %xmm1, 0x4(%rbx,%rax)
testb $0x1, %r13b
je 0x7306
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
movl %r15d, %eax
shll $0x4, %eax
movss %xmm1, 0x8(%rbx,%rax)
testb $0x1, %r12b
je 0x73c0
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
shll $0x4, %r15d
movss %xmm0, 0xc(%rbx,%r15)
jmp 0x73c0
btq $0x33, %r14
jae 0x733c
movl %r15d, %ecx
shll $0x4, %ecx
movl $0x3f800000, 0x7dec0(%rbx,%rcx) # imm = 0x3F800000
movaps %xmm0, %xmm3
shufps $0x55, %xmm0, %xmm3     # xmm3 = xmm3[1,1],xmm0[1,1]
testb $0x1, %al
je 0x7395
ucomiss %xmm1, %xmm3
jbe 0x7386
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
movsd %xmm1, 0x8(%rsp)
movaps %xmm3, 0x10(%rsp)
callq 0x23c0
cvtss2sd %xmm0, %xmm0
divsd 0x1fa1(%rip), %xmm0     # 0x9310
mulsd 0x8(%rsp), %xmm0
callq 0x2200
movaps 0x10(%rsp), %xmm3
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
movl %r15d, %eax
shll $0x4, %eax
movss %xmm1, 0x7dec4(%rbx,%rax)
testb $0x1, %r13b
je 0x73aa
movl %r15d, %eax
shll $0x4, %eax
movss %xmm3, 0x7dec8(%rbx,%rax)
testb $0x1, %r12b
je 0x73c0
shll $0x4, %r15d
movl $0x3f800000, 0x7decc(%rbx,%r15) # imm = 0x3F800000
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq