// File: /workspace/github_cpp_makefile_star2_O1/MPSLab-ASU[P]DiRAC/./src/controller.cc
// Function: controller::write_back_DRAM(unsigned short)
void controller::write_back_DRAM(uint16_t current_SPM_pass)
{
  assert(current_operand_writeback < total_operands && "invalid operand for write back!");
  if(write_operand_SPM_pass[current_SPM_pass][current_operand_writeback])
  {
    // schedule write-back of operand from SPM to DRAM
    if(current_DMAC_invocation_operand_writeback < write_operand_offset_base_addr_SPM[current_SPM_pass][current_operand_writeback].size())
    {
      uint8_t buffer_number_comm = spm_buffer_number_op_writeback[current_operand_writeback];
      uint32_t offset_SPM = write_operand_offset_base_addr_SPM[current_SPM_pass][current_operand_writeback][current_DMAC_invocation_operand_writeback];
      uint32_t offset_DRAM = write_operand_offset_base_addr_DRAM[current_SPM_pass][current_operand_writeback][current_DMAC_invocation_operand_writeback];
      uint32_t burst_size = write_operand_burst_width_bytes_SPM_pass[current_SPM_pass][current_operand_writeback][current_DMAC_invocation_operand_writeback];
      assert(burst_size > 0 && "burst size for DMAC request must be greater than zero.");
      data_type *address_operand_DRAM = tensor_operands[current_operand_writeback] + (offset_DRAM / sizeof(data_type));
      data_type *address_operand_SPM = scratchpad_mem->get_ptr() + ((operand_start_addr_SPM_buffer[buffer_number_comm][current_operand_writeback] + offset_SPM) / sizeof(data_type));
      bus_req_DMA = true;
      data_mov_SPM_DRAM_in_prog = true;
      DMAC->write_back<data_type>(address_operand_SPM, address_operand_DRAM, burst_size);
      current_DMAC_invocation_operand_writeback += 1;
    }
    else {
      current_DMAC_invocation_operand_writeback = 0;
      current_operand_writeback += 1;
    }
  }
  else
    current_operand_writeback += 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movb 0xcb(%rdi), %cl
movq $0x60b556, %rax         # imm = 0x60B556
cmpb (%rax), %cl
jae 0x41009f
movq %rdi, %rbx
addq $0xcb, %rdi
movzbl %cl, %eax
movq $0x60b668, %rdx         # imm = 0x60B668
movq (%rdx), %r8
movzwl %si, %edx
movq (%r8,%rdx,8), %rsi
cmpb $0x1, (%rsi,%rax)
jne 0x410087
leaq 0xcd(%rbx), %r12
movzbl 0xcd(%rbx), %esi
movq $0x60b670, %r8          # imm = 0x60B670
movq (%r8), %r8
movq (%r8,%rdx,8), %r10
leaq (%rax,%rax,2), %r9
movq (%r10,%r9,8), %r8
movq 0x8(%r10,%r9,8), %r10
subq %r8, %r10
sarq $0x2, %r10
cmpq %rsi, %r10
jbe 0x410082
movq $0x60b678, %rcx         # imm = 0x60B678
movq (%rcx), %rcx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%r9,8), %rcx
movl (%rcx,%rsi,4), %ebp
testl %ebp, %ebp
je 0x4100be
movq $0x60b680, %rcx         # imm = 0x60B680
movq (%rcx), %rcx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%r9,8), %rcx
shll $0x2, %esi
movl (%rcx,%rsi), %r14d
movl (%r8,%rsi), %r15d
movq $0x60b720, %rcx         # imm = 0x60B720
movq (%rcx), %rcx
movzbl (%rcx,%rax), %r13d
movq $0x60b560, %rcx         # imm = 0x60B560
movq (%rcx), %rcx
andl $-0x2, %r14d
addq (%rcx,%rax,8), %r14
movq 0xb0(%rbx), %rdi
callq 0x4169c4
movq $0x60b640, %rcx         # imm = 0x60B640
movq (%rcx), %rcx
movq (%rcx,%r13,8), %rcx
movzbl 0xcb(%rbx), %edx
addl (%rcx,%rdx,4), %r15d
andl $-0x2, %r15d
addq %rax, %r15
movb $0x1, %al
movb %al, 0xb8(%rbx)
movb %al, 0xc9(%rbx)
movq 0xa8(%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x411020
movb 0xcd(%rbx), %cl
jmp 0x41008a
movb $0x0, (%r12)
movq %rdi, %r12
incb %cl
movb %cl, (%r12)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x185b4e(%rip), %rdi    # 0x595bf4
leaq 0x185abd(%rip), %rsi    # 0x595b6a
leaq 0x185b90(%rip), %rcx    # 0x595c44
movl $0x180, %edx            # imm = 0x180
callq 0x4d75c0
leaq 0x185ae4(%rip), %rdi    # 0x595ba9
leaq 0x185a9e(%rip), %rsi    # 0x595b6a
leaq 0x185b71(%rip), %rcx    # 0x595c44
movl $0x18a, %edx            # imm = 0x18A
callq 0x4d75c0
nop