// File: MPSLab-ASU[P]DiRAC/./src/network.cc
// Function: MultiCastController_InputNetwork::execute()
void MultiCastController_InputNetwork::execute()
{
  if(!isRowWise_controller) {
    assert(((*config==0) || (*forward==0)) && "Column-wise controller cannot "
      "operate on data in both config and forward mode simultanously!");
  }

  // Do the follownig for the controller of an input/InOut network
  // if configuration of the controller is needed
  if(*config)
  {
    bus_forward_colWiseControllers = 0;
    counter_tag_match = 0;
    if((isRowWise_controller) && (*forward == 0) && (*rowTagIn == rowId) ||
       (!isRowWise_controller) && (*forward == 0) && (*colTagIn == colId))
    {
      // self-configure the controller
      if(counter_config == 0)
        configVal = *dataIn;
      else if(counter_config == 1)
        start_offset = *dataIn;
      else if (counter_config == 2)
        cnt_keepVal = *dataIn;
      else if (counter_config == 3)
        cnt_skipVal = *dataIn;
      counter_config++;
      bus_config_colWiseControllers = 0;

      // we don't need the following code in synthesized logic implementation
      // since counter_config should be of 2 bits
      if(counter_config == 4) counter_config = 0;
    }
    else if((isRowWise_controller) && (*forward) && (*rowTagIn == rowId))
    // forward the configuration to column-wise controllers
    {
      dataOut = *dataIn;
      colTagOut = *colTagIn;
      bus_config_colWiseControllers = 1;
    }
    else
      bus_config_colWiseControllers = 0;
  }
  // need to forward the data?
  else if((*config == 0) && (*forward == 1))
  {
    uint8_t inputTag = (isRowWise_controller) ? (*rowTagIn) : (*colTagIn);
    bus_config_colWiseControllers = 0;
    // After "offset" cycles, raise config value till "keepVal" Cycles
    // then, config value is 0 (i.e. no match) for "skipVal" cycles.
    // This repeats afterward till reconfiguration of controller
    // i.e., raise values for "keepVal" cycles, and skip for "skipVal" cycles.
    // When configVal is raised (during a total of "keepVal" cycles),
    // the configVal is compared with incoming tag of controller
    // If tag matches, data is forwarded further.
    if((counter_tag_match >= start_offset) &&
       (counter_tag_match < start_offset + cnt_keepVal) &&
       (configVal == inputTag))
    {
      dataOut = *dataIn;
      colTagOut = (isRowWise_controller) ? (*colTagIn) : 0;
      bus_forward_colWiseControllers = 1;
    }
    else
    {
      bus_forward_colWiseControllers = 0;
    }
    counter_tag_match++;
    if(counter_tag_match == start_offset + cnt_keepVal + cnt_skipVal)
      counter_tag_match = start_offset;
  }
  else
  {
    bus_config_colWiseControllers = 0;
    bus_forward_colWiseControllers = 0;
    counter_config = 0;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
testb $0x1, 0x35(%rax)
jne 0x4198a9
movq -0x18(%rbp), %rax
movq (%rax), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x419876
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x19(%rbp)
jne 0x41987d
movb $0x1, %al
movb %al, -0x19(%rbp)
jmp 0x41987d
movb -0x19(%rbp), %al
testb $0x1, %al
jne 0x419886
jmp 0x419888
jmp 0x4198a7
leaq 0x18a620(%rip), %rdi    # 0x5a3eaf
leaq 0x18a69e(%rip), %rsi    # 0x5a3f34
movl $0x52, %edx
leaq 0x18a6a3(%rip), %rcx    # 0x5a3f45
callq 0x4e53d0
jmp 0x4198a9
movq -0x18(%rbp), %rax
movq (%rax), %rax
testb $0x1, (%rax)
je 0x419a24
movq -0x18(%rbp), %rax
movb $0x0, 0x1b(%rax)
movw $0x0, 0x3c(%rax)
testb $0x1, 0x35(%rax)
je 0x4198f4
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x4198f4
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rax
movzbl (%rax), %eax
movzwl 0x36(%rcx), %ecx
cmpl %ecx, %eax
je 0x419931
movq -0x18(%rbp), %rax
testb $0x1, 0x35(%rax)
jne 0x4199cd
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x4199cd
movq -0x18(%rbp), %rcx
movq 0x28(%rcx), %rax
movzbl (%rax), %eax
movzwl 0x38(%rcx), %ecx
cmpl %ecx, %eax
jne 0x4199cd
movq -0x18(%rbp), %rax
movzbl 0x3a(%rax), %eax
cmpl $0x0, %eax
jne 0x41994e
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movw (%rcx), %cx
movb %cl, 0x31(%rax)
jmp 0x4199a9
movq -0x18(%rbp), %rax
movzbl 0x3a(%rax), %eax
cmpl $0x1, %eax
jne 0x41996b
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movw (%rcx), %cx
movb %cl, 0x32(%rax)
jmp 0x4199a7
movq -0x18(%rbp), %rax
movzbl 0x3a(%rax), %eax
cmpl $0x2, %eax
jne 0x419988
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movw (%rcx), %cx
movb %cl, 0x33(%rax)
jmp 0x4199a5
movq -0x18(%rbp), %rax
movzbl 0x3a(%rax), %eax
cmpl $0x3, %eax
jne 0x4199a3
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movw (%rcx), %cx
movb %cl, 0x34(%rax)
jmp 0x4199a5
jmp 0x4199a7
jmp 0x4199a9
movq -0x18(%rbp), %rax
movb 0x3a(%rax), %cl
addb $0x1, %cl
movb %cl, 0x3a(%rax)
movb $0x0, 0x1a(%rax)
movzbl 0x3a(%rax), %eax
cmpl $0x4, %eax
jne 0x4199cb
movq -0x18(%rbp), %rax
movb $0x0, 0x3a(%rax)
jmp 0x419a1f
movq -0x18(%rbp), %rax
testb $0x1, 0x35(%rax)
je 0x419a15
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
testb $0x1, (%rax)
je 0x419a15
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rax
movzbl (%rax), %eax
movzwl 0x36(%rcx), %ecx
cmpl %ecx, %eax
jne 0x419a15
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movw (%rcx), %cx
movw %cx, 0x18(%rax)
movq 0x28(%rax), %rcx
movb (%rcx), %cl
movb %cl, 0x30(%rax)
movb $0x1, 0x1a(%rax)
jmp 0x419a1d
movq -0x18(%rbp), %rax
movb $0x0, 0x1a(%rax)
jmp 0x419a1f
jmp 0x419b45
movq -0x18(%rbp), %rax
movq (%rax), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x419b33
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x419b33
movq -0x18(%rbp), %rax
testb $0x1, 0x35(%rax)
je 0x419a6c
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movb (%rax), %al
movb %al, -0x1a(%rbp)
jmp 0x419a79
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movb (%rax), %al
movb %al, -0x1a(%rbp)
movq -0x18(%rbp), %rcx
movb -0x1a(%rbp), %al
movb %al, -0x9(%rbp)
movb $0x0, 0x1a(%rcx)
movzwl 0x3c(%rcx), %eax
movzbl 0x32(%rcx), %ecx
cmpl %ecx, %eax
jl 0x419af5
movq -0x18(%rbp), %rdx
movzwl 0x3c(%rdx), %eax
movzbl 0x32(%rdx), %ecx
movzbl 0x33(%rdx), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x419af5
movq -0x18(%rbp), %rax
movzbl 0x31(%rax), %eax
movzbl -0x9(%rbp), %ecx
cmpl %ecx, %eax
jne 0x419af5
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movw (%rcx), %cx
movw %cx, 0x18(%rax)
testb $0x1, 0x35(%rax)
je 0x419ade
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movzbl (%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0x419ae5
xorl %eax, %eax
movl %eax, -0x20(%rbp)
jmp 0x419ae5
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
movb %cl, 0x30(%rax)
movb $0x1, 0x1b(%rax)
jmp 0x419afd
movq -0x18(%rbp), %rax
movb $0x0, 0x1b(%rax)
movq -0x18(%rbp), %rdx
movw 0x3c(%rdx), %ax
addw $0x1, %ax
movw %ax, 0x3c(%rdx)
movzwl 0x3c(%rdx), %eax
movzbl 0x32(%rdx), %ecx
movzbl 0x33(%rdx), %esi
addl %esi, %ecx
movzbl 0x34(%rdx), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jne 0x419b31
movq -0x18(%rbp), %rax
movzbl 0x32(%rax), %ecx
movw %cx, 0x3c(%rax)
jmp 0x419b43
movq -0x18(%rbp), %rax
movb $0x0, 0x1a(%rax)
movb $0x0, 0x1b(%rax)
movb $0x0, 0x3a(%rax)
jmp 0x419b45
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)