// File: /workspace/github_cpp_makefile_star2_O1/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 0x25c7c
leaq 0x24da0(%rip), %rax     # 0x44858
movq %rax, (%rbx)
leaq 0x2a0(%rbx), %rdi
leaq 0x2f0(%rbx), %rcx
movl $0x0, 0x2f0(%rbx)
xorl %eax, %eax
movq %rax, 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 %rcx, 0x300(%rbx)
movq %rcx, 0xf0(%rsp)
movq %rcx, 0x308(%rbx)
movq %rax, 0x310(%rbx)
movups %xmm0, 0x320(%rbx)
movups %xmm0, 0x330(%rbx)
movups %xmm0, 0x340(%rbx)
movups %xmm0, 0x350(%rbx)
movq %rax, 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 0x263c1(%rip), %r15     # 0x45f50
movl 0x1c8(%r15), %eax
movl %eax, 0x2d0(%rbx)
movq 0x270(%rbx), %rax
cmpq %rax, 0x278(%rbx)
je 0x1fbb3
movq %rax, 0x278(%rbx)
leaq 0x2e8(%rbx), %rax
movq %rax, 0x70(%rsp)
leaq 0x350(%rbx), %rax
movq %rax, 0x78(%rsp)
leaq 0x378(%rbx), %rax
movq %rax, 0x60(%rsp)
leaq 0x390(%rbx), %rax
movq %rax, 0x68(%rsp)
movl $0x1d0, %esi            # imm = 0x1D0
addq 0x253b1(%rip), %rsi     # 0x44fa0
movq %rdi, 0xe8(%rsp)
movq %rbx, 0x38(%rsp)
callq 0xc46a
movb $0x0, 0x2e0(%rbx)
movb $0x1, 0x318(%rbx)
cmpl $0x0, 0x40(%r15)
setne %al
cmpl $0x0, 0x38(%r15)
setne %cl
andb %al, %cl
movb %cl, 0x318(%rbx)
movq %rbx, %rdi
callq 0x20536
movq 0x2539a(%rip), %rdi     # 0x44fd0
leaq 0x143f3(%rip), %rsi     # 0x34030
movl $0x11, %edx
callq 0x5350
movq 0x1d0(%r15), %r14
movq 0x1d8(%r15), %rbx
cmpq %rbx, %r14
je 0x1fcd5
leaq 0x90(%rsp), %r12
leaq 0x80(%rsp), %r13
movq 0x2535f(%rip), %rbp     # 0x44fd0
leaq 0x143ca(%rip), %r15     # 0x34042
movq %r12, 0x80(%rsp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xcc1c
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %rbp, %rdi
callq 0x5350
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x5350
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0x1fccc
callq 0x52a0
addq $0x20, %r14
cmpq %rbx, %r14
jne 0x1fc78
movq 0x252f4(%rip), %rdi     # 0x44fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
movq 0x38(%rsp), %r12
callq 0x52b0
leaq 0x26257(%rip), %r13     # 0x45f50
movsbl %al, %esi
movq 0x252cd(%rip), %rdi     # 0x44fd0
callq 0x5030
movq %rax, %rdi
callq 0x51f0
cmpb $0x1, 0x2e0(%r12)
jne 0x1fdd4
leaq 0x88(%rsp), %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x8(%rbx)
movaps %xmm0, 0x18(%rbx)
movaps %xmm0, -0x8(%rbx)
movq %rbx, 0x10(%rbx)
movq %rbx, 0x18(%rbx)
movq $0x0, 0x20(%rbx)
movq 0x70(%rsp), %rdi
callq 0xc9fc
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1fdbf
movl 0x88(%rsp), %ecx
movl %ecx, 0x2f0(%r12)
movq %rax, 0x2f8(%r12)
movups 0x98(%rsp), %xmm0
movups %xmm0, 0x300(%r12)
movq 0xf0(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0xa8(%rsp), %rax
movq %rax, 0x310(%r12)
xorl %eax, %eax
movq %rax, 0x90(%rsp)
movq %rbx, 0x98(%rsp)
movq %rbx, 0xa0(%rsp)
movq %rax, 0xa8(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xca60
movq %r12, %rdi
callq 0x20abe
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl $0xc, %edi
callq 0x52e0
leaq 0x20(%rsp), %rdx
movq %rax, (%rdx)
movq %rax, 0x8(%rdx)
movq %rax, %rcx
addq $0xc, %rcx
movq %rcx, 0x10(%rdx)
movl $0x0, 0x8(%rax)
movq $0x0, (%rax)
movq %rcx, 0x8(%rdx)
leaq 0x40(%rsp), %rdi
leaq 0xd0(%rsp), %rcx
movl $0x5, %esi
callq 0xc5b2
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups 0x2b8(%r12), %xmm0
movq 0x2c8(%r12), %rax
leaq 0x40(%rsp), %r15
movaps (%r15), %xmm1
movups %xmm1, 0x2b8(%r12)
movq 0x10(%r15), %rcx
movq %rcx, 0x2c8(%r12)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movaps %xmm1, (%r15)
movq %rcx, 0x10(%r15)
callq 0xc642
movq %r15, %rdi
callq 0xc642
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1fea6
callq 0x52a0
movl 0x1f0(%r13), %eax
movq 0x2b8(%r12), %rcx
movq 0x18(%rcx), %rdx
movl %eax, 0x4(%rdx)
movl 0x1ec(%r13), %eax
movq (%rcx), %rcx
movl %eax, 0x4(%rcx)
movl 0x1f4(%r13), %eax
movl %eax, (%rdx)
movl 0x1f8(%r13), %eax
movl %eax, (%rcx)
leaq 0x262be(%rip), %rax     # 0x461a0
movl $0x0, (%rax)
movq $0x0, 0x2d8(%r12)
leaq 0x80(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0x22d68
leaq 0x25bf0(%rip), %rdi     # 0x45b10
leaq 0x80(%rsp), %r15
movq %r15, %rsi
callq 0x22f14
movq %r15, %rdi
callq 0x22ed0
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
callq 0x22d68
leaq 0x25bf7(%rip), %rdi     # 0x45b60
leaq 0x80(%rsp), %r15
movq %r15, %rsi
callq 0x22f14
movq %r15, %rdi
callq 0x22ed0
movl $0x8, %edi
callq 0x52e0
movq $0x0, (%rax)
movq %rax, %rcx
addq $0x8, %rcx
movq 0x320(%r12), %rdi
movq %rax, 0x320(%r12)
movq %rcx, 0x328(%r12)
movq %rcx, 0x330(%r12)
testq %rdi, %rdi
je 0x1ffc3
callq 0x52a0
movl $0x8, %edi
callq 0x52e0
movq $0x0, (%rax)
movq %rax, %rcx
addq $0x8, %rcx
movq 0x338(%r12), %rdi
movq %rax, 0x338(%r12)
movq %rcx, 0x340(%r12)
movq %rcx, 0x348(%r12)
testq %rdi, %rdi
je 0x20005
callq 0x52a0
movq 0x78(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x20028
callq 0x52a0
xorps %xmm0, %xmm0
movq 0x270(%r12), %rbx
movq 0x278(%r12), %r15
movslq 0x2d0(%r12), %rsi
leaq 0xd0(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
callq 0xc5b2
subq %rbx, %r15
sarq $0x3, %r15
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
movq %r15, %rsi
callq 0x22c72
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups 0x3e8(%r12), %xmm0
movq 0x3f8(%r12), %rax
leaq 0x40(%rsp), %r15
movaps (%r15), %xmm1
movups %xmm1, 0x3e8(%r12)
movq 0x10(%r15), %rcx
movq %rcx, 0x3f8(%r12)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movaps %xmm1, (%r15)
movq %rcx, 0x10(%r15)
callq 0xc7c6
movq %r15, %rdi
callq 0xc7c6
leaq 0x20(%rsp), %rdi
callq 0xc642
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x20104
callq 0x52a0
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x8, %edi
callq 0x52e0
leaq 0x20(%rsp), %rdx
movq %rax, (%rdx)
movq %rax, 0x8(%rdx)
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x10(%rdx)
movq $0x0, (%rax)
movq %rcx, 0x8(%rdx)
leaq 0x40(%rsp), %rdi
leaq 0xd0(%rsp), %rcx
movl $0x3, %esi
callq 0xc5b2
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups 0x430(%r12), %xmm0
movq 0x440(%r12), %rax
leaq 0x40(%rsp), %r15
movaps (%r15), %xmm1
movups %xmm1, 0x430(%r12)
movq 0x10(%r15), %rcx
movq %rcx, 0x440(%r12)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movaps %xmm1, (%r15)
movq %rcx, 0x10(%r15)
callq 0xc642
movq %r15, %rdi
callq 0xc642
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x201cf
callq 0x52a0
movq 0x1d0(%r13), %rbx
movq 0x1d8(%r13), %r15
movslq 0x2d0(%r12), %rsi
leaq 0xd0(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
callq 0x15482
subq %rbx, %r15
sarq $0x5, %r15
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
movq %r15, %rsi
callq 0xc5b2
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups 0x400(%r12), %xmm0
movq 0x410(%r12), %rax
leaq 0x40(%rsp), %r15
movaps (%r15), %xmm1
movups %xmm1, 0x400(%r12)
movq 0x10(%r15), %rcx
movq %rcx, 0x410(%r12)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movaps %xmm1, (%r15)
movq %rcx, 0x10(%r15)
callq 0xc642
movq %r15, %rdi
callq 0xc642
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x20297
callq 0x52a0
movslq 0x2d0(%r12), %r15
leaq 0xd0(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
movq %r15, %rsi
callq 0x15482
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
movq %r15, %rsi
callq 0xc5b2
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups 0x418(%r12), %xmm0
movq 0x428(%r12), %rax
leaq 0x40(%rsp), %r14
movaps (%r14), %xmm1
movups %xmm1, 0x418(%r12)
movq 0x10(%r14), %rcx
movq %rcx, 0x428(%r12)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movaps %xmm1, (%r14)
movq %rcx, 0x10(%r14)
callq 0xc642
movq %r14, %rdi
callq 0xc642
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2034d
callq 0x52a0
cmpb $0x1, 0x1cd(%r13)
jne 0x20397
movq 0x60(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x2037a
callq 0x52a0
xorps %xmm0, %xmm0
movq 0x68(%rsp), %rax
movq (%rax), %rdi
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x20397
callq 0x52a0
xorps %xmm0, %xmm0
movups %xmm0, 0x368(%r12)
movups %xmm0, 0x3a8(%r12)
movups %xmm0, 0x3b8(%r12)
movups %xmm0, 0x3c8(%r12)
movups %xmm0, 0x3d8(%r12)
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x20409
jmp 0x2041c
jmp 0x20409
jmp 0x2041c
jmp 0x20409
jmp 0x2041c
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0xc642
jmp 0x203f7
movq %rax, %r14
movq 0xd0(%rsp), %rdi
jmp 0x20411
jmp 0x2041c
jmp 0x2041c
jmp 0x2041c
jmp 0x2041c
movq %rax, %r14
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
jne 0x20431
jmp 0x20436
jmp 0x2041c
jmp 0x2041c
movq %rax, %r14
jmp 0x20436
movq %rax, %r14
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0x20436
callq 0x52a0
movq 0x38(%rsp), %rax
leaq 0x3e8(%rax), %r15
leaq 0x400(%rax), %r13
leaq 0x418(%rax), %rbp
leaq 0x430(%rax), %rdi
callq 0xc642
movq %rbp, %rdi
callq 0xc642
movq %r13, %rdi
callq 0xc642
movq %r15, %rdi
callq 0xc7c6
movq 0x68(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x20486
callq 0x52a0
movq 0x60(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x20498
callq 0x52a0
movq 0x78(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x204aa
callq 0x52a0
movq 0x38(%rsp), %r12
leaq 0x320(%r12), %rbx
movq 0x338(%r12), %rdi
testq %rdi, %rdi
je 0x204c9
callq 0x52a0
leaq 0x2b8(%r12), %r15
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x204de
callq 0x52a0
leaq 0x270(%r12), %rbx
movq 0x70(%rsp), %rdi
callq 0xca60
movq %r15, %rdi
callq 0xc642
movq 0xe8(%rsp), %rdi
callq 0xc830
movq 0x288(%r12), %rdi
testq %rdi, %rdi
je 0x20517
callq 0x52a0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x20524
callq 0x52a0
movq 0x38(%rsp), %rdi
callq 0x284d2
movq %r14, %rdi
callq 0x55a0