// File: /workspace/github_cpp_makefile_star2_O3/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 %dl
movq $0x60b73a, %rax         # imm = 0x60B73A
movzwl (%rax), %esi
movzwl %si, %esi
testw %si, %si
sete %r8b
orb %dl, %r8b
jne 0x4101bb
movq $0x60b554, %rdx         # imm = 0x60B554
movzwl (%rdx), %edx
incl %edx
cmpl %esi, %edx
jne 0x41030a
incl %esi
movw %si, (%rax)
xorl %edx, %edx
movw %dx, 0xca(%rdi)
movw %dx, (%rcx)
movq $0x60b556, %rcx         # imm = 0x60B556
cmpb $0x0, (%rcx)
je 0x41030a
movq $0x60b554, %rdx         # imm = 0x60B554
movzwl (%rdx), %ebp
xorl %edi, %edi
movq $0x60b648, %r8          # imm = 0x60B648
movq $0x60b668, %r9          # imm = 0x60B668
movq $0x60b720, %r11         # imm = 0x60B720
movl $0x1, %ebx
movq $0x60b728, %r14         # imm = 0x60B728
movq $0x60b730, %r15         # imm = 0x60B730
movzwl %si, %r13d
cmpw %bp, %si
jae 0x410226
movq (%r8), %r12
movq (%r12,%r13,8), %r12
movb (%r12,%rdi), %r12b
jmp 0x410229
xorl %r12d, %r12d
movzwl %bp, %r10d
addl $0x2, %r10d
cmpl %r13d, %r10d
jbe 0x410251
movq (%r9), %r10
movq (%r10,%r13,8), %r10
cmpb $0x0, (%r10,%rdi)
movl $0x1, %r13d
jne 0x41024e
movzbl %r12b, %r13d
movl %r13d, %r12d
testb %r12b, %r12b
je 0x410287
movq $0x60b718, %rsi         # imm = 0x60B718
movq (%rsi), %rsi
movb (%rsi,%rdi), %r10b
notb %r10b
andb $0x1, %r10b
movb %r10b, (%rsi,%rdi)
movq (%r11), %rsi
movb (%rsi,%rdi), %r10b
notb %r10b
andb $0x1, %r10b
movb %r10b, (%rsi,%rdi)
movzwl (%rax), %esi
movzwl (%rdx), %ebp
movzwl %si, %r12d
leal -0x1(%rsi), %r10d
cmpw %bp, %r10w
jae 0x4102a7
movq (%r8), %r10
leal -0x1(%r12), %r13d
movq (%r10,%r13,8), %r10
movb (%r10,%rdi), %r13b
jmp 0x4102aa
xorl %r13d, %r13d
movzwl %bp, %r10d
addl $0x2, %r10d
cmpl %r12d, %r10d
jbe 0x4102cb
movq (%r9), %r10
movq (%r10,%r12,8), %r10
movzbl %r13b, %r13d
cmpb $0x0, (%r10,%rdi)
cmovnel %ebx, %r13d
testb %r13b, %r13b
je 0x4102fa
movq (%r14), %rsi
movb (%rsi,%rdi), %r10b
notb %r10b
andb $0x1, %r10b
movb %r10b, (%rsi,%rdi)
movq (%r15), %rsi
movb (%rsi,%rdi), %r10b
notb %r10b
andb $0x1, %r10b
movb %r10b, (%rsi,%rdi)
movzwl (%rax), %esi
movzwl (%rdx), %ebp
incq %rdi
movzbl (%rcx), %r10d
cmpq %r10, %rdi
jb 0x410210
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop