// File: /workspace/github_cpp_makefile_star2_O3/MPSLab-ASU[P]DiRAC/./src/pe.cc
// Function: PE::determine_next_state()
void PE::determine_next_state()
{
  // Execution events to occur when PE is in execution mode.
  if(PE_State == execute)
  {
    counter_PE_exec += 1;

    // If execution of an RF pass finishes, change current state as next state.
    if (counter_PE_exec == total_cycles_RF_pass)
    {
      PE_State = PE_Next_State;
      if(PE_Next_State == execute)
      {
        update_trigger_states();
        update_reg_idx_Ops();
      }
      else
      {
        state_fetch = false;
      }

      counter_PE_exec = 0;
    }
    // If compute cycles are less than total cycles for an RF pass, stall!
    else if((counter_PE_exec == total_compute_cycles_RF_pass) && (counter_PE_exec < total_cycles_RF_pass))
    {
      state_fetch = false;
    }
  }
  // When PE is idle, check whether it needs to execute.
  else if((PE_Next_State == execute) && (counter_PE_exec == 0))
  {
    update_trigger_states();
    update_reg_idx_Ops();
  }
  // PE waiting for an execution pass to perform write-back.
  else if((PE_WB_next_pass == true) && (counter_PE_exec == 0))
  {
    update_trigger_states();
    update_reg_idx_Ops();
  }
  // PE does not execute on new data, just writeback to interconnect.
  // else if((sig_write_back_current_RF_Pass == true) && (counter_PE_exec == 0))
  // {
  //   // do nothing
  // }

  // Since Write-Back is triggered separately than PE-execution or
  // prefetching data via network, we need to monitor states for write-back
  // continuously and update the states upon the trigger.
  update_trigger_states_write_data();

  // Bits/Word for trigger:
  // i) PE execution (Bit0),
  // ii) Write back (Bit1),
  // iii) Zero-Initialize current RF pass (Bit2)
  // iii) reduction (Bit3).
  PE_Next_State   = (*trigger_from_controller_PE_exec == 1) ? execute : PE_Next_State;
  PE_WB_next_pass = (*trigger_from_controller_write_back == 1) ? true : PE_WB_next_pass;
  PE_zero_initialize_next_pass  = (*trigger_from_controller_zero_initialize == 1) ? true : PE_zero_initialize_next_pass;
  PE_spatial_reduce_next_pass   = (*trigger_from_controller_spatial_reduce == 1) ? true : PE_spatial_reduce_next_pass;
  sig_update_buffer_num_Op1_next_pass = (*trigger_from_controller_update_buf_num_Op1 == 1) ? true : sig_update_buffer_num_Op1_next_pass;
  sig_update_buffer_num_Op2_next_pass = (*trigger_from_controller_update_buf_num_Op2 == 1) ? true : sig_update_buffer_num_Op2_next_pass;
  sig_update_buffer_num_Op3_next_pass = (*trigger_from_controller_update_buf_num_Op3 == 1) ? true : sig_update_buffer_num_Op3_next_pass;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
cmpl $0x1, 0x8(%rdi)
jne 0x416d91
movl 0x9c(%rbx), %eax
incl %eax
movw %ax, 0x9c(%rbx)
movq $0x60b5e0, %rcx         # imm = 0x60B5E0
cmpw (%rcx), %ax
jne 0x416e40
movl 0xc(%rbx), %eax
movl %eax, 0x8(%rbx)
cmpl $0x1, %eax
jne 0x416e57
movq %rbx, %rdi
callq 0x416fa4
movzbl 0xde(%rbx), %eax
movzwl 0xf8(%rbx,%rax,2), %eax
movw %ax, 0x26(%rbx)
movzbl 0xdf(%rbx), %eax
movzwl 0xfc(%rbx,%rax,2), %eax
movw %ax, 0x28(%rbx)
movzbl 0xe0(%rbx), %eax
movzwl 0x100(%rbx,%rax,2), %eax
movw %ax, 0x2a(%rbx)
movw %ax, 0x2c(%rbx)
movzbl 0xe1(%rbx), %eax
movzwl 0xf8(%rbx,%rax,2), %eax
movw %ax, 0x2e(%rbx)
movzbl 0xe2(%rbx), %eax
movzwl 0xfc(%rbx,%rax,2), %eax
movw %ax, 0x30(%rbx)
movzbl 0xe3(%rbx), %eax
movzwl 0x100(%rbx,%rax,2), %eax
movw %ax, 0x32(%rbx)
jmp 0x416e5e
cmpl $0x1, 0xc(%rbx)
sete %cl
movzwl 0x9c(%rbx), %eax
testw %ax, %ax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
je 0x416dc0
testw %ax, %ax
sete %al
andb 0xd8(%rbx), %al
cmpb $0x1, %al
jne 0x416e67
movq %rbx, %rdi
callq 0x416fa4
movzbl 0xde(%rbx), %eax
movzwl 0xf8(%rbx,%rax,2), %eax
movw %ax, 0x26(%rbx)
movzbl 0xdf(%rbx), %eax
movzwl 0xfc(%rbx,%rax,2), %eax
movw %ax, 0x28(%rbx)
movzbl 0xe0(%rbx), %eax
movzwl 0x100(%rbx,%rax,2), %eax
movw %ax, 0x2a(%rbx)
movw %ax, 0x2c(%rbx)
movzbl 0xe1(%rbx), %eax
movzwl 0xf8(%rbx,%rax,2), %eax
movw %ax, 0x2e(%rbx)
movzbl 0xe2(%rbx), %eax
movzwl 0xfc(%rbx,%rax,2), %eax
movw %ax, 0x30(%rbx)
movzbl 0xe3(%rbx), %eax
movzwl 0x100(%rbx,%rax,2), %eax
movw %ax, 0x32(%rbx)
jmp 0x416e67
jae 0x416e67
movq $0x60b5e2, %rcx         # imm = 0x60B5E2
cmpw (%rcx), %ax
jne 0x416e67
movb $0x0, 0x80(%rbx)
jmp 0x416e67
movb $0x0, 0x80(%rbx)
movw $0x0, 0x9c(%rbx)
movb 0xd8(%rbx), %cl
cmpb $0x1, %cl
jne 0x416e89
movb $0x1, 0x138(%rbx)
movb $0x0, 0xd8(%rbx)
movl $0x0, 0x36(%rbx)
xorl %ecx, %ecx
movq 0xa0(%rbx), %rax
movq 0xa8(%rbx), %rdx
cmpb $0x0, (%rax)
movl $0x1, %eax
movl $0x1, %esi
jne 0x416ea9
movl 0xc(%rbx), %esi
movl %esi, 0xc(%rbx)
movq 0xb0(%rbx), %rsi
movzbl %cl, %ecx
cmpb $0x0, (%rsi)
cmovnel %eax, %ecx
movb %cl, 0xd8(%rbx)
movzbl 0xd9(%rbx), %ecx
cmpb $0x0, (%rdx)
cmovnel %eax, %ecx
movb %cl, 0xd9(%rbx)
movq 0xb8(%rbx), %rcx
movzbl 0xda(%rbx), %edx
cmpb $0x0, (%rcx)
cmovnel %eax, %edx
movb %dl, 0xda(%rbx)
movq 0xc0(%rbx), %rcx
cmpb $0x0, (%rcx)
movzbl 0xdb(%rbx), %ecx
cmovnel %eax, %ecx
movb %cl, 0xdb(%rbx)
movq 0xc8(%rbx), %rcx
cmpb $0x0, (%rcx)
movl $0x1, %ecx
jne 0x416f20
movl 0xdc(%rbx), %ecx
movb %cl, 0xdc(%rbx)
movq 0xd0(%rbx), %rcx
cmpb $0x0, (%rcx)
movzbl 0xdd(%rbx), %ecx
cmovnel %eax, %ecx
movb %cl, 0xdd(%rbx)
popq %rbx
retq