// File: /workspace/github_cpp_makefile_star2_O1/NishadSaraf[P]Championship-Simulator/src/drc_controller.cc
// Function: DRC_MEMORY_CONTROLLER::reset_remain_requests(PACKET_QUEUE*)
void DRC_MEMORY_CONTROLLER::reset_remain_requests(PACKET_QUEUE *queue)
{
    for (uint32_t i=0; i<queue->SIZE; i++) {
        if (queue->entry[i].scheduled) {

            uint64_t op_addr = queue->entry[i].address;
            uint32_t op_cpu = queue->entry[i].cpu,
                     op_channel = drc_get_channel(op_addr), 
                     op_rank = drc_get_rank(op_addr), 
                     op_bank = drc_get_bank(op_addr), 
                     op_row = drc_get_row(op_addr);

#ifdef DEBUG_PRINT
            //uint32_t op_column = drc_get_column(op_addr);
#endif

            // update open row
            if ((bank_request[op_channel][op_rank][op_bank].cycle_available - tCAS) <= current_core_cycle[op_cpu])
                bank_request[op_channel][op_rank][op_bank].open_row = op_row;
            else
                bank_request[op_channel][op_rank][op_bank].open_row = UINT32_MAX;

            // this bank is ready for another DRC request
            bank_request[op_channel][op_rank][op_bank].request_index = -1;
            bank_request[op_channel][op_rank][op_bank].row_buffer_hit = 0;
            bank_request[op_channel][op_rank][op_bank].working = 0;
            bank_request[op_channel][op_rank][op_bank].cycle_available = current_core_cycle[op_cpu];
            if (bank_request[op_channel][op_rank][op_bank].is_write) {
                scheduled_writes--;
                bank_request[op_channel][op_rank][op_bank].is_write = 0;
            }
            else if (bank_request[op_channel][op_rank][op_bank].is_read) {
                scheduled_reads--;
                bank_request[op_channel][op_rank][op_bank].is_read = 0;
            }

            queue->entry[i].scheduled = 0;
            queue->entry[i].event_cycle = current_core_cycle[op_cpu];

            DP ( if (warmup_complete[op_cpu]) {
            cout << queue->NAME << " instr_id: " << queue->entry[i].instr_id << " swrites: " << scheduled_writes << " sreads: " << scheduled_reads << endl; });

        }
    }
    
    update_schedule_cycle(&RQ);
    update_schedule_cycle(&WQ);
    update_process_cycle(&RQ);
    update_process_cycle(&WQ);

#ifdef SANITY_CHECK
    if (queue->is_WQ) {
        if (scheduled_writes != 0)
            assert(0);
    }
    else {
        if (scheduled_reads != 0)
            assert(0);
    }
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq %rsi, (%rsp)
movl 0x20(%rsi), %edi
testq %rdi, %rdi
je 0x11a5e
movq (%rsp), %rax
movq 0x98(%rax), %rax
leaq 0x409470(%rbx), %rcx
movl 0x409464(%rbx), %edx
movl 0x409468(%rbx), %esi
imulq $0x380, %rdi, %rdi      # imm = 0x380
xorl %r8d, %r8d
leaq 0x6f54b(%rip), %r10     # 0x80ec0
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
cmpb $0x0, 0x2(%rax,%r15)
je 0x11a4e
movl 0x330(%rax,%r15), %r12d
movl 0x340(%rax,%r15), %ebp
movl %ebp, %r13d
shrl $0x5, %r13d
andl $0x3, %r13d
movl %ebp, %r14d
shrl $0xb, %r14d
andl $0x1, %r14d
movl %ebp, %r9d
shrl $0x7, %r9d
andl $0xf, %r9d
leaq (%r13,%r13,4), %r13
shll $0x8, %r13d
addq %rcx, %r13
leaq (%r14,%r14,4), %r14
shll $0x7, %r14d
addq %r13, %r14
leaq (%r9,%r9,4), %r9
leaq (%r14,%r9,8), %r13
movq (%r13), %r9
leaq 0xa837(%rip), %r14      # 0x1c21c
movl (%r14), %r14d
subq %r14, %r9
movq (%r10,%r12,8), %r14
shrl $0xc, %ebp
andl $0xfff, %ebp            # imm = 0xFFF
cmpq %r14, %r9
cmoval %r11d, %ebp
movl %ebp, 0x18(%r13)
movl %r11d, 0x24(%r13)
movb %r8b, 0x1e(%r13)
movb %r8b, 0x1c(%r13)
movq %r14, (%r13)
cmpb %r8b, 0x20(%r13)
je 0x11a28
decl %esi
movl %esi, 0x409468(%rbx)
movb $0x0, 0x20(%r13)
jmp 0x11a3c
cmpb $0x0, 0x21(%r13)
je 0x11a3c
decl %edx
movl %edx, 0x409464(%rbx)
movb $0x0, 0x21(%r13)
movb $0x0, 0x2(%rax,%r15)
movq (%r10,%r12,8), %r9
movq %r9, 0x378(%rax,%r15)
addq $0x380, %r15            # imm = 0x380
cmpq %r15, %rdi
jne 0x1197e
leaq 0x40c510(%rbx), %rsi
callq 0x11bc8
leaq 0x40a870(%rbx), %rsi
callq 0x11bc8
movl 0x40c530(%rbx), %ecx
movq $-0x1, %rax
testq %rcx, %rcx
je 0x11ac7
movq 0x40c5a8(%rbx), %rsi
addq $0x2, %rsi
movq $-0x1, %rdx
xorl %r8d, %r8d
movl %ecx, %edi
cmpb $0x0, (%rsi)
je 0x11ab6
movq 0x376(%rsi), %r9
cmpq %rdx, %r9
cmovbq %r9, %rdx
cmovbl %r8d, %edi
incq %r8
addq $0x380, %rsi            # imm = 0x380
cmpq %r8, %rcx
jne 0x11a9f
jmp 0x11ad0
movq $-0x1, %rdx
movl %ecx, %edi
movq %rdx, 0x40c568(%rbx)
movl %edi, 0x40c554(%rbx)
movl 0x40a890(%rbx), %ecx
testq %rcx, %rcx
je 0x11b25
movq 0x40a908(%rbx), %rdx
addq $0x2, %rdx
movq $-0x1, %rax
xorl %edi, %edi
movl %ecx, %esi
cmpb $0x0, (%rdx)
je 0x11b14
movq 0x376(%rdx), %r8
cmpq %rax, %r8
cmovbq %r8, %rax
cmovbl %edi, %esi
incq %rdi
addq $0x380, %rdx            # imm = 0x380
cmpq %rdi, %rcx
jne 0x11afe
jmp 0x11b27
movl %ecx, %esi
movq %rax, 0x40a8c8(%rbx)
movl %esi, 0x40a8b4(%rbx)
movq (%rsp), %rax
cmpb $0x0, 0x25(%rax)
je 0x11b66
cmpl $0x0, 0x409468(%rbx)
je 0x11b6f
leaq 0x2519(%rip), %rdi      # 0x14067
leaq 0x354b(%rip), %rsi      # 0x150a0
leaq 0x355a(%rip), %rcx      # 0x150b6
movl $0x3d, %edx
callq 0x3160
cmpl $0x0, 0x409464(%rbx)
jne 0x11b7e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x24e2(%rip), %rdi      # 0x14067
leaq 0x3514(%rip), %rsi      # 0x150a0
leaq 0x3523(%rip), %rcx      # 0x150b6
movl $0x41, %edx
callq 0x3160
nop