// File: estwings57[P]CasHMC/sources/CommandQueue.cpp
// Function: CasHMC::CommandQueue::isIssuable(CasHMC::DRAMCommand*)
bool CommandQueue::isIssuable(DRAMCommand *issueCMD)
{
	switch(issueCMD->commandType) {
		case REFRESH:
			break;
		case ACTIVATE:
			if((BANKSTATE(issueCMD->bank)->currentBankState == IDLE || BANKSTATE(issueCMD->bank)->currentBankState == REFRESHING) 
			&& BANKSTATE(issueCMD->bank)->nextActivate <= currentClockCycle 
			&& tFAWCountdown.size() < 4) {
				return true;
			}
			else {
				return false;
			}
			break;
		case WRITE:
		case WRITE_P:
			if(BANKSTATE(issueCMD->bank)->currentBankState == ROW_ACTIVE 
			&& BANKSTATE(issueCMD->bank)->nextWrite <= currentClockCycle
			&& BANKSTATE(issueCMD->bank)->openRowAddress == issueCMD->row
			&& !(!issueCMD->atomic && rowAccessCounter[issueCMD->bank] >= MAX_ROW_ACCESSES)) {
				//Check the available buffer space of the vault controller with regard to read/write return data
				if(issueCMD->atomic) {
					return true;
				}
				else if(issueCMD->posted == false) {
					if(vaultContP->pendingDataSize+(issueCMD->dataSize/16)+1 <= (vaultContP->upBufferMax)-(vaultContP->upBuffers.size())) {
						return true;
					}
					else{
						return false;
					}
				}
				else {
					return true;
				}
			}
			else {
				return false;
			}
			break;
		case READ:
		case READ_P:
			if(BANKSTATE(issueCMD->bank)->currentBankState == ROW_ACTIVE
			&& BANKSTATE(issueCMD->bank)->nextRead <= currentClockCycle
			&& BANKSTATE(issueCMD->bank)->openRowAddress == issueCMD->row
			&& rowAccessCounter[issueCMD->bank] < MAX_ROW_ACCESSES) {
				//Check the available buffer space of the vault controller with regard to read/write return data
				if(vaultContP->pendingDataSize+(issueCMD->dataSize/16)+1 <= (vaultContP->upBufferMax)-(vaultContP->upBuffers.size())) {
					return true;
				}
				else{
					return false;
				}
			}
			else {
				return false;
			}
			break;
		case PRECHARGE:
			if(BANKSTATE(issueCMD->bank)->currentBankState == ROW_ACTIVE
			&& BANKSTATE(issueCMD->bank)->nextPrecharge <= currentClockCycle) {
				return true;
			}
			else {
				return false;
			}
			break;
		default:
			ERROR(header<<"  == Error - Trying to issue a unknown bus packet type : "<<*issueCMD<<"  (CurrentClock : "<<currentClockCycle<<")");
			exit(0);
	}
	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x20(%rbp)
subq $0x8, %rax
ja 0x216ed
movq -0x20(%rbp), %rax
leaq 0x31630(%rip), %rcx     # 0x52908
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x217a9
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq (%rax), %rax
cmpl $0x0, 0x4(%rax)
je 0x21346
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq (%rax), %rax
cmpl $0x3, 0x4(%rax)
jne 0x2139d
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq -0x28(%rbp), %rcx
movq (%rax), %rax
movq 0x10(%rax), %rax
cmpq 0x8(%rcx), %rax
ja 0x2139d
movq -0x28(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
callq 0x17eb0
cmpq $0x4, %rax
jae 0x2139d
movb $0x1, -0x1(%rbp)
jmp 0x217ad
movb $0x0, -0x1(%rbp)
jmp 0x217ad
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq (%rax), %rax
cmpl $0x1, 0x4(%rax)
jne 0x21521
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq -0x28(%rbp), %rcx
movq (%rax), %rax
movq 0x20(%rax), %rax
cmpq 0x8(%rcx), %rax
ja 0x21521
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq (%rax), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jne 0x21521
movq -0x18(%rbp), %rax
testb $0x1, 0x30(%rax)
jne 0x21484
movq -0x28(%rbp), %rdi
addq $0x268, %rdi            # imm = 0x268
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x17e90
movl (%rax), %eax
leaq 0x451b8(%rip), %rcx     # 0x66634
cmpl (%rcx), %eax
jae 0x21521
movq -0x18(%rbp), %rax
testb $0x1, 0x30(%rax)
je 0x21497
movb $0x1, -0x1(%rbp)
jmp 0x217ad
movq -0x18(%rbp), %rax
movb 0x28(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x21518
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rcx
movl 0x234(%rcx), %ecx
movq -0x18(%rbp), %rdx
movl 0x24(%rdx), %edx
shrl $0x4, %edx
addl %edx, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq %rcx, -0x30(%rbp)
movq 0x1d8(%rax), %rcx
movslq 0x1cc(%rcx), %rcx
movq %rcx, -0x38(%rbp)
movq 0x1d8(%rax), %rdi
addq $0x1e8, %rdi            # imm = 0x1E8
callq 0x22d60
movq -0x38(%rbp), %rcx
movq %rax, %rdx
movq -0x30(%rbp), %rax
subq %rdx, %rcx
cmpq %rcx, %rax
ja 0x2150f
movb $0x1, -0x1(%rbp)
jmp 0x217ad
movb $0x0, -0x1(%rbp)
jmp 0x217ad
movb $0x1, -0x1(%rbp)
jmp 0x217ad
movb $0x0, -0x1(%rbp)
jmp 0x217ad
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq (%rax), %rax
cmpl $0x1, 0x4(%rax)
jne 0x2166a
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq -0x28(%rbp), %rcx
movq (%rax), %rax
movq 0x18(%rax), %rax
cmpq 0x8(%rcx), %rax
ja 0x2166a
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq (%rax), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jne 0x2166a
movq -0x28(%rbp), %rdi
addq $0x268, %rdi            # imm = 0x268
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x17e90
movl (%rax), %eax
leaq 0x4503e(%rip), %rcx     # 0x66634
cmpl (%rcx), %eax
jae 0x2166a
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rcx
movl 0x234(%rcx), %ecx
movq -0x18(%rbp), %rdx
movl 0x24(%rdx), %edx
shrl $0x4, %edx
addl %edx, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq %rcx, -0x40(%rbp)
movq 0x1d8(%rax), %rcx
movslq 0x1cc(%rcx), %rcx
movq %rcx, -0x48(%rbp)
movq 0x1d8(%rax), %rdi
addq $0x1e8, %rdi            # imm = 0x1E8
callq 0x22d60
movq -0x48(%rbp), %rcx
movq %rax, %rdx
movq -0x40(%rbp), %rax
subq %rdx, %rcx
cmpq %rcx, %rax
ja 0x21661
movb $0x1, -0x1(%rbp)
jmp 0x217ad
movb $0x0, -0x1(%rbp)
jmp 0x217ad
movb $0x0, -0x1(%rbp)
jmp 0x217ad
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq (%rax), %rax
cmpl $0x1, 0x4(%rax)
jne 0x216e4
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rax
movq 0x210(%rax), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %esi
callq 0x22c30
movq -0x28(%rbp), %rcx
movq (%rax), %rax
movq 0x28(%rax), %rax
cmpq 0x8(%rcx), %rax
ja 0x216e4
movb $0x1, -0x1(%rbp)
jmp 0x217ad
movb $0x0, -0x1(%rbp)
jmp 0x217ad
movq 0x448fc(%rip), %rdi     # 0x65ff0
leaq 0x2f93f(%rip), %rsi     # 0x5103a
callq 0x4380
movq %rax, %rdi
leaq 0x31296(%rip), %rsi     # 0x529a0
callq 0x4380
movq %rax, %rdi
leaq 0x3011c(%rip), %rsi     # 0x51835
callq 0x4380
movq %rax, %rdi
movl $0x203, %esi            # imm = 0x203
callq 0x4610
movq %rax, %rdi
leaq 0x2f924(%rip), %rsi     # 0x51059
callq 0x4380
movq -0x28(%rbp), %rsi
movq %rax, %rdi
addq $0x20, %rsi
callq 0x4320
movq %rax, %rdi
leaq 0x31265(%rip), %rsi     # 0x529b9
callq 0x4380
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x30f50
movq %rax, %rdi
leaq 0x3343c(%rip), %rsi     # 0x54bab
callq 0x4380
movq %rax, %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x40f0
movq %rax, %rdi
leaq 0x32beb(%rip), %rsi     # 0x54379
callq 0x4380
movq %rax, %rdi
movq 0x44813(%rip), %rsi     # 0x65fb0
callq 0x43c0
xorl %edi, %edi
callq 0x4460
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)