// File: 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:
subq $0x88, %rsp
movb %cl, %al
movq %rdi, 0x80(%rsp)
movl %esi, 0x7c(%rsp)
movl %edx, 0x78(%rsp)
andb $0x1, %al
movb %al, 0x77(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x48(%rsp)
testb $0x1, 0x80(%rax)
jne 0x54d5a
jmp 0x5512f
movq $0x0, 0x68(%rsp)
testb $0x1, 0x77(%rsp)
je 0x54d6f
jmp 0x5512f
leaq 0x3f27a(%rip), %rax     # 0x93ff0
testb $0x1, 0xdc(%rax)
jne 0x5512d
movq 0x48(%rsp), %rdi
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x58860
movq %rax, %rcx
movq 0x48(%rsp), %rax
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movq 0x8(%rax), %rdi
movslq 0x7c(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0x78(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movq %rax, 0x68(%rsp)
movl $0x0, 0x54(%rsp)
movq 0x48(%rsp), %rdi
movl 0x54(%rsp), %eax
movq %rax, 0x40(%rsp)
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
callq 0x58940
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
jae 0x54eea
movq 0x48(%rsp), %rdi
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
movl 0x54(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq (%rax), %rax
testb $0x1, 0x14(%rax)
jne 0x54e60
movl 0x54(%rsp), %eax
movq %rax, 0x58(%rsp)
jmp 0x54eea
movq 0x48(%rsp), %rdi
movq 0x60(%rsp), %rax
movq %rax, 0x38(%rsp)
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
movl 0x54(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq (%rcx), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x54ed8
movq 0x48(%rsp), %rdi
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
movl 0x54(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x60(%rsp)
movl 0x54(%rsp), %eax
movq %rax, 0x58(%rsp)
jmp 0x54eda
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x54ded
movq 0x48(%rsp), %rdi
movq 0x68(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x58860
movq 0x20(%rsp), %rcx
movq 0x48(%rsp), %rdi
movq (%rax), %rax
movq %rcx, (%rax)
leaq 0x3f086(%rip), %rax     # 0x93fb8
movq (%rax), %rax
movq %rax, 0x28(%rsp)
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x58860
movq 0x28(%rsp), %rcx
movq 0x48(%rsp), %rdi
movq (%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x68(%rsp), %rax
movb (%rax), %al
movb %al, 0x33(%rsp)
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x58860
movb 0x33(%rsp), %cl
movq 0x48(%rsp), %rdi
movq (%rax), %rax
andb $0x1, %cl
movb %cl, 0x14(%rax)
movq 0x68(%rsp), %rax
cvttsd2si 0x130(%rax), %eax
movl %eax, 0x34(%rsp)
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x58860
movl 0x34(%rsp), %ecx
movq 0x48(%rsp), %rdi
movq (%rax), %rax
movl %ecx, 0x10(%rax)
addq $0x40, %rdi
leaq 0x1d7fb(%rip), %rsi     # 0x727e8
callq 0xfa60
testb $0x1, %al
jne 0x54ffb
jmp 0x550d3
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
movq %rax, 0x18(%rsp)
leaq 0x3efdd(%rip), %rdi     # 0x93ff0
addq $0x1d0, %rdi            # imm = 0x1D0
callq 0xf190
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x55094
movq 0x68(%rsp), %rdi
addq $0xd0, %rdi
movl 0x50(%rsp), %eax
movl %eax, %esi
callq 0xf900
movq 0x48(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x14(%rsp)
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x58860
movq (%rax), %rdi
addq $0x20, %rdi
movl 0x50(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl 0x14(%rsp), %ecx
movl %ecx, (%rax)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x55003
movq 0x48(%rsp), %rdi
movq 0x68(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x8(%rsp)
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x58860
movq 0x8(%rsp), %rcx
movq (%rax), %rax
movq %rcx, 0x18(%rax)
jmp 0x5512b
movq 0x48(%rsp), %rdi
addq $0x40, %rdi
leaq 0x1d70e(%rip), %rsi     # 0x727f1
callq 0xfa60
testb $0x1, %al
jne 0x550ee
jmp 0x55129
movq 0x48(%rsp), %rdi
movq 0x68(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, (%rsp)
addq $0x88, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x58920
movq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x58860
movq (%rsp), %rcx
movq (%rax), %rax
movq %rcx, 0x18(%rax)
jmp 0x5512b
jmp 0x5512d
jmp 0x5512f
addq $0x88, %rsp
retq
nopw (%rax,%rax)