// File: /workspace/github_cpp_makefile_star2_O2/gvaumour[P]cache-simulator/src/Predictor.cc
// Function: Predictor::evictRecording(int, int, bool)
void  
Predictor::evictRecording(int set, int assoc_victim , bool inNVM)
{
	if(!m_trackError)
		return;

	CacheEntry* current=NULL;
		
	if(inNVM)
	{
		//Checking NVM MT tags
		//Choose the oldest victim for the missing tags to replace from the current one 	
		/*
		uint64_t cpt_longestime = m_NVM_missing_tags[set][0]->last_time_touched;
		uint64_t index_victim = 0;
		current = m_tableNVM[set][assoc_victim];
		for(unsigned i = 0 ; i < m_NVM_missing_tags[set].size(); i++)
		{
			if(!m_NVM_missing_tags[set][i]->isValid)
			{
				index_victim = i;
				break;
			}	
		
			if(cpt_longestime > m_NVM_missing_tags[set][i]->last_time_touched){
				cpt_longestime = m_NVM_missing_tags[set][i]->last_time_touched; 
				index_victim = i;
			}	
		}

		m_NVM_missing_tags[set][index_victim]->addr = current->address;
		m_NVM_missing_tags[set][index_victim]->last_time_touched = cpt_time;
		m_NVM_missing_tags[set][index_victim]->isValid = current->isValid;
		m_NVM_missing_tags[set][index_victim]->cost_value = current->cost_value;
		*/
	}
	else
	{
		//Checking SRAM MT tags
		//Choose the oldest victim for the missing tags to replace from the current one 	
		if(!simu_parameters.enableFullSRAMtraffic)
		{
			uint64_t cpt_longestime = m_SRAM_missing_tags[set][0]->last_time_touched;
			uint64_t index_victim = 0;
			current = m_tableSRAM[set][assoc_victim];
		
			for(unsigned i = 0 ; i < m_SRAM_missing_tags[set].size(); i++)
			{
				if(!m_SRAM_missing_tags[set][i]->isValid)
				{
					index_victim = i;
					break;
				}	
		
				if(cpt_longestime > m_SRAM_missing_tags[set][i]->last_time_touched){
					cpt_longestime = m_SRAM_missing_tags[set][i]->last_time_touched; 
					index_victim = i;
				}	
			}

			m_SRAM_missing_tags[set][index_victim]->addr = current->address;
			m_SRAM_missing_tags[set][index_victim]->last_time_touched = cpt_time;
			m_SRAM_missing_tags[set][index_victim]->isValid = current->isValid;
			m_SRAM_missing_tags[set][index_victim]->cost_value = current->cost_value;
		
			if(m_policy == "Cerebron")
			{
				for(unsigned i = 0 ; i < simu_parameters.PHC_features.size() ; i++)
					m_SRAM_missing_tags[set][index_victim]->features_hash[i] = current->PHC_allocation_pred[i].first;
		
				m_SRAM_missing_tags[set][index_victim]->missPC = current->missPC;
			}		
			else if(m_policy == "SimplePerceptron")
			{
				//for(unsigned i = 0 ; i < simu_parameters.simple_perceptron_features.size() ; i++)
				//	m_SRAM_missing_tags[set][index_victim]->features_hash[i] = current->simple_perceptron_hash[i];
				
				m_SRAM_missing_tags[set][index_victim]->missPC = current->missPC;
			}		
		}
	}
}

// Assembly:
movb 0x80(%rdi), %al
xorb $0x1, %al
orb %cl, %al
jne 0x1f3a0
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x1ece6(%rip), %rbp     # 0x3df50
cmpb $0x0, 0xdc(%rbp)
jne 0x1f392
movq %rdi, %rbx
movslq %esi, %rax
movq 0x8(%rdi), %rdi
movq 0x88(%rbx), %rcx
imulq $0x18, %rax, %r15
movq (%rcx,%r15), %rax
movq 0x8(%rcx,%r15), %rcx
movq (%rax), %rsi
movq 0x8(%rsi), %rsi
movq (%rdi), %rdi
movslq %edx, %rdx
movq (%rdi,%r15), %rdi
movq (%rdi,%rdx,8), %r12
subq %rax, %rcx
sarq $0x3, %rcx
xorl %r13d, %r13d
xorl %edx, %edx
movl %edx, %edi
cmpq %rdi, %rcx
jbe 0x1f2db
movq (%rax,%rdi,8), %rdx
cmpb $0x1, 0x14(%rdx)
jne 0x1f2e1
movq 0x8(%rdx), %rdx
cmpq %rdx, %rsi
cmovaeq %rdx, %rsi
cmovaq %rdi, %r13
leal 0x1(%rdi), %edx
jmp 0x1f2b6
movq (%rax,%r13,8), %rdx
jmp 0x1f2e4
movq %rdi, %r13
movq 0x8(%r12), %rax
movq %rax, (%rdx)
leaq 0x1ec25(%rip), %rax     # 0x3df18
movq (%rax), %rax
movq %rax, 0x8(%rdx)
movb (%r12), %al
movb %al, 0x14(%rdx)
cvttsd2si 0x130(%r12), %eax
movl %eax, 0x10(%rdx)
leaq 0x40(%rbx), %r14
leaq 0xb4ae(%rip), %rsi      # 0x2a7c7
movq %r14, %rdi
callq 0x9f59
testb %al, %al
je 0x1f367
movq 0x1d8(%rbp), %rax
subq 0x1d0(%rbp), %rax
sarq $0x5, %rax
movq 0x88(%rbx), %rcx
addq %r15, %rcx
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, %rax
jbe 0x1f37a
movq 0xd0(%r12), %rsi
movl (%rsi,%rdx,8), %esi
movq (%rcx), %rdi
movq (%rdi,%r13,8), %rdi
movq 0x20(%rdi), %rdi
movl %esi, (%rdi,%rdx,4)
incl %edx
jmp 0x1f343
leaq 0xb462(%rip), %rsi      # 0x2a7d0
movq %r14, %rdi
callq 0x9f59
testb %al, %al
je 0x1f392
movq 0x20(%r12), %rax
movq 0x88(%rbx), %rcx
movq (%rcx,%r15), %rcx
movq (%rcx,%r13,8), %rcx
movq %rax, 0x18(%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop