// File: /workspace/github_cpp_makefile_star2_O3/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 0x25a74
leaq 0x24f00(%rip), %rax     # 0x44888
movq %rax, (%rbx)
leaq 0x2a0(%rbx), %rdi
leaq 0x2e8(%rbx), %rax
movq %rax, 0x70(%rsp)
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)
leaq 0x350(%rbx), %rcx
movq %rcx, 0x78(%rsp)
leaq 0x378(%rbx), %rcx
movq %rcx, 0x60(%rsp)
leaq 0x390(%rbx), %rcx
movq %rcx, 0x68(%rsp)
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 0x264c1(%rip), %r15     # 0x45f50
movl 0x1c8(%r15), %eax
movl %eax, 0x2d0(%rbx)
leaq 0x1d0(%r15), %rsi
movq %rdi, 0xe8(%rsp)
movq %rbx, 0x38(%rsp)
callq 0xc3b4
movb $0x0, 0x2e0(%rbx)
cmpl $0x0, 0x40(%r15)
setne %al
cmpl $0x0, 0x38(%r15)
setne %cl
andb %al, %cl
movb %cl, 0x318(%rbx)
movq %rbx, %rdi
callq 0x20390
movq 0x254ed(%rip), %rdi     # 0x44fd0
leaq 0x1451a(%rip), %rsi     # 0x34004
movl $0x11, %edx
callq 0x5360
movq 0x1d0(%r15), %r14
movq 0x1d8(%r15), %rbx
cmpq %rbx, %r14
je 0x1fb82
leaq 0x90(%rsp), %r12
leaq 0x80(%rsp), %r13
movq 0x254b2(%rip), %rbp     # 0x44fd0
leaq 0x144f1(%rip), %r15     # 0x34016
movq %r12, 0x80(%rsp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xcbd6
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq %rbp, %rdi
callq 0x5360
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x5360
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0x1fb79
callq 0x52b0
addq $0x20, %r14
cmpq %rbx, %r14
jne 0x1fb25
movq 0x25447(%rip), %rdi     # 0x44fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
movq 0x38(%rsp), %r12
callq 0x52c0
leaq 0x263aa(%rip), %r13     # 0x45f50
movsbl %al, %esi
movq 0x25420(%rip), %rdi     # 0x44fd0
callq 0x5030
movq %rax, %rdi
callq 0x5200
cmpb $0x1, 0x2e0(%r12)
jne 0x1fc7b
leaq 0x88(%rsp), %rbx
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%rbx)
xorl %eax, %eax
movq %rax, 0x8(%rbx)
movq %rbx, 0x10(%rbx)
movq %rbx, 0x18(%rbx)
movq %rax, 0x20(%rbx)
movq 0x70(%rsp), %rdi
callq 0xc9a8
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1fc66
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 0xca0c
movq %r12, %rdi
callq 0x20930
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl $0xc, %edi
callq 0x52f0
leaq 0x20(%rsp), %rdx
movq %rax, (%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 0xc524
movq 0x2c8(%r12), %rax
leaq 0x40(%rsp), %r15
movaps (%r15), %xmm0
movq 0x10(%r15), %rcx
movq %rcx, 0x2c8(%r12)
movups 0x2b8(%r12), %xmm1
movups %xmm0, 0x2b8(%r12)
leaq 0x80(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
callq 0xc5b4
movq %r15, %rdi
callq 0xc5b4
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1fd3b
callq 0x52b0
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 0x26429(%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 0x22bac
leaq 0x25d5b(%rip), %rdi     # 0x45b10
leaq 0x80(%rsp), %r15
movq %r15, %rsi
callq 0x22d5e
movq %r15, %rdi
callq 0x22d14
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 0x22bac
leaq 0x25d62(%rip), %rdi     # 0x45b60
leaq 0x80(%rsp), %r15
movq %r15, %rsi
callq 0x22d5e
movq %r15, %rdi
callq 0x22d14
movl $0x8, %edi
callq 0x52f0
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 0x1fe58
callq 0x52b0
movl $0x8, %edi
callq 0x52f0
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 0x1fe9a
callq 0x52b0
movq 0x78(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x1febd
callq 0x52b0
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 0xc524
subq %rbx, %r15
sarq $0x3, %r15
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
movq %r15, %rsi
callq 0x22ab6
movq 0x3f8(%r12), %rax
leaq 0x40(%rsp), %r15
movaps (%r15), %xmm0
movq 0x10(%r15), %rcx
movq %rcx, 0x3f8(%r12)
movups 0x3e8(%r12), %xmm1
movups %xmm0, 0x3e8(%r12)
leaq 0x80(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
callq 0xc752
movq %r15, %rdi
callq 0xc752
leaq 0x20(%rsp), %rdi
callq 0xc5b4
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x1ff8b
callq 0x52b0
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x8, %edi
callq 0x52f0
leaq 0x20(%rsp), %rdx
movq %rax, (%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 0xc524
movq 0x440(%r12), %rax
leaq 0x40(%rsp), %r15
movaps (%r15), %xmm0
movq 0x10(%r15), %rcx
movq %rcx, 0x440(%r12)
movups 0x430(%r12), %xmm1
movups %xmm0, 0x430(%r12)
leaq 0x80(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
callq 0xc5b4
movq %r15, %rdi
callq 0xc5b4
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x20044
callq 0x52b0
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 0x152ee
subq %rbx, %r15
sarq $0x5, %r15
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
movq %r15, %rsi
callq 0xc524
movq 0x410(%r12), %rax
leaq 0x40(%rsp), %r15
movaps (%r15), %xmm0
movq 0x10(%r15), %rcx
movq %rcx, 0x410(%r12)
movups 0x400(%r12), %xmm1
movups %xmm0, 0x400(%r12)
leaq 0x80(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
callq 0xc5b4
movq %r15, %rdi
callq 0xc5b4
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x200fe
callq 0x52b0
movslq 0x2d0(%r12), %r15
leaq 0xd0(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
movq %r15, %rsi
callq 0x152ee
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
movq %r15, %rsi
callq 0xc524
movq 0x428(%r12), %rax
leaq 0x40(%rsp), %r14
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x428(%r12)
movups 0x418(%r12), %xmm1
movups %xmm0, 0x418(%r12)
leaq 0x80(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0xc5b4
movq %r14, %rdi
callq 0xc5b4
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x201a6
callq 0x52b0
cmpb $0x1, 0x1cd(%r13)
jne 0x201f0
movq 0x60(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x201d3
callq 0x52b0
xorps %xmm0, %xmm0
movq 0x68(%rsp), %rax
movq (%rax), %rdi
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x201f0
callq 0x52b0
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 0x20262
jmp 0x20275
jmp 0x20262
jmp 0x20275
jmp 0x20262
jmp 0x20275
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0xc5b4
jmp 0x20250
movq %rax, %r14
movq 0xd0(%rsp), %rdi
jmp 0x2026a
jmp 0x20275
jmp 0x20275
jmp 0x20275
jmp 0x20275
movq %rax, %r14
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
jne 0x2028a
jmp 0x2028f
jmp 0x20275
jmp 0x20275
movq %rax, %r14
jmp 0x2028f
movq %rax, %r14
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0x2028f
callq 0x52b0
movq 0x38(%rsp), %rax
leaq 0x3e8(%rax), %r15
leaq 0x400(%rax), %r13
leaq 0x418(%rax), %rbp
leaq 0x430(%rax), %rdi
callq 0xc5b4
movq %rbp, %rdi
callq 0xc5b4
movq %r13, %rdi
callq 0xc5b4
movq %r15, %rdi
callq 0xc752
movq 0x68(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x202df
callq 0x52b0
movq 0x60(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x202f1
callq 0x52b0
movq 0x78(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x20303
callq 0x52b0
movq 0x38(%rsp), %r12
leaq 0x320(%r12), %rbx
movq 0x338(%r12), %rdi
testq %rdi, %rdi
je 0x20322
callq 0x52b0
leaq 0x2b8(%r12), %r15
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x20337
callq 0x52b0
leaq 0x270(%r12), %rbx
movq 0x70(%rsp), %rdi
callq 0xca0c
movq %r15, %rdi
callq 0xc5b4
movq 0xe8(%rsp), %rdi
callq 0xc7c2
movq 0x288(%r12), %rdi
testq %rdi, %rdi
je 0x20370
callq 0x52b0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x2037d
callq 0x52b0
movq 0x38(%rsp), %rdi
callq 0x2819a
movq %r14, %rdi
callq 0x55a0
nop