// File: /workspace/github_cpp_makefile_star2_O3/dramninjasUMD[P]BOBSim/BOBWrapper.cpp
// Function: BOBSim::BOBWrapper::Update()
void BOBWrapper::Update()
{
	maxReadsPerCycle = max<uint64_t>(maxReadsPerCycle, readsPerCycle);
	maxWritesPerCycle = max<uint64_t>(maxWritesPerCycle, writesPerCycle);
	readsPerCycle = writesPerCycle = 0;

	bob->Update();

	//BOOK-KEEPING
	for(unsigned i=0; i<NUM_PORTS; i++)
	{
		//STATS
		if(inFlightResponse[i]==NULL)
		{
			responsePortEmptyCount[i]++;
		}

		if(inFlightRequest[i]==NULL)
		{
			requestPortEmptyCount[i]++;
		}

		//
		//Requests
		//
		if(inFlightRequestHeaderCounter[i]>0)
		{
			inFlightRequestHeaderCounter[i]--;
			//done
			if(inFlightRequestHeaderCounter[i]==0)
			{
				if(inFlightRequest[i]!=NULL)
				{
					if(DEBUG_PORTS)DEBUG("== Header done - Adding "<<*inFlightRequest[i]<<" to port "<<i);
					bob->ports[i].inputBuffer.push_back(inFlightRequest[i]);
				}
				else
				{
					ERROR("== Error - inFlightResponse null when not supposed to be");
					exit(0);
				}
			}
		}

		if(inFlightRequestCounter[i]>0)
		{
			inFlightRequestCounter[i]--;
			if(inFlightRequestCounter[i]==0)
			{
				inFlightRequest[i]=NULL;
			}
		}

		//
		//Responses
		//
		if(inFlightResponseHeaderCounter[i]>0)
		{
			//does nothing
			inFlightResponseHeaderCounter[i]--;
		}

		if(inFlightResponseCounter[i]>0)
		{
			inFlightResponseCounter[i]--;
			if(inFlightResponseCounter[i]==0)
			{
				if(inFlightResponse[i]->transactionType==RETURN_DATA)
				{
					if (readDoneCallback)
					{
						(*readDoneCallback)(i, inFlightResponse[i]->address);
					}

					UpdateLatencyStats(inFlightResponse[i]);

					returnsPerPort[i]++;
				}
				else if(inFlightResponse[i]->transactionType==LOGIC_RESPONSE)
				{
					if(logicDoneCallback)
					{
						(*logicDoneCallback)(inFlightResponse[i]->mappedChannel, (void*)inFlightResponse[i]->address);
					}

					UpdateLatencyStats(inFlightResponse[i]);

					totalLogicResponses++;
				}
				else
				{
					ERROR("== ERROR - unknown packet type coming down : "<<*inFlightResponse[i]);
					exit(0);
				}

				bob->ports[i].outputBuffer.erase(bob->ports[i].outputBuffer.begin());
				delete inFlightResponse[i];
				inFlightResponse[i]=NULL;
			}
		}
	}

	//NEW STUFF
	for(unsigned i=0; i<NUM_PORTS; i++)
	{
		//look for new stuff to return from bob controller
		if(bob->ports[i].outputBuffer.size()>0 &&
		        inFlightResponseCounter[i]==0)
		{
			inFlightResponse[i] = bob->ports[i].outputBuffer[0];
			inFlightResponseHeaderCounter[i] = 1;

			if(inFlightResponse[i]->transactionType==RETURN_DATA)
			{
				inFlightResponseCounter[i] = TRANSACTION_SIZE / PORT_WIDTH;
			}
			else if(inFlightResponse[i]->transactionType==LOGIC_RESPONSE)
			{
				inFlightResponseCounter[i] = 1;
			}
			else
			{
				ERROR("== Error - wrong type of transaction out of");
				ERROR("== "<<*inFlightResponse[i]);
				exit(0);
			}
		}
	}

	if(currentClockCycle%EPOCH_LENGTH==0 && currentClockCycle>0)
	{
		PrintStats(false);
	}
	currentClockCycle++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movdqu 0xa8(%rdi), %xmm0
movdqu 0xb8(%rdi), %xmm1
movdqa 0x8f50(%rip), %xmm2     # 0x13040
movdqa %xmm1, %xmm3
pxor %xmm2, %xmm3
pxor %xmm0, %xmm2
movdqa %xmm2, %xmm4
pcmpgtd %xmm3, %xmm4
pshufd $0xa0, %xmm4, %xmm5     # xmm5 = xmm4[0,0,2,2]
pcmpeqd %xmm3, %xmm2
pshufd $0xf5, %xmm2, %xmm2     # xmm2 = xmm2[1,1,3,3]
pand %xmm5, %xmm2
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
por %xmm2, %xmm3
pand %xmm3, %xmm0
pandn %xmm1, %xmm3
por %xmm0, %xmm3
movdqu %xmm3, 0xa8(%rdi)
pxor %xmm0, %xmm0
movdqu %xmm0, 0xb8(%rdi)
movq 0x10(%rdi), %rdi
movq (%rdi), %rax
callq *(%rax)
leaq 0xf081(%rip), %r15      # 0x191d0
cmpl $0x0, (%r15)
je 0xa38d
movl $0x10, %r12d
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x60(%rbx), %rax
cmpq $0x0, (%rax,%r14,8)
jne 0xa17b
movq 0xe0(%rbx), %rax
incl (%rax,%r14,4)
movq 0x18(%rbx), %rdx
movq (%rdx,%r14,8), %rax
testq %rax, %rax
jne 0xa193
movq 0xc8(%rbx), %rcx
incl (%rcx,%r14,4)
movq 0x48(%rbx), %rcx
movl (%rcx,%r14,4), %esi
testl %esi, %esi
je 0xa1da
decl %esi
movl %esi, (%rcx,%r14,4)
jne 0xa1da
testq %rax, %rax
je 0xa3dd
movq 0x10(%rbx), %rcx
movq 0x10(%rcx), %rdi
movq 0x18(%rdi,%r13,8), %rsi
cmpq 0x20(%rdi,%r13,8), %rsi
je 0xa1cf
movq %rax, (%rsi)
addq $0x8, 0x18(%rdi,%r13,8)
jmp 0xa1da
addq %r13, %rdx
addq %r12, %rdi
callq 0x7b4c
movq 0x30(%rbx), %rax
movl (%rax,%r14,4), %ecx
testl %ecx, %ecx
je 0xa1fa
decl %ecx
movl %ecx, (%rax,%r14,4)
jne 0xa1fa
movq 0x18(%rbx), %rax
movq $0x0, (%rax,%r14,8)
movq 0x90(%rbx), %rax
movl (%rax,%r14,4), %ecx
testl %ecx, %ecx
je 0xa20f
decl %ecx
movl %ecx, (%rax,%r14,4)
movq 0x78(%rbx), %rax
movl (%rax,%r14,4), %ecx
testl %ecx, %ecx
je 0xa2f9
decl %ecx
movl %ecx, (%rax,%r14,4)
jne 0xa2f9
movq 0x60(%rbx), %rax
movq (%rax,%r14,8), %rsi
movl (%rsi), %eax
cmpl $0x4, %eax
je 0xa279
cmpl $0x2, %eax
jne 0xa43e
movq 0x158(%rbx), %rdi
testq %rdi, %rdi
je 0xa264
movq 0x8(%rsi), %rdx
movq (%rdi), %rax
movl %r14d, %esi
callq *0x10(%rax)
movq 0x60(%rbx), %rax
movq (%rax,%r14,8), %rsi
movq %rbx, %rdi
callq 0xa572
movq 0x140(%rbx), %rax
incl (%rax,%r14,4)
jmp 0xa2aa
movq 0x168(%rbx), %rdi
testq %rdi, %rdi
je 0xa29c
movl 0x10(%rsi), %eax
movq 0x8(%rsi), %rdx
movq (%rdi), %rcx
movl %eax, %esi
callq *0x10(%rcx)
movq 0x60(%rbx), %rax
movq (%rax,%r14,8), %rsi
movq %rbx, %rdi
callq 0xa572
incl 0x2a8(%rbx)
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rbp
movq 0x28(%rbp,%r13,8), %rdi
movq 0x30(%rbp,%r13,8), %rdx
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0xa2d2
subq %rsi, %rdx
callq 0x32f0
movq 0x30(%rbp,%r13,8), %rdx
addq $-0x8, %rdx
movq %rdx, 0x30(%rbp,%r13,8)
movq 0x60(%rbx), %rax
movq (%rax,%r14,8), %rdi
movl $0x90, %esi
callq 0x31f0
movq 0x60(%rbx), %rax
movq $0x0, (%rax,%r14,8)
incq %r14
movl (%r15), %eax
addq $0x8, %r13
addq $0x40, %r12
cmpq %rax, %r14
jb 0xa165
testl %eax, %eax
je 0xa38d
movl $0xc, %eax
xorl %r14d, %r14d
movq 0x10(%rbx), %rcx
movq 0x10(%rcx), %rdx
movq -0x8(%rdx,%rax,4), %rcx
cmpq %rcx, (%rdx,%rax,4)
je 0xa37e
movq 0x78(%rbx), %rdx
cmpl $0x0, (%rdx,%r14,4)
jne 0xa37e
movq (%rcx), %rcx
movq 0x60(%rbx), %rdx
movq %rcx, (%rdx,%r14,8)
movq 0x90(%rbx), %rcx
movl $0x1, (%rcx,%r14,4)
movq 0x60(%rbx), %rcx
movq (%rcx,%r14,8), %rcx
movl (%rcx), %edx
movl $0x4, %ecx
cmpl $0x2, %edx
je 0xa376
cmpl $0x4, %edx
jne 0xa497
movl $0x1, %ecx
movq 0x78(%rbx), %rdx
movl %ecx, (%rdx,%r14,4)
incq %r14
movl (%r15), %ecx
addq $0x10, %rax
cmpq %rcx, %r14
jb 0xa31c
movq 0x8(%rbx), %rcx
movabsq $0x431bde82d7b634db, %rdx # imm = 0x431BDE82D7B634DB
movq %rcx, %rax
mulq %rdx
testq %rcx, %rcx
je 0xa3c7
shrq $0x12, %rdx
imulq $0xf4240, %rdx, %rax    # imm = 0xF4240
movq %rcx, %rdx
subq %rax, %rdx
jne 0xa3c7
movq %rbx, %rdi
xorl %esi, %esi
callq 0xa978
movq 0x8(%rbx), %rcx
incq %rcx
movq %rcx, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xec0c(%rip), %rdi      # 0x18ff0
leaq 0x8ddd(%rip), %rsi      # 0x131c8
callq 0x31c0
leaq 0x9846(%rip), %rsi      # 0x13c3d
movq %rax, %rdi
callq 0x31c0
leaq 0x8d6b(%rip), %rsi      # 0x13171
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
movl $0x185, %esi            # imm = 0x185
callq 0x3330
leaq 0x8db7(%rip), %rsi      # 0x131d9
movq %rax, %rdi
callq 0x31c0
leaq 0x986e(%rip), %rsi      # 0x13c9f
movq %rax, %rdi
callq 0x31c0
jmp 0xa563
movq 0xebab(%rip), %rdi      # 0x18ff0
leaq 0x8d7c(%rip), %rsi      # 0x131c8
callq 0x31c0
leaq 0x97e5(%rip), %rsi      # 0x13c3d
movq %rax, %rdi
callq 0x31c0
leaq 0x8d0a(%rip), %rsi      # 0x13171
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
movl $0x1ba, %esi            # imm = 0x1BA
callq 0x3330
leaq 0x8d56(%rip), %rsi      # 0x131d9
movq %rax, %rdi
callq 0x31c0
leaq 0x9846(%rip), %rsi      # 0x13cd8
jmp 0xa54b
movq 0xeb52(%rip), %rdi      # 0x18ff0
leaq 0x8d23(%rip), %r15      # 0x131c8
movq %r15, %rsi
callq 0x31c0
leaq 0x9789(%rip), %r12      # 0x13c3d
movq %rax, %rdi
movq %r12, %rsi
callq 0x31c0
leaq 0x8cab(%rip), %r13      # 0x13171
movq %rax, %rdi
movq %r13, %rsi
callq 0x31c0
movq %rax, %rdi
movl $0x1d9, %esi            # imm = 0x1D9
callq 0x3330
leaq 0x8cf4(%rip), %rbp      # 0x131d9
movq %rax, %rdi
movq %rbp, %rsi
callq 0x31c0
leaq 0x980f(%rip), %rsi      # 0x13d06
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x30d0
movq 0xeae2(%rip), %rdi      # 0x18ff0
movq %r15, %rsi
callq 0x31c0
movq %rax, %rdi
movq %r12, %rsi
callq 0x31c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x31c0
movq %rax, %rdi
movl $0x1da, %esi            # imm = 0x1DA
callq 0x3330
movq %rax, %rdi
movq %rbp, %rsi
callq 0x31c0
leaq 0x8ffd(%rip), %rsi      # 0x13548
movq %rax, %rdi
callq 0x31c0
movq 0x60(%rbx), %rcx
movq (%rcx,%r14,8), %rsi
movq %rax, %rdi
callq 0x12307
movq %rax, %rdi
callq 0x30d0
xorl %edi, %edi
callq 0x3220