// File: /workspace/github_cpp_makefile_star2_O1/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 0xdb93
cmpl $0x0, 0x960(%rbx)
jne 0xdb93
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movl 0x980(%rbx), %r15d
movl $0x0, 0x928(%rbx)
cmpl %r15d, %r14d
jae 0xdc17
imulq $0x758, %r14, %r12      # imm = 0x758
addq $0x68, %r12
leaq 0x73305(%rip), %r13     # 0x80ec0
movq 0x9b8(%rbx), %rax
cmpb $0x0, -0x1f(%rax,%r12)
je 0xdc03
cmpl $0x2, -0x4(%rax,%r12)
jne 0xdb89
movq -0x28(%rax,%r12), %rcx
movl (%rbx), %edx
cmpq (%r13,%rdx,8), %rcx
ja 0xdb89
cmpl $0x63, 0x928(%rbx)
ja 0xdb89
cmpb $0x0, -0xf(%rax,%r12)
je 0xdc03
cmpl $0x1, (%rax,%r12)
jne 0xdc03
movq %rbx, %rdi
movl %r14d, %esi
callq 0xdd08
incq %r14
addq $0x758, %r12            # imm = 0x758
cmpq %r14, %r15
jne 0xdbbb
jmp 0xdb89
leaq 0x732a2(%rip), %r12     # 0x80ec0
cmpl 0x950(%rbx), %r14d
jae 0xdc8e
imulq $0x758, %r14, %r13      # imm = 0x758
addq $0x68, %r13
movq 0x9b8(%rbx), %rax
cmpb $0x0, -0x1f(%rax,%r13)
je 0xdc79
cmpl $0x2, -0x4(%rax,%r13)
jne 0xdc8e
movq -0x28(%rax,%r13), %rcx
movl (%rbx), %edx
cmpq (%r12,%rdx,8), %rcx
ja 0xdc8e
cmpl $0x63, 0x928(%rbx)
ja 0xdc8e
cmpb $0x0, -0xf(%rax,%r13)
je 0xdc79
cmpl $0x1, (%rax,%r13)
jne 0xdc79
movq %rbx, %rdi
movl %r14d, %esi
callq 0xdd08
incq %r14
movl 0x950(%rbx), %eax
addq $0x758, %r13            # imm = 0x758
cmpq %rax, %r14
jb 0xdc32
testq %r15, %r15
je 0xdb89
movl $0x68, %r13d
xorl %r14d, %r14d
movq 0x9b8(%rbx), %rax
cmpb $0x0, -0x1f(%rax,%r13)
je 0xdcf3
cmpl $0x2, -0x4(%rax,%r13)
jne 0xdb89
movq -0x28(%rax,%r13), %rcx
movl (%rbx), %edx
cmpq (%r12,%rdx,8), %rcx
ja 0xdb89
cmpl $0x63, 0x928(%rbx)
ja 0xdb89
cmpb $0x0, -0xf(%rax,%r13)
je 0xdcf3
cmpl $0x1, (%rax,%r13)
jne 0xdcf3
movq %rbx, %rdi
movl %r14d, %esi
callq 0xdd08
incq %r14
addq $0x758, %r13            # imm = 0x758
cmpq %r14, %r15
jne 0xdca0
jmp 0xdb89
nop