// File: /workspace/github_cpp_makefile_star2_O3/MPSLab-ASU[P]DiRAC/./src/controller.cc
// Function: controller::prefetch_to_SPM(unsigned short)
void controller::prefetch_to_SPM(uint16_t current_SPM_pass)
{
  assert(current_operand_prefetch < total_operands && "invalid operand to be prefetched!");
  if(read_operand_SPM_pass[current_SPM_pass][current_operand_prefetch])
  {
    // schedule prefetch of operand to SPM
    if(current_DMAC_invocation_operand_prefetch < read_operand_offset_base_addr_SPM[current_SPM_pass][current_operand_prefetch].size())
    {
      uint8_t buffer_number_comm = spm_buffer_number_op_prefetch[current_operand_prefetch];
      uint32_t offset_SPM = read_operand_offset_base_addr_SPM[current_SPM_pass][current_operand_prefetch][current_DMAC_invocation_operand_prefetch];
      uint32_t offset_DRAM = read_operand_offset_base_addr_DRAM[current_SPM_pass][current_operand_prefetch][current_DMAC_invocation_operand_prefetch];
      uint32_t burst_size = read_operand_burst_width_bytes_SPM_pass[current_SPM_pass][current_operand_prefetch][current_DMAC_invocation_operand_prefetch];
      assert(burst_size > 0 && "burst size for DMAC request must be greater than zero.");
      data_type *address_operand_DRAM = tensor_operands[current_operand_prefetch] + (offset_DRAM / sizeof(data_type));
      data_type *address_operand_SPM = scratchpad_mem->get_ptr() + ((operand_start_addr_SPM_buffer[buffer_number_comm][current_operand_prefetch] + offset_SPM) / sizeof(data_type));
      bus_req_DMA = true;
      data_mov_SPM_DRAM_in_prog = true;
      DMAC->prefetch<data_type>(address_operand_DRAM, address_operand_SPM, burst_size);
      current_DMAC_invocation_operand_prefetch += 1;
    }
    else {
      current_DMAC_invocation_operand_prefetch = 0;
      current_operand_prefetch += 1;
    }
  }
  else
    current_operand_prefetch += 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movzbl 0xca(%rdi), %eax
movq $0x60b556, %rcx         # imm = 0x60B556
cmpb (%rcx), %al
jae 0x41044e
movq %rdi, %rbx
movq $0x60b648, %rcx         # imm = 0x60B648
movq (%rcx), %rdx
movzwl %si, %ecx
movq (%rdx,%rcx,8), %rdx
cmpb $0x1, (%rdx,%rax)
jne 0x41043d
movzbl 0xcc(%rbx), %edx
movq $0x60b650, %rsi         # imm = 0x60B650
movq (%rsi), %rsi
movq (%rsi,%rcx,8), %r8
leaq (%rax,%rax,2), %rdi
movq (%r8,%rdi,8), %rsi
movq 0x8(%r8,%rdi,8), %r8
subq %rsi, %r8
sarq $0x2, %r8
cmpq %rdx, %r8
jbe 0x410436
movq $0x60b658, %r8          # imm = 0x60B658
movq (%r8), %r8
movq (%r8,%rcx,8), %r8
movq (%r8,%rdi,8), %r8
movl (%r8,%rdx,4), %ebp
testl %ebp, %ebp
je 0x41046d
movq $0x60b660, %r8          # imm = 0x60B660
movq (%r8), %r8
movq (%r8,%rcx,8), %rcx
movq (%rcx,%rdi,8), %rcx
shll $0x2, %edx
movl (%rcx,%rdx), %r14d
movl (%rsi,%rdx), %r15d
movq $0x60b718, %rcx         # imm = 0x60B718
movq (%rcx), %rcx
movzbl (%rcx,%rax), %r12d
movq $0x60b560, %rcx         # imm = 0x60B560
movq (%rcx), %rcx
andl $-0x2, %r14d
addq (%rcx,%rax,8), %r14
movq 0xb0(%rbx), %rdi
callq 0x417508
movq $0x60b640, %rcx         # imm = 0x60B640
movq (%rcx), %rcx
movq (%rcx,%r12,8), %rcx
movzbl 0xca(%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 %r14, %rsi
movq %r15, %rdx
movl %ebp, %ecx
callq 0x41101c
incb 0xcc(%rbx)
jmp 0x410445
movb $0x0, 0xcc(%rbx)
incb %al
movb %al, 0xca(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1856c4(%rip), %rdi    # 0x595b19
leaq 0x18570e(%rip), %rsi    # 0x595b6a
leaq 0x18571b(%rip), %rcx    # 0x595b7e
movl $0x162, %edx            # imm = 0x162
callq 0x4d8100
leaq 0x185735(%rip), %rdi    # 0x595ba9
leaq 0x1856ef(%rip), %rsi    # 0x595b6a
leaq 0x1856fc(%rip), %rcx    # 0x595b7e
movl $0x16c, %edx            # imm = 0x16C
callq 0x4d8100