// File: /workspace/github_cpp_makefile_star2_O2/dramninjasUMD[P]BOBSim/BOBWrapper.cpp
// Function: BOBSim::BOBWrapper::UpdateLatencyStats(BOBSim::Transaction*)
void BOBWrapper::UpdateLatencyStats(Transaction *returnedRead)
{
	if(returnedRead->transactionType==LOGIC_RESPONSE)
	{
		DEBUG("  == Got Logic Response : "<<*returnedRead);
		DEBUG("  == Logic All Done!");
		DEBUG("  == Took : "<<CPU_CLK_PERIOD*(currentClockCycle - returnedRead->fullStartTime)<<"ns");
		return;
	}
	else if(returnedRead->transactionType==RETURN_DATA)
	{
		returnedRead->fullTimeTotal = currentClockCycle - returnedRead->fullStartTime;
		returnedRead->cyclesRspPort = currentClockCycle - returnedRead->cyclesRspPort;

		unsigned chanID = returnedRead->mappedChannel;

		//add latencies to lists
		perChanFullLatencies[chanID].push_back(returnedRead->fullTimeTotal);
		perChanReqPort[chanID].push_back(returnedRead->cyclesReqPort);
		perChanRspPort[chanID].push_back(returnedRead->cyclesRspPort);
		perChanReqLink[chanID].push_back(returnedRead->cyclesReqLink);
		perChanRspLink[chanID].push_back(returnedRead->cyclesRspLink);
		perChanAccess[chanID].push_back(returnedRead->dramTimeTotal);
		perChanRRQ[chanID].push_back(returnedRead->cyclesInReadReturnQ);
		perChanWorkQTimes[chanID].push_back(returnedRead->cyclesInWorkQueue);
		/*
			DEBUGN("== Read Returned");
			DEBUGN(" full: "<< returnedRead->fullTimeTotal * CPU_CLK_PERIOD<<"ns");
			DEBUGN(" dram: "<< returnedRead->dramTimeTotal * CPU_CLK_PERIOD<<"ns");
			DEBUG(" chan: "<< returnedRead->channelTimeTotal * CPU_CLK_PERIOD<<"ns");
		*/
		fullLatencies.push_back(returnedRead->fullTimeTotal);
		fullSum+=returnedRead->fullTimeTotal;

		dramLatencies.push_back(returnedRead->dramTimeTotal);
		dramSum+=returnedRead->dramTimeTotal;

		chanLatencies.push_back(returnedRead->channelTimeTotal);
		chanSum+=returnedRead->channelTimeTotal;

		//latencies[((returnedRead->fullTimeTotal/10)*10)*CPU_CLK_PERIOD]++;

		returnedReads++;
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl (%rsi), %eax
cmpl $0x2, %eax
je 0x7f4b
cmpl $0x4, %eax
jne 0x80b7
leaq 0xe2f3(%rip), %r15      # 0x161b4
cmpl $0x0, (%r15)
je 0x80b7
movq 0xe0f6(%rip), %rdi      # 0x15fc8
leaq 0x7dc9(%rip), %rsi      # 0xfca2
callq 0x2180
movq %rax, %rdi
movq %rbx, %rsi
callq 0xe728
movq %rax, %rdi
callq 0x20b0
cmpl $0x0, (%r15)
je 0x80b7
movq 0xe0c6(%rip), %rdi      # 0x15fc8
leaq 0x7db4(%rip), %rsi      # 0xfcbd
callq 0x2180
movq %rax, %rdi
callq 0x20b0
cmpl $0x0, (%r15)
je 0x80b7
movq 0xe0a1(%rip), %rdi      # 0x15fc8
leaq 0x7da4(%rip), %rsi      # 0xfcd2
callq 0x2180
movq 0x8(%r14), %rcx
subq 0x60(%rbx), %rcx
js 0x80c3
cvtsi2ss %rcx, %xmm0
jmp 0x80d8
movq 0x8(%r14), %rax
movq %rax, %rcx
subq 0x60(%rbx), %rcx
movq %rcx, 0x68(%rbx)
subq 0x40(%rbx), %rax
movq %rax, 0x40(%rbx)
movl 0x10(%rbx), %eax
imulq $0x18, %rax, %r15
movq 0x170(%r14), %rdi
addq %r15, %rdi
leaq 0x4(%rsp), %r12
movl %ecx, (%r12)
movq %r12, %rsi
callq 0x936a
movq 0x188(%r14), %rdi
addq %r15, %rdi
movl 0x38(%rbx), %eax
movl %eax, (%r12)
leaq 0x4(%rsp), %r12
movq %r12, %rsi
callq 0x936a
movq 0x1a0(%r14), %rdi
addq %r15, %rdi
movl 0x40(%rbx), %eax
movl %eax, (%r12)
leaq 0x4(%rsp), %r12
movq %r12, %rsi
callq 0x936a
movq 0x1b8(%r14), %rdi
addq %r15, %rdi
movl 0x48(%rbx), %eax
movl %eax, (%r12)
leaq 0x4(%rsp), %r12
movq %r12, %rsi
callq 0x936a
movq 0x1d0(%r14), %rdi
addq %r15, %rdi
movl 0x50(%rbx), %eax
movl %eax, (%r12)
leaq 0x4(%rsp), %r12
movq %r12, %rsi
callq 0x936a
movq 0x1e8(%r14), %rdi
addq %r15, %rdi
movl 0x78(%rbx), %eax
movl %eax, (%r12)
leaq 0x4(%rsp), %r12
movq %r12, %rsi
callq 0x936a
movq 0x200(%r14), %rdi
addq %r15, %rdi
leaq 0x58(%rbx), %rsi
callq 0x90e6
addq 0x218(%r14), %r15
leaq 0x5c(%rbx), %rsi
movq %r15, %rdi
callq 0x90e6
leaq 0x230(%r14), %rdi
movl 0x68(%rbx), %eax
movl %eax, (%r12)
leaq 0x4(%rsp), %r15
movq %r15, %rsi
callq 0x936a
movl 0x68(%rbx), %eax
addl %eax, 0x248(%r14)
leaq 0x250(%r14), %rdi
movl 0x78(%rbx), %eax
movl %eax, (%r15)
leaq 0x4(%rsp), %r15
movq %r15, %rsi
callq 0x936a
movl 0x78(%rbx), %eax
addl %eax, 0x268(%r14)
leaq 0x270(%r14), %rdi
movl 0x88(%rbx), %eax
movl %eax, (%r15)
leaq 0x4(%rsp), %rsi
callq 0x936a
movl 0x88(%rbx), %eax
addl %eax, 0x288(%r14)
incl 0x298(%r14)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
mulss 0x6f68(%rip), %xmm0     # 0xf048
movq %rax, %rdi
callq 0x2120
leaq 0x7d09(%rip), %rsi      # 0xfdf8
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x20b0