// File: /workspace/github_cpp_makefile_star2_O1/MPSLab-ASU[P]DiRAC/./src/controller.cc
// Function: controller::prefetch_to_PE(unsigned short)
void controller::prefetch_to_PE(uint16_t current_RF_pass)
{
  assert(PE_prefetch_RF_incomplete == 1 && "Communication of data to PEs is incomplete.");
  bool prefetch_completed = true;

  for(uint8_t i=0; i < inNetworks; i++) {

    configNetwork[i] = 0;
    forwardDataToNetwork[i] = 0;
    network_read_op_comm_completed[i] = 1;

    if(read_data_RF_pass[current_RF_pass][i])
    {
      // schedule prefetch of operand to PE
      if(cnt_prefetch_via_network_RF_pass[i] < RF_pass_network_read_operand[current_RF_pass][i].size())
      {
        uint16_t burst_size_op = RF_pass_network_read_operand_burst_width_elements[current_RF_pass][i][cnt_prefetch_via_network_RF_pass[i]];
        network_read_op_comm_completed[i] = 0; // communication incomplete yet.
        if(idx_read_network_packet[i] < burst_size_op) {
          uint8_t operand = RF_pass_network_read_operand[current_RF_pass][i][cnt_prefetch_via_network_RF_pass[i]];
          uint8_t buffer_number_comp = spm_buffer_number_op_comp_read[operand];
          uint16_t idx_packet = RF_pass_network_read_operand_offset_network_packet[current_RF_pass][i][cnt_prefetch_via_network_RF_pass[i]];
          uint32_t offset_SPM = RF_pass_network_read_operand_offset_base_addr_SPM[current_RF_pass][i][cnt_prefetch_via_network_RF_pass[i]];
          uint32_t address_SPM = ((operand_start_addr_SPM_buffer[buffer_number_comp][operand] + offset_SPM) / sizeof(data_type)) + idx_read_network_packet[i];
          data_type data = scratchpad_mem->read(address_SPM);
          send_data_via_read_network(operand, i, idx_packet + idx_read_network_packet[i], data);
          idx_read_network_packet[i] += 1;
        }
        else {
          cnt_prefetch_via_network_RF_pass[i] += 1;
          idx_read_network_packet[i] = 0;
        }
      }
    }
    prefetch_completed &= (network_read_op_comm_completed[i] == 1);
  }

  counter_RF_pass_prefetch += 1;

  if ((counter_RF_pass_prefetch >= total_cycles_RF_pass) && (prefetch_completed)) {
    PE_prefetch_RF_incomplete = false;
    for(uint8_t i=0; i < inNetworks; i++)
      cnt_prefetch_via_network_RF_pass[i] = 0;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpb $0x1, 0xce(%rdi)
jne 0x410edb
movq %rdi, %rbx
movq $0x609151, %r8          # imm = 0x609151
cmpb $0x0, (%r8)
je 0x410e83
movzwl %si, %r12d
movb $0x1, %bpl
xorl %r9d, %r9d
movq $0x60b688, %r10         # imm = 0x60B688
movq $0x60b690, %r11         # imm = 0x60B690
movq $0x60b6a0, %r14         # imm = 0x60B6A0
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x58(%rbx), %rax
movb %r9b, (%rax,%r13)
movq 0x60(%rbx), %rax
movb %r9b, (%rax,%r13)
movq 0x100(%rbx), %rax
movb $0x1, (%rax,%r13)
movq (%r10), %rcx
movq (%rcx,%r12,8), %rcx
cmpb $0x1, (%rcx,%r13)
jne 0x410e62
movq 0xd8(%rbx), %rdx
movzbl (%rdx,%r13), %ecx
movq (%r11), %rsi
movq (%rsi,%r12,8), %rdi
movq (%rdi,%r15), %rsi
movq 0x8(%rdi,%r15), %rdi
subq %rsi, %rdi
cmpq %rcx, %rdi
jbe 0x410e62
movq (%r14), %rdi
movq (%rdi,%r12,8), %rdi
movq (%rdi,%r15), %rdi
movzwl (%rdi,%rcx,4), %edi
movb $0x0, (%rax,%r13)
movq 0xe8(%rbx), %rax
movzwl (%rax,%r13,2), %eax
movzbl (%rdx,%r13), %ecx
cmpl %eax, %edi
jbe 0x410e4e
movzbl (%rsi,%rcx), %esi
movq $0x60b728, %rdx         # imm = 0x60B728
movq (%rdx), %rdx
movzbl (%rdx,%rsi), %edx
movq %rsi, %r9
movq %rsi, (%rsp)
movq $0x60b698, %rsi         # imm = 0x60B698
movq (%rsi), %rsi
leal (,%r12,8), %edi
movq (%rsi,%rdi), %rsi
movq (%rsi,%r15), %r8
movq $0x60b6a8, %rsi         # imm = 0x60B6A8
movq (%rsi), %rsi
movq (%rsi,%rdi), %rsi
movq (%rsi,%r15), %rdi
movq $0x60b640, %rsi         # imm = 0x60B640
movq (%rsi), %rsi
movq (%rsi,%rdx,8), %rdx
movl (%rdx,%r9,4), %esi
addl (%rdi,%rcx,4), %esi
movzwl (%r8,%rcx,2), %r14d
shrl %esi
addl %eax, %esi
movq 0xb0(%rbx), %rdi
callq 0x4169b0
movq 0xe8(%rbx), %rcx
addw (%rcx,%r13,2), %r14w
movzwl %ax, %r8d
movzwl %r14w, %ecx
movq $0x60b6a0, %r14         # imm = 0x60B6A0
movzbl %r13b, %edx
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x410efa
movq $0x60b690, %r11         # imm = 0x60B690
movq $0x60b688, %r10         # imm = 0x60B688
xorl %r9d, %r9d
movq $0x609151, %r8          # imm = 0x609151
movq 0xe8(%rbx), %rax
incw (%rax,%r13,2)
jmp 0x410e62
incb %cl
movb %cl, (%rdx,%r13)
movq 0xe8(%rbx), %rax
movw $0x0, (%rax,%r13,2)
movq 0x100(%rbx), %rax
andb (%rax,%r13), %bpl
incq %r13
movzbl (%r8), %eax
addq $0x18, %r15
cmpq %rax, %r13
jb 0x410d0b
jmp 0x410e86
movb $0x1, %bpl
movl 0xd0(%rbx), %eax
incl %eax
movw %ax, 0xd0(%rbx)
movq $0x60b5e0, %rcx         # imm = 0x60B5E0
cmpw (%rcx), %ax
jb 0x410ecc
testb %bpl, %bpl
je 0x410ecc
movb $0x0, 0xce(%rbx)
cmpb $0x0, (%r8)
je 0x410ecc
xorl %eax, %eax
movq 0xd8(%rbx), %rcx
movb $0x0, (%rcx,%rax)
incq %rax
movzbl (%r8), %ecx
cmpq %rcx, %rax
jb 0x410eb5
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x184d8d(%rip), %rdi    # 0x595c6f
leaq 0x184c81(%rip), %rsi    # 0x595b6a
leaq 0x184dcf(%rip), %rcx    # 0x595cbf
movl $0x22f, %edx            # imm = 0x22F
callq 0x4d75c0