// File: gvaumour[P]cache-simulator/src/InstructionPredictor.cc
// Function: InstructionPredictor::evictPolicy(int, bool)
int
InstructionPredictor::evictPolicy(int set, bool inNVM)
{	
	//DPRINTF("InstructionPredictor::evictPolicy set %d\n" , set);
	int assoc_victim = -1;
	assert(m_replacementPolicyNVM_ptr != NULL);
	assert(m_replacementPolicySRAM_ptr != NULL);
	

	if(inNVM)
		assoc_victim = m_replacementPolicyNVM_ptr->evictPolicy(set);
	else
		assoc_victim = m_replacementPolicySRAM_ptr->evictPolicy(set);


	/* Update the status of the instruction */ 
	CacheEntry* current;
	if(inNVM)
		current = m_tableNVM[set][assoc_victim];
	else
		current = m_tableSRAM[set][assoc_victim];

	if(current->isValid){
		//DPRINTF("InstructionPredictor::evictPolicy is Valid\n");
		if( current->cost_value >= simu_parameters.cost_threshold)
		{
			pc_counters[current->m_pc]++;
			if(pc_counters[current->m_pc] == 3)
				pc_counters[current->m_pc] = 3;
		
		}
		else
		{
			pc_counters[current->m_pc]--;
			if(pc_counters[current->m_pc] < 0)
				pc_counters[current->m_pc] = 0;
		}	
	}
	
	evictRecording(set , assoc_victim , inNVM);
	
	return assoc_victim;
}

// Assembly:
subq $0x28, %rsp
movb %dl, %al
movq %rdi, 0x20(%rsp)
movl %esi, 0x1c(%rsp)
andb $0x1, %al
movb %al, 0x1b(%rsp)
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
cmpq $0x0, 0x60(%rax)
je 0x4462f
jmp 0x4464e
leaq 0x2cb6b(%rip), %rdi     # 0x711a1
leaq 0x2e80a(%rip), %rsi     # 0x72e47
movl $0x90, %edx
leaq 0x2e81a(%rip), %rcx     # 0x72e63
callq 0x5260
movq (%rsp), %rax
cmpq $0x0, 0x68(%rax)
je 0x4465b
jmp 0x4467a
leaq 0x2cb98(%rip), %rdi     # 0x711fa
leaq 0x2e7de(%rip), %rsi     # 0x72e47
movl $0x91, %edx
leaq 0x2e7ee(%rip), %rcx     # 0x72e63
callq 0x5260
testb $0x1, 0x1b(%rsp)
je 0x44699
movq (%rsp), %rax
movq 0x60(%rax), %rdi
movl 0x1c(%rsp), %esi
movq (%rdi), %rax
callq *0x20(%rax)
movl %eax, 0x14(%rsp)
jmp 0x446af
movq (%rsp), %rax
movq 0x68(%rax), %rdi
movl 0x1c(%rsp), %esi
movq (%rdi), %rax
callq *0x20(%rax)
movl %eax, 0x14(%rsp)
testb $0x1, 0x1b(%rsp)
je 0x446df
movq (%rsp), %rax
movq 0x10(%rax), %rdi
movslq 0x1c(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0x14(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x44706
movq (%rsp), %rax
movq 0x8(%rax), %rdi
movslq 0x1c(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0x14(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
testb $0x1, (%rax)
je 0x447f6
movq 0x8(%rsp), %rax
movsd 0x130(%rax), %xmm0
leaq 0x4f8c8(%rip), %rax     # 0x93ff0
cvtsi2sdl 0xbc(%rax), %xmm1
ucomisd %xmm1, %xmm0
jb 0x44795
movq (%rsp), %rdi
addq $0x280, %rdi            # imm = 0x280
movq 0x8(%rsp), %rsi
addq $0x10, %rsi
callq 0x44970
movq (%rsp), %rdi
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
addq $0x280, %rdi            # imm = 0x280
movq 0x8(%rsp), %rsi
addq $0x10, %rsi
callq 0x44970
cmpl $0x3, (%rax)
jne 0x44793
movq (%rsp), %rdi
addq $0x280, %rdi            # imm = 0x280
movq 0x8(%rsp), %rsi
addq $0x10, %rsi
callq 0x44970
movl $0x3, (%rax)
jmp 0x447f4
movq (%rsp), %rdi
addq $0x280, %rdi            # imm = 0x280
movq 0x8(%rsp), %rsi
addq $0x10, %rsi
callq 0x44970
movq (%rsp), %rdi
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
addq $0x280, %rdi            # imm = 0x280
movq 0x8(%rsp), %rsi
addq $0x10, %rsi
callq 0x44970
cmpl $0x0, (%rax)
jge 0x447f2
movq (%rsp), %rdi
addq $0x280, %rdi            # imm = 0x280
movq 0x8(%rsp), %rsi
addq $0x10, %rsi
callq 0x44970
movl $0x0, (%rax)
jmp 0x447f4
jmp 0x447f6
movq (%rsp), %rdi
movl 0x1c(%rsp), %esi
movl 0x14(%rsp), %edx
movb 0x1b(%rsp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x44b30
movl 0x14(%rsp), %eax
addq $0x28, %rsp
retq
nopl (%rax)