// File: /workspace/github_cpp_makefile_star2_O3/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:
movl 0x958(%rdi), %eax
cmpl 0x95c(%rdi), %eax
jne 0xd906
cmpl $0x0, 0x960(%rdi)
jne 0xd906
retq
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x9b8(%rdi), %rsi
movl (%rdi), %r8d
movl 0x920(%rdi), %eax
movl 0x2e40(%rdi), %ebx
xorl %r9d, %r9d
movl $0xfe, %r10d
leaq 0x7358d(%rip), %rcx     # 0x80ec0
movl $0x100, %r11d           # imm = 0x100
xorl %edx, %edx
movl %ebx, %r14d
movl 0x2a40(%rdi,%r14,4), %r15d
cmpq $0xff, %r15
ja 0xd9b8
imulq $0x758, %r15, %r12      # imm = 0x758
movq (%rcx,%r8,8), %r15
cmpq %r15, 0x40(%rsi,%r12)
ja 0xd9a4
leaq (%rsi,%r12), %rbx
addq $0x40, %rbx
movl $0x1, 0x38(%rbx)
movl 0x7355d(%rip), %r12d    # 0x80ed4
addq %r12, %r15
movq %r15, (%rbx)
incl %eax
movl %eax, 0x920(%rdi)
movl %r11d, 0x2a40(%rdi,%r14,4)
movl 0x2e40(%rdi), %ebx
incl %ebx
cmpl %r11d, %ebx
cmovel %r9d, %ebx
movl %ebx, 0x2e40(%rdi)
incl %edx
addl $-0x1, %r10d
jae 0xd9af
cmpl $0x6, %edx
jb 0xd93b
cmpl $0x5, %edx
ja 0xda4b
movq 0x9b8(%rdi), %rsi
movl (%rdi), %r8d
movl 0x3248(%rdi), %ebx
movl $0xfe, %r9d
movl $0x100, %r10d           # imm = 0x100
xorl %r11d, %r11d
movl %ebx, %r14d
movl 0x2e48(%rdi,%r14,4), %r15d
cmpq $0xff, %r15
ja 0xda4b
imulq $0x758, %r15, %r12      # imm = 0x758
movq (%rcx,%r8,8), %r15
cmpq %r15, 0x40(%rsi,%r12)
ja 0xda40
leaq (%rsi,%r12), %rbx
addq $0x40, %rbx
movl $0x1, 0x38(%rbx)
movl 0x734c1(%rip), %r12d    # 0x80ed4
addq %r12, %r15
movq %r15, (%rbx)
incl %eax
movl %eax, 0x920(%rdi)
movl %r10d, 0x2e48(%rdi,%r14,4)
movl 0x3248(%rdi), %ebx
incl %ebx
cmpl %r10d, %ebx
cmovel %r11d, %ebx
movl %ebx, 0x3248(%rdi)
incl %edx
addl $-0x1, %r9d
jae 0xda4b
cmpl $0x6, %edx
jb 0xd9d7
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop