// File: /workspace/github_cpp_makefile_star2_O1/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 0xa919
cmpl $0x4, %eax
jne 0xab88
leaq 0xe999(%rip), %r12      # 0x191d4
cmpl $0x0, (%r12)
je 0xa892
movq 0xe77f(%rip), %r15      # 0x18fc8
leaq 0x9442(%rip), %rsi      # 0x13c92
movl $0x1a, %edx
movq %r15, %rdi
callq 0x3200
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1243b
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
cmpl $0x0, (%r12)
je 0xa8db
movq 0xe728(%rip), %r15      # 0x18fc8
leaq 0x9406(%rip), %rsi      # 0x13cad
movl $0x14, %edx
movq %r15, %rdi
callq 0x3200
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
cmpl $0x0, (%r12)
je 0xab88
movq 0xe6db(%rip), %r15      # 0x18fc8
leaq 0x93ce(%rip), %rsi      # 0x13cc2
movl $0xc, %edx
movq %r15, %rdi
callq 0x3200
movq 0x8(%r14), %rax
subq 0x60(%rbx), %rax
js 0xab94
cvtsi2ss %rax, %xmm0
jmp 0xaba9
movq 0x8(%r14), %rcx
movq %rcx, %rax
subq 0x60(%rbx), %rax
movq %rax, 0x68(%rbx)
subq 0x40(%rbx), %rcx
movq %rcx, 0x40(%rbx)
movl 0x10(%rbx), %ecx
movq 0x170(%r14), %rdx
leaq (%rcx,%rcx,2), %r15
leaq (%rdx,%r15,8), %rdi
movl %eax, 0x4(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xa95c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xa966
leaq 0x4(%rsp), %rdx
callq 0xc360
movq 0x188(%r14), %rax
leaq (%rax,%r15,8), %rdi
movl 0x38(%rbx), %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xa98e
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xa998
leaq 0x4(%rsp), %rdx
callq 0xc360
movq 0x1a0(%r14), %rax
leaq (%rax,%r15,8), %rdi
movl 0x40(%rbx), %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xa9c0
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xa9ca
leaq 0x4(%rsp), %rdx
callq 0xc360
movq 0x1b8(%r14), %rax
leaq (%rax,%r15,8), %rdi
movl 0x48(%rbx), %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xa9f2
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xa9fc
leaq 0x4(%rsp), %rdx
callq 0xc360
movq 0x1d0(%r14), %rax
leaq (%rax,%r15,8), %rdi
movl 0x50(%rbx), %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xaa24
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xaa2e
leaq 0x4(%rsp), %rdx
callq 0xc360
movq 0x1e8(%r14), %rax
leaq (%rax,%r15,8), %rdi
movl 0x78(%rbx), %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xaa56
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xaa60
leaq 0x4(%rsp), %rdx
callq 0xc360
movq 0x200(%r14), %rax
leaq (%rax,%r15,8), %rdi
leaq 0x58(%rbx), %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xaa87
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xaa8c
callq 0xc480
movq 0x218(%r14), %rax
leaq (%rax,%r15,8), %rdi
leaq 0x5c(%rbx), %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xaab3
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xaab8
callq 0xc480
movl 0x68(%rbx), %eax
movl %eax, 0x4(%rsp)
movq 0x238(%r14), %rsi
cmpq 0x240(%r14), %rsi
je 0xaade
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x238(%r14)
jmp 0xaaef
leaq 0x230(%r14), %rdi
leaq 0x4(%rsp), %rdx
callq 0xc360
movl 0x68(%rbx), %eax
addl %eax, 0x248(%r14)
movl 0x78(%rbx), %eax
movl %eax, 0x4(%rsp)
movq 0x258(%r14), %rsi
cmpq 0x260(%r14), %rsi
je 0xab1f
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x258(%r14)
jmp 0xab30
leaq 0x250(%r14), %rdi
leaq 0x4(%rsp), %rdx
callq 0xc360
movl 0x78(%rbx), %eax
addl %eax, 0x268(%r14)
movl 0x88(%rbx), %eax
movl %eax, 0x4(%rsp)
movq 0x278(%r14), %rsi
cmpq 0x280(%r14), %rsi
je 0xab63
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x278(%r14)
jmp 0xab74
leaq 0x270(%r14), %rdi
leaq 0x4(%rsp), %rdx
callq 0xc360
movl 0x88(%rbx), %eax
addl %eax, 0x288(%r14)
incl 0x298(%r14)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
mulss 0x84f3(%rip), %xmm0     # 0x130a4
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
callq 0x32e0
movq %rax, %rbx
leaq 0x9221(%rip), %rsi      # 0x13de8
movl $0x2, %edx
movq %rax, %rdi
callq 0x3200
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x3130