// File: MPSLab-ASU[P]DiRAC/./src/controller.cc
// Function: controller::setup_PEs()
void controller::setup_PEs() {
	PEs = new PE*[nRows_PE_Array];
  bus_trigger_PEs_exec            = new bool*[nRows_PE_Array];
  bus_trigger_PEs_zero_initialize = new bool*[nRows_PE_Array];
  bus_trigger_PEs_write_back      = new bool*[nRows_PE_Array];
  bus_trigger_PEs_spatial_reduce  = new bool*[nRows_PE_Array];
  bus_trigger_PEs_update_buf_num_Op1 = new bool*[nRows_PE_Array];
  bus_trigger_PEs_update_buf_num_Op2 = new bool*[nRows_PE_Array];
  bus_trigger_PEs_update_buf_num_Op3 = new bool*[nRows_PE_Array];

	for(auto i=0; i < nRows_PE_Array; i++) {
		PEs[i] = new PE[nCols_PE_Array];
    bus_trigger_PEs_exec[i]             = new bool[nCols_PE_Array]();
    bus_trigger_PEs_zero_initialize[i]  = new bool[nCols_PE_Array]();
    bus_trigger_PEs_write_back[i]       = new bool[nCols_PE_Array]();
    bus_trigger_PEs_spatial_reduce[i]   = new bool[nCols_PE_Array]();
    bus_trigger_PEs_update_buf_num_Op1[i] = new bool[nCols_PE_Array]();
    bus_trigger_PEs_update_buf_num_Op2[i] = new bool[nCols_PE_Array]();
    bus_trigger_PEs_update_buf_num_Op3[i] = new bool[nCols_PE_Array]();

		for(auto j=0; j < nCols_PE_Array; j++) {
      PEs[i][j].setup(i,j);
			PEs[i][j].initialize();
      PEs[i][j].setTriggerFromController( &bus_trigger_PEs_exec[i][j],
        &bus_trigger_PEs_zero_initialize[i][j],
        &bus_trigger_PEs_write_back[i][j],
        &bus_trigger_PEs_spatial_reduce[i][j],
        &bus_trigger_PEs_update_buf_num_Op1[i][j],
        &bus_trigger_PEs_update_buf_num_Op2[i][j],
        &bus_trigger_PEs_update_buf_num_Op3[i][j]);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x61e5ac, %rax         # imm = 0x61E5AC
movzwl (%rax), %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x425dd0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq $0x61e5ac, %rax         # imm = 0x61E5AC
movzwl (%rax), %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x425dd0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq $0x61e5ac, %rax         # imm = 0x61E5AC
movzwl (%rax), %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x425dd0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq $0x61e5ac, %rax         # imm = 0x61E5AC
movzwl (%rax), %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x425dd0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq $0x61e5ac, %rax         # imm = 0x61E5AC
movzwl (%rax), %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x425dd0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq $0x61e5ac, %rax         # imm = 0x61E5AC
movzwl (%rax), %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x425dd0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x30(%rax)
movq $0x61e5ac, %rax         # imm = 0x61E5AC
movzwl (%rax), %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x425dd0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x38(%rax)
movq $0x61e5ac, %rax         # imm = 0x61E5AC
movzwl (%rax), %eax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x425dd0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x40(%rax)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq $0x61e5ac, %rcx         # imm = 0x61E5AC
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x4156a9
movq $0x61e5ae, %rax         # imm = 0x61E5AE
movzwl (%rax), %eax
movq %rax, -0x40(%rbp)
movl $0x148, %ecx            # imm = 0x148
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x48(%rbp)
callq 0x425dd0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, -0x38(%rbp)
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x30(%rbp)
cmpq $0x0, %rax
je 0x41531e
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
imulq $0x148, %rcx, %rdx      # imm = 0x148
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x58(%rbp)
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq %rdi, -0x60(%rbp)
callq 0x422680
jmp 0x415307
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %rax
addq $0x148, %rax            # imm = 0x148
cmpq %rcx, %rax
movq %rax, -0x50(%rbp)
jne 0x4152f8
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rdx
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq $0x61e5ae, %rax         # imm = 0x61E5AE
movzwl (%rax), %eax
movl %eax, %edi
movq %rdi, -0xd0(%rbp)
callq 0x425dd0
movq -0xd0(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0xc8(%rbp)
xorl %esi, %esi
callq 0x401080
movq -0xc8(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq $0x61e5ae, %rax         # imm = 0x61E5AE
movzwl (%rax), %eax
movl %eax, %edi
movq %rdi, -0xc0(%rbp)
callq 0x425dd0
movq -0xc0(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0xb8(%rbp)
xorl %esi, %esi
callq 0x401080
movq -0xb8(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq $0x61e5ae, %rax         # imm = 0x61E5AE
movzwl (%rax), %eax
movl %eax, %edi
movq %rdi, -0xb0(%rbp)
callq 0x425dd0
movq -0xb0(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0xa8(%rbp)
xorl %esi, %esi
callq 0x401080
movq -0xa8(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq $0x61e5ae, %rax         # imm = 0x61E5AE
movzwl (%rax), %eax
movl %eax, %edi
movq %rdi, -0xa0(%rbp)
callq 0x425dd0
movq -0xa0(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x98(%rbp)
xorl %esi, %esi
callq 0x401080
movq -0x98(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq $0x61e5ae, %rax         # imm = 0x61E5AE
movzwl (%rax), %eax
movl %eax, %edi
movq %rdi, -0x90(%rbp)
callq 0x425dd0
movq -0x90(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x88(%rbp)
xorl %esi, %esi
callq 0x401080
movq -0x88(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq $0x61e5ae, %rax         # imm = 0x61E5AE
movzwl (%rax), %eax
movl %eax, %edi
movq %rdi, -0x80(%rbp)
callq 0x425dd0
movq -0x80(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x78(%rbp)
xorl %esi, %esi
callq 0x401080
movq -0x78(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq $0x61e5ae, %rax         # imm = 0x61E5AE
movzwl (%rax), %eax
movl %eax, %edi
movq %rdi, -0x70(%rbp)
callq 0x425dd0
movq -0x70(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x68(%rbp)
xorl %esi, %esi
callq 0x401080
movq -0x28(%rbp), %rax
movq -0x68(%rbp), %rdx
movq 0x40(%rax), %rax
movslq -0xc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq $0x61e5ae, %rcx         # imm = 0x61E5AE
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x415699
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x20(%rbp), %rax
imulq $0x148, %rax, %rax      # imm = 0x148
addq %rax, %rdi
movl -0xc(%rbp), %eax
movw %ax, %cx
movl -0x20(%rbp), %eax
movzwl %cx, %esi
movzwl %ax, %edx
callq 0x423020
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x20(%rbp), %rax
imulq $0x148, %rax, %rax      # imm = 0x148
addq %rax, %rdi
callq 0x423060
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
movslq -0xc(%rbp), %rdx
movq (%rcx,%rdx,8), %rdi
movslq -0x20(%rbp), %rcx
imulq $0x148, %rcx, %rcx      # imm = 0x148
addq %rcx, %rdi
movq 0x10(%rax), %rcx
movslq -0xc(%rbp), %rdx
movq (%rcx,%rdx,8), %rsi
movslq -0x20(%rbp), %rcx
addq %rcx, %rsi
movq 0x18(%rax), %rcx
movslq -0xc(%rbp), %rdx
movq (%rcx,%rdx,8), %rdx
movslq -0x20(%rbp), %rcx
addq %rcx, %rdx
movq 0x20(%rax), %rcx
movslq -0xc(%rbp), %r8
movq (%rcx,%r8,8), %rcx
movslq -0x20(%rbp), %r8
addq %r8, %rcx
movq 0x28(%rax), %r8
movslq -0xc(%rbp), %r9
movq (%r8,%r9,8), %r8
movslq -0x20(%rbp), %r9
addq %r9, %r8
movq 0x30(%rax), %r9
movslq -0xc(%rbp), %r10
movq (%r9,%r10,8), %r9
movslq -0x20(%rbp), %r10
addq %r10, %r9
movq 0x38(%rax), %r10
movslq -0xc(%rbp), %r11
movq (%r10,%r11,8), %r10
movslq -0x20(%rbp), %r11
addq %r11, %r10
movq 0x40(%rax), %rax
movslq -0xc(%rbp), %r11
movq (%rax,%r11,8), %rax
movslq -0x20(%rbp), %r11
addq %r11, %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x423160
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x415512
movq -0x30(%rbp), %rcx
movq %rax, %rsi
movq -0x60(%rbp), %rax
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpq %rax, %rcx
movq %rax, -0xd8(%rbp)
je 0x41568a
movq -0xd8(%rbp), %rdi
addq $-0x148, %rdi           # imm = 0xFEB8
movq %rdi, -0xe0(%rbp)
callq 0x422d10
movq -0x30(%rbp), %rcx
movq -0xe0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0xd8(%rbp)
jne 0x415659
movq -0x48(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x4248b0
jmp 0x4156b2
jmp 0x41569b
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x41526e
addq $0xf0, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x4d0770
nopl (%rax,%rax)