// File: MPSLab-ASU[P]DiRAC/./src/controller.cc
// Function: controller::execute_SPM_pass()
void controller::execute_SPM_pass()
{
  if(data_mov_SPM_DRAM_in_prog == 0)
  {
    if(current_SPM_pass < (SPM_passes + WB_delay_SPM_pass))
    {
      if ((current_SPM_pass >= SPM_passes) && (current_SPM_pass < SPM_passes + WB_delay_SPM_pass))
      {
        // don't do anything for read operands
        // process write operands
        if(current_operand_writeback < total_operands)
          write_back_DRAM(current_SPM_pass);
        else if(current_operand_writeback == total_operands)
          inc_SPM_pass();
        else
          assert("Should not reach here.");
      }
      else if (current_SPM_pass < WB_delay_SPM_pass)
      {
        // don't do anything for write operands
        // process read operands
        if(current_operand_prefetch < total_operands)
          prefetch_to_SPM(current_SPM_pass);
        else if(current_operand_prefetch == total_operands)
          inc_SPM_pass();
        else
          assert("Should not reach here.");
      }
      else
      {
        // process both read operands and write operands
        if(current_operand_prefetch < total_operands)
          prefetch_to_SPM(current_SPM_pass);
        else if (current_operand_writeback < total_operands)
          write_back_DRAM(current_SPM_pass);
        else if ((current_operand_prefetch == total_operands) && (current_operand_writeback == total_operands))
          inc_SPM_pass();
        else
          assert("Should not reach here.");
      }
    }
    else {
      acc_controller_state = terminate_exec;
      return;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movb 0xc9(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x416dc5
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %eax
movq $0x61e554, %rcx         # imm = 0x61E554
movzwl (%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0x416db4
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %eax
movq $0x61e554, %rcx         # imm = 0x61E554
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jl 0x416ca5
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %eax
movq $0x61e554, %rcx         # imm = 0x61E554
movzwl (%rcx), %ecx
addl $0x2, %ecx
cmpl %ecx, %eax
jge 0x416ca5
movq -0x10(%rbp), %rax
movzbl 0xcb(%rax), %eax
movq $0x61e556, %rcx         # imm = 0x61E556
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x416c78
movq -0x10(%rbp), %rdi
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %esi
callq 0x416dd0
jmp 0x416ca0
movq -0x10(%rbp), %rax
movzbl 0xcb(%rax), %eax
movq $0x61e556, %rcx         # imm = 0x61E556
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x416c9c
movq -0x10(%rbp), %rdi
callq 0x417080
jmp 0x416c9e
jmp 0x416c9e
jmp 0x416ca0
jmp 0x416db2
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %eax
cmpl $0x2, %eax
jge 0x416d0f
movq -0x10(%rbp), %rax
movzbl 0xca(%rax), %eax
movq $0x61e556, %rcx         # imm = 0x61E556
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x416ce2
movq -0x10(%rbp), %rdi
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %esi
callq 0x417330
jmp 0x416d0a
movq -0x10(%rbp), %rax
movzbl 0xca(%rax), %eax
movq $0x61e556, %rcx         # imm = 0x61E556
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x416d06
movq -0x10(%rbp), %rdi
callq 0x417080
jmp 0x416d08
jmp 0x416d08
jmp 0x416d0a
jmp 0x416db0
movq -0x10(%rbp), %rax
movzbl 0xca(%rax), %eax
movq $0x61e556, %rcx         # imm = 0x61E556
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x416d3d
movq -0x10(%rbp), %rdi
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %esi
callq 0x417330
jmp 0x416dae
movq -0x10(%rbp), %rax
movzbl 0xcb(%rax), %eax
movq $0x61e556, %rcx         # imm = 0x61E556
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x416d6b
movq -0x10(%rbp), %rdi
movq $0x61e73a, %rax         # imm = 0x61E73A
movzwl (%rax), %esi
callq 0x416dd0
jmp 0x416dac
movq -0x10(%rbp), %rax
movzbl 0xca(%rax), %eax
movq $0x61e556, %rcx         # imm = 0x61E556
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x416da8
movq -0x10(%rbp), %rax
movzbl 0xcb(%rax), %eax
movq $0x61e556, %rcx         # imm = 0x61E556
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x416da8
movq -0x10(%rbp), %rdi
callq 0x417080
jmp 0x416daa
jmp 0x416daa
jmp 0x416dac
jmp 0x416dae
jmp 0x416db0
jmp 0x416db2
jmp 0x416dc3
movq $0x61e620, %rax         # imm = 0x61E620
movl $0x3, (%rax)
jmp 0x416dc5
jmp 0x416dc5
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)