// File: ys1998[P]spsim/src/alu.cpp
// Function: ALU1::tick()
void ALU1::tick(void){
	if(stall_cycles == 0){
		if(i.is_valid()){	
			operate();
			in->read();
		}
		if(in->valid() && read){
			auto inp = in->read();
			in->write(inp);
			i = std::get<0>(inp);
			if(i.is_valid())
				read = false;
			in1 = std::get<1>(inp);
			in2 = std::get<2>(inp);
			i.EXEC = CLOCK;
			i.MEM = CLOCK + 1;
			if(i.is_valid() && latencies[std::get<1>(i.type())] == 1){
				operate();
				in->read();
			}else{
				stall_cycles = latencies[std::get<1>(i.type())] - 1;	
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1b0(%rbp)
cmpl $0x0, 0xb0(%rax)
jne 0x47f7
movq -0x1b0(%rbp), %rdi
addq $0x8, %rdi
callq 0x6280
testb $0x1, %al
jne 0x454d
jmp 0x457f
movq -0x1b0(%rbp), %rdi
callq 0x3c60
movq -0x1b0(%rbp), %rax
movq 0xc8(%rax), %rsi
leaq -0x88(%rbp), %rdi
callq 0x62b0
leaq -0x88(%rbp), %rdi
callq 0x62f0
movq -0x1b0(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0x6310
testb $0x1, %al
jne 0x459b
jmp 0x47f5
movq -0x1b0(%rbp), %rax
testb $0x1, 0xc0(%rax)
je 0x47f5
movq -0x1b0(%rbp), %rax
movq 0xc8(%rax), %rsi
leaq -0x108(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x62b0
movq -0x1b0(%rbp), %rax
movq -0x1b8(%rbp), %rsi
movq 0xc8(%rax), %rdi
callq 0x6330
jmp 0x45ec
leaq -0x108(%rbp), %rdi
callq 0x6360
movq -0x1b0(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rdi
callq 0x6380
jmp 0x460d
movq -0x1b0(%rbp), %rdi
addq $0x8, %rdi
callq 0x6280
movb %al, -0x1b9(%rbp)
jmp 0x4625
movb -0x1b9(%rbp), %al
testb $0x1, %al
jne 0x4631
jmp 0x4664
movq -0x1b0(%rbp), %rax
movb $0x0, 0xc0(%rax)
jmp 0x4664
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x62f0
jmp 0x4800
leaq -0x108(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x63e0
movq -0x1c8(%rbp), %rdi
movq %rax, %rcx
movq -0x1b0(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, 0xb4(%rax)
callq 0x6400
movq %rax, %rcx
movq -0x1b0(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, 0xb8(%rax)
leaq 0x2ac0e(%rip), %rcx     # 0x2f2bc
movl (%rcx), %edx
movq %rax, %rdi
addq $0x8, %rdi
movl %edx, 0x48(%rax)
movl (%rcx), %ecx
incl %ecx
movl %ecx, 0x50(%rax)
callq 0x6280
movb %al, -0x1ba(%rbp)
jmp 0x46ce
movb -0x1ba(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x1c9(%rbp)
jne 0x46e3
jmp 0x4741
movq -0x1b0(%rbp), %rsi
movq %rsi, %rax
subq $-0x80, %rax
movq %rax, -0x1d8(%rbp)
addq $0x8, %rsi
leaq -0x11c(%rbp), %rdi
callq 0x105b0
jmp 0x470a
leaq -0x11c(%rbp), %rdi
callq 0x61f0
movq -0x1d8(%rbp), %rdi
movq %rax, %rsi
callq 0x60d0
movq %rax, -0x1e0(%rbp)
jmp 0x472e
movq -0x1e0(%rbp), %rax
cmpl $0x1, (%rax)
sete %al
movb %al, -0x1c9(%rbp)
movb -0x1c9(%rbp), %al
testb $0x1, %al
jne 0x474d
jmp 0x4785
movq -0x1b0(%rbp), %rdi
callq 0x3c60
jmp 0x475b
movq -0x1b0(%rbp), %rax
movq 0xc8(%rax), %rsi
leaq -0x1a0(%rbp), %rdi
callq 0x62b0
jmp 0x4777
leaq -0x1a0(%rbp), %rdi
callq 0x62f0
jmp 0x47e9
movq -0x1b0(%rbp), %rsi
movq %rsi, %rax
subq $-0x80, %rax
movq %rax, -0x1e8(%rbp)
addq $0x8, %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x105b0
jmp 0x47ac
leaq -0x1a8(%rbp), %rdi
callq 0x61f0
movq -0x1e8(%rbp), %rdi
movq %rax, %rsi
callq 0x60d0
movq %rax, -0x1f0(%rbp)
jmp 0x47d0
movq -0x1b0(%rbp), %rax
movq -0x1f0(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movl %ecx, 0xb0(%rax)
leaq -0x108(%rbp), %rdi
callq 0x62f0
jmp 0x47f7
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
movq -0x110(%rbp), %rdi
callq 0x3480
nopl (%rax)