// File: 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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x24(%rbp)
subl $0x1, %eax
je 0x26ebc
jmp 0x26e9d
movl -0x24(%rbp), %eax
subl $0x3, %eax
je 0x26fbd
jmp 0x26eab
movl -0x24(%rbp), %eax
subl $0x4, %eax
je 0x270be
jmp 0x2714b
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl -0x20(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
jne 0x26f68
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl -0x20(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x26f68
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rax
movq 0x78(%rcx), %rcx
movl -0x1c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movl -0x20(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
cmpq 0x10(%rcx), %rax
jb 0x26f68
movq -0x30(%rbp), %rax
movq 0x170(%rax), %rdi
addq $0x200, %rdi            # imm = 0x200
callq 0xbe60
movq -0x30(%rbp), %rcx
movl 0xf0(%rcx), %ecx
addq %rcx, %rax
movl 0x11580(%rip), %ecx     # 0x384d0
imulq %rcx, %rax
movl 0x115aa(%rip), %ecx     # 0x38504
cmpq %rcx, %rax
jae 0x26f68
movb $0x1, -0x1(%rbp)
jmp 0x271c9
movq -0x30(%rbp), %rax
movq 0x170(%rax), %rdi
addq $0x200, %rdi            # imm = 0x200
callq 0xbe60
movq -0x30(%rbp), %rcx
movl 0xf0(%rcx), %ecx
addq %rcx, %rax
movl 0x1153e(%rip), %ecx     # 0x384d0
imulq %rcx, %rax
movl 0x11568(%rip), %ecx     # 0x38504
cmpq %rcx, %rax
jb 0x26fb4
movq -0x30(%rbp), %rax
movl 0xec(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xec(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x271c9
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl -0x20(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
jne 0x27069
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl -0x20(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x27069
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rax
movq 0x78(%rcx), %rcx
movl -0x1c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movl -0x20(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
cmpq 0x18(%rcx), %rax
jb 0x27069
movq -0x30(%rbp), %rax
movq 0x170(%rax), %rdi
addq $0x200, %rdi            # imm = 0x200
callq 0xbe60
movq -0x30(%rbp), %rcx
movl 0xf0(%rcx), %ecx
addq %rcx, %rax
movl 0x1147f(%rip), %ecx     # 0x384d0
imulq %rcx, %rax
movl 0x114a9(%rip), %ecx     # 0x38504
cmpq %rcx, %rax
jae 0x27069
movb $0x1, -0x1(%rbp)
jmp 0x271c9
movq -0x30(%rbp), %rax
movq 0x170(%rax), %rdi
addq $0x200, %rdi            # imm = 0x200
callq 0xbe60
movq -0x30(%rbp), %rcx
movl 0xf0(%rcx), %ecx
addq %rcx, %rax
movl 0x1143d(%rip), %ecx     # 0x384d0
imulq %rcx, %rax
movl 0x11467(%rip), %ecx     # 0x38504
cmpq %rcx, %rax
jb 0x270b5
movq -0x30(%rbp), %rax
movl 0xec(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xec(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x271c9
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl -0x20(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0x27145
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rax
movq 0x78(%rcx), %rcx
movl -0x1c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
movl -0x20(%rbp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jb 0x27145
movq -0x30(%rbp), %rdi
addq $0xc8, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0xbec0
cmpl $0x0, (%rax)
jbe 0x27145
movq -0x30(%rbp), %rdi
addq $0xb0, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x17040
movq %rax, %rdi
callq 0x17100
cmpq $0x4, %rax
jae 0x27145
movb $0x1, -0x1(%rbp)
jmp 0x271c9
movb $0x0, -0x1(%rbp)
jmp 0x271c9
movq 0x10e9e(%rip), %rdi     # 0x37ff0
leaq 0x2fb7(%rip), %rsi      # 0x2a110
callq 0x31c0
movq %rax, %rdi
leaq 0x4fe2(%rip), %rsi      # 0x2c14a
callq 0x31c0
movq %rax, %rdi
leaq 0x2f42(%rip), %rsi      # 0x2a0b9
callq 0x31c0
movq %rax, %rdi
movl $0x259, %esi            # imm = 0x259
callq 0x3380
movq %rax, %rdi
leaq 0x2f8e(%rip), %rsi      # 0x2a121
callq 0x31c0
movq %rax, %rdi
leaq 0x5084(%rip), %rsi      # 0x2c226
callq 0x31c0
movq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x18f90
movq %rax, %rdi
movq 0x10deb(%rip), %rsi     # 0x37fa8
callq 0x3200
xorl %edi, %edi
callq 0x3270
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)