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

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

	if(!entry->isValid)
		return assoc_victim;

	allocDecision des = getDecision(entry);
	if(simu_parameters.perceptron_drawFeatureMaps)
	{
		bool global_error = false;
		
		if(( des == ALLOCATE_IN_SRAM && inNVM ) || \
			( des == ALLOCATE_IN_NVM && !inNVM ))
			global_error = true;

		int hash1 = hashing_function1(m_features_hash[0] , entry->address , entry->missPC);
		int hash2 = (m_features.size() > 1) ? hashing_function1(m_features_hash[1], entry->address , entry->missPC) : 0;
		if(global_error)
			stats_global_error[hash1][hash2].first++;
		else
			stats_global_error[hash1][hash2].second++;
		
	
		for(unsigned i = 0; i < m_features.size() ; i++)
		{
			int hash = hashing_function1( m_features_hash[i] , entry->address , entry->missPC);

			bool local_error = false;
			if( des == ALLOCATE_IN_NVM && entry->PHC_allocation_pred[i].second == ALLOCATE_IN_SRAM)
				local_error = true;
			else if(  des == ALLOCATE_IN_SRAM && entry->PHC_allocation_pred[i].second == ALLOCATE_IN_NVM )
			 	local_error = true;
			 					
			if(local_error)	
				stats_local_error[i][hash].first++;
			else 
				stats_local_error[i][hash].second++;
				
		}

	}
		
	if( (des == ALLOCATE_IN_NVM && !inNVM) || \
		(des == ALLOCATE_IN_SRAM && inNVM) )
	{
		if(simu_parameters.printDebug)
		{
			string a = inNVM ? "NVM" : "SRAM"; 
			debug_file << cpt_time << ": Eviction of 0x" << std::hex  << entry->address \
				   << std::dec << " , wrongly allocated in " << a << ", cost=" << entry->cost_value << endl;
			
			for(unsigned i = 0; i < m_features.size() ; i++)
			{
				int hash = hashing_function1( m_features_hash[i] , entry->address , entry->missPC);
				int confidence = m_features[i]->getConfidence(hash, false);
				allocDecision des = m_features[i]->getAllocDecision(hash, false);
				debug_file << "\t-Feature " << i << "\t" << str_allocDecision[des] << "\t" << confidence << endl;
			}
		}
		
		stats_wrong_alloc++;
	}
	else
		stats_good_alloc++;
		
	/* Trigger the learning process */ 
	if( entry->isLearning_weight && !simu_parameters.Cerebron_fastlearning)
		doLearning(entry, inNVM);
	

	if(entry->nbWrite == 0 && entry->nbRead == 0)
		stats_nbDeadLine[stats_nbDeadLine.size()-1]++;

	evictRecording(set , assoc_victim , inNVM);	
	return assoc_victim;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq 0x60(%rdi), %rax
testq %rax, %rax
je 0xa198
movq %rdi, %r14
movq 0x68(%rdi), %rdi
testq %rdi, %rdi
je 0xa1b7
movl %esi, %ebp
movslq %esi, %rbx
testb %dl, %dl
cmovneq %rax, %rdi
movl %edx, %r13d
movzbl %dl, %r15d
movq (%rdi), %rax
movl %ebx, %esi
callq *0x20(%rax)
movl %eax, %r12d
movq 0x8(%r14,%r15,8), %rax
movq (%rax), %rax
leaq (%rbx,%rbx,2), %rcx
movslq %r12d, %rdx
movq (%rax,%rcx,8), %rax
movq (%rax,%rdx,8), %rcx
cmpb $0x1, (%rcx)
jne 0xa183
movl %r12d, 0x4(%rsp)
leaq 0x3c3d9(%rip), %rax     # 0x45f50
cmpb $0x1, 0x226(%rax)
jne 0x9b9a
movq %rax, %rdx
movq 0x138(%rcx), %rax
cmpq 0x140(%rcx), %rax
movq %rdx, %rax
seta %sil
jmp 0x9bae
movsd 0x130(%rcx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
setbe %sil
movl 0x4(%rsp), %r12d
xorb %sil, %r13b
cmpb $0x0, 0x1cc(%rax)
movq %rcx, 0x8(%rsp)
je 0x9e0e
movb %sil, 0x3(%rsp)
movl %r13d, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq 0x288(%r14), %r12
leaq 0xd0(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq %rcx, %r13
callq 0xcbd6
movq 0x20(%r12), %rax
movq %rax, 0x20(%rbx)
movq 0x8(%r13), %rsi
movq 0x20(%r13), %rdx
movq %rbx, %rdi
callq 0x159f0
movl %eax, %ebx
movl %ebp, 0x14(%rsp)
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
je 0x9c3a
callq 0x52b0
movq 0x278(%r14), %rax
subq 0x270(%r14), %rax
xorl %ebp, %ebp
cmpq $0x9, %rax
movl 0x10(%rsp), %esi
jb 0x9cba
movq 0x288(%r14), %r12
leaq 0xa8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x28(%r12), %rsi
movq 0x30(%r12), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rbp
movq %rbp, %rdi
callq 0xcbd6
movq 0x48(%r12), %rax
movq %rax, 0x20(%rbp)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x20(%rax), %rdx
movq %rbp, %rdi
callq 0x159f0
movl %eax, %ebp
movq 0x98(%rsp), %rdi
cmpq %r15, %rdi
je 0x9cb6
callq 0x52b0
movl 0x10(%rsp), %esi
movslq %ebx, %rax
movq 0x490(%r14), %rcx
leaq (%rax,%rax,2), %rax
movslq %ebp, %rdx
movq (%rcx,%rax,8), %rax
leaq (%rax,%rdx,8), %rcx
leaq (%rax,%rdx,8), %rax
addq $0x4, %rax
testb %sil, %sil
cmovneq %rcx, %rax
incl (%rax)
movq 0x278(%r14), %rax
cmpq 0x270(%r14), %rax
je 0x9de3
movl $0x1, %r15d
leaq 0x80(%rsp), %rbx
xorl %r12d, %r12d
movq %r14, 0x20(%rsp)
movq 0x288(%r14), %rbp
leaq (%r12,%r12,4), %r13
movq %rbx, 0x70(%rsp)
movq (%rbp,%r13,8), %rsi
movq 0x8(%rbp,%r13,8), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %r14
movq %r14, %rdi
callq 0xcbd6
movq 0x20(%rbp,%r13,8), %rax
movq %rax, 0x90(%rsp)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x20(%rax), %rdx
movq %r14, %rdi
callq 0x159f0
movl %eax, %ebp
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
je 0x9d6b
callq 0x52b0
movq 0x8(%rsp), %rax
movq 0xd0(%rax), %rax
movl 0x4(%rax,%r12,8), %ecx
movslq %ebp, %rax
cmpb $0x0, 0x3(%rsp)
movq 0x20(%rsp), %r14
je 0x9da8
testl %ecx, %ecx
je 0x9dad
movq 0x478(%r14), %rcx
leaq (%r12,%r12,2), %rdx
movq (%rcx,%rdx,8), %rcx
leaq (%rcx,%rax,8), %rax
addq $0x4, %rax
jmp 0x9dc0
cmpl $0x1, %ecx
jne 0x9d8f
movq 0x478(%r14), %rcx
leaq (%r12,%r12,2), %rdx
shlq $0x3, %rax
addq (%rcx,%rdx,8), %rax
incl (%rax)
movq 0x278(%r14), %rax
subq 0x270(%r14), %rax
movl %r15d, %r12d
sarq $0x3, %rax
incl %r15d
cmpq %r12, %rax
ja 0x9d0e
movl $0x430, %esi            # imm = 0x430
cmpb $0x0, 0x10(%rsp)
movl 0x14(%rsp), %ebp
movq 0x18(%rsp), %r15
movl 0x4(%rsp), %r12d
movq 0x8(%rsp), %rcx
leaq 0x3c149(%rip), %rax     # 0x45f50
jne 0x9e1c
jmp 0xa123
movl $0x430, %esi            # imm = 0x430
testb %r13b, %r13b
je 0xa123
movl $0x438, %esi            # imm = 0x438
cmpb $0x1, (%rax)
jne 0xa123
leaq 0x2a9af(%rip), %rax     # 0x347e0
leaq 0x2a9b1(%rip), %rsi     # 0x347e9
testb %r15b, %r15b
cmovneq %rax, %rsi
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r15, %rax
negq %rax
leaq (%rsi,%rax), %rdx
addq $0x4, %rdx
leaq 0x28(%rsp), %rdi
callq 0xcc6c
movq %r15, 0x18(%rsp)
movl %ebp, 0x14(%rsp)
leaq 0x3c0a8(%rip), %rax     # 0x45f18
movq (%rax), %rsi
leaq 0x3b5e6(%rip), %rdi     # 0x45460
callq 0x51f0
movq %rax, %rbx
leaq 0x2a369(%rip), %rsi     # 0x341f2
movl $0x10, %edx
movq %rax, %rdi
callq 0x5360
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rbx,%rax)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x51f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x2a328(%rip), %rsi     # 0x34203
movl $0x18, %edx
movq %rbx, %rdi
callq 0x5360
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %rbx, %rdi
callq 0x5360
movq %rax, %rbx
leaq 0x2a318(%rip), %rsi     # 0x3421c
movl $0x7, %edx
movq %rax, %rdi
callq 0x5360
movq 0x8(%rsp), %rax
movsd 0x130(%rax), %xmm0
movq %rbx, %rdi
callq 0x5500
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq 0x278(%r14), %rax
cmpq 0x270(%r14), %rax
je 0xa0f0
movl $0x1, %ebp
xorl %r15d, %r15d
leaq 0x48(%rsp), %r12
movq 0x288(%r14), %rbx
movq %r12, %r13
leaq (%r15,%r15,4), %r12
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq (%rbx,%r12,8), %rsi
movq 0x8(%rbx,%r12,8), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xcbd6
leaq (%rbx,%r12,8), %rax
movq 0x20(%rax), %rax
movq %rax, 0x68(%rsp)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x20(%rax), %rdx
movq %r13, %rdi
callq 0x159f0
movl %eax, %ebx
movq %r13, %r12
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x9fd8
callq 0x52b0
movq 0x270(%r14), %rax
movq (%rax,%r15,8), %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x1491e
movl %eax, %r13d
movq 0x270(%r14), %rax
movq (%rax,%r15,8), %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x147cc
movl %eax, %ebx
movl $0xa, %edx
leaq 0x3b44f(%rip), %rdi     # 0x45460
leaq 0x2a20c(%rip), %rsi     # 0x34224
callq 0x5360
leaq 0x3b43c(%rip), %rdi     # 0x45460
movq %r15, %rsi
callq 0x51f0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2bc35(%rip), %rsi     # 0x35c73
callq 0x5360
movl %ebx, %eax
leaq 0x3b344(%rip), %rcx     # 0x45390
movq (%rcx,%rax,8), %rbx
testq %rbx, %rbx
je 0xa06d
movq %rbx, %rdi
callq 0x5160
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x5360
jmp 0xa087
movq (%r15), %rax
movq -0x18(%rax), %rax
movq %r15, %rdi
addq %rax, %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x5560
movl $0x1, %edx
movq %r15, %rdi
leaq 0x2bbdd(%rip), %rsi     # 0x35c73
callq 0x5360
movq %r15, %rdi
movl %r13d, %esi
callq 0x5580
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq 0x278(%r14), %rax
subq 0x270(%r14), %rax
movl %ebp, %r15d
sarq $0x3, %rax
incl %ebp
cmpq %r15, %rax
ja 0x9f71
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xa104
callq 0x52b0
movl 0x14(%rsp), %ebp
movq 0x18(%rsp), %r15
movl 0x4(%rsp), %r12d
movq 0x8(%rsp), %rcx
leaq 0x3be32(%rip), %rax     # 0x45f50
movl $0x438, %esi            # imm = 0x438
incq (%r14,%rsi)
cmpb $0x1, 0x14a(%rcx)
jne 0xa151
cmpb $0x0, 0x225(%rax)
jne 0xa151
movq %r14, %rdi
movq %rcx, %rsi
movl %r15d, %edx
callq 0x9550
movq 0x8(%rsp), %rcx
movl 0x4(%rsp), %r12d
cmpl $0x0, 0x11c(%rcx)
jne 0xa173
cmpl $0x0, 0x120(%rcx)
jne 0xa173
movq 0x3a8(%r14), %rax
incq -0x8(%rax)
movl 0x4(%rsp), %r12d
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x264ec
movl %r12d, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x29fd6(%rip), %rdi     # 0x34175
leaq 0x29ebd(%rip), %rsi     # 0x34063
leaq 0x29feb(%rip), %rcx     # 0x34198
movl $0xf0, %edx
callq 0x51d0
leaq 0x2a010(%rip), %rdi     # 0x341ce
leaq 0x29e9e(%rip), %rsi     # 0x34063
leaq 0x29fcc(%rip), %rcx     # 0x34198
movl $0xf1, %edx
callq 0x51d0
movq %rax, %r14
jmp 0xa23f
movq %rax, %r14
movq 0x98(%rsp), %rdi
jmp 0xa1f3
movq %rax, %r14
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
jne 0xa23a
jmp 0xa23f
jmp 0xa228
jmp 0xa228
movq %rax, %r14
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa22b
callq 0x52b0
jmp 0xa22b
jmp 0xa228
movq %rax, %r14
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
jne 0xa23a
jmp 0xa23f
movq %rax, %r14
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xa23f
callq 0x52b0
movq %r14, %rdi
callq 0x55a0
nop