// File: /workspace/github_cpp_makefile_star2_O3/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 %rbx
pushq %rax
movq %rdi, %rbx
movq 0x258(%rdi), %rsi
testq %rsi, %rsi
je 0x2e877
decl 0x260(%rbx)
jne 0x2e877
leaq 0xcd37(%rip), %rax      # 0x3b488
cmpb $0x1, (%rax)
jne 0x2e84b
movq 0xc86f(%rip), %rax      # 0x3afd0
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 0x2e798
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0xc821(%rip), %rdi      # 0x3afd0
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 0x2e7ef
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x258(%rbx), %rsi
movq %r14, %rdi
callq 0x1c32a
movq %rax, %r14
leaq 0x56e0(%rip), %rsi      # 0x33ef0
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 0x2e860
cmpl $0x0, 0x18(%rax)
jne 0x2e860
movl 0x8(%rbx), %ecx
movl %ecx, 0x18(%rax)
movq 0x210(%rbx), %rdi
callq 0x1abb4
movq $0x0, 0x258(%rbx)
movq 0x268(%rbx), %rsi
movb $0x1, %bpl
testq %rsi, %rsi
je 0x2ea86
decl 0x270(%rbx)
je 0x2e899
xorl %ebp, %ebp
jmp 0x2ea86
leaq 0xcbe8(%rip), %rax      # 0x3b488
cmpb $0x1, (%rax)
jne 0x2e99a
movq 0xc720(%rip), %rax      # 0x3afd0
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 0x2e8e7
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0xc6d2(%rip), %rdi      # 0x3afd0
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 0x2e93e
movq %r15, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r15)
movb $0x20, 0xe0(%r15)
movq 0x268(%rbx), %rsi
movq %r14, %rdi
callq 0x1c32a
movq %rax, %r14
leaq 0x55af(%rip), %rsi      # 0x33f0e
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 0x2ea68
cmpb $0x0, 0x30(%rsi)
jne 0x2e9b4
cmpb $0x0, 0x28(%rsi)
je 0x2ea60
movq 0x8(%rsi), %r14
testq %r14, %r14
je 0x2ea68
cmpb $0x1, 0x28(%rsi)
jne 0x2ea68
movq 0x8(%rbx), %r15
movq %r15, %xmm1
punpckldq 0x1744(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x172c(%rip), %xmm1     # 0x30110
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
leaq 0xcba9(%rip), %rax      # 0x3b5a0
mulsd (%rax), %xmm0
leaq 0xca96(%rip), %rax      # 0x3b498
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 0x13542
movl $0x20, %esi
movq %r14, %rdi
callq 0x4300
jmp 0x2ea68
movq %rbx, %rdi
callq 0x2d684
movq 0x210(%rbx), %rdi
movq 0x268(%rbx), %rsi
callq 0x1abb4
movq $0x0, 0x268(%rbx)
movq 0x290(%rbx), %rdi
movq 0x298(%rbx), %rdx
cmpq %rdi, %rdx
je 0x2eb5b
cmpl $0x0, (%rdi)
jne 0x2eb3a
testb %bpl, %bpl
je 0x2ec5a
movq 0x278(%rbx), %rax
movq (%rax), %rcx
movq %rcx, 0x268(%rbx)
leaq 0xcac5(%rip), %rcx      # 0x3b58c
movl (%rcx), %ecx
shrl $0x5, %ecx
movl %ecx, 0x270(%rbx)
leaq 0x4(%rdi), %rsi
cmpq %rdx, %rsi
je 0x2eaf1
subq %rsi, %rdx
callq 0x4480
movq 0x278(%rbx), %rax
movq 0x298(%rbx), %rdx
addq $-0x4, %rdx
movq %rdx, 0x298(%rbx)
leaq 0x8(%rax), %rsi
movq 0x280(%rbx), %rcx
cmpq %rcx, %rsi
je 0x2eb28
subq %rsi, %rcx
movq %rax, %rdi
movq %rcx, %rdx
callq 0x4480
movq 0x280(%rbx), %rcx
movq 0x298(%rbx), %rdx
addq $-0x8, %rcx
movq %rcx, 0x280(%rbx)
movq 0x290(%rbx), %rdi
cmpq %rdi, %rdx
je 0x2eb5b
subq %rdi, %rdx
sarq $0x2, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %eax, %eax
decl (%rdi,%rax,4)
incq %rax
cmpq %rax, %rdx
jne 0x2eb50
decl 0x208(%rbx)
jne 0x2ebad
movq 0x218(%rbx), %rax
movb $0x1, 0x1d0(%rax)
leaq 0xca24(%rip), %rax      # 0x3b59c
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
leaq 0xca1a(%rip), %rax      # 0x3b5a0
divsd (%rax), %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x208(%rbx)
leaq 0xc8ec(%rip), %rax      # 0x3b488
cmpb $0x1, (%rax)
jne 0x2ebad
leaq 0xc8e1(%rip), %rax      # 0x3b489
cmpb $0x0, (%rax)
je 0x2ebb8
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0xc411(%rip), %rax      # 0x3afd0
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 0x2ebf6
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0xc3c3(%rip), %rdi      # 0x3afd0
callq 0x4340
movq %rax, %rbx
leaq 0x5350(%rip), %rsi      # 0x33f6c
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
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x41f0
movq 0xc38f(%rip), %rdi      # 0x3aff0
leaq 0x13ba(%rip), %rsi      # 0x30022
callq 0x42e0
leaq 0x4f9c(%rip), %rsi      # 0x33c10
movq %rax, %rdi
callq 0x42e0
leaq 0x1c14(%rip), %rsi      # 0x30897
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x14d, %esi            # imm = 0x14D
callq 0x4500
leaq 0x13a2(%rip), %rsi      # 0x30041
movq %rax, %rdi
callq 0x42e0
leaq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x4290
leaq 0x528f(%rip), %rsi      # 0x33f49
movq %rax, %rdi
callq 0x42e0
movq 0x268(%rbx), %rsi
movq %rax, %rdi
callq 0x1c32a
leaq 0x5033(%rip), %rsi      # 0x33d0b
movq %rax, %rdi
callq 0x42e0
movq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x40c0
leaq 0x47ee(%rip), %rsi      # 0x334e1
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
xorl %edi, %edi
callq 0x4360