// File: /workspace/github_cpp_makefile_star2_O2/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 0xaf49
cmpl $0x0, 0x960(%rbx)
jne 0xaf49
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movl 0x980(%rbx), %r15d
andl $0x0, 0x928(%rbx)
cmpl %r15d, %r14d
jae 0xafc7
imulq $0x758, %r14, %r12      # imm = 0x758
addq $0x68, %r12
leaq 0x71f42(%rip), %r13     # 0x7ceb0
cmpq %r15, %r14
jae 0xaf3f
movq 0x9b8(%rbx), %rax
cmpb $0x0, -0x1f(%rax,%r12)
je 0xafbb
cmpl $0x2, -0x4(%rax,%r12)
jne 0xaf3f
movq -0x28(%rax,%r12), %rcx
movl (%rbx), %edx
cmpq (%r13,%rdx,8), %rcx
ja 0xaf3f
cmpl $0x63, 0x928(%rbx)
ja 0xaf3f
cmpb $0x0, -0xf(%rax,%r12)
je 0xafbb
cmpl $0x1, (%rax,%r12)
jne 0xafbb
movq %rbx, %rdi
movl %r14d, %esi
callq 0xb0a6
incq %r14
addq $0x758, %r12            # imm = 0x758
jmp 0xaf6e
imulq $0x758, %r14, %r13      # imm = 0x758
addq $0x68, %r13
leaq 0x71ed7(%rip), %r12     # 0x7ceb0
movl 0x950(%rbx), %eax
cmpq %rax, %r14
jae 0xb037
movq 0x9b8(%rbx), %rax
cmpb $0x0, -0x1f(%rax,%r13)
je 0xb02b
cmpl $0x2, -0x4(%rax,%r13)
jne 0xb037
movq -0x28(%rax,%r13), %rcx
movl (%rbx), %edx
cmpq (%r12,%rdx,8), %rcx
ja 0xb037
cmpl $0x63, 0x928(%rbx)
ja 0xb037
cmpb $0x0, -0xf(%rax,%r13)
je 0xb02b
cmpl $0x1, (%rax,%r13)
jne 0xb02b
movq %rbx, %rdi
movl %r14d, %esi
callq 0xb0a6
incq %r14
addq $0x758, %r13            # imm = 0x758
jmp 0xafd9
pushq $0x68
popq %r13
xorl %r14d, %r14d
cmpq %r14, %r15
je 0xaf3f
movq 0x9b8(%rbx), %rax
cmpb $0x0, -0x1f(%rax,%r13)
je 0xb09a
cmpl $0x2, -0x4(%rax,%r13)
jne 0xaf3f
movq -0x28(%rax,%r13), %rcx
movl (%rbx), %edx
cmpq (%r12,%rdx,8), %rcx
ja 0xaf3f
cmpl $0x63, 0x928(%rbx)
ja 0xaf3f
cmpb $0x0, -0xf(%rax,%r13)
je 0xb09a
cmpl $0x1, (%rax,%r13)
jne 0xb09a
movq %rbx, %rdi
movl %r14d, %esi
callq 0xb0a6
incq %r14
addq $0x758, %r13            # imm = 0x758
jmp 0xb03e