// File: /workspace/github_cpp_makefile_star2_O2/estwings57[P]CasHMC/sources/LinkMaster.cpp
// Function: CasHMC::LinkMaster::UpdateField(int, CasHMC::Packet*)
void LinkMaster::UpdateField(int nextWriteP, Packet *packet)
{
	//Sequence number updated
	packet->SEQ = (masterSEQ<7) ? masterSEQ++ : 0;
	//Update retry buffer pointer field
	packet->RRP = lastestRRP;
	packet->FRP = (nextWriteP < MAX_RETRY_BUF) ? nextWriteP : nextWriteP - MAX_RETRY_BUF;
	//CRC field updated
	startCRC = false;
	if(CRC_CHECK)	packet->CRC = packet->GetCRC();
	//Decrement the token count register by the number of packet in the transmitted packet
	if(packet->packetType != FLOW) {
		tokenCount -= packet->LNG;
		DEBUG(ALI(18)<<header<<ALI(15)<<*packet<<(downstream ? "Down) " : "Up)   ")
			<<"Decreased TOKEN : "<<packet->LNG<<" (remaining : "<<tokenCount<<"/"<<MAX_LINK_BUF<<")");
	}
	//Save packet in retry buffer
	Packet *retryPacket = new Packet(*packet);
	if(retryBuffers[retBufWriteP] == NULL) {
		retryBuffers[retBufWriteP] = retryPacket;
	}
	else {
		ERROR(header<<"  == Error - retryBuffers["<<retBufWriteP<<"] is not NULL  (CurrentClock : "<<currentClockCycle<<")");
		exit(0);
	}
	for(int i=1; i<packet->LNG; i++) {
		retryBuffers[(retBufWriteP+i<MAX_RETRY_BUF ? retBufWriteP+i : retBufWriteP+i-MAX_RETRY_BUF)] = NULL;
	}
	DEBUG(ALI(18)<<header<<ALI(15)<<*packet<<(downstream ? "Down) " : "Up)   ")
			<<"RETRY BUFFER["<<retBufWriteP<<"] (FRP : "<<packet->FRP<<")");
	retBufWriteP = packet->FRP;
	//Send packet to standby buffer where the packet is ready to be transmitted
	packet->bufPopDelay = 1;
	linkRxTx.push_back(packet);
	//DEBUG(ALI(18)<<header<<ALI(15)<<*Buffers[0]<<(downstream ? "Down) " : "Up)   ")
	//			<<"SENDING packet to link "<<linkMasterID<<" (LK_"<<(downstream ? "D" : "U")<<linkMasterID<<")");
	Buffers.erase(Buffers.begin(), Buffers.begin()+packet->LNG);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movq %rdi, %rbx
movq %rdx, 0x8(%rsp)
movl 0x238(%rdi), %ecx
xorl %eax, %eax
movl $0x0, %edx
cmpl $0x6, %ecx
jg 0x1b960
leal 0x1(%rcx), %edx
movl %edx, 0x238(%rbx)
movl %ecx, %edx
movl %edx, 0x444(%r14)
movl 0x20c(%rbx), %ecx
movl %ecx, 0x44c(%r14)
leaq 0x15b41(%rip), %r12     # 0x314bc
movl (%r12), %ecx
cmpl %esi, %ecx
cmovlel %ecx, %eax
subl %eax, %esi
movl %esi, 0x448(%r14)
movb $0x0, 0x240(%rbx)
leaq 0x15b31(%rip), %rax     # 0x314cc
cmpb $0x1, (%rax)
jne 0x1b9af
movq %r14, %rdi
callq 0x1e0c4
movl %eax, 0x438(%r14)
cmpl $0x2, 0x10(%r14)
je 0x1bacc
movl 0x430(%r14), %eax
subl %eax, 0x208(%rbx)
leaq 0x15aba(%rip), %rax     # 0x31488
cmpb $0x1, (%rax)
jne 0x1bacc
leaq 0x15aab(%rip), %rax     # 0x31489
cmpb $0x0, (%rax)
jne 0x1bacc
movq 0x155e2(%rip), %rdi     # 0x30fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x12, 0x10(%rdi,%rax)
pushq $0x20
popq %rbp
movl %ebp, %esi
callq 0x4440
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0xf, 0x10(%rax,%rcx)
movq %rax, %rdi
movl %ebp, %esi
callq 0x4440
movq %rax, %rdi
movq %r14, %rsi
callq 0x1e2c8
leaq 0xad28(%rip), %rcx      # 0x26768
leaq 0xad28(%rip), %rsi      # 0x2676f
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rcx, %rsi
movq %rax, %rdi
callq 0x4300
leaq 0xb18f(%rip), %rsi      # 0x26bf0
movq %rax, %rdi
callq 0x4300
movl 0x430(%r14), %esi
movq %rax, %rdi
callq 0x4210
leaq 0xb184(%rip), %rsi      # 0x26c03
movq %rax, %rdi
callq 0x4300
movl 0x208(%rbx), %esi
movq %rax, %rdi
callq 0x4210
leaq 0x883e(%rip), %rsi      # 0x242da
movq %rax, %rdi
callq 0x4300
leaq 0x15a0d(%rip), %rcx     # 0x314b8
movl (%rcx), %esi
movq %rax, %rdi
callq 0x44f0
leaq 0xba15(%rip), %rsi      # 0x274d1
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
movl $0x468, %edi            # imm = 0x468
callq 0x4310
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x1df98
movl 0x260(%rbx), %edx
movq 0x270(%rbx), %rax
cmpq $0x0, (%rax,%rdx,8)
jne 0x1bc75
movq %r15, (%rax,%rdx,8)
movl (%r12), %eax
movl 0x430(%r14), %ecx
incl %edx
pushq $0x1
popq %rsi
xorl %edi, %edi
cmpl %ecx, %esi
jae 0x1bb37
cmpl %eax, %edx
movl %eax, %r8d
cmovbl %edi, %r8d
movl %edx, %r9d
subl %r8d, %r9d
movq 0x270(%rbx), %r8
andq $0x0, (%r8,%r9,8)
incl %esi
incl %edx
jmp 0x1bb12
leaq 0x1594a(%rip), %rax     # 0x31488
cmpb $0x0, (%rax)
je 0x1bc1c
leaq 0x1593b(%rip), %rax     # 0x31489
cmpb $0x0, (%rax)
jne 0x1bc1c
movq 0x15472(%rip), %rdi     # 0x30fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x12, 0x10(%rdi,%rax)
pushq $0x20
popq %rbp
movl %ebp, %esi
callq 0x4440
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0xf, 0x10(%rax,%rcx)
movq %rax, %rdi
movl %ebp, %esi
callq 0x4440
movq %rax, %rdi
movq %r14, %rsi
callq 0x1e2c8
leaq 0xabb8(%rip), %rcx      # 0x26768
leaq 0xabb8(%rip), %rsi      # 0x2676f
cmpb $0x0, 0x1cc(%rbx)
cmovneq %rcx, %rsi
movq %rax, %rdi
callq 0x4300
leaq 0xb07c(%rip), %rsi      # 0x26c4d
movq %rax, %rdi
callq 0x4300
movl 0x260(%rbx), %esi
movq %rax, %rdi
callq 0x4210
leaq 0xb06d(%rip), %rsi      # 0x26c5b
movq %rax, %rdi
callq 0x4300
movl 0x448(%r14), %esi
movq %rax, %rdi
callq 0x4210
leaq 0xb8c5(%rip), %rsi      # 0x274d1
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
movl 0x448(%r14), %eax
movl %eax, 0x260(%rbx)
movl $0x1, 0x14(%r14)
leaq 0x1e8(%rbx), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x13442
movq 0x1d0(%rbx), %rsi
addq $0x1d0, %rbx            # imm = 0x1D0
movq (%r14), %rax
movl 0x430(%rax), %eax
leaq (%rsi,%rax,8), %rdx
movq %rbx, %rdi
callq 0x132b4
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x15374(%rip), %rdi     # 0x30ff0
leaq 0x839f(%rip), %rsi      # 0x24022
callq 0x4300
leaq 0xac50(%rip), %rsi      # 0x268df
movq %rax, %rdi
callq 0x4300
leaq 0x8bd9(%rip), %rsi      # 0x24877
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
movl $0x1b5, %esi            # imm = 0x1B5
callq 0x44f0
leaq 0x8387(%rip), %rsi      # 0x24041
movq %rax, %rdi
callq 0x4300
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
leaq 0xaf3d(%rip), %rsi      # 0x26c12
movq %rax, %rdi
callq 0x4300
movl 0x260(%rbx), %esi
movq %rax, %rdi
callq 0x43c0
leaq 0xaf3b(%rip), %rsi      # 0x26c2d
movq %rax, %rdi
callq 0x4300
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x40d0
leaq 0xb7c4(%rip), %rsi      # 0x274d1
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
xorl %edi, %edi
callq 0x4370
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq %r15, %rdi
callq 0x4320
movq %rbx, %rdi
callq 0x4520