// File: /workspace/github_cpp_makefile_star2_O2/gvaumour[P]cache-simulator/src/PHC.cc
// Function: PHCPredictor::PHCPredictor(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*)
PHCPredictor::PHCPredictor(int id, int nbAssoc , int nbSet, int nbNVMways, DataArray& SRAMtable, DataArray& NVMtable, HybridCache* cache) :\
	Predictor(id, nbAssoc , nbSet , nbNVMways , SRAMtable , NVMtable , cache)
{	
	m_tableSize = simu_parameters.perceptron_table_size;

	m_features.clear();

	m_criterias_names = simu_parameters.PHC_features;

	m_need_callee_file = false;
	
	m_enableAllocation = true;
	if(simu_parameters.nvm_assoc == 0 || simu_parameters.sram_assoc == 0)
		m_enableAllocation = false;
	
	initFeatures();
	
	cout <<  "\tFeatures used : ";
	for(auto p : simu_parameters.PHC_features)
		cout << p << ",";
	cout << endl;


	
	if(m_need_callee_file)
	{
		m_callee_map = map<uint64_t,int>();
		load_callee_file();
	}
		
	m_costAccess = vector< vector<int> >(NUM_RW_TYPE , vector<int>(NUM_RD_TYPE, 0));
	m_costAccess[true][RD_MEDIUM] = simu_parameters.PHC_cost_mediumWrite;
	m_costAccess[false][RD_MEDIUM] = simu_parameters.PHC_cost_mediumRead;
	m_costAccess[true][RD_SHORT] = simu_parameters.PHC_cost_shortWrite;
	m_costAccess[false][RD_SHORT] = simu_parameters.PHC_cost_shortRead;
	
//	m_costAccess[true][RD_NOT_ACCURATE] = -30;
//	m_costAccess[false][RD_NOT_ACCURATE] = -30;
		
	
	miss_counter = 0;
	m_cpt = 0;

	m_global_PChistory = deque<uint64_t>();
	m_callee_PChistory = deque<uint64_t>();

	stats_nbBPrequests = vector<uint64_t>(1, 0);
	stats_nbDeadLine = vector<uint64_t>(1, 0);
	stats_missCounter = vector<int>();
	stats_histo_value = vector<vector<vector<int> > >( m_features.size() , vector<vector<int> >(m_tableSize, vector<int>()));
	stats_access_class = vector<vector<int> >(NUM_RD_TYPE ,  vector<int>(2, 0));	

	stats_local_error = vector< vector<int> >(simu_parameters.PHC_features.size() , vector<int>(m_tableSize, 0));
	stats_global_error = vector< vector<int> >(m_tableSize , vector<int>(m_tableSize , 0 ));
	
	if(simu_parameters.perceptron_compute_variance)
	{
		stats_variances_buffer = vector<double>();
		stats_variances = vector<double>();
	}	

	stats_allocate = 0;
	stats_nbMiss = 0;
	stats_nbHits = 0;

	stats_update_learning = 0, stats_update = 0;
	stats_allocate = 0, stats_allocate_learning = 0;
	stats_prediction_preemptive = 0 , stats_prediction_confident = 0;
	stats_cptLearningSRAMerror = 0, stats_cptSRAMerror = 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, %rbx
movaps 0x130(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1e8c0
leaq 0x228ac(%rip), %rax     # 0x3c8a0
movq %rax, (%rbx)
leaq 0x2a0(%rbx), %rdi
leaq 0x2b8(%rbx), %rax
movq %rax, 0x98(%rsp)
leaq 0x2e8(%rbx), %rax
movq %rax, 0x58(%rsp)
andl $0x0, 0x2f0(%rbx)
leaq 0x2f0(%rbx), %rax
andq $0x0, 0x2f8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x270(%rbx)
movups %xmm0, 0x280(%rbx)
movups %xmm0, 0x290(%rbx)
movups %xmm0, 0x2a0(%rbx)
movups %xmm0, 0x2b0(%rbx)
movups %xmm0, 0x2c0(%rbx)
movq %rax, 0x300(%rbx)
movq %rax, 0x308(%rbx)
andq $0x0, 0x310(%rbx)
leaq 0x320(%rbx), %rax
movq %rax, 0x90(%rsp)
leaq 0x338(%rbx), %rax
movq %rax, 0x88(%rsp)
leaq 0x350(%rbx), %rax
movq %rax, 0x80(%rsp)
leaq 0x378(%rbx), %rax
movq %rax, 0x48(%rsp)
leaq 0x390(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x3e8(%rbx), %rax
movq %rax, 0x78(%rsp)
leaq 0x400(%rbx), %rax
movq %rax, 0x68(%rsp)
leaq 0x418(%rbx), %rax
movq %rax, 0x60(%rsp)
leaq 0x430(%rbx), %rax
movq %rax, 0x70(%rsp)
movups %xmm0, 0x320(%rbx)
movups %xmm0, 0x330(%rbx)
movups %xmm0, 0x340(%rbx)
movups %xmm0, 0x350(%rbx)
andq $0x0, 0x360(%rbx)
movups %xmm0, 0x378(%rbx)
movups %xmm0, 0x388(%rbx)
movups %xmm0, 0x398(%rbx)
movups %xmm0, 0x438(%rbx)
movups %xmm0, 0x428(%rbx)
movups %xmm0, 0x418(%rbx)
movups %xmm0, 0x408(%rbx)
movups %xmm0, 0x3f8(%rbx)
movups %xmm0, 0x3e8(%rbx)
leaq 0x23dff(%rip), %rcx     # 0x3df50
movl 0x1c8(%rcx), %eax
movl %eax, 0x2d0(%rbx)
leaq 0x1d0(%rcx), %rsi
movq %rdi, 0xf0(%rsp)
callq 0x9bc0
movb $0x0, 0x2e0(%rbx)
leaq 0x23dd1(%rip), %rcx     # 0x3df50
cmpl $0x0, 0x40(%rcx)
setne %al
cmpl $0x0, 0x38(%rcx)
setne %cl
andb %al, %cl
movb %cl, 0x318(%rbx)
movq %rbx, %rdi
callq 0x1a7ae
movq 0x22e2c(%rip), %rdi     # 0x3cfd0
leaq 0xee75(%rip), %rsi      # 0x29020
callq 0x52c0
leaq 0x23d99(%rip), %rax     # 0x3df50
movq 0x1d0(%rax), %rbp
movq 0x1d8(%rax), %r13
leaq 0xa0(%rsp), %r14
movq 0x22dfc(%rip), %r15     # 0x3cfd0
leaq 0xee57(%rip), %r12      # 0x29032
cmpq %r13, %rbp
je 0x1a20f
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5410
movq %r15, %rdi
movq %r14, %rsi
callq 0x5290
movq %rax, %rdi
movq %r12, %rsi
callq 0x52c0
movq %r14, %rdi
callq 0x5618
addq $0x20, %rbp
jmp 0x1a1db
movq 0x22dba(%rip), %rdi     # 0x3cfd0
callq 0x5190
cmpb $0x1, 0x2e0(%rbx)
jne 0x1a26a
leaq 0xa8(%rsp), %rax
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0xa0(%rsp), %r14
movq 0x58(%rsp), %rdi
movq %r14, %rsi
callq 0xa19a
movq %r14, %rdi
callq 0xa27e
movq %rbx, %rdi
callq 0x1abde
leaq 0x30(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x18(%rsp), %rdi
pushq $0x3
popq %rsi
leaq 0x17(%rsp), %rcx
callq 0x9c8a
leaq 0xa0(%rsp), %rdi
pushq $0x5
popq %rsi
leaq 0x18(%rsp), %rdx
leaq 0x16(%rsp), %rcx
callq 0x9ce0
leaq 0xa0(%rsp), %r14
movq 0x98(%rsp), %rdi
movq %r14, %rsi
callq 0xa710
movq %r14, %rdi
callq 0x9d36
leaq 0x18(%rsp), %rdi
callq 0xa49a
leaq 0x23c81(%rip), %rsi     # 0x3df50
movl 0x1f0(%rsi), %eax
movq 0x2b8(%rbx), %rcx
movq 0x18(%rcx), %rdx
movl %eax, 0x4(%rdx)
movl 0x1ec(%rsi), %eax
movq (%rcx), %rcx
movl %eax, 0x4(%rcx)
movl 0x1f4(%rsi), %eax
movl %eax, (%rdx)
movl 0x1f8(%rsi), %eax
movl %eax, (%rcx)
leaq 0x23e9a(%rip), %rax     # 0x3e1a0
andl $0x0, (%rax)
andq $0x0, 0x2d8(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%r14)
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
leaq 0xa0(%rsp), %rdi
callq 0x1c334
leaq 0x237d0(%rip), %rdi     # 0x3db10
leaq 0xa0(%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 0xa0(%rsp), %rdi
callq 0x1c334
leaq 0x237d9(%rip), %rdi     # 0x3db60
leaq 0xa0(%rsp), %r14
movq %r14, %rsi
callq 0x1c534
movq %r14, %rdi
callq 0x1c500
leaq 0x18(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0xa0(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x30(%rsp), %rcx
callq 0x9d90
leaq 0xa0(%rsp), %r14
movq 0x90(%rsp), %rdi
movq %r14, %rsi
callq 0xab1e
movq %r14, %rdi
callq 0xa4a8
leaq 0x18(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0xa0(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x30(%rsp), %rcx
callq 0x9d90
leaq 0xa0(%rsp), %r14
movq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0xab1e
movq %r14, %rdi
callq 0xa4a8
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
leaq 0xa0(%rsp), %r14
movq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0xa52e
movq %r14, %rdi
callq 0xa49a
movq 0x270(%rbx), %r15
movq 0x278(%rbx), %r14
movslq 0x2d0(%rbx), %rsi
leaq 0x30(%rsp), %rdx
xorps %xmm0, %xmm0
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x18(%rsp), %rdi
leaq 0x17(%rsp), %rcx
callq 0x9ce0
subq %r15, %r14
sarq $0x3, %r14
leaq 0xa0(%rsp), %rdi
leaq 0x18(%rsp), %rdx
leaq 0x16(%rsp), %rcx
movq %r14, %rsi
callq 0x1c298
leaq 0xa0(%rsp), %r14
movq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0x1c738
movq %r14, %rdi
callq 0x9eb4
leaq 0x18(%rsp), %rdi
callq 0x9d36
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0xa49a
andl $0x0, (%r14)
leaq 0x18(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0x30(%rsp), %rdx
leaq 0x17(%rsp), %rcx
callq 0x9c8a
leaq 0xa0(%rsp), %rdi
pushq $0x3
popq %rsi
leaq 0x18(%rsp), %rdx
leaq 0x16(%rsp), %rcx
callq 0x9ce0
leaq 0xa0(%rsp), %r14
movq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0xa710
movq %r14, %rdi
callq 0x9d36
leaq 0x18(%rsp), %rdi
callq 0xa49a
leaq 0x23a1d(%rip), %rax     # 0x3df50
movq 0x1d0(%rax), %r15
movq 0x1d8(%rax), %r14
movslq 0x2d0(%rbx), %rsi
leaq 0x30(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x18(%rsp), %rdi
leaq 0x17(%rsp), %rcx
callq 0x9c8a
subq %r15, %r14
sarq $0x5, %r14
leaq 0xa0(%rsp), %rdi
leaq 0x18(%rsp), %rdx
leaq 0x16(%rsp), %rcx
movq %r14, %rsi
callq 0x9ce0
leaq 0xa0(%rsp), %r14
movq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0xa710
movq %r14, %rdi
callq 0x9d36
leaq 0x18(%rsp), %rdi
callq 0xa49a
movslq 0x2d0(%rbx), %r14
leaq 0x30(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x18(%rsp), %rdi
leaq 0x17(%rsp), %rcx
movq %r14, %rsi
callq 0x9c8a
leaq 0xa0(%rsp), %rdi
leaq 0x18(%rsp), %rdx
leaq 0x16(%rsp), %rcx
movq %r14, %rsi
callq 0x9ce0
leaq 0xa0(%rsp), %r14
movq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0xa710
movq %r14, %rdi
callq 0x9d36
leaq 0x18(%rsp), %rdi
callq 0xa49a
leaq 0x23940(%rip), %rax     # 0x3df50
cmpb $0x1, 0x1cd(%rax)
jne 0x1a66b
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %r14
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
movq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0xadd2
movq %r14, %rdi
callq 0xa7d8
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
leaq 0xa0(%rsp), %r14
movq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0xadd2
movq %r14, %rdi
callq 0xa7d8
xorps %xmm0, %xmm0
movups %xmm0, 0x368(%rbx)
movups %xmm0, 0x3a8(%rbx)
movups %xmm0, 0x3b8(%rbx)
movups %xmm0, 0x3c8(%rbx)
movups %xmm0, 0x3d8(%rbx)
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1a6d0
jmp 0x1a6e3
jmp 0x1a6d0
jmp 0x1a6e3
jmp 0x1a6d0
jmp 0x1a6e3
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x9d36
jmp 0x1a6c1
movq %rax, %r14
leaq 0x30(%rsp), %rdi
jmp 0x1a6d8
jmp 0x1a6e3
jmp 0x1a6e3
jmp 0x1a6e3
jmp 0x1a6e3
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0xa49a
jmp 0x1a6f8
jmp 0x1a6e3
jmp 0x1a6e3
movq %rax, %r14
jmp 0x1a6f8
movq %rax, %r14
leaq 0xa0(%rsp), %rdi
callq 0x5618
leaq 0x270(%rbx), %r15
leaq 0x288(%rbx), %r12
movq 0x70(%rsp), %rdi
callq 0x9d36
movq 0x60(%rsp), %rdi
callq 0x9d36
movq 0x68(%rsp), %rdi
callq 0x9d36
movq 0x78(%rsp), %rdi
callq 0x9eb4
movq 0x50(%rsp), %rdi
callq 0xa7d8
movq 0x48(%rsp), %rdi
callq 0xa7d8
movq 0x80(%rsp), %rdi
callq 0xa49a
movq 0x88(%rsp), %rdi
callq 0xa4a8
movq 0x90(%rsp), %rdi
callq 0xa4a8
movq 0x58(%rsp), %rdi
callq 0xa27e
movq 0x98(%rsp), %rdi
callq 0x9d36
movq 0xf0(%rsp), %rdi
callq 0x9ef6
movq %r12, %rdi
callq 0x1c526
movq %r15, %rdi
callq 0xa762
movq %rbx, %rdi
callq 0x2087a
movq %r14, %rdi
callq 0x5570
nop