// File: gvaumour[P]cache-simulator/src/Perceptron.cc
// Function: PerceptronPredictor::evictPolicy(int, bool)
int PerceptronPredictor::evictPolicy(int set, bool inNVM)
{
	int assoc_victim = -1;
	assert(m_replacementPolicyNVM_ptr != NULL);
	assert(m_replacementPolicySRAM_ptr != NULL);

	CacheEntry* current = NULL;
	if(inNVM)
	{	
		assoc_victim = m_replacementPolicyNVM_ptr->evictPolicy(set);
		current = m_tableNVM[set][assoc_victim];
	}
	else
	{
		assoc_victim = m_replacementPolicySRAM_ptr->evictPolicy(set);
		current = m_tableSRAM[set][assoc_victim];		
	}

	if(current->isValid && current->isLearning)
	{
		for(unsigned i =  0 ; i < m_BP_features.size() ; i++)
		{
			if(current->predictedReused[i] || current->perceptron_BPpred[i] < simu_parameters.perceptron_bypass_learning)
			{
				int hash = m_BP_features_hash[i](current->address , current->m_pc);
 				m_BP_features[i]->increaseConfidence(hash);
			}
		}
		
		if(current->nbWrite == 0 && current->nbRead == 0)
			stats_nbDeadLine[stats_nbDeadLine.size()-1]++;
	}
	
	evictRecording(set , assoc_victim , inNVM);	
	return assoc_victim;
}

// Assembly:
subq $0x68, %rsp
movb %dl, %al
movq %rdi, 0x60(%rsp)
movl %esi, 0x5c(%rsp)
andb $0x1, %al
movb %al, 0x5b(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
cmpq $0x0, 0x60(%rax)
je 0x52660
jmp 0x5267f
leaq 0x1eb3a(%rip), %rdi     # 0x711a1
leaq 0x20dfa(%rip), %rsi     # 0x73468
movl $0x17f, %edx            # imm = 0x17F
leaq 0x20e2d(%rip), %rcx     # 0x734a7
callq 0x5260
movq 0x20(%rsp), %rax
cmpq $0x0, 0x68(%rax)
je 0x5268d
jmp 0x526ac
leaq 0x1eb66(%rip), %rdi     # 0x711fa
leaq 0x20dcd(%rip), %rsi     # 0x73468
movl $0x180, %edx            # imm = 0x180
leaq 0x20e00(%rip), %rcx     # 0x734a7
callq 0x5260
movq $0x0, 0x48(%rsp)
testb $0x1, 0x5b(%rsp)
je 0x526ff
movq 0x20(%rsp), %rax
movq 0x60(%rax), %rdi
movl 0x5c(%rsp), %esi
movq (%rdi), %rax
callq *0x20(%rax)
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x54(%rsp)
movq 0x10(%rax), %rdi
movslq 0x5c(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0x54(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x52740
movq 0x20(%rsp), %rax
movq 0x68(%rax), %rdi
movl 0x5c(%rsp), %esi
movq (%rdi), %rax
callq *0x20(%rax)
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x54(%rsp)
movq 0x8(%rax), %rdi
movslq 0x5c(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0x54(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
testb $0x1, (%rax)
je 0x528be
movq 0x48(%rsp), %rax
testb $0x1, 0x148(%rax)
je 0x528be
movl $0x0, 0x44(%rsp)
movq 0x20(%rsp), %rdi
movl 0x44(%rsp), %eax
movq %rax, 0x18(%rsp)
addq $0x2b8, %rdi            # imm = 0x2B8
callq 0xf840
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x52866
movq 0x48(%rsp), %rdi
addq $0xa8, %rdi
movl 0x44(%rsp), %eax
movl %eax, %esi
callq 0xfa90
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
leaq 0x30(%rsp), %rdi
callq 0xfaf0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, 0x17(%rsp)
jne 0x527f5
movq 0x48(%rsp), %rdi
addq $0x48, %rdi
movl 0x44(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl (%rax), %eax
leaq 0x41808(%rip), %rcx     # 0x93ff0
cmpl 0x1bc(%rcx), %eax
setl %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x527ff
jmp 0x52854
movq 0x20(%rsp), %rdi
addq $0x2d0, %rdi            # imm = 0x2D0
movl 0x44(%rsp), %eax
movl %eax, %esi
callq 0x4d780
movq (%rax), %rax
movq 0x48(%rsp), %rcx
movq 0x8(%rcx), %rdi
movq 0x48(%rsp), %rcx
movq 0x10(%rcx), %rsi
callq *%rax
movq 0x20(%rsp), %rdi
movl %eax, 0x2c(%rsp)
addq $0x2b8, %rdi            # imm = 0x2B8
movl 0x44(%rsp), %eax
movl %eax, %esi
callq 0xf8c0
movq (%rax), %rdi
movl 0x2c(%rsp), %esi
callq 0x2d600
jmp 0x52856
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x52768
movq 0x48(%rsp), %rax
cmpl $0x0, 0x11c(%rax)
jne 0x528bc
movq 0x48(%rsp), %rax
cmpl $0x0, 0x120(%rax)
jne 0x528bc
movq 0x20(%rsp), %rdi
movq %rdi, %rax
addq $0x368, %rax            # imm = 0x368
movq %rax, 0x8(%rsp)
addq $0x368, %rdi            # imm = 0x368
callq 0xfa40
movq 0x8(%rsp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0xfa20
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x528be
movq 0x20(%rsp), %rdi
movl 0x5c(%rsp), %esi
movl 0x54(%rsp), %edx
movb 0x5b(%rsp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x528f0
movl 0x54(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)