// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x258(%rdi), %rsi
testq %rsi, %rsi
je 0x228ac
decl 0x260(%rbx)
jne 0x228ac
leaq 0xec7e(%rip), %rax      # 0x31488
cmpb $0x1, (%rax)
jne 0x22883
movq 0xe7ba(%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 0x258(%rbx), %rsi
movq %rax, %rdi
callq 0x15274
leaq 0x5674(%rip), %rsi      # 0x27ee0
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
movq 0x258(%rbx), %rsi
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x22898
cmpl $0x0, 0x18(%rax)
jne 0x22898
movl 0x8(%rbx), %ecx
movl %ecx, 0x18(%rax)
movq 0x210(%rbx), %rdi
callq 0x13f26
andq $0x0, 0x258(%rbx)
movq 0x268(%rbx), %rsi
movb $0x1, %r15b
testq %rsi, %rsi
je 0x22a30
decl 0x270(%rbx)
je 0x228cf
xorl %r15d, %r15d
jmp 0x22a30
leaq 0xebb2(%rip), %rax      # 0x31488
cmpb $0x1, (%rax)
jne 0x2294f
movq 0xe6ee(%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 0x268(%rbx), %rsi
movq %rax, %rdi
callq 0x15274
leaq 0x55c6(%rip), %rsi      # 0x27efe
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
movq 0x268(%rbx), %rsi
cmpb $0x1, 0x29(%rsi)
jne 0x22a15
cmpb $0x0, 0x30(%rsi)
jne 0x22969
cmpb $0x0, 0x28(%rsi)
je 0x22a0d
movq 0x8(%rsi), %r14
testq %r14, %r14
je 0x22a15
cmpb $0x1, 0x28(%rsi)
jne 0x22a15
movq 0x8(%rbx), %r12
movq %r12, %xmm1
punpckldq 0x179f(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x17a7(%rip), %xmm1     # 0x24140
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
leaq 0xebf4(%rip), %rax      # 0x315a0
mulsd (%rax), %xmm0
leaq 0xeae1(%rip), %rax      # 0x31498
divsd (%rax), %xmm0
callq 0x4080
movl 0x8(%r14), %eax
movl 0x10(%r14), %ecx
cvtsi2sd %rax, %xmm1
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
cvttsd2si %xmm2, %rax
cvtsi2sd %rcx, %xmm1
movl %eax, 0xc(%r14)
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x14(%r14)
subl 0x18(%r14), %r12d
movl %r12d, 0x1c(%r14)
movq %r14, %rdi
callq 0xdd6c
pushq $0x20
popq %rsi
movq %r14, %rdi
callq 0x4320
jmp 0x22a15
movq %rbx, %rdi
callq 0x21cce
movq 0x210(%rbx), %rdi
movq 0x268(%rbx), %rsi
callq 0x13f26
andq $0x0, 0x268(%rbx)
movq 0x290(%rbx), %rsi
movq 0x298(%rbx), %rax
cmpq %rsi, %rax
je 0x22aba
cmpl $0x0, (%rsi)
jne 0x22aa4
testb %r15b, %r15b
je 0x22b5f
leaq 0x290(%rbx), %rdi
leaq 0x278(%rbx), %r14
movq 0x278(%rbx), %rax
movq (%rax), %rax
movq %rax, 0x268(%rbx)
leaq 0xeb15(%rip), %rax      # 0x3158c
movl (%rax), %eax
shrl $0x5, %eax
movl %eax, 0x270(%rbx)
callq 0x111a8
movq 0x278(%rbx), %rsi
movq %r14, %rdi
callq 0x111e2
movq 0x290(%rbx), %rsi
movq 0x298(%rbx), %rax
subq %rsi, %rax
sarq $0x2, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x22aba
decl (%rsi,%rcx,4)
incq %rcx
jmp 0x22aad
decl 0x208(%rbx)
jne 0x22b09
movq 0x218(%rbx), %rax
movb $0x1, 0x1d0(%rax)
leaq 0xeac5(%rip), %rax      # 0x3159c
cvtsi2sdl (%rax), %xmm0
leaq 0xeabe(%rip), %rax      # 0x315a0
divsd (%rax), %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x208(%rbx)
leaq 0xe990(%rip), %rax      # 0x31488
cmpb $0x1, (%rax)
jne 0x22b09
leaq 0xe985(%rip), %rax      # 0x31489
cmpb $0x0, (%rax)
je 0x22b12
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0xe4b7(%rip), %rdi      # 0x30fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x27, 0x10(%rdi,%rax)
pushq $0x20
popq %rsi
callq 0x4440
addq $0x20, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x42b0
leaq 0x5415(%rip), %rsi      # 0x27f5c
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x4180
movq 0xe48a(%rip), %rdi      # 0x30ff0
leaq 0x14b5(%rip), %rsi      # 0x24022
callq 0x4300
leaq 0x5087(%rip), %rsi      # 0x27c00
movq %rax, %rdi
callq 0x4300
leaq 0x1cef(%rip), %rsi      # 0x24877
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
movl $0x14d, %esi            # imm = 0x14D
callq 0x44f0
leaq 0x149d(%rip), %rsi      # 0x24041
movq %rax, %rdi
callq 0x4300
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x42b0
leaq 0x537a(%rip), %rsi      # 0x27f39
movq %rax, %rdi
callq 0x4300
movq 0x268(%rbx), %rsi
movq %rax, %rdi
callq 0x15274
leaq 0x511e(%rip), %rsi      # 0x27cfb
movq %rax, %rdi
callq 0x4300
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x40d0
leaq 0x48d9(%rip), %rsi      # 0x274d1
movq %rax, %rdi
callq 0x4300
movq %rax, %rdi
callq 0x4180
xorl %edi, %edi
callq 0x4370
nop