// File: /workspace/github_cpp_makefile_star2_O2/MPSLab-ASU[P]DiRAC/./src/controller.cc
// Function: controller::trigger_PEs()
void controller::trigger_PEs()
{
  // Trigger execution of PEs at the beginning of RF pass.
  if(cnt_bus_trigger == 0)
  {
    for(uint16_t rowID=0; rowID < nRows_PE_Array; rowID++) {
      for(uint16_t colID=0; colID < nCols_PE_Array; colID++) {
        bus_trigger_PEs_exec[rowID][colID]            = trigger_exec_pass_PEs_exec[current_SPM_pass][current_RF_pass];
        bus_trigger_PEs_zero_initialize[rowID][colID] = trigger_exec_pass_zero_init[current_SPM_pass][current_RF_pass];
        bus_trigger_PEs_update_buf_num_Op1[rowID][colID] = trigger_exec_pass_update_buf_num_Op1[current_SPM_pass][current_RF_pass];
        bus_trigger_PEs_update_buf_num_Op2[rowID][colID] = trigger_exec_pass_update_buf_num_Op2[current_SPM_pass][current_RF_pass];
        bus_trigger_PEs_update_buf_num_Op3[rowID][colID] = trigger_exec_pass_update_buf_num_Op3[current_SPM_pass][current_RF_pass];
      }
    }
  }
  else
  {
    for(uint16_t rowID=0; rowID < nRows_PE_Array; rowID++) {
      for(uint16_t colID=0; colID < nCols_PE_Array; colID++) {
        bus_trigger_PEs_exec[rowID][colID]            = 0;
        bus_trigger_PEs_zero_initialize[rowID][colID] = 0;
        bus_trigger_PEs_update_buf_num_Op1[rowID][colID] = 0;
        bus_trigger_PEs_update_buf_num_Op2[rowID][colID] = 0;
        bus_trigger_PEs_update_buf_num_Op3[rowID][colID] = 0;
      }
    }
  }


  assert(PE_trigger_latency > 0 && "PE trigger latency cannot be zero!");

  // Trigger write-back and spatial_reduce differently
  // PEs need to be triggered at certain offset-cycles for correct
  // communication via interconnect network.
  if((cnt_bus_trigger % PE_trigger_latency == 0) && (cnt_bus_trigger < PE_trigger_latency*total_PEs))
  {
    uint16_t rowID = (cnt_bus_trigger / (PE_trigger_latency * nCols_PE_Array)) % nRows_PE_Array;
    uint16_t colID = (cnt_bus_trigger / PE_trigger_latency) % nCols_PE_Array;
    assert(rowID < nRows_PE_Array && "Invalid rowID for a PE to be triggered.");
    assert(colID < nCols_PE_Array && "Invalid colID for a PE to be triggered.");
    bus_trigger_PEs_write_back[rowID][colID]      = trigger_exec_pass_writeback[current_SPM_pass][current_RF_pass];
    bus_trigger_PEs_spatial_reduce[rowID][colID]  = trigger_exec_pass_spatial_reduce[current_SPM_pass][current_RF_pass];
  }
  else {
    for(auto i=0; i < nRows_PE_Array; i++) {
      for(auto j=0; j < nCols_PE_Array; j++) {
        bus_trigger_PEs_write_back[i][j]      = 0;
        bus_trigger_PEs_spatial_reduce[i][j]  = 0;
      }
    }
  }
  if(cnt_bus_trigger < PE_trigger_latency*total_PEs)
    cnt_bus_trigger += 1;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl 0xf8(%rdi), %ecx
movl %ecx, 0x4(%rsp)
movq $0x6085ac, %rax         # imm = 0x6085AC
movzwl (%rax), %r15d
movq $0x6085ae, %rax         # imm = 0x6085AE
movzwl (%rax), %eax
testl %ecx, %ecx
je 0x40cff8
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %r15, %rdx
je 0x40d0ee
movq 0x10(%rdi), %rsi
movq 0x18(%rdi), %r14
movq 0x30(%rdi), %r8
movq 0x38(%rdi), %r9
movq 0x40(%rdi), %r10
xorl %r11d, %r11d
cmpq %r11, %rax
je 0x40cff3
movq (%rsi,%rdx,8), %rbx
movb %cl, (%rbx,%r11)
movq (%r14,%rdx,8), %rbx
movb %cl, (%rbx,%r11)
movq (%r8,%rdx,8), %rbx
movb %cl, (%rbx,%r11)
movq (%r9,%rdx,8), %rbx
movb %cl, (%rbx,%r11)
movq (%r10,%rdx,8), %rbx
movb %cl, (%rbx,%r11)
incq %r11
jmp 0x40cfc1
incq %rdx
jmp 0x40cfa1
xorl %edx, %edx
movq %rdi, 0x10(%rsp)
movq %r15, 0x8(%rsp)
cmpq %r15, %rdx
je 0x40d0ee
movq $0x6086e0, %rcx         # imm = 0x6086E0
movq (%rcx), %rcx
movq %rcx, 0x20(%rsp)
movq $0x60873a, %rcx         # imm = 0x60873A
movzwl (%rcx), %ebp
movq $0x608738, %rcx         # imm = 0x608738
movzwl (%rcx), %r9d
movq 0x10(%rdi), %rcx
movq %rcx, 0x18(%rsp)
movq 0x18(%rdi), %rsi
movq $0x6086e8, %rcx         # imm = 0x6086E8
movq (%rcx), %r10
movq $0x608700, %rcx         # imm = 0x608700
movq (%rcx), %r11
movq 0x30(%rdi), %rbx
movq $0x608708, %rcx         # imm = 0x608708
movq (%rcx), %r14
movq 0x38(%rdi), %r15
movq $0x608710, %rcx         # imm = 0x608710
movq (%rcx), %r12
movq 0x40(%rdi), %r8
shll $0x3, %ebp
xorl %r13d, %r13d
cmpq %r13, %rax
je 0x40d0dc
movq 0x20(%rsp), %rcx
movq (%rcx,%rbp), %rdi
movb (%rdi,%r9), %dil
movq 0x18(%rsp), %rcx
movq (%rcx,%rdx,8), %rcx
movb %dil, (%rcx,%r13)
movq (%r10,%rbp), %rcx
movb (%rcx,%r9), %cl
movq (%rsi,%rdx,8), %rdi
movb %cl, (%rdi,%r13)
movq (%r11,%rbp), %rcx
movb (%rcx,%r9), %cl
movq (%rbx,%rdx,8), %rdi
movb %cl, (%rdi,%r13)
movq (%r14,%rbp), %rcx
movb (%rcx,%r9), %cl
movq (%r15,%rdx,8), %rdi
movb %cl, (%rdi,%r13)
movq (%r12,%rbp), %rcx
movb (%rcx,%r9), %cl
movq (%r8,%rdx,8), %rdi
movb %cl, (%rdi,%r13)
incq %r13
jmp 0x40d078
incq %rdx
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r15
jmp 0x40d004
movq $0x6086d8, %rax         # imm = 0x6086D8
movzwl (%rax), %r10d
testl %r10d, %r10d
je 0x40d215
movl 0x4(%rsp), %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %r10d
testl %edx, %edx
je 0x40d120
movq $0x6085ae, %rax         # imm = 0x6085AE
movzwl (%rax), %edx
jmp 0x40d1b1
movl %eax, %esi
movq $0x6085a8, %rax         # imm = 0x6085A8
movl (%rax), %r11d
imull %r10d, %r11d
movq $0x6085ae, %rax         # imm = 0x6085AE
movzwl (%rax), %edx
cmpl %r11d, %ecx
jae 0x40d1b1
movl %ecx, %eax
movzwl %dx, %ecx
imull %ecx, %r10d
xorl %edx, %edx
divl %r10d
xorl %edx, %edx
divl %r15d
movl %edx, %r8d
movl %esi, %eax
xorl %edx, %edx
divl %ecx
movq $0x6086f0, %rax         # imm = 0x6086F0
movq (%rax), %rax
movq $0x60873a, %rcx         # imm = 0x60873A
movzwl (%rcx), %ecx
shll $0x3, %ecx
movq (%rax,%rcx), %rax
movq $0x608738, %rsi         # imm = 0x608738
movzwl (%rsi), %esi
movb (%rax,%rsi), %al
movq 0x20(%rdi), %r9
shll $0x3, %r8d
movq (%r9,%r8), %r9
movb %al, (%r9,%rdx)
movq $0x6086f8, %rax         # imm = 0x6086F8
movq (%rax), %rax
movq (%rax,%rcx), %rax
movb (%rax,%rsi), %al
movq 0x28(%rdi), %rcx
movq (%rcx,%r8), %rcx
movb %al, (%rcx,%rdx)
jmp 0x40d1f5
movzwl %dx, %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %r15, %rdx
je 0x40d1e7
movq 0x20(%rdi), %rsi
movq 0x28(%rdi), %r11
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x40d1e2
movq (%rsi,%rdx,8), %r9
movb %cl, (%r9,%r8)
movq (%r11,%rdx,8), %r9
movb %cl, (%r9,%r8)
incq %r8
jmp 0x40d1c8
incq %rdx
jmp 0x40d1b8
movq $0x6085a8, %rax         # imm = 0x6085A8
imull (%rax), %r10d
movl %r10d, %r11d
movl 0x4(%rsp), %eax
cmpl %r11d, %eax
jae 0x40d206
incl %eax
movl %eax, 0xf8(%rdi)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x184bd7(%rip), %rdi    # 0x591df3
leaq 0x184947(%rip), %rsi    # 0x591b6a
leaq 0x184c08(%rip), %rcx    # 0x591e32
movl $0x2c8, %edx            # imm = 0x2C8
callq 0x4d36d0