// File: /workspace/github_cpp_makefile_star2_O1/MPSLab-ASU[P]DiRAC/./src/controller.cc
// Function: controller::inc_SPM_pass()
void controller::inc_SPM_pass()
{
  // Move to next SPM pass only if PEs are done processing previous data
  // i.e., execution in all RF passes of an SPM pass.
  if ((current_RF_pass == RF_passes + WB_delay_RF_pass) || (current_SPM_pass == 0) || (current_SPM_pass == SPM_passes + 1))
  {
    current_SPM_pass += 1;
    current_operand_prefetch = 0;
    current_operand_writeback = 0;
    current_RF_pass = 0;

    for(uint8_t i=0; i < total_operands; i++)
    {
      bool update_idx_buffer_comm = false;
      bool update_idx_buffer_comp = false;

      // We need to update buffer idx responsible for communication in two cases:
      // 1) DMA is going to prefetch some data in the upcoming pass.
      // 2) DMA will write-back in the upcoming pass.
      // In either cases, need to communicate data between SPM and DRAM
      // via different buffer.
      if(current_SPM_pass < SPM_passes)
        if(read_operand_SPM_pass[current_SPM_pass][i])
          update_idx_buffer_comm = true;

      if((current_SPM_pass < SPM_passes + WB_delay_SPM_pass) && write_operand_SPM_pass[current_SPM_pass][i])
        update_idx_buffer_comm = true;

      if(update_idx_buffer_comm)
      {
        spm_buffer_number_op_prefetch[i] = (spm_buffer_number_op_prefetch[i] + 1) % 2;
        spm_buffer_number_op_writeback[i] = (spm_buffer_number_op_writeback[i] + 1) % 2;
      }

      // We need to update buffer idx responsible for computation in two cases:
      // 1) DMA prefetched some data in previous pass.
      //    Need to compute from different buffer.
      // 2) DMA will write-back in the upcoming pass.
      //    PE-array should write output in the different scratchpad buffer.

      if(current_SPM_pass > 0 && current_SPM_pass < SPM_passes + 1)
      {
        if(read_operand_SPM_pass[current_SPM_pass-1][i])
        {
          update_idx_buffer_comp = true;
        }
      }

      if((current_SPM_pass < SPM_passes + WB_delay_SPM_pass) && write_operand_SPM_pass[current_SPM_pass][i])
        update_idx_buffer_comp = true;

      if(update_idx_buffer_comp)
      {
        spm_buffer_number_op_comp_read[i] = (spm_buffer_number_op_comp_read[i] + 1) % 2;
        spm_buffer_number_op_comp_write[i] = (spm_buffer_number_op_comp_write[i] + 1) % 2;
      }
    }

  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq $0x60b738, %rcx         # imm = 0x60B738
movzwl (%rcx), %eax
movq $0x60b552, %rdx         # imm = 0x60B552
movzwl (%rdx), %edx
addl $0x2, %edx
cmpl %eax, %edx
sete %sil
movq $0x60b73a, %rax         # imm = 0x60B73A
movzwl (%rax), %edx
movzwl %dx, %edx
testw %dx, %dx
sete %r8b
orb %sil, %r8b
jne 0x410132
movq $0x60b554, %rsi         # imm = 0x60B554
movzwl (%rsi), %esi
incl %esi
cmpl %edx, %esi
jne 0x410279
incl %edx
movw %dx, (%rax)
xorl %edx, %edx
movw %dx, 0xca(%rdi)
movw %dx, (%rcx)
movq $0x60b556, %rcx         # imm = 0x60B556
cmpb $0x0, (%rcx)
je 0x410279
xorl %edx, %edx
movq $0x60b554, %rsi         # imm = 0x60B554
movq $0x60b648, %rdi         # imm = 0x60B648
movq $0x60b668, %r8          # imm = 0x60B668
movq $0x60b718, %r9          # imm = 0x60B718
movq $0x60b720, %r10         # imm = 0x60B720
movl $0x1, %r11d
movq $0x60b728, %rbx         # imm = 0x60B728
movq $0x60b730, %r14         # imm = 0x60B730
movzwl (%rax), %r15d
movzwl (%rsi), %r12d
cmpw %r12w, %r15w
jae 0x4101a9
movq (%rdi), %r13
movq (%r13,%r15,8), %r13
movb (%r13,%rdx), %bpl
jmp 0x4101ab
xorl %ebp, %ebp
addl $0x2, %r12d
cmpl %r15d, %r12d
jbe 0x4101cf
movq (%r8), %r12
movq (%r12,%r15,8), %r15
cmpb $0x0, (%r15,%rdx)
movl $0x1, %r15d
jne 0x4101cc
movzbl %bpl, %r15d
movl %r15d, %ebp
testb %bpl, %bpl
je 0x4101f8
movq (%r9), %r15
movb (%r15,%rdx), %bpl
notb %bpl
andb $0x1, %bpl
movb %bpl, (%r15,%rdx)
movq (%r10), %r15
movb (%r15,%rdx), %bpl
notb %bpl
andb $0x1, %bpl
movb %bpl, (%r15,%rdx)
movzwl (%rax), %r15d
movzwl (%rsi), %r12d
leal -0x1(%r15), %ebp
cmpw %r12w, %bp
jae 0x41021d
movq (%rdi), %r13
leal -0x1(%r15), %ebp
movq (%r13,%rbp,8), %r13
movb (%r13,%rdx), %bpl
jmp 0x41021f
xorl %ebp, %ebp
movzwl %r12w, %r12d
addl $0x2, %r12d
cmpl %r15d, %r12d
jbe 0x410240
movq (%r8), %r12
movq (%r12,%r15,8), %r15
movzbl %bpl, %ebp
cmpb $0x0, (%r15,%rdx)
cmovnel %r11d, %ebp
testb %bpl, %bpl
je 0x410269
movq (%rbx), %r15
movb (%r15,%rdx), %bpl
notb %bpl
andb $0x1, %bpl
movb %bpl, (%r15,%rdx)
movq (%r14), %r15
movb (%r15,%rdx), %bpl
notb %bpl
andb $0x1, %bpl
movb %bpl, (%r15,%rdx)
incq %rdx
movzbl (%rcx), %r15d
cmpq %r15, %rdx
jb 0x41018c
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq