// File: /workspace/github_cpp_makefile_star2_O2/dramninjasUMD[P]BOBSim/SimpleController.cpp
// Function: BOBSim::SimpleController::IsIssuable(BOBSim::BusPacket*)
bool SimpleController::IsIssuable(BusPacket *busPacket)
{
	unsigned rank = busPacket->rank;
	unsigned bank = busPacket->bank;

	//if((channel->readReturnQueue.size()+outstandingReads) * TRANSACTION_SIZE >= CHANNEL_RETURN_Q_MAX)
	//if((channel->readReturnQueue.size()) * TRANSACTION_SIZE >= CHANNEL_RETURN_Q_MAX)
	//	{
	//RRQFull++;
	//DEBUG("!!!!!!!!!"<<*busPacket)
	//exit(0);
	//return false;
	//}


	switch(busPacket->busPacketType)
	{
	case READ_P:
		if(bankStates[rank][bank].currentBankState == ROW_ACTIVE &&
		        bankStates[rank][bank].openRowAddress == busPacket->row &&
		        currentClockCycle >= bankStates[rank][bank].nextRead &&
		        (channel->readReturnQueue.size()+outstandingReads) * TRANSACTION_SIZE < CHANNEL_RETURN_Q_MAX)
		{
			return true;
		}
		else
		{

			if((channel->readReturnQueue.size()+outstandingReads) * TRANSACTION_SIZE >= CHANNEL_RETURN_Q_MAX)
			{
				RRQFull++;
			}

			return false;
		}

		break;
	case WRITE_P:
		if(bankStates[rank][bank].currentBankState == ROW_ACTIVE &&
		        bankStates[rank][bank].openRowAddress == busPacket->row &&
		        currentClockCycle >= bankStates[rank][bank].nextWrite &&
		        (channel->readReturnQueue.size()+outstandingReads) * TRANSACTION_SIZE < CHANNEL_RETURN_Q_MAX)
		{
			return true;
		}
		else
		{
			if((channel->readReturnQueue.size()+outstandingReads) * TRANSACTION_SIZE >= CHANNEL_RETURN_Q_MAX)
			{
				RRQFull++;
			}
			return false;
		}
		break;
	case ACTIVATE:
		if(bankStates[rank][bank].currentBankState == IDLE &&
		        currentClockCycle >= bankStates[rank][bank].nextActivate &&
		        refreshCounters[rank]>0 &&
		        tFAWWindow[rank].size()<4)
		{
			return true;
		}
		else return false;
		break;
	default:
		ERROR("== Error - Checking issuability on unknown packet type: " << *busPacket);
		exit(0);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl 0x14(%rsi), %ecx
movl 0x4(%rsi), %edx
movl 0x10(%rsi), %eax
cmpl $0x4, %edx
je 0xdd19
movq %rsi, %r14
cmpl $0x3, %edx
je 0xdca1
cmpl $0x1, %edx
jne 0xdd6d
movabsq $0x3fffffffffffff0, %r15 # imm = 0x3FFFFFFFFFFFFF0
movq 0x78(%rbx), %rdx
movq (%rdx,%rcx,8), %rcx
shlq $0x6, %rax
cmpl $0x1, (%rcx,%rax)
jne 0xdcf2
addq %rax, %rcx
movl 0x4(%rcx), %eax
cmpl 0xc(%r14), %eax
jne 0xdcf2
movq 0x8(%rbx), %rax
cmpq 0x10(%rcx), %rax
jae 0xdcd3
jmp 0xdcf2
movabsq $0x3fffffffffffff0, %r15 # imm = 0x3FFFFFFFFFFFFF0
movq 0x78(%rbx), %rdx
movq (%rdx,%rcx,8), %rcx
shlq $0x6, %rax
cmpl $0x1, (%rcx,%rax)
jne 0xdcf2
addq %rax, %rcx
movl 0x4(%rcx), %eax
cmpl 0xc(%r14), %eax
jne 0xdcf2
movq 0x8(%rbx), %rax
cmpq 0x18(%rcx), %rax
jb 0xdcf2
movl $0x200, %edi            # imm = 0x200
addq 0x170(%rbx), %rdi
callq 0x5364
movl 0xf0(%rbx), %ecx
addq %rax, %rcx
testq %r15, %rcx
je 0xdd69
movl $0x200, %edi            # imm = 0x200
addq 0x170(%rbx), %rdi
callq 0x5364
movl 0xf0(%rbx), %ecx
addq %rax, %rcx
testq %r15, %rcx
je 0xdd61
incl 0xec(%rbx)
jmp 0xdd61
movq 0x78(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
shlq $0x6, %rax
cmpl $0x0, (%rdx,%rax)
jne 0xdd61
addq %rax, %rdx
movq 0x8(%rbx), %rax
cmpq 0x8(%rdx), %rax
jb 0xdd61
movq 0xc8(%rbx), %rax
cmpl $0x0, (%rax,%rcx,4)
je 0xdd61
movq 0xb0(%rbx), %rax
imulq $0x18, %rcx, %rcx
movq 0x8(%rax,%rcx), %rdx
subq (%rax,%rcx), %rdx
movb $0x1, %al
cmpq $0x10, %rdx
jb 0xdd63
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
movb $0x1, %al
jmp 0xdd63
movq 0x827c(%rip), %rdi      # 0x15ff0
leaq 0x1405(%rip), %rsi      # 0xf180
callq 0x2180
leaq 0x2c29(%rip), %rsi      # 0x109b0
movq %rax, %rdi
callq 0x2180
leaq 0x1393(%rip), %rsi      # 0xf129
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movl $0x259, %esi            # imm = 0x259
callq 0x22e0
leaq 0x13df(%rip), %rsi      # 0xf191
movq %rax, %rdi
callq 0x2180
leaq 0x2c35(%rip), %rsi      # 0x109f6
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movq %r14, %rsi
callq 0x98b8
movq %rax, %rdi
callq 0x20b0
xorl %edi, %edi
callq 0x21d0
nop