// File: estwings57[P]CasHMC/sources/Link.cpp
// Function: CasHMC::Link::UpdateStatistic(CasHMC::Packet*)
void Link::UpdateStatistic(Packet *packet)
{
	if(downstream) {
		statis->downLinkTransmitSize[linkID] += packet->LNG * 16;
		if(packet->LNG > 1) {
			statis->downLinkDataSize[linkID] += (packet->LNG-1) * 16;
		}
	}
	else {
		statis->upLinkTransmitSize[linkID] += packet->LNG * 16;
		if(packet->LNG > 1) {
			statis->upLinkDataSize[linkID] += (packet->LNG-1) * 16;
		}
	}
	
	switch(packet->packetType) {
		case REQUEST:
			statis->reqPerLink[linkID]++;
			packet->trace->linkTransmitTime = linkMasterP->currentClockCycle;

			if((WR16 <= packet->CMD && packet->CMD <= MD_WR)
			|| packet->CMD == WR256
			|| (P_WR16 <= packet->CMD && packet->CMD <= P_WR128)
			|| packet->CMD == P_WR256) {
				statis->writePerLink[linkID]++;
			}
			else if((RD16 <= packet->CMD && packet->CMD <= RD128)
			|| packet->CMD == RD256
			|| packet->CMD == MD_RD) {
				statis->readPerLink[linkID]++;
			}
			else {
				statis->atomicPerLink[linkID]++;
			}
			break;
		case RESPONSE:
			statis->resPerLink[linkID]++;
			break;
		case FLOW:
			statis->flowPerLink[linkID]++;
			break;
		default:
			ERROR(header<<"  == Error - Unknown packet type");
			ERROR("         Type : "<<packet->packetType);
			exit(0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
testb $0x1, 0x1cc(%rax)
je 0x3bbe2
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x430(%rcx), %ecx
shll $0x4, %ecx
movl %ecx, %ecx
movq %rcx, -0x20(%rbp)
movq 0x1e0(%rax), %rdi
addq $0x130, %rdi            # imm = 0x130
movl 0x1c8(%rax), %eax
movl %eax, %esi
callq 0x17df0
movq -0x20(%rbp), %rcx
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x430(%rax)
jbe 0x3bbdd
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x430(%rcx), %ecx
subl $0x1, %ecx
shll $0x4, %ecx
movl %ecx, %ecx
movq %rcx, -0x28(%rbp)
movq 0x1e0(%rax), %rdi
addq $0x160, %rdi            # imm = 0x160
movl 0x1c8(%rax), %eax
movl %eax, %esi
callq 0x17df0
movq -0x28(%rbp), %rcx
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x3bc6c
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x430(%rcx), %ecx
shll $0x4, %ecx
movl %ecx, %ecx
movq %rcx, -0x30(%rbp)
movq 0x1e0(%rax), %rdi
addq $0x148, %rdi            # imm = 0x148
movl 0x1c8(%rax), %eax
movl %eax, %esi
callq 0x17df0
movq -0x30(%rbp), %rcx
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x430(%rax)
jbe 0x3bc6a
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x430(%rcx), %ecx
subl $0x1, %ecx
shll $0x4, %ecx
movl %ecx, %ecx
movq %rcx, -0x38(%rbp)
movq 0x1e0(%rax), %rdi
addq $0x178, %rdi            # imm = 0x178
movl 0x1c8(%rax), %eax
movl %eax, %esi
callq 0x17df0
movq -0x38(%rbp), %rcx
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x3bc6c
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x3c(%rbp)
testl %eax, %eax
je 0x3bc9b
jmp 0x3bc7c
movl -0x3c(%rbp), %eax
subl $0x1, %eax
je 0x3bdf7
jmp 0x3bc8a
movl -0x3c(%rbp), %eax
subl $0x2, %eax
je 0x3be25
jmp 0x3be53
movq -0x18(%rbp), %rax
movq 0x1e0(%rax), %rdi
addq $0xb0, %rdi
movl 0x1c8(%rax), %eax
movl %eax, %esi
callq 0x17df0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq (%rcx), %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
movq 0x1d8(%rax), %rax
movq 0x8(%rax), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rcx
movl $0x8, %eax
cmpl 0x434(%rcx), %eax
jg 0x3bd01
movq -0x10(%rbp), %rax
cmpl $0x10, 0x434(%rax)
jle 0x3bd39
movq -0x10(%rbp), %rax
cmpl $0x4f, 0x434(%rax)
je 0x3bd39
movq -0x10(%rbp), %rcx
movl $0x18, %eax
cmpl 0x434(%rcx), %eax
jg 0x3bd2c
movq -0x10(%rbp), %rax
cmpl $0x1f, 0x434(%rax)
jle 0x3bd39
movq -0x10(%rbp), %rax
cmpl $0x5f, 0x434(%rax)
jne 0x3bd67
movq -0x18(%rbp), %rax
movq 0x1e0(%rax), %rdi
addq $0x80, %rdi
movl 0x1c8(%rax), %eax
movl %eax, %esi
callq 0x17df0
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x3bdf2
movq -0x10(%rbp), %rcx
movl $0x30, %eax
cmpl 0x434(%rcx), %eax
jg 0x3bd85
movq -0x10(%rbp), %rax
cmpl $0x37, 0x434(%rax)
jle 0x3bd9f
movq -0x10(%rbp), %rax
cmpl $0x77, 0x434(%rax)
je 0x3bd9f
movq -0x10(%rbp), %rax
cmpl $0x28, 0x434(%rax)
jne 0x3bdc7
movq -0x18(%rbp), %rax
movq 0x1e0(%rax), %rdi
addq $0x68, %rdi
movl 0x1c8(%rax), %eax
movl %eax, %esi
callq 0x17df0
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x3bdf0
movq -0x18(%rbp), %rax
movq 0x1e0(%rax), %rdi
addq $0x98, %rdi
movl 0x1c8(%rax), %eax
movl %eax, %esi
callq 0x17df0
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x3bdf2
jmp 0x3bf4f
movq -0x18(%rbp), %rax
movq 0x1e0(%rax), %rdi
addq $0xc8, %rdi
movl 0x1c8(%rax), %eax
movl %eax, %esi
callq 0x17df0
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x3bf4f
movq -0x18(%rbp), %rax
movq 0x1e0(%rax), %rdi
addq $0xe0, %rdi
movl 0x1c8(%rax), %eax
movl %eax, %esi
callq 0x17df0
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x3bf4f
movq 0x2a196(%rip), %rdi     # 0x65ff0
leaq 0x151d9(%rip), %rsi     # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x17837(%rip), %rsi     # 0x536a7
callq 0x4380
movq %rax, %rdi
leaq 0x159b6(%rip), %rsi     # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x88, %esi
callq 0x4610
movq %rax, %rdi
leaq 0x151be(%rip), %rsi     # 0x51059
callq 0x4380
movq -0x18(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x177fe(%rip), %rsi     # 0x536b8
callq 0x4380
movq %rax, %rdi
movq 0x2a0e7(%rip), %rsi     # 0x65fb0
callq 0x43c0
movq 0x2a11b(%rip), %rdi     # 0x65ff0
leaq 0x1515e(%rip), %rsi     # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x177bc(%rip), %rsi     # 0x536a7
callq 0x4380
movq %rax, %rdi
leaq 0x1593b(%rip), %rsi     # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x89, %esi
callq 0x4610
movq %rax, %rdi
leaq 0x15143(%rip), %rsi     # 0x51059
callq 0x4380
movq %rax, %rdi
leaq 0x15175(%rip), %rsi     # 0x5109a
callq 0x4380
movq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %esi
callq 0x4610
movq %rax, %rdi
movq 0x2a06d(%rip), %rsi     # 0x65fb0
callq 0x43c0
xorl %edi, %edi
callq 0x4460
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)