// File: /workspace/github_cpp_makefile_star2_O3/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 0x4116b4
testb %al, %al
je 0x4116ee
movb $0x0, 0x1b(%rdi)
movw $0x0, 0x3c(%rdi)
movq 0x8(%rdi), %rdx
movq 0x20(%rdi), %rax
movzbl (%rax), %eax
movzwl 0x36(%rdi), %ecx
cmpb $0x0, (%rdx)
je 0x41174d
cmpw %ax, %cx
jne 0x4117c6
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 0x4116ee
movq 0x8(%rdi), %rax
cmpb $0x0, (%rax)
jne 0x4117cb
movb $0x0, 0x1b(%rdi)
movw $0x0, 0x3c(%rdi)
movq 0x8(%rdi), %rax
cmpb $0x0, (%rax)
jne 0x4117c6
movq 0x28(%rdi), %rax
movzbl (%rax), %eax
cmpw %ax, 0x38(%rdi)
je 0x411752
jmp 0x4117c6
movq 0x8(%rdi), %rax
cmpb $0x1, (%rax)
jne 0x411742
movq 0x28(%rdi), %r8
movq %r8, %rax
testb %cl, %cl
je 0x411706
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 0x41177f
cmpl %esi, %edx
jbe 0x41177f
cmpb %r10b, 0x31(%rdi)
jne 0x41177f
movq 0x10(%rdi), %r9
movzwl (%r9), %r9d
movw %r9w, 0x18(%rdi)
testb %cl, %cl
je 0x411777
movb (%r8), %cl
jmp 0x411779
movw $0x0, 0x1a(%rdi)
movb $0x0, 0x3a(%rdi)
retq
cmpw %ax, %cx
jne 0x4117c6
movzbl 0x3a(%rdi), %eax
cmpq $0x3, %rax
ja 0x4117c1
leaq 0x1848f1(%rip), %rcx    # 0x596054
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movq 0x10(%rdi), %rcx
movb (%rcx), %cl
movb %cl, 0x31(%rdi)
jmp 0x4117c1
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 0x41174c
movw %ax, 0x3c(%rdi)
retq
movq 0x10(%rdi), %rcx
movb (%rcx), %cl
movb %cl, 0x33(%rdi)
jmp 0x4117c1
movq 0x10(%rdi), %rax
movb (%rax), %al
movb %al, 0x34(%rdi)
xorl %eax, %eax
movb %al, 0x1a(%rdi)
movb %al, 0x3a(%rdi)
retq
movq 0x10(%rdi), %rcx
movb (%rcx), %cl
movb %cl, 0x32(%rdi)
incb %al
movb %al, 0x3a(%rdi)
movb $0x0, 0x1a(%rdi)
retq
pushq %rax
leaq 0x18492d(%rip), %rdi    # 0x596100
leaq 0x1849ab(%rip), %rsi    # 0x596185
leaq 0x1849b5(%rip), %rcx    # 0x596196
movl $0x52, %edx
callq 0x4d8100
nop