// File: /workspace/github_cpp_makefile_star2_O1/gvaumour[P]cache-simulator/src/Cerebron.cc
// Function: CerebronPredictor::CerebronPredictor(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*)
CerebronPredictor::CerebronPredictor(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;


	m_activation_function = simu_parameters.Cerebron_activation_function;
	if(m_activation_function != "linear" && m_activation_function != "max")
		assert(false && "Wrong Activation function for the Cerebron predictor");
	
	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_costParameters = simu_parameters.optTarget;
	
	miss_counter = 0;
	m_cpt = 0;


	if(simu_parameters.printDebug)
		debug_file.open(CEREBRON_DEBUG_FILE);
		
	stats_nbBPrequests = vector<uint64_t>(1, 0);
	stats_nbDeadLine = vector<uint64_t>(1, 0);
	stats_missCounter = vector<int>();
	stats_access_class = vector<vector<int> >(NUM_RD_TYPE ,  vector<int>(2, 0));
	
	
	if(simu_parameters.perceptron_drawFeatureMaps)
	{
		stats_local_error = vector< vector< pair<int,int> > >(simu_parameters.PHC_features.size() \
		 , vector< pair<int,int> >(m_tableSize, pair<int,int>(0,0)));
		stats_global_error = vector< vector< pair<int,int> > >(m_tableSize , \
			vector< pair<int,int> >(m_tableSize , pair<int,int>(0,0)));
	}
	
	if(simu_parameters.perceptron_compute_variance)
	{
		stats_variances_buffer = vector<double>();
		stats_variances = vector<double>();
	}	


	stats_nbMigrations = vector<int>(2,0);
	
	stats_allocate = 0;
	stats_nbMiss = 0;
	stats_nbHits = 0;

	stats_good_alloc = 0, stats_wrong_alloc = 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, %r14
movaps 0x130(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x25c7c
leaq 0x3e048(%rip), %rax     # 0x44590
movq %rax, (%r14)
leaq 0x2a0(%r14), %r15
leaq 0x2c8(%r14), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x270(%r14)
movups %xmm0, 0x280(%r14)
movups %xmm0, 0x290(%r14)
movups %xmm0, 0x2a0(%r14)
xorl %ebx, %ebx
movq %rbx, 0x2b0(%r14)
movq %rax, 0xe0(%rsp)
movq %rax, 0x2b8(%r14)
movq %rbx, 0x2c0(%r14)
movb $0x0, 0x2c8(%r14)
movups %xmm0, 0x2d8(%r14)
movq %rbx, 0x2e8(%r14)
leaq 0x310(%r14), %rax
movl $0x0, 0x310(%r14)
movq %rbx, 0x318(%r14)
movq %rax, 0x320(%r14)
movq %rax, 0xf0(%rsp)
movq %rax, 0x328(%r14)
movq %rbx, 0x330(%r14)
leaq 0x340(%r14), %rdi
movl $0x90, %edx
movq %rdi, 0xb0(%rsp)
xorl %esi, %esi
callq 0x51b0
xorps %xmm0, %xmm0
movups %xmm0, 0x3e0(%r14)
movups %xmm0, 0x3f0(%r14)
movups %xmm0, 0x400(%r14)
movups %xmm0, 0x460(%r14)
movups %xmm0, 0x470(%r14)
movups %xmm0, 0x480(%r14)
movups %xmm0, 0x490(%r14)
movups %xmm0, 0x4a0(%r14)
movups %xmm0, 0x4b0(%r14)
movups %xmm0, 0x4c0(%r14)
movq %rbx, 0x4d0(%r14)
leaq 0x3f8ec(%rip), %rbx     # 0x45f50
movl 0x1c8(%rbx), %eax
movl %eax, 0x2f0(%r14)
movq 0x270(%r14), %rax
cmpq %rax, 0x278(%r14)
je 0x6688
movq %rax, 0x278(%r14)
leaq 0x2b8(%r14), %rax
movq %rax, 0xb8(%rsp)
leaq 0x2d8(%r14), %rax
movq %rax, 0xa8(%rsp)
leaq 0x308(%r14), %rax
movq %rax, 0x98(%rsp)
leaq 0x3b8(%r14), %rax
movq %rax, 0xa0(%rsp)
leaq 0x3e0(%r14), %rax
movq %rax, 0x90(%rsp)
leaq 0x3f8(%r14), %rax
movq %rax, 0x88(%rsp)
movl $0x1d0, %esi            # imm = 0x1D0
addq 0x3e8b2(%rip), %rsi     # 0x44fa0
movq %r15, %rdi
movq %r14, 0x40(%rsp)
movq %r15, 0xe8(%rsp)
callq 0xc46a
movb $0x0, 0x300(%r14)
movb $0x1, 0x338(%r14)
cmpl $0x0, 0x40(%rbx)
setne %al
cmpl $0x0, 0x38(%rbx)
setne %cl
andb %al, %cl
movb %cl, 0x338(%r14)
movq %r14, %rdi
callq 0x6fce
movq 0x3e897(%rip), %rdi     # 0x44fd0
leaq 0x2d8f0(%rip), %rsi     # 0x34030
movl $0x11, %edx
callq 0x5350
movq 0x1d0(%rbx), %r12
movq 0x1d8(%rbx), %rbx
cmpq %rbx, %r12
je 0x67c8
leaq 0x60(%rsp), %rbp
leaq 0x50(%rsp), %r14
movq 0x3e862(%rip), %r13     # 0x44fd0
leaq 0x2d8cd(%rip), %r15     # 0x34042
movq %rbp, 0x50(%rsp)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xcc1c
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq %r13, %rdi
callq 0x5350
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x5350
movq 0x50(%rsp), %rdi
cmpq %rbp, %rdi
je 0x67bf
callq 0x52a0
addq $0x20, %r12
cmpq %rbx, %r12
jne 0x6775
movq 0x3e801(%rip), %rdi     # 0x44fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
movq 0x40(%rsp), %r15
movq 0xb8(%rsp), %rbx
callq 0x52b0
leaq 0x3f75c(%rip), %r12     # 0x45f50
movsbl %al, %esi
movq 0x3e7d2(%rip), %rdi     # 0x44fd0
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movl $0x200, %esi            # imm = 0x200
addq 0x3e789(%rip), %rsi     # 0x44fa0
movq %rbx, %rdi
callq 0x51a0
leaq 0x2d81e(%rip), %rsi     # 0x34044
movq %rbx, %rdi
callq 0x50f0
testl %eax, %eax
je 0x6849
leaq 0x2d812(%rip), %rsi     # 0x3404b
movq %rbx, %rdi
callq 0x50f0
testl %eax, %eax
jne 0x6e37
cmpb $0x1, 0x300(%r15)
jne 0x68f0
leaq 0x58(%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 0x98(%rsp), %rdi
callq 0xc9fc
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x68de
movl 0x58(%rsp), %ecx
movl %ecx, 0x310(%r15)
movq %rax, 0x318(%r15)
movups 0x68(%rsp), %xmm0
movups %xmm0, 0x320(%r15)
movq 0xf0(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x78(%rsp), %rax
movq %rax, 0x330(%r15)
xorl %eax, %eax
movq %rax, 0x60(%rsp)
movq %rbx, 0x68(%rsp)
movq %rbx, 0x70(%rsp)
movq %rax, 0x78(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xca60
movq %r15, %rdi
callq 0x7202
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 0xc0(%rsp), %rdi
leaq 0x48(%rsp), %rcx
movl $0x5, %esi
callq 0xc5b2
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups 0x2d8(%r15), %xmm0
movq 0x2e8(%r15), %rax
leaq 0xc0(%rsp), %r14
movaps (%r14), %xmm1
movups %xmm1, 0x2d8(%r15)
movq 0x10(%r14), %rcx
movq %rcx, 0x2e8(%r15)
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 0x69be
callq 0x52a0
movl 0x1f0(%r12), %eax
movq 0xa8(%rsp), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx), %rdx
movl %eax, 0x4(%rdx)
movl 0x1ec(%r12), %eax
movq (%rcx), %rcx
movl %eax, 0x4(%rcx)
movl 0x1f4(%r12), %eax
movl %eax, (%rdx)
movl 0x1f8(%r12), %eax
movl %eax, (%rcx)
leaq 0xe8(%r12), %rsi
movq 0xb0(%rsp), %rdi
callq 0xca74
leaq 0x358(%r15), %rdi
movl $0x100, %esi            # imm = 0x100
addq 0x3e57e(%rip), %rsi     # 0x44fa0
callq 0xca74
leaq 0x370(%r15), %rdi
movl $0x118, %esi            # imm = 0x118
addq 0x3e566(%rip), %rsi     # 0x44fa0
callq 0xca74
leaq 0x3f75a(%rip), %rax     # 0x461a0
movl $0x0, (%rax)
movq $0x0, 0x2f8(%r15)
cmpb $0x1, (%r12)
jne 0x6a76
leaq 0x3e9fb(%rip), %rdi     # 0x45460
leaq 0x2d695(%rip), %rsi     # 0x34101
movl $0x10, %edx
callq 0x5060
movl $0x8, %edi
callq 0x52e0
movq $0x0, (%rax)
movq %rax, %rcx
addq $0x8, %rcx
movq 0x388(%r15), %rdi
movq %rax, 0x388(%r15)
movq %rcx, 0x390(%r15)
movq %rcx, 0x398(%r15)
testq %rdi, %rdi
je 0x6ab4
callq 0x52a0
movl $0x8, %edi
callq 0x52e0
movq $0x0, (%rax)
movq %rax, %rcx
addq $0x8, %rcx
movq 0x3a0(%r15), %rdi
movq %rax, 0x3a0(%r15)
movq %rcx, 0x3a8(%r15)
movq %rcx, 0x3b0(%r15)
testq %rdi, %rdi
je 0x6af2
callq 0x52a0
movq 0xa0(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x6b18
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 0xc0(%rsp), %rdi
leaq 0x48(%rsp), %rcx
movl $0x3, %esi
callq 0xc5b2
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups 0x4a8(%r15), %xmm0
movq 0x4b8(%r15), %rax
leaq 0xc0(%rsp), %r14
movaps (%r14), %xmm1
movups %xmm1, 0x4a8(%r15)
movq 0x10(%r14), %rcx
movq %rcx, 0x4b8(%r15)
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 0x6bdc
callq 0x52a0
cmpb $0x1, 0x1cc(%r12)
jne 0x6d63
movq 0x1d0(%r12), %rbx
movq 0x1d8(%r12), %r14
movslq 0x2f0(%r15), %rsi
leaq 0x48(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
callq 0xc682
subq %rbx, %r14
sarq $0x5, %r14
leaq 0xc0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
movq %r14, %rsi
callq 0xc6f6
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups 0x478(%r15), %xmm0
movq 0x488(%r15), %rax
leaq 0xc0(%rsp), %r14
movaps (%r14), %xmm1
movups %xmm1, 0x478(%r15)
movq 0x10(%r14), %rcx
movq %rcx, 0x488(%r15)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movaps %xmm1, (%r14)
movq %rcx, 0x10(%r14)
callq 0xc786
movq %r14, %rdi
callq 0xc786
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x6cb1
callq 0x52a0
movslq 0x2f0(%r15), %r14
leaq 0x48(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
movq %r14, %rsi
callq 0xc682
leaq 0xc0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
movq %r14, %rsi
callq 0xc6f6
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movups 0x490(%r15), %xmm0
movq 0x4a0(%r15), %rax
leaq 0xc0(%rsp), %r14
movaps (%r14), %xmm1
movups %xmm1, 0x490(%r15)
movq 0x10(%r14), %rcx
movq %rcx, 0x4a0(%r15)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movaps %xmm1, (%r14)
movq %rcx, 0x10(%r14)
callq 0xc786
movq %r14, %rdi
callq 0xc786
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x6d63
callq 0x52a0
cmpb $0x1, 0x1cd(%r12)
jne 0x6db4
movq 0x90(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x6d94
callq 0x52a0
xorps %xmm0, %xmm0
movq 0x88(%rsp), %rax
movq (%rax), %rdi
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x6db4
callq 0x52a0
movl $0x8, %edi
callq 0x52e0
movq $0x0, (%rax)
movq %rax, %rcx
addq $0x8, %rcx
movq 0x4c0(%r15), %rdi
movq %rax, 0x4c0(%r15)
movq %rcx, 0x4c8(%r15)
movq %rcx, 0x4d0(%r15)
testq %rdi, %rdi
je 0x6df2
callq 0x52a0
xorps %xmm0, %xmm0
movups %xmm0, 0x3d0(%r15)
movups %xmm0, 0x410(%r15)
movups %xmm0, 0x420(%r15)
movups %xmm0, 0x430(%r15)
movups %xmm0, 0x440(%r15)
movups %xmm0, 0x450(%r15)
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2d211(%rip), %rdi     # 0x3404f
leaq 0x2d24a(%rip), %rsi     # 0x3408f
leaq 0x2d253(%rip), %rcx     # 0x3409f
movl $0x25, %edx
callq 0x51d0
jmp 0x6e68
jmp 0x6e7b
jmp 0x6e68
jmp 0x6e7b
jmp 0x6e7b
jmp 0x6e68
jmp 0x6e7b
jmp 0x6e7b
jmp 0x6e7b
movq %rax, %r12
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
jne 0x6e8d
jmp 0x6e92
jmp 0x6e7b
jmp 0x6e7b
movq %rax, %r12
jmp 0x6e92
movq %rax, %r12
movq 0x50(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6e92
callq 0x52a0
movq 0x40(%rsp), %rax
leaq 0x460(%rax), %r14
leaq 0x478(%rax), %r15
leaq 0x490(%rax), %r13
leaq 0x4a8(%rax), %rbp
movq 0x4c0(%rax), %rdi
testq %rdi, %rdi
je 0x6ec4
callq 0x52a0
movq %rbp, %rdi
callq 0xc642
movq %r13, %rdi
callq 0xc786
movq %r15, %rdi
callq 0xc786
movq %r14, %rdi
callq 0xc7c6
movq 0x88(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6ef9
callq 0x52a0
movq 0x90(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6f0e
callq 0x52a0
movq 0xa0(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6f23
callq 0x52a0
movq 0x40(%rsp), %r14
movq 0x3a0(%r14), %rdi
testq %rdi, %rdi
je 0x6f39
callq 0x52a0
movq 0x388(%r14), %rdi
testq %rdi, %rdi
je 0x6f4a
callq 0x52a0
leaq 0x270(%r14), %rbx
addq $0x288, %r14            # imm = 0x288
movq 0xb0(%rsp), %rdi
callq 0xc800
movq 0x98(%rsp), %rdi
callq 0xca60
movq 0xa8(%rsp), %rdi
callq 0xc642
movq 0xb8(%rsp), %rax
movq (%rax), %rdi
cmpq 0xe0(%rsp), %rdi
je 0x6f99
callq 0x52a0
movq 0xe8(%rsp), %rdi
callq 0xc830
movq %r14, %rdi
callq 0xc874
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x6fbb
callq 0x52a0
movq 0x40(%rsp), %rdi
callq 0x284d2
movq %r12, %rdi
callq 0x55a0
nop