// File: /workspace/github_cpp_makefile_star2_O2/gvaumour[P]cache-simulator/src/Predictor.cc
// Function: Predictor::Predictor(int, int, int, int, std::vector<std::vector<CacheEntry*, std::allocator<CacheEntry*>>, std::allocator<std::vector<CacheEntry*, std::allocator<CacheEntry*>>>>&, std::vector<std::vector<CacheEntry*, std::allocator<CacheEntry*>>, std::allocator<std::vector<CacheEntry*, std::allocator<CacheEntry*>>>>&, HybridCache*)
Predictor::Predictor(int id, int nbAssoc , int nbSet, int nbNVMways, DataArray& SRAMtable , DataArray& NVMtable, HybridCache* cache) :\
	m_tableSRAM(SRAMtable), m_tableNVM(NVMtable)
{
	
	m_nb_set = nbSet;
	m_assoc = nbAssoc;
	m_nbNVMways = nbNVMways;
	m_nbSRAMways = nbAssoc - nbNVMways;
	m_ID = id;
	m_policy = cache->getPolicy();
	
	m_cpt_bypassTag = 0;
	m_replacementPolicyNVM_ptr = new LRUPolicy(m_nbNVMways , m_nb_set , NVMtable);
	m_replacementPolicySRAM_ptr = new LRUPolicy(m_nbSRAMways , m_nb_set, SRAMtable);	
	
	m_cache = cache;

	stats_NVM_errors = vector<int>(1, 0);
	stats_SRAM_errors = vector<int>(1, 0);
	stats_BP_errors = vector<int>(1,0);
	stats_MigrationErrors = vector<int>(1,0);
	
	m_trackError = (m_ID == -1);
	stats_COREerrors = 0;
	stats_WBerrors = 0;
	
	stats_beginTimeFrame = 0;
	
	m_global_PChistory = deque<uint64_t>();
	m_callee_PChistory = deque<uint64_t>();
	
	if(simu_parameters.printDebug && simu_parameters.enableDatasetSpilling)
	{
		//stats_SRAMpressure = vector< vector<bool> >();
	}
	/********************************************/ 
	if(simu_parameters.simulate_conflicts)
	{
	
		/* Allocation of array of tracking conflict/capacity miss,
		 simulation of a FU cache of the same size */ 
	
		int size_SRAM_FU =  m_nbSRAMways*nbSet;
		int size_NVM_FU =  m_nbNVMways*nbSet;
	
		m_NVM_FU.resize(size_NVM_FU);
		for(int i = 0 ; i < size_NVM_FU; i++)
		{
			m_NVM_FU[i] = new MissingTagEntry();
		}
		m_SRAM_FU.resize(size_SRAM_FU);
		for(int i = 0 ; i < size_SRAM_FU; i++)
		{
			m_SRAM_FU[i] = new MissingTagEntry();
		}
	}	 
//	/********************************************/ 
//	m_trackError = false;
//	if(m_nbNVMways != 0 && simu_parameters.size_MT_SRAMtags != 0)
//		m_trackError = true;
	

	/* Allocation of the BP missing tags array*/
	BP_missing_tags.resize(m_nb_set);
	for(int i = 0 ; i < m_nb_set; i++)
	{
		BP_missing_tags[i].resize(m_assoc);
		for(unsigned j = 0 ; j < BP_missing_tags[i].size(); j++)
		{
			BP_missing_tags[i][j] = new MissingTagEntry();
		}
	}

	m_SRAMassoc_MT_size = simu_parameters.size_MT_SRAMtags;
	m_NVMassoc_MT_size = simu_parameters.size_MT_NVMtags;
	m_nb_MTcouters_sampling = simu_parameters.nb_MTcouters_sampling;

	if(m_ID == -1){
	
		/* Allocation of the SRAM missing tags array*/
		m_SRAM_missing_tags.resize(m_nb_set);
		//m_NVM_missing_tags.resize(m_nb_set);

		for(int i = 0 ; i < m_nb_set; i++)
		{
			m_SRAM_missing_tags[i].resize(m_SRAMassoc_MT_size);
			//m_NVM_missing_tags[i].resize(m_NVMassoc_MT_size);

			for(int j = 0 ; j < m_SRAMassoc_MT_size; j++)
			{
				m_SRAM_missing_tags[i][j] = new MissingTagEntry();
				if(m_policy == "Cerebron" || m_policy == "SimplePerceptron")
					m_SRAM_missing_tags[i][j]->initFeaturesHash(m_policy);
			}
			/*
			for(int j = 0 ; j < m_NVMassoc_MT_size; j++)
			{
				m_NVM_missing_tags[i][j] = new MissingTagEntry();
				if(m_policy == "Cerebron")
					m_NVM_missing_tags[i][j]->initFeaturesHash();
			}*/
		}
		if(simu_parameters.enableDatasetSpilling)
		{
		
			m_SRAM_MT_counters = vector<uint64_t>(m_nb_set , 0);		
			m_isSRAMbusy = vector<bool>(m_nb_set , false);		

			m_NVM_MT_counters = vector<uint64_t>(m_nb_set , 0);		
			m_isNVMbusy = vector<bool>(m_nb_set , false);		
		}
	}
	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %r9, %r14
movl %ecx, %ebp
movq %rdi, %r12
movq 0x178(%rsp), %rcx
movq 0x170(%rsp), %rdi
leaq 0x1e0c0(%rip), %rax     # 0x3c9b0
movq %rax, (%r12)
movq %r9, 0x8(%r12)
movq %rdi, 0x10(%r12)
leaq 0x40(%r12), %rbx
leaq 0x50(%r12), %rax
movq %rax, 0x40(%r12)
andq $0x0, 0x48(%r12)
movb $0x0, 0x50(%r12)
andq $0x0, 0xf8(%r12)
leaq 0x88(%r12), %rax
movq %rax, 0x20(%rsp)
andl $0x0, 0x100(%r12)
leaq 0xb8(%r12), %rax
movq %rax, 0x68(%rsp)
andq $0x0, 0x120(%r12)
leaq 0xd0(%r12), %rax
movq %rax, 0x58(%rsp)
andl $0x0, 0x128(%r12)
leaq 0xe8(%r12), %rax
movq %rax, 0x60(%rsp)
andq $0x0, 0x130(%r12)
leaq 0x110(%r12), %rax
movq %rax, 0x50(%rsp)
andl $0x0, 0x190(%r12)
leaq 0x190(%r12), %rax
andq $0x0, 0x198(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x88(%r12)
movups %xmm0, 0x98(%r12)
movups %xmm0, 0xa8(%r12)
movups %xmm0, 0xb8(%r12)
movups %xmm0, 0xc8(%r12)
movups %xmm0, 0xd8(%r12)
movups %xmm0, 0xe4(%r12)
movups %xmm0, 0x108(%r12)
andl $0x0, 0x118(%r12)
movups %xmm0, 0x170(%r12)
movups %xmm0, 0x160(%r12)
movups %xmm0, 0x150(%r12)
movups %xmm0, 0x140(%r12)
andq $0x0, 0x180(%r12)
movq %rax, 0x1a0(%r12)
movq %rax, 0x1a8(%r12)
andq $0x0, 0x1b0(%r12)
leaq 0x140(%r12), %rax
movq %rax, 0x48(%rsp)
movups %xmm0, 0x1e0(%r12)
movups %xmm0, 0x1f0(%r12)
movups %xmm0, 0x200(%r12)
movups %xmm0, 0x210(%r12)
movups %xmm0, 0x220(%r12)
movups %xmm0, 0x230(%r12)
movups %xmm0, 0x240(%r12)
andq $0x0, 0x250(%r12)
movl %ebp, 0x18(%r12)
movl %edx, 0x1c(%r12)
movl %r8d, 0x20(%r12)
subl %r8d, %edx
leaq 0x158(%r12), %rax
movq %rax, 0x38(%rsp)
movl %edx, 0x24(%r12)
leaq 0x170(%r12), %rax
movq %rax, 0x30(%rsp)
movl %esi, 0x30(%r12)
leaq 0x1e0(%r12), %rax
movq %rax, 0x88(%rsp)
leaq 0x1f8(%r12), %rax
movq %rax, 0x80(%rsp)
leaq 0x210(%r12), %rax
movq %rax, 0x78(%rsp)
leaq 0x228(%r12), %rax
movq %rax, 0x70(%rsp)
leaq 0x70(%rcx), %rsi
leaq 0x90(%rsp), %rdi
movq %r12, 0x10(%rsp)
movq %rbx, 0x28(%rsp)
callq 0x5410
movq %r14, 0x40(%rsp)
leaq 0x90(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x53c0
movq %r14, %rdi
callq 0x5618
andq $0x0, 0x38(%r12)
pushq $0x30
popq %rdi
callq 0x52e0
movq %rax, %r14
movl 0x18(%r12), %r15d
movl 0x20(%r12), %r13d
leaq 0x100(%rsp), %rdi
movq 0x170(%rsp), %rsi
callq 0x20a50
leaq 0x100(%rsp), %rcx
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x2187a
movq 0x10(%rsp), %rbx
movq %r14, 0x60(%rbx)
leaq 0x100(%rsp), %rdi
callq 0x174be
pushq $0x30
popq %rdi
callq 0x52e0
movq %rax, %r14
movl 0x18(%rbx), %r15d
movl 0x24(%rbx), %r13d
leaq 0xe8(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x20a50
leaq 0xe8(%rsp), %rcx
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x2187a
movq 0x10(%rsp), %rbx
movq %r14, 0x68(%rbx)
leaq 0xe8(%rsp), %rdi
callq 0x174be
movq 0x178(%rsp), %rax
movq %rax, 0x70(%rbx)
leaq 0x18(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x90(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0xf(%rsp), %rcx
callq 0x9c8a
leaq 0x90(%rsp), %r14
movq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0xa52e
movq %r14, %rdi
callq 0xa49a
leaq 0x18(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x90(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0xf(%rsp), %rcx
callq 0x9c8a
leaq 0x90(%rsp), %r14
movq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0xa52e
movq %r14, %rdi
callq 0xa49a
leaq 0x18(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x90(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0xf(%rsp), %rcx
callq 0x9c8a
leaq 0x90(%rsp), %r14
movq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0xa52e
movq %r14, %rdi
callq 0xa49a
leaq 0x18(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x90(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0xf(%rsp), %rcx
callq 0x9c8a
leaq 0x90(%rsp), %r14
movq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0xa52e
movq %r14, %rdi
callq 0xa49a
movq 0x10(%rsp), %rax
cmpl $-0x1, 0x30(%rax)
sete 0x80(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x258(%rax)
andq $0x0, 0x268(%rax)
movaps %xmm0, 0x40(%r14)
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
leaq 0x90(%rsp), %rdi
callq 0x1c334
leaq 0x1ef30(%rip), %rdi     # 0x3dc60
leaq 0x90(%rsp), %r14
movq %r14, %rsi
callq 0x1c534
movq %r14, %rdi
callq 0x1c500
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%r14)
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
leaq 0x90(%rsp), %rdi
callq 0x1c334
leaq 0x1ef39(%rip), %rdi     # 0x3dcb0
leaq 0x90(%rsp), %r14
movq %r14, %rsi
callq 0x1c534
movq %r14, %rdi
callq 0x1c500
leaq 0x1f1ba(%rip), %rax     # 0x3df50
cmpb $0x0, 0x88(%rax)
je 0x1ee4b
movslq %ebp, %rax
movq 0x10(%rsp), %rcx
imull 0x24(%rcx), %ebp
movslq 0x20(%rcx), %r14
imulq %rax, %r14
movq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x20aaa
xorl %ebx, %ebx
testl %r14d, %r14d
cmovlel %ebx, %r14d
pushq $0x38
popq %r15
cmpq %rbx, %r14
je 0x1ee02
movq %r15, %rdi
callq 0x52e0
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0xf(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movq 0x38(%rsp), %rcx
movq (%rcx), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x1edd1
movslq %ebp, %rsi
movq 0x30(%rsp), %rdi
callq 0x20aaa
xorl %ebx, %ebx
testl %ebp, %ebp
cmovlel %ebx, %ebp
pushq $0x38
popq %r14
cmpq %rbx, %rbp
je 0x1ee4b
movq %r14, %rdi
callq 0x52e0
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0xf(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movq 0x30(%rsp), %rcx
movq (%rcx), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x1ee1a
movq 0x10(%rsp), %rax
movslq 0x18(%rax), %rsi
movq 0x48(%rsp), %rdi
callq 0x20adc
xorl %ebx, %ebx
pushq $0x38
popq %r14
leaq 0x1f0e5(%rip), %rbp     # 0x3df50
movq 0x10(%rsp), %rcx
movslq 0x18(%rcx), %rsi
cmpq %rsi, %rbx
jge 0x1eee2
imulq $0x18, %rbx, %r15
movq 0x140(%rcx), %rdi
addq %r15, %rdi
movslq 0x1c(%rcx), %rsi
callq 0x20aaa
xorl %eax, %eax
movl %eax, %r12d
movq 0x48(%rsp), %rax
movq (%rax), %r13
movq 0x8(%r13,%r15), %rax
subq (%r13,%r15), %rax
sarq $0x3, %rax
cmpq %r12, %rax
jbe 0x1eedd
movq %r14, %rdi
callq 0x52e0
addq %r15, %r13
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0xf(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movq (%r13), %rcx
movq %rax, (%rcx,%r12,8)
leal 0x1(%r12), %eax
jmp 0x1ee92
incq %rbx
jmp 0x1ee6b
movq 0xc0(%rbp), %rax
movq %rax, 0x28(%rcx)
movl 0xd8(%rbp), %eax
movl %eax, 0x138(%rcx)
cmpl $-0x1, 0x30(%rcx)
jne 0x1f0fd
movq 0x20(%rsp), %rdi
callq 0x20adc
xorl %ecx, %ecx
pushq $0x38
popq %rbp
leaq 0xb8ae(%rip), %r15      # 0x2a7c7
leaq 0x118(%rsp), %r13
movq 0x10(%rsp), %rax
movslq 0x18(%rax), %rsi
cmpq %rsi, %rcx
jge 0x1effa
movq %rcx, 0x40(%rsp)
imulq $0x18, %rcx, %rbx
movq 0x88(%rax), %rdi
addq %rbx, %rdi
movslq 0x28(%rax), %rsi
callq 0x20aaa
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
movslq 0x28(%rax), %rax
cmpq %rax, %r12
jge 0x1efed
movq %rbp, %rdi
callq 0x52e0
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0xf(%rax)
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movq (%rcx,%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x9f59
testb %al, %al
jne 0x1efb5
movq 0x28(%rsp), %rdi
leaq 0xb824(%rip), %rsi      # 0x2a7d0
callq 0x9f59
testb %al, %al
je 0x1efe5
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rbx), %rax
movq (%rax,%r12,8), %r14
movq %r13, %rdi
movq 0x28(%rsp), %rsi
callq 0x5410
movq %r14, %rdi
movq %r13, %rsi
callq 0x20b12
movq %r13, %rdi
callq 0x5618
incq %r12
jmp 0x1ef52
movq 0x40(%rsp), %rcx
incq %rcx
jmp 0x1ef21
leaq 0x1ef4f(%rip), %rax     # 0x3df50
cmpb $0x0, 0x158(%rax)
je 0x1f0fd
leaq 0x18(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x90(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x9d90
leaq 0x90(%rsp), %r14
movq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0xab1e
movq %r14, %rdi
callq 0xa4a8
movq 0x10(%rsp), %rbx
movslq 0x18(%rbx), %rsi
leaq 0x18(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x90(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x174e0
leaq 0x90(%rsp), %r14
movq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x17544
movq %r14, %rdi
callq 0xe9b4
movslq 0x18(%rbx), %rsi
leaq 0x18(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x90(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x9d90
leaq 0x90(%rsp), %r14
movq 0x58(%rsp), %rdi
movq %r14, %rsi
callq 0xab1e
movq %r14, %rdi
callq 0xa4a8
movslq 0x18(%rbx), %rsi
leaq 0x18(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x90(%rsp), %rdi
leaq 0xf(%rsp), %rcx
callq 0x174e0
leaq 0x90(%rsp), %rbx
movq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x17544
movq %rbx, %rdi
callq 0xe9b4
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
movq %rax, %rbp
leaq 0xe8(%rsp), %rdi
jmp 0x1f13f
jmp 0x1f146
movq %rax, %rbp
leaq 0x100(%rsp), %rdi
callq 0x174be
jmp 0x1f149
movq %rax, %rbp
movq %r14, %rdi
callq 0x52a0
jmp 0x1f176
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
jmp 0x1f173
movq %rax, %rbp
leaq 0x118(%rsp), %rdi
callq 0x5618
jmp 0x1f176
jmp 0x1f173
movq %rax, %rbp
movq 0x10(%rsp), %rbx
leaq 0x240(%rbx), %rdi
leaq 0xa0(%rbx), %r14
addq $0x188, %rbx            # imm = 0x188
callq 0x20b84
movq 0x70(%rsp), %rdi
callq 0xa49a
movq 0x78(%rsp), %rdi
callq 0xa49a
movq 0x80(%rsp), %rdi
callq 0xa49a
movq 0x88(%rsp), %rdi
callq 0xa49a
movq %rbx, %rdi
callq 0x178ba
movq 0x30(%rsp), %rdi
callq 0x20e5a
movq 0x38(%rsp), %rdi
callq 0x20e5a
movq 0x48(%rsp), %rdi
callq 0x20ba6
movq 0x50(%rsp), %rdi
callq 0xe9b4
movq 0x60(%rsp), %rdi
callq 0xe9b4
movq 0x58(%rsp), %rdi
callq 0xa4a8
movq 0x68(%rsp), %rdi
callq 0xa4a8
movq %r14, %rdi
callq 0x20ba6
movq 0x20(%rsp), %rdi
callq 0x20ba6
movq 0x28(%rsp), %rdi
callq 0x5618
movq %rbp, %rdi
callq 0x5570
nop