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

    // execution is out-of-order but we have an in-order scheduling algorithm to detect all RAW dependencies
    uint32_t limit = ROB.next_schedule;
    num_searched = 0;
    if (ROB.head < limit) {
        for (uint32_t i=ROB.head; i<limit; i++) {

            if (ROB.entry[i].is_memory == 0)
                continue;

            if ((ROB.entry[i].fetched != COMPLETED) || (ROB.entry[i].event_cycle > current_core_cycle[cpu]) || (num_searched >= SCHEDULER_SIZE))
                break;

            if (ROB.entry[i].is_memory && ROB.entry[i].reg_ready && (ROB.entry[i].scheduled == INFLIGHT))
                do_memory_scheduling(i);
        }
    }
    else {
        for (uint32_t i=ROB.head; i<ROB.SIZE; i++) {

            if (ROB.entry[i].is_memory == 0)
                continue;

            if ((ROB.entry[i].fetched != COMPLETED) || (ROB.entry[i].event_cycle > current_core_cycle[cpu]) || (num_searched >= SCHEDULER_SIZE))
                break;

            if (ROB.entry[i].is_memory && ROB.entry[i].reg_ready && (ROB.entry[i].scheduled == INFLIGHT))
                do_memory_scheduling(i);
        }
        for (uint32_t i=0; i<limit; i++) {

            if (ROB.entry[i].is_memory == 0)
                continue;

            if ((ROB.entry[i].fetched != COMPLETED) || (ROB.entry[i].event_cycle > current_core_cycle[cpu]) || (num_searched >= SCHEDULER_SIZE))
                break;

            if (ROB.entry[i].is_memory && ROB.entry[i].reg_ready && (ROB.entry[i].scheduled == INFLIGHT))
                do_memory_scheduling(i);
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
movl 0x958(%rdi), %r14d
cmpl 0x95c(%rdi), %r14d
jne 0xdacb
cmpl $0x0, 0x960(%rbx)
jne 0xdacb
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movl 0x980(%rbx), %r15d
movl $0x0, 0x928(%rbx)
cmpl %r15d, %r14d
jae 0xdb4f
imulq $0x758, %r14, %r12      # imm = 0x758
addq $0x68, %r12
leaq 0x733cd(%rip), %r13     # 0x80ec0
movq 0x9b8(%rbx), %rax
cmpb $0x0, -0x1f(%rax,%r12)
je 0xdb3b
cmpl $0x2, -0x4(%rax,%r12)
jne 0xdac1
movq -0x28(%rax,%r12), %rcx
movl (%rbx), %edx
cmpq (%r13,%rdx,8), %rcx
ja 0xdac1
cmpl $0x63, 0x928(%rbx)
ja 0xdac1
cmpb $0x0, -0xf(%rax,%r12)
je 0xdb3b
cmpl $0x1, (%rax,%r12)
jne 0xdb3b
movq %rbx, %rdi
movl %r14d, %esi
callq 0xdc44
incl %r14d
addq $0x758, %r12            # imm = 0x758
cmpl %r14d, %r15d
jne 0xdaf3
jmp 0xdac1
movl 0x950(%rbx), %eax
leaq 0x73364(%rip), %r12     # 0x80ec0
cmpl %eax, %r14d
jae 0xdbca
imulq $0x758, %r14, %r13      # imm = 0x758
addq $0x68, %r13
movq 0x9b8(%rbx), %rcx
cmpb $0x0, -0x1f(%rcx,%r13)
je 0xdbb9
cmpl $0x2, -0x4(%rcx,%r13)
jne 0xdbca
movq -0x28(%rcx,%r13), %rdx
movl (%rbx), %esi
cmpq (%r12,%rsi,8), %rdx
ja 0xdbca
cmpl $0x63, 0x928(%rbx)
ja 0xdbca
cmpb $0x0, -0xf(%rcx,%r13)
je 0xdbb9
cmpl $0x1, (%rcx,%r13)
jne 0xdbb9
movq %rbx, %rdi
movl %r14d, %esi
callq 0xdc44
movl 0x950(%rbx), %eax
incq %r14
movl %eax, %ecx
addq $0x758, %r13            # imm = 0x758
cmpq %rcx, %r14
jb 0xdb6c
testq %r15, %r15
je 0xdac1
movl $0x68, %r13d
xorl %r14d, %r14d
movq 0x9b8(%rbx), %rax
cmpb $0x0, -0x1f(%rax,%r13)
je 0xdc2f
cmpl $0x2, -0x4(%rax,%r13)
jne 0xdac1
movq -0x28(%rax,%r13), %rcx
movl (%rbx), %edx
cmpq (%r12,%rdx,8), %rcx
ja 0xdac1
cmpl $0x63, 0x928(%rbx)
ja 0xdac1
cmpb $0x0, -0xf(%rax,%r13)
je 0xdc2f
cmpl $0x1, (%rax,%r13)
jne 0xdc2f
movq %rbx, %rdi
movl %r14d, %esi
callq 0xdc44
incq %r14
addq $0x758, %r13            # imm = 0x758
cmpq %r14, %r15
jne 0xdbdc
jmp 0xdac1
nop