// File: Ziang95[P]Tomasulo_simulator/FU.cpp
// Function: ldsdUnit::FU_automat()
void ldsdUnit::FU_automat()
{
    next_vdd = 0;
    while (true)
    {
A:      at_rising_edge(next_vdd);
        if (squash_p.flag)
        {
            squash_p.flag = false;
            at_falling_edge(next_vdd);
            continue;
        }
        auto newTask = queue.deQ();
        if (newTask)
        {
            task = *newTask;
            ROBEntry *R = CPU_ROB->get_entry(task.dest);
            R->output.exe = sys_clk.get_prog_cyc();
            for (int i = 0; ;i++)
            {
                if (squash_p.flag)
                {
                    squash_p.flag = false;
                    if (is_prev_index(squash_p.ROB_i, task.dest, squash_p.R_f, squash_p.R_r))
                        break;
                }
                msg_log("Calculating address "+to_string(task.oprnd1->i)+" + "+to_string(task.offset) + ", ROB = " + to_string(task.dest), 3);
                if (i == CPU_cfg->ld_str->exe_time - 1)
                {
                    task.lsqe->addr = task.oprnd1->i + task.offset;
                    if (task.code == SD)
                    {
                        *task.busy = false;
                        if (task.lsqe->SD_source == -1)
                        {
                            at_falling_edge(next_vdd);
                            task.lsqe->ready = true;
                            R->finished = true;
                            goto A;
                        }
                    }
                    else
                    {
                        at_falling_edge(next_vdd);
                        task.lsqe->ready = true;
                        goto A;
                    }
                    break;
                }
                at_falling_edge(next_vdd);
                at_rising_edge(next_vdd);
            }
        }
        at_falling_edge(next_vdd);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x138(%rbp)
movl $0x0, 0x3888(%rax)
jmp 0x73c6
movq -0x138(%rbp), %rdi
addq $0x3888, %rdi           # imm = 0x3888
callq 0x12130
movq -0x138(%rbp), %rax
testb $0x1, 0x38a4(%rax)
je 0x7405
movq -0x138(%rbp), %rdi
movb $0x0, 0x38a4(%rdi)
addq $0x3888, %rdi           # imm = 0x3888
callq 0x121a0
jmp 0x73c4
movq -0x138(%rbp), %rdi
addq $0x8, %rdi
callq 0x5790
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x7804
movq -0x138(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x3838, %rdi           # imm = 0x3838
movl $0x38, %edx
callq 0x42f0
movq -0x138(%rbp), %rax
leaq 0x28012(%rip), %rcx     # 0x2f460
movq (%rcx), %rdi
movl 0x383c(%rax), %esi
callq 0xe4d0
movq %rax, -0x18(%rbp)
leaq 0x28931(%rip), %rdi     # 0x2fd98
callq 0x116c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x54(%rax)
movl $0x0, -0x1c(%rbp)
movq -0x138(%rbp), %rax
testb $0x1, 0x38a4(%rax)
je 0x74c4
movq -0x138(%rbp), %rax
movb $0x0, 0x38a4(%rax)
movl 0x38a0(%rax), %edi
movl 0x383c(%rax), %esi
movl 0x3898(%rax), %edx
movl 0x389c(%rax), %ecx
callq 0x1aec0
testb $0x1, %al
jne 0x74bd
jmp 0x74c2
jmp 0x7802
jmp 0x74c4
movq -0x138(%rbp), %rax
movq 0x3848(%rax), %rax
movl (%rax), %esi
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x8410
movq -0x140(%rbp), %rdx
leaq 0x1ab9a(%rip), %rsi     # 0x2208f
leaq -0xc0(%rbp), %rdi
callq 0x83c0
jmp 0x7503
leaq 0x1ab4a(%rip), %rdx     # 0x22054
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x8810
jmp 0x751f
movq -0x138(%rbp), %rax
movl 0x3860(%rax), %esi
leaq -0x110(%rbp), %rdi
callq 0x8410
jmp 0x753a
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x8740
jmp 0x7553
leaq 0x1b22b(%rip), %rdx     # 0x22785
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x8810
jmp 0x7569
movq -0x138(%rbp), %rax
movl 0x383c(%rax), %esi
leaq -0x130(%rbp), %rdi
callq 0x8410
jmp 0x7584
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x130(%rbp), %rdx
callq 0x8740
jmp 0x759a
leaq -0x40(%rbp), %rdi
movl $0x3, %esi
callq 0x12060
jmp 0x75aa
leaq -0x40(%rbp), %rdi
callq 0x4240
leaq -0x130(%rbp), %rdi
callq 0x4240
leaq -0x60(%rbp), %rdi
callq 0x4240
leaq -0x80(%rbp), %rdi
callq 0x4240
leaq -0x110(%rbp), %rdi
callq 0x4240
leaq -0xa0(%rbp), %rdi
callq 0x4240
leaq -0xc0(%rbp), %rdi
callq 0x4240
leaq -0xe0(%rbp), %rdi
callq 0x4240
movl -0x1c(%rbp), %eax
leaq 0x27e45(%rip), %rcx     # 0x2f450
movq (%rcx), %rcx
movq 0x20(%rcx), %rcx
movl 0x4(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x77ce
movq -0x138(%rbp), %rax
movq 0x3848(%rax), %rcx
movl (%rcx), %edx
addl 0x3860(%rax), %edx
movq 0x3858(%rax), %rcx
movl %edx, 0x10(%rcx)
cmpl $0x7, 0x3838(%rax)
jne 0x77a2
movq -0x138(%rbp), %rax
movq 0x3868(%rax), %rcx
movb $0x0, (%rcx)
movq 0x3858(%rax), %rax
cmpl $-0x1, 0x4(%rax)
jne 0x77a0
movq -0x138(%rbp), %rdi
addq $0x3888, %rdi           # imm = 0x3888
callq 0x121a0
movq -0x138(%rbp), %rax
movq 0x3858(%rax), %rax
movb $0x1, 0x14(%rax)
movq -0x18(%rbp), %rax
movb $0x1, (%rax)
jmp 0x73c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x7792
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x7786
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x777a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x776e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x7765
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x775c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x7750
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4240
leaq -0x130(%rbp), %rdi
callq 0x4240
leaq -0x60(%rbp), %rdi
callq 0x4240
leaq -0x80(%rbp), %rdi
callq 0x4240
leaq -0x110(%rbp), %rdi
callq 0x4240
leaq -0xa0(%rbp), %rdi
callq 0x4240
leaq -0xc0(%rbp), %rdi
callq 0x4240
leaq -0xe0(%rbp), %rdi
callq 0x4240
jmp 0x781c
jmp 0x77cc
movq -0x138(%rbp), %rdi
addq $0x3888, %rdi           # imm = 0x3888
callq 0x121a0
movq -0x138(%rbp), %rax
movq 0x3858(%rax), %rax
movb $0x1, 0x14(%rax)
jmp 0x73c6
jmp 0x7802
movq -0x138(%rbp), %rdi
addq $0x3888, %rdi           # imm = 0x3888
callq 0x121a0
movq -0x138(%rbp), %rdi
addq $0x3888, %rdi           # imm = 0x3888
callq 0x12130
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x747c
jmp 0x7804
movq -0x138(%rbp), %rdi
addq $0x3888, %rdi           # imm = 0x3888
callq 0x121a0
jmp 0x73c4
movq -0xe8(%rbp), %rdi
callq 0x45f0
nopl (%rax,%rax)