// File: /workspace/github_cpp_makefile_star2_O1/estwings57[P]CasHMC/sources/VaultController.cpp
// Function: CasHMC::VaultController::UpdateCountdown()
void VaultController::UpdateCountdown()
{
	//Check for outgoing command and handle countdowns
	if(cmdBus != NULL) {
		cmdCyclesLeft--;
		if(cmdCyclesLeft == 0) {	//command is ready to be transmitted
			DE_CR(ALI(18)<<header<<ALI(15)<<*cmdBus<<"Down) ISSUING command to DRAM");
			if(cmdBus->trace != NULL && cmdBus->trace->vaultIssueTime == 0) {
				cmdBus->trace->vaultIssueTime = currentClockCycle;
			}
			dramP->receiveCMD(cmdBus);
			cmdBus = NULL;
		}
	}
	//Check for outgoing write data packets and handle countdowns
	if(dataBus != NULL) {
		dataCyclesLeft--;
		if(dataCyclesLeft == 0) {
			DE_CR(ALI(18)<<header<<ALI(15)<<*dataBus<<"Down) ISSUING data corresponding to previous write command");
			if(dataBus->lastCMD) {
				if(!dataBus->atomic && !dataBus->posted) {
					MakeRespondPacket(dataBus);
				}
				else if(dataBus->trace != NULL && dataBus->posted) {
					dataBus->trace->tranFullLat = ceil((double)currentClockCycle * (double)tCK/CPU_CLK_PERIOD) - dataBus->trace->tranTransmitTime;
					dataBus->trace->linkFullLat = ceil((double)currentClockCycle * (double)tCK/CPU_CLK_PERIOD) - dataBus->trace->linkTransmitTime;
					dataBus->trace->vaultFullLat = currentClockCycle - dataBus->trace->vaultIssueTime;
					delete dataBus->trace;
				}
			}
			dramP->receiveCMD(dataBus);
			dataBus = NULL;
		}
	}
	//Check write data to be sent to DRAM and handle countdowns
	if(writeDataCountdown.size() > 0) {
		if(writeDataCountdown[0] == 0) {
			if(dataBus != NULL) {
				ERROR(header<<"   == Error - Data Bus Collision  "<<*dataBus<<"  (CurrentClock : "<<currentClockCycle<<")");
				exit(0);
			}
			dataBus = writeDataToSend[0];
			dataCyclesLeft = BL;	//block size according to address mapping / DATA_WIDTH

			writeDataCountdown.erase(writeDataCountdown.begin());
			writeDataToSend.erase(writeDataToSend.begin());
		}
		
		for(int i=0; i<writeDataCountdown.size(); i++) {
			writeDataCountdown[i]--;
		}
	}
	
	//Time for a refresh issue a refresh
	refreshCountdown--;
	if(refreshCountdown == 0) {
		commandQueue->refreshWaiting = true;
		refreshCountdown = REFRESH_PERIOD/tCK;
		DEBUG(ALI(39)<<header<<"REFRESH countdown is over");
	}
	//If a rank is powered down, make sure we power it up in time for a refresh
	else if(powerDown && refreshCountdown<=tXP)	{
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
cmpq $0x0, 0x258(%rdi)
je 0x2f1fd
decl 0x260(%rbx)
jne 0x2f1fd
leaq 0xd3bf(%rip), %rax      # 0x3c488
cmpb $0x1, (%rax)
jne 0x2f1ca
movq 0xcef7(%rip), %rax      # 0x3bfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x12, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r14
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x2f117
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0xcea2(%rip), %rdi      # 0x3bfd0
callq 0x4340
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rcx
movq $0xf, 0x10(%r14,%rcx)
movq -0x18(%rax), %rax
leaq (%r14,%rax), %r15
cmpb $0x0, 0xe1(%r14,%rax)
jne 0x2f175
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x258(%rbx), %rsi
movq %r14, %rdi
callq 0x1caba
movq %rax, %r14
leaq 0x5cda(%rip), %rsi      # 0x34e70
movl $0x1d, %edx
movq %rax, %rdi
callq 0x4340
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq 0x258(%rbx), %rsi
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x2f1e6
cmpl $0x0, 0x18(%rax)
jne 0x2f1e6
movl 0x8(%rbx), %ecx
movl %ecx, 0x18(%rax)
movq 0x210(%rbx), %rdi
callq 0x1b388
movq $0x0, 0x258(%rbx)
cmpq $0x0, 0x268(%rbx)
je 0x2f412
decl 0x270(%rbx)
jne 0x2f412
leaq 0xd26a(%rip), %rax      # 0x3c488
cmpb $0x1, (%rax)
jne 0x2f31f
movq 0xcda2(%rip), %rax      # 0x3bfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x12, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r14
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x2f26c
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0xcd4d(%rip), %rdi      # 0x3bfd0
callq 0x4340
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rcx
movq $0xf, 0x10(%r14,%rcx)
movq -0x18(%rax), %rax
leaq (%r14,%rax), %r15
cmpb $0x0, 0xe1(%r14,%rax)
jne 0x2f2ca
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r15)
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x268(%rbx), %rsi
movq %r14, %rdi
callq 0x1caba
movq %rax, %r14
leaq 0x5ba3(%rip), %rsi      # 0x34e8e
movl $0x3a, %edx
movq %rax, %rdi
callq 0x4340
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq 0x268(%rbx), %rsi
cmpb $0x1, 0x29(%rsi)
jne 0x2f3f4
cmpb $0x0, 0x30(%rsi)
jne 0x2f340
cmpb $0x0, 0x28(%rsi)
je 0x2f3ec
movq 0x8(%rsi), %r14
testq %r14, %r14
je 0x2f3f4
cmpb $0x1, 0x28(%rsi)
jne 0x2f3f4
movq 0x8(%rbx), %r15
movq %r15, %xmm1
punpckldq 0x1d98(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1d80(%rip), %xmm1     # 0x310f0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
leaq 0xd21d(%rip), %rax      # 0x3c5a0
mulsd (%rax), %xmm0
leaq 0xd10a(%rip), %rax      # 0x3c498
divsd (%rax), %xmm0
callq 0x4090
movl 0x8(%r14), %eax
movl 0x10(%r14), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
cvttsd2si %xmm2, %rax
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
movl %eax, 0xc(%r14)
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x14(%r14)
subl 0x18(%r14), %r15d
movl %r15d, 0x1c(%r14)
movq %r14, %rdi
callq 0x139fc
movl $0x20, %esi
movq %r14, %rdi
callq 0x4300
jmp 0x2f3f4
movq %rbx, %rdi
callq 0x2dfdc
movq 0x210(%rbx), %rdi
movq 0x268(%rbx), %rsi
callq 0x1b388
movq $0x0, 0x268(%rbx)
movq 0x290(%rbx), %rdi
movq 0x298(%rbx), %rdx
cmpq %rdi, %rdx
je 0x2f4cb
cmpl $0x0, (%rdi)
jne 0x2f49f
cmpq $0x0, 0x268(%rbx)
jne 0x2f5c7
movq 0x278(%rbx), %rax
movq (%rax), %rax
movq %rax, 0x268(%rbx)
leaq 0xd138(%rip), %rax      # 0x3c58c
movl (%rax), %eax
shrl $0x5, %eax
movl %eax, 0x270(%rbx)
leaq 0x4(%rdi), %rsi
cmpq %rdx, %rsi
je 0x2f470
subq %rsi, %rdx
callq 0x4480
addq $-0x4, 0x298(%rbx)
movq 0x278(%rbx), %rdi
movq 0x280(%rbx), %rdx
leaq 0x8(%rdi), %rsi
cmpq %rdx, %rsi
je 0x2f497
subq %rsi, %rdx
callq 0x4480
addq $-0x8, 0x280(%rbx)
movq 0x290(%rbx), %rax
movq 0x298(%rbx), %rcx
subq %rax, %rcx
je 0x2f4cb
sarq $0x2, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
decl (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x2f4c0
decl 0x208(%rbx)
jne 0x2f51d
movq 0x218(%rbx), %rax
movb $0x1, 0x1d0(%rax)
leaq 0xd0b4(%rip), %rax      # 0x3c59c
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
leaq 0xd0aa(%rip), %rax      # 0x3c5a0
divsd (%rax), %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x208(%rbx)
leaq 0xcf7c(%rip), %rax      # 0x3c488
cmpb $0x1, (%rax)
jne 0x2f51d
leaq 0xcf71(%rip), %rax      # 0x3c489
cmpb $0x0, (%rax)
je 0x2f523
popq %rbx
popq %r14
popq %r15
retq
movq 0xcaa6(%rip), %rax      # 0x3bfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x27, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r14
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x2f568
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0xca51(%rip), %rdi      # 0x3bfd0
callq 0x4340
movq %rax, %rbx
leaq 0x595e(%rip), %rsi      # 0x34eec
movl $0x19, %edx
movq %rax, %rdi
callq 0x4340
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x41f0
movq 0xca22(%rip), %rdi      # 0x3bff0
leaq 0x1a4d(%rip), %rsi      # 0x31022
callq 0x42e0
leaq 0x55af(%rip), %rsi      # 0x34b90
movq %rax, %rdi
callq 0x42e0
leaq 0x2247(%rip), %rsi      # 0x31837
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x14d, %esi            # imm = 0x14D
callq 0x4500
leaq 0x1a35(%rip), %rsi      # 0x31041
movq %rax, %rdi
callq 0x42e0
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x4290
leaq 0x58a2(%rip), %rsi      # 0x34ec9
movq %rax, %rdi
callq 0x42e0
movq 0x268(%rbx), %rsi
movq %rax, %rdi
callq 0x1caba
leaq 0x5646(%rip), %rsi      # 0x34c8b
movq %rax, %rdi
callq 0x42e0
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x4e01(%rip), %rsi      # 0x34461
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
xorl %edi, %edi
callq 0x4360
nop