// File: MPSLab-ASU[P]DiRAC/./src/network.cc
// Function: MultiCastNetwork_Output::setupNetwork(bool**, unsigned short**, PE**, unsigned char)
void MultiCastNetwork_Output::setupNetwork(bool **outWriteBack,
  data_type **outData, PE** PEArray, uint8_t networkId)
{
  // setup row-wise multicast controllers
  // connect them to the accelerator controller
  for(uint16_t i=0; i < nRows_PE_Array; i++) {
    rowWiseMC[i].setupController(1);
    rowWiseMC[i].setupBus();
    outWriteBack[i] = rowWiseMC[i].getPtrWriteBack();
    outData[i] = rowWiseMC[i].getPtrOutData();
  }

  // set up column-wise multicast controllers
  for(uint16_t i=0; i < nRows_PE_Array; i++) {
    for(uint16_t j=0; j < nCols_PE_Array; j++) {
      // connect each column-wise multicast controller to its
      // corresponding row-wise multicast controller
      rowWiseMC[i].setWriteBack(j, colWiseMC[i][j].getPtrWriteBack());
      rowWiseMC[i].setInData(j, colWiseMC[i][j].getPtrOutData());
      colWiseMC[i][j].setupController(0);
      colWiseMC[i][j].setupBus();

      // connect each column-wise multicast controller to a PE
      colWiseMC[i][j].setWriteBack(0, PEArray[i][j].getPtrWriteBack(networkId));
      colWiseMC[i][j].setInData(0, PEArray[i][j].getPtrOutData(networkId));
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movb %al, -0x21(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movw $0x0, -0x24(%rbp)
movzwl -0x24(%rbp), %eax
movq $0x61e5ac, %rcx         # imm = 0x61E5AC
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x41a022
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movzwl -0x24(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movl $0x1, %esi
callq 0x41a200
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movzwl -0x24(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x41a220
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movzwl -0x24(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x41a2c0
movq %rax, %rsi
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movzwl -0x24(%rbp), %edx
movq %rsi, (%rcx,%rdx,8)
movq (%rax), %rdi
movzwl -0x24(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x41a2e0
movq %rax, %rdx
movq -0x18(%rbp), %rax
movzwl -0x24(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movw -0x24(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x24(%rbp)
jmp 0x419f7c
movw $0x0, -0x26(%rbp)
movzwl -0x26(%rbp), %eax
movq $0x61e5ac, %rcx         # imm = 0x61E5AC
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x41a1fa
movw $0x0, -0x28(%rbp)
movzwl -0x28(%rbp), %eax
movq $0x61e5ae, %rcx         # imm = 0x61E5AE
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x41a1e7
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movzwl -0x26(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq %rcx, -0x60(%rbp)
movw -0x28(%rbp), %cx
movw %cx, -0x52(%rbp)
movq 0x8(%rax), %rax
movzwl -0x26(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movzwl -0x28(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x41a2c0
movq -0x60(%rbp), %rdi
movq %rax, %rdx
movw -0x52(%rbp), %ax
movzwl %ax, %esi
callq 0x41a300
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movzwl -0x26(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq %rcx, -0x50(%rbp)
movw -0x28(%rbp), %cx
movw %cx, -0x42(%rbp)
movq 0x8(%rax), %rax
movzwl -0x26(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movzwl -0x28(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x41a2e0
movq -0x50(%rbp), %rdi
movq %rax, %rdx
movw -0x42(%rbp), %ax
movzwl %ax, %esi
callq 0x41a330
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movzwl -0x26(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movzwl -0x28(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
xorl %esi, %esi
callq 0x41a200
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movzwl -0x26(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movzwl -0x28(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x41a220
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movzwl -0x26(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movzwl -0x28(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movzwl -0x26(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movzwl -0x28(%rbp), %eax
imulq $0x148, %rax, %rax      # imm = 0x148
addq %rax, %rdi
movzbl -0x21(%rbp), %esi
callq 0x423c50
movq -0x40(%rbp), %rdi
movq %rax, %rdx
xorl %esi, %esi
callq 0x41a300
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movzwl -0x26(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movzwl -0x28(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movzwl -0x26(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movzwl -0x28(%rbp), %eax
imulq $0x148, %rax, %rax      # imm = 0x148
addq %rax, %rdi
movzbl -0x21(%rbp), %esi
callq 0x423c20
movq -0x38(%rbp), %rdi
movq %rax, %rdx
xorl %esi, %esi
callq 0x41a330
movw -0x28(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x28(%rbp)
jmp 0x41a044
jmp 0x41a1e9
movw -0x26(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x26(%rbp)
jmp 0x41a028
addq $0x60, %rsp
popq %rbp
retq