// File: /workspace/github_cpp_makefile_star2_O2/NishadSaraf[P]Championship-Simulator/src/ooo_cpu.cc
// Function: O3_CPU::execute_instruction()
void O3_CPU::execute_instruction()
{
    if ((ROB.head == ROB.tail) && ROB.occupancy == 0)
        return;

    // out-of-order execution for non-memory instructions
    // memory instructions are handled by memory_instruction()
    uint32_t exec_issued = 0, num_iteration = 0;

    while (exec_issued < EXEC_WIDTH) {
        if (RTE0[RTE0_head] < ROB_SIZE) {
            uint32_t exec_index = RTE0[RTE0_head];
            if (ROB.entry[exec_index].event_cycle <= current_core_cycle[cpu]) {
                do_execution(exec_index);

                RTE0[RTE0_head] = ROB_SIZE;
                RTE0_head++;
                if (RTE0_head == ROB_SIZE)
                    RTE0_head = 0;
                exec_issued++;
            }
        }
        else {
            //DP (if (warmup_complete[cpu]) {
            //cout << "[RTE0] is empty head: " << RTE0_head << " tail: " << RTE0_tail << endl; });
            break;
        }

        num_iteration++;
        if (num_iteration == (ROB_SIZE-1))
            break;
    }

    num_iteration = 0;
    while (exec_issued < EXEC_WIDTH) {
        if (RTE1[RTE1_head] < ROB_SIZE) {
            uint32_t exec_index = RTE1[RTE1_head];
            if (ROB.entry[exec_index].event_cycle <= current_core_cycle[cpu]) {
                do_execution(exec_index);

                RTE1[RTE1_head] = ROB_SIZE;
                RTE1_head++;
                if (RTE1_head == ROB_SIZE)
                    RTE1_head = 0;
                exec_issued++;
            }
        }
        else {
            //DP (if (warmup_complete[cpu]) {
            //cout << "[RTE1] is empty head: " << RTE1_head << " tail: " << RTE1_tail << endl; });
            break;
        }

        num_iteration++;
        if (num_iteration == (ROB_SIZE-1))
            break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x958(%rdi), %eax
cmpl 0x95c(%rdi), %eax
jne 0xadbe
cmpl $0x0, 0x960(%rbx)
jne 0xadbe
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x2e40(%rbx), %eax
xorl %r15d, %r15d
movl $0xfe, %r12d
leaq 0x720dc(%rip), %r14     # 0x7ceb0
movl $0x100, %r13d           # imm = 0x100
xorl %ebp, %ebp
movl %eax, %ecx
movl 0x2a40(%rbx,%rcx,4), %esi
cmpq $0xff, %rsi
ja 0xae4a
movq 0x9b8(%rbx), %rcx
imulq $0x758, %rsi, %rdx      # imm = 0x758
movq 0x40(%rcx,%rdx), %rcx
movl (%rbx), %edx
cmpq (%r14,%rdx,8), %rcx
ja 0xae36
movq %rbx, %rdi
callq 0xaed2
movl 0x2e40(%rbx), %eax
movl %r13d, 0x2a40(%rbx,%rax,4)
movl 0x2e40(%rbx), %eax
incl %eax
cmpl %r13d, %eax
cmovel %r15d, %eax
movl %eax, 0x2e40(%rbx)
incl %ebp
addl $-0x1, %r12d
jae 0xae41
cmpl $0x6, %ebp
jb 0xaddc
cmpl $0x5, %ebp
ja 0xadaf
movl 0x3248(%rbx), %eax
movl $0xfe, %r15d
movl $0x100, %r12d           # imm = 0x100
xorl %r13d, %r13d
movl %eax, %ecx
movl 0x2e48(%rbx,%rcx,4), %esi
cmpq $0xff, %rsi
ja 0xadaf
movq 0x9b8(%rbx), %rcx
imulq $0x758, %rsi, %rdx      # imm = 0x758
movq 0x40(%rcx,%rdx), %rcx
movl (%rbx), %edx
cmpq (%r14,%rdx,8), %rcx
ja 0xaebd
movq %rbx, %rdi
callq 0xaed2
movl 0x3248(%rbx), %eax
movl %r12d, 0x2e48(%rbx,%rax,4)
movl 0x3248(%rbx), %eax
incl %eax
cmpl %r12d, %eax
cmovel %r13d, %eax
movl %eax, 0x3248(%rbx)
incl %ebp
addl $-0x1, %r15d
jae 0xadaf
cmpl $0x6, %ebp
jb 0xae5f
jmp 0xadaf
nop