// File: /workspace/github_cpp_makefile_star2_O2/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 $0x608556, %rcx         # imm = 0x608556
cmpb (%rcx), %al
jae 0x40cc3a
movq %rdi, %rbx
movq $0x608648, %rcx         # imm = 0x608648
movq (%rcx), %rdx
movzwl %si, %ecx
movq (%rdx,%rcx,8), %rdx
cmpb $0x1, (%rdx,%rax)
jne 0x40cc29
movzbl 0xcc(%rbx), %edx
movq $0x608650, %rsi         # imm = 0x608650
movq (%rsi), %rsi
movq (%rsi,%rcx,8), %r8
imulq $0x18, %rax, %rdi
movq (%r8,%rdi), %rsi
movq 0x8(%r8,%rdi), %r8
subq %rsi, %r8
sarq $0x2, %r8
cmpq %rdx, %r8
jbe 0x40cc22
movq $0x608658, %r8          # imm = 0x608658
movq (%r8), %r8
movq (%r8,%rcx,8), %r8
movq (%r8,%rdi), %r8
movl (%r8,%rdx,4), %ebp
testl %ebp, %ebp
je 0x40cc59
movq $0x608660, %r8          # imm = 0x608660
movq (%r8), %r8
movq (%r8,%rcx,8), %rcx
movq (%rcx,%rdi), %rcx
shll $0x2, %edx
movl (%rcx,%rdx), %r14d
movl (%rsi,%rdx), %r15d
movq $0x608718, %rcx         # imm = 0x608718
movq (%rcx), %rcx
movzbl (%rcx,%rax), %r12d
movq $0x608560, %rcx         # imm = 0x608560
movq (%rcx), %rcx
andl $-0x2, %r14d
addq (%rcx,%rax,8), %r14
movq 0xb0(%rbx), %rdi
callq 0x412978
movq $0x608640, %rcx         # imm = 0x608640
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 0x40d738
incb 0xcc(%rbx)
jmp 0x40cc31
movb $0x0, 0xcc(%rbx)
incb %al
movb %al, 0xca(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x184ed8(%rip), %rdi    # 0x591b19
leaq 0x184f22(%rip), %rsi    # 0x591b6a
leaq 0x184f2f(%rip), %rcx    # 0x591b7e
movl $0x162, %edx            # imm = 0x162
callq 0x4d36d0
leaq 0x184f49(%rip), %rdi    # 0x591ba9
leaq 0x184f03(%rip), %rsi    # 0x591b6a
leaq 0x184f10(%rip), %rcx    # 0x591b7e
movl $0x16c, %edx            # imm = 0x16C
callq 0x4d36d0