// File: /workspace/github_cpp_makefile_star2_O2/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:
movb 0x35(%rdi), %cl
movq (%rdi), %rax
movb (%rax), %al
testb %cl, %cl
je 0x40dd55
testb $0x1, %al
je 0x40ddb9
movb $0x0, 0x1b(%rdi)
andw $0x0, 0x3c(%rdi)
movq 0x8(%rdi), %rdx
movq 0x20(%rdi), %rax
movzbl (%rax), %eax
movzwl 0x36(%rdi), %ecx
cmpb $0x0, (%rdx)
je 0x40de17
cmpw %ax, %cx
jne 0x40de20
movq 0x10(%rdi), %rax
movq 0x28(%rdi), %rcx
movzwl (%rax), %eax
movw %ax, 0x18(%rdi)
movb (%rcx), %al
movb %al, 0x30(%rdi)
movb $0x1, 0x1a(%rdi)
retq
testb %al, %al
je 0x40ddb9
movq 0x8(%rdi), %rax
cmpb $0x0, (%rax)
jne 0x40de76
movb $0x0, 0x1b(%rdi)
andw $0x0, 0x3c(%rdi)
movq 0x8(%rdi), %rax
cmpb $0x0, (%rax)
jne 0x40de20
movq 0x28(%rdi), %rax
movzbl (%rax), %eax
cmpw %ax, 0x38(%rdi)
jne 0x40de20
movzbl 0x3a(%rdi), %eax
cmpq $0x3, %rax
ja 0x40de68
leaq 0x1842b2(%rip), %rcx    # 0x592054
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movq 0x10(%rdi), %rcx
movb (%rcx), %cl
movb %cl, 0x31(%rdi)
jmp 0x40de68
movq 0x8(%rdi), %rax
cmpb $0x1, (%rax)
jne 0x40de0d
movq 0x28(%rdi), %r8
movq %r8, %rax
testb %cl, %cl
je 0x40ddd1
movq 0x20(%rdi), %rax
movb (%rax), %r10b
movb $0x0, 0x1a(%rdi)
movzwl 0x3c(%rdi), %esi
movzbl 0x32(%rdi), %eax
movzbl 0x33(%rdi), %edx
addl %eax, %edx
xorl %r9d, %r9d
cmpl %eax, %esi
jb 0x40de2d
cmpl %esi, %edx
jbe 0x40de2d
cmpb %r10b, 0x31(%rdi)
jne 0x40de2d
movq 0x10(%rdi), %r9
movzwl (%r9), %r9d
movw %r9w, 0x18(%rdi)
testb %cl, %cl
je 0x40de25
movb (%r8), %cl
jmp 0x40de27
andw $0x0, 0x1a(%rdi)
movb $0x0, 0x3a(%rdi)
retq
cmpw %ax, %cx
je 0x40dd8d
movb $0x0, 0x1a(%rdi)
retq
xorl %ecx, %ecx
movb %cl, 0x30(%rdi)
movb $0x1, %r9b
movb %r9b, 0x1b(%rdi)
incl %esi
movw %si, 0x3c(%rdi)
movzwl %si, %ecx
movzbl 0x34(%rdi), %esi
addl %esi, %edx
cmpl %ecx, %edx
jne 0x40de75
movw %ax, 0x3c(%rdi)
retq
movq 0x10(%rdi), %rcx
movb (%rcx), %cl
movb %cl, 0x33(%rdi)
jmp 0x40de68
movq 0x10(%rdi), %rcx
movb (%rcx), %cl
movb %cl, 0x34(%rdi)
jmp 0x40de68
movq 0x10(%rdi), %rcx
movb (%rcx), %cl
movb %cl, 0x32(%rdi)
incl %eax
movb %al, 0x3a(%rdi)
movb $0x0, 0x1a(%rdi)
cmpb $0x4, %al
je 0x40de12
retq
pushq %rax
leaq 0x184282(%rip), %rdi    # 0x592100
leaq 0x184300(%rip), %rsi    # 0x592185
leaq 0x18430a(%rip), %rcx    # 0x592196
pushq $0x52
popq %rdx
callq 0x4d36d0