// File: MPSLab-ASU[P]DiRAC/./src/controller.cc
// Function: controller::execute_RF_pass()
void controller::execute_RF_pass()
{
  // DMA prefetches data in 0th SPM pass.
  // Networks and PEs are already configured.
  // No need to configure networks further or communicate data.
  if(current_SPM_pass == 0)
  {
    for(uint8_t i=0; i < inNetworks; i++)
    {
      configNetwork[i] = 0;
      forwardDataToNetwork[i] = 0;
    }
  }

  if(current_SPM_pass > 0 && current_SPM_pass < SPM_passes + 1)
  {
    trigger_PEs();
    if ((current_RF_pass >= RF_passes) && (current_RF_pass < RF_passes + WB_delay_RF_pass))
    {
      // don't process read operands. need to process write operands
      if(PE_writeback_RF_incomplete)
        write_back_controller(current_RF_pass);
      else
        inc_RF_pass();
    }
    else if (current_RF_pass < WB_delay_RF_pass)
    {
      // don't process write operands. need to process read operands
      if(PE_prefetch_RF_incomplete)
        prefetch_to_PE(current_RF_pass);
      else
        inc_RF_pass();
    }
    else if((current_RF_pass >= WB_delay_RF_pass) && (current_RF_pass < RF_passes))
    {
      // process both read operands and write operands
      if(PE_prefetch_RF_incomplete)
        prefetch_to_PE(current_RF_pass);
      if (PE_writeback_RF_incomplete)
        write_back_controller(current_RF_pass);

      if ((PE_prefetch_RF_incomplete == 0) && (PE_writeback_RF_incomplete == 0))
        inc_RF_pass();
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0x4178f1
movb $0x0, -0x9(%rbp)
movzbl -0x9(%rbp), %eax
movq $0x61c151, %rcx         # imm = 0x61C151
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x4178ef
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rcx
movzbl -0x9(%rbp), %edx
movb $0x0, (%rcx,%rdx)
movq 0x60(%rax), %rax
movzbl -0x9(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movb -0x9(%rbp), %al
addb $0x1, %al
movb %al, -0x9(%rbp)
jmp 0x4178b7
jmp 0x4178f1
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %eax
cmpl $0x0, %eax
jle 0x417a72
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %eax
movq $0x61e554, %rcx         # imm = 0x61E554
movzwl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x417a72
movq -0x18(%rbp), %rdi
callq 0x417b50
movq $0x61e738, %rax         # imm = 0x61E738
movzwl (%rax), %eax
movq $0x61e552, %rcx         # imm = 0x61E552
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jl 0x41798f
movq $0x61e738, %rax         # imm = 0x61E738
movzwl (%rax), %eax
movq $0x61e552, %rcx         # imm = 0x61E552
movzwl (%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0x41798f
movq -0x18(%rbp), %rax
testb $0x1, 0xcf(%rax)
je 0x417981
movq -0x18(%rbp), %rdi
movq $0x61e738, %rax         # imm = 0x61E738
movzwl (%rax), %esi
callq 0x418080
jmp 0x41798a
movq -0x18(%rbp), %rdi
callq 0x418410
jmp 0x417a70
movq $0x61e738, %rax         # imm = 0x61E738
movzwl (%rax), %eax
cmpl $0x2, %eax
jge 0x4179ce
movq -0x18(%rbp), %rax
testb $0x1, 0xce(%rax)
je 0x4179c0
movq -0x18(%rbp), %rdi
movq $0x61e738, %rax         # imm = 0x61E738
movzwl (%rax), %esi
callq 0x4184b0
jmp 0x4179c9
movq -0x18(%rbp), %rdi
callq 0x418410
jmp 0x417a6e
movq $0x61e738, %rax         # imm = 0x61E738
movzwl (%rax), %eax
cmpl $0x2, %eax
jl 0x417a6c
movq $0x61e738, %rax         # imm = 0x61E738
movzwl (%rax), %eax
movq $0x61e552, %rcx         # imm = 0x61E552
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x417a6c
movq -0x18(%rbp), %rax
testb $0x1, 0xce(%rax)
je 0x417a19
movq -0x18(%rbp), %rdi
movq $0x61e738, %rax         # imm = 0x61E738
movzwl (%rax), %esi
callq 0x4184b0
movq -0x18(%rbp), %rax
testb $0x1, 0xcf(%rax)
je 0x417a39
movq -0x18(%rbp), %rdi
movq $0x61e738, %rax         # imm = 0x61E738
movzwl (%rax), %esi
callq 0x418080
movq -0x18(%rbp), %rax
movb 0xce(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x417a6a
movq -0x18(%rbp), %rax
movb 0xcf(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x417a6a
movq -0x18(%rbp), %rdi
callq 0x418410
jmp 0x417a6c
jmp 0x417a6e
jmp 0x417a70
jmp 0x417a72
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)