// File: /workspace/github_cpp_makefile_star2_O2/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 0x40d693
movq %rdi, %rbx
movzwl %si, %r12d
movb $0x1, %bpl
xorl %r9d, %r9d
movq $0x606151, %r8          # imm = 0x606151
movq $0x608688, %r10         # imm = 0x608688
movq $0x608690, %r11         # imm = 0x608690
movq $0x6086a0, %r14         # imm = 0x6086A0
xorl %r15d, %r15d
xorl %r13d, %r13d
movzbl (%r8), %eax
cmpq %rax, %r13
jae 0x40d63f
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 0x40d628
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 0x40d628
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 0x40d615
movzbl (%rsi,%rcx), %esi
movq $0x608728, %rdx         # imm = 0x608728
movq (%rdx), %rdx
movzbl (%rdx,%rsi), %edx
movq %rsi, %r9
movq %rsi, (%rsp)
movq $0x608698, %rsi         # imm = 0x608698
movq (%rsi), %rsi
leal (,%r12,8), %edi
movq (%rsi,%rdi), %rsi
movq (%rsi,%r15), %r8
movq $0x6086a8, %rsi         # imm = 0x6086A8
movq (%rsi), %rsi
movq (%rsi,%rdi), %rsi
movq (%rsi,%r15), %rdi
movq $0x608640, %rsi         # imm = 0x608640
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 0x412964
movq 0xe8(%rbx), %rcx
addw (%rcx,%r13,2), %r14w
movzwl %ax, %r8d
movzwl %r14w, %ecx
movq $0x6086a0, %r14         # imm = 0x6086A0
movzbl %r13b, %edx
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x40d6b2
movq $0x608690, %r11         # imm = 0x608690
movq $0x608688, %r10         # imm = 0x608688
xorl %r9d, %r9d
movq $0x606151, %r8          # imm = 0x606151
movq 0xe8(%rbx), %rax
incw (%rax,%r13,2)
jmp 0x40d628
incb %cl
movb %cl, (%rdx,%r13)
movq 0xe8(%rbx), %rax
andw $0x0, (%rax,%r13,2)
movq 0x100(%rbx), %rax
andb (%rax,%r13), %bpl
incq %r13
addq $0x18, %r15
jmp 0x40d4c5
movl 0xd0(%rbx), %ecx
incl %ecx
movw %cx, 0xd0(%rbx)
movq $0x6085e0, %rdx         # imm = 0x6085E0
cmpw (%rdx), %cx
setae %cl
testb %bpl, %cl
je 0x40d684
movb $0x0, 0xce(%rbx)
xorl %ecx, %ecx
movzbl %al, %eax
cmpq %rax, %rcx
jae 0x40d684
movq 0xd8(%rbx), %rax
movb $0x0, (%rax,%rcx)
incq %rcx
movb (%r8), %al
jmp 0x40d669
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1845d5(%rip), %rdi    # 0x591c6f
leaq 0x1844c9(%rip), %rsi    # 0x591b6a
leaq 0x184617(%rip), %rcx    # 0x591cbf
movl $0x22f, %edx            # imm = 0x22F
callq 0x4d36d0