// File: gvaumour[P]cache-simulator/src/Predictor.cc
// Function: Predictor::reportMiss(unsigned long, int)
bool
Predictor::reportMiss(uint64_t block_addr , int id_set)
{

	stats_total_miss++;
	
	/* Miss classification between cold/conflict/capacity */
	if(simu_parameters.simulate_conflicts)
	{
		//DPRINTF(DebugFUcache , "Predictor::reportMiss block %#lx \n" , block_addr);
		if(m_accessedBlocks.count(block_addr) == 0)
		{
			stats_cold_miss++;
			//DPRINTF(DebugFUcache , "Predictor::reportMiss block not been accessed \n" );
		}
		else
		{
			bool find = false;
			for(unsigned i = 0; i < m_NVM_FU.size() && !find; i++)
			{
				if(m_NVM_FU[i]->addr == block_addr)
				{
					stats_nvm_conflict_miss++;
					find = true;
					break;
				}
			}
			for(unsigned i = 0; i < m_SRAM_FU.size() && !find; i++)
			{
				if(m_SRAM_FU[i]->addr == block_addr)
				{
					stats_sram_conflict_miss++;
					find = true;
					break;
				}
			}
			if(!find)
				stats_capacity_miss++;
		}
	 }
	 
	/************************************************************/
	bool sram_error = hitInSRAMMissingTags(block_addr, id_set);
	if(sram_error)
	{
		stats_SRAM_errors[stats_SRAM_errors.size()-1]++;	
		
		if(simu_parameters.enableDatasetSpilling)
		{
			int starting_set = (id_set/m_nb_MTcouters_sampling) * m_nb_MTcouters_sampling; 
			for(int i = starting_set ; i < starting_set + m_nb_MTcouters_sampling ; i++)
				m_SRAM_MT_counters[id_set]++;
		
		}
	}
	/*
	if(simu_parameters.enableDatasetSpilling)
	{	
		bool nvm_error = hitInNVMMissingTags(block_addr , id_set);
		if(nvm_error)
			m_NVM_MT_counters[id_set]++;
	}*/
	
	bool bypass_error = checkBypassTag(block_addr , id_set);
	if( bypass_error )
		stats_BP_errors[stats_BP_errors.size()-1]++;
	
	
	return sram_error;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movl %edx, 0x54(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x1d8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x1d8(%rax)
leaq 0x3d71b(%rip), %rax     # 0x93ff0
testb $0x1, 0x88(%rax)
je 0x56a7b
movq 0x30(%rsp), %rdi
addq $0x188, %rdi            # imm = 0x188
leaq 0x58(%rsp), %rsi
callq 0x3dc90
cmpq $0x0, %rax
jne 0x5691a
movq 0x30(%rsp), %rax
movq 0x1d0(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x1d0(%rax)
jmp 0x56a79
movb $0x0, 0x53(%rsp)
movl $0x0, 0x4c(%rsp)
movq 0x30(%rsp), %rdi
movl 0x4c(%rsp), %eax
movq %rax, 0x20(%rsp)
addq $0x158, %rdi            # imm = 0x158
callq 0x58940
movq 0x20(%rsp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x2f(%rsp)
jae 0x5695e
movb 0x53(%rsp), %al
xorb $-0x1, %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x56968
jmp 0x569bc
movq 0x30(%rsp), %rdi
addq $0x158, %rdi            # imm = 0x158
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq (%rax), %rax
movq (%rax), %rax
cmpq 0x58(%rsp), %rax
jne 0x569aa
movq 0x30(%rsp), %rax
movq 0x1c0(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x1c0(%rax)
movb $0x1, 0x53(%rsp)
jmp 0x569bc
jmp 0x569ac
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x56927
movl $0x0, 0x48(%rsp)
movq 0x30(%rsp), %rdi
movl 0x48(%rsp), %eax
movq %rax, 0x10(%rsp)
addq $0x170, %rdi            # imm = 0x170
callq 0x58940
movq 0x10(%rsp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x1f(%rsp)
jae 0x569fb
movb 0x53(%rsp), %al
xorb $-0x1, %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x56a05
jmp 0x56a59
movq 0x30(%rsp), %rdi
addq $0x170, %rdi            # imm = 0x170
movl 0x48(%rsp), %eax
movl %eax, %esi
callq 0x58860
movq (%rax), %rax
movq (%rax), %rax
cmpq 0x58(%rsp), %rax
jne 0x56a47
movq 0x30(%rsp), %rax
movq 0x1c8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x1c8(%rax)
movb $0x1, 0x53(%rsp)
jmp 0x56a59
jmp 0x56a49
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x569c4
testb $0x1, 0x53(%rsp)
jne 0x56a77
movq 0x30(%rsp), %rax
movq 0x1b8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x1b8(%rax)
jmp 0x56a79
jmp 0x56a7b
movq 0x30(%rsp), %rdi
movq 0x58(%rsp), %rsi
movl 0x54(%rsp), %edx
callq 0x56bc0
andb $0x1, %al
movb %al, 0x47(%rsp)
testb $0x1, 0x47(%rsp)
je 0x56b51
movq 0x30(%rsp), %rdi
movq %rdi, %rax
addq $0x1f8, %rax            # imm = 0x1F8
movq %rax, 0x8(%rsp)
addq $0x1f8, %rdi            # imm = 0x1F8
callq 0x11020
movq 0x8(%rsp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0xef90
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x3d513(%rip), %rax     # 0x93ff0
testb $0x1, 0x158(%rax)
je 0x56b4f
movq 0x30(%rsp), %rcx
movl 0x54(%rsp), %eax
cltd
idivl 0x138(%rcx)
imull 0x138(%rcx), %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x30(%rsp), %rdx
movl 0x3c(%rsp), %eax
movl 0x40(%rsp), %ecx
addl 0x138(%rdx), %ecx
cmpl %ecx, %eax
jge 0x56b4d
movq 0x30(%rsp), %rdi
addq $0xb8, %rdi
movslq 0x54(%rsp), %rsi
callq 0xfa20
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x56b09
jmp 0x56b4f
jmp 0x56b51
movq 0x30(%rsp), %rdi
movq 0x58(%rsp), %rsi
movl 0x54(%rsp), %edx
callq 0x567f0
andb $0x1, %al
movb %al, 0x3b(%rsp)
testb $0x1, 0x3b(%rsp)
je 0x56ba6
movq 0x30(%rsp), %rdi
movq %rdi, %rax
addq $0x210, %rax            # imm = 0x210
movq %rax, (%rsp)
addq $0x210, %rdi            # imm = 0x210
callq 0x11020
movq (%rsp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0xef90
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movb 0x47(%rsp), %al
andb $0x1, %al
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)