// File: /workspace/github_cpp_makefile_star2_O2/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 $0xd8, %rsp
movq %rdi, %rbx
movaps 0x110(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1e8c0
leaq 0x36888(%rip), %rax     # 0x3c600
movq %rax, (%rbx)
leaq 0x2a0(%rbx), %r14
leaq 0x2b8(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0x2c8(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x270(%rbx)
movups %xmm0, 0x280(%rbx)
movups %xmm0, 0x290(%rbx)
movups %xmm0, 0x2a0(%rbx)
andq $0x0, 0x2b0(%rbx)
movq %rax, 0x2b8(%rbx)
andq $0x0, 0x2c0(%rbx)
movb $0x0, 0x2c8(%rbx)
movups %xmm0, 0x2d8(%rbx)
andq $0x0, 0x2e8(%rbx)
leaq 0x310(%rbx), %rax
andl $0x0, 0x310(%rbx)
andq $0x0, 0x318(%rbx)
movq %rax, 0x320(%rbx)
movq %rax, 0x328(%rbx)
andq $0x0, 0x330(%rbx)
leaq 0x2d8(%rbx), %rax
movq %rax, 0xc8(%rsp)
leaq 0x308(%rbx), %rax
movq %rax, 0x90(%rsp)
leaq 0x340(%rbx), %rdi
leaq 0x388(%rbx), %rax
movq %rax, 0xb8(%rsp)
leaq 0x3a0(%rbx), %rax
movq %rax, 0xb0(%rsp)
leaq 0x3b8(%rbx), %rax
movq %rax, 0xa8(%rsp)
leaq 0x3e0(%rbx), %rax
movq %rax, 0x88(%rsp)
leaq 0x3f8(%rbx), %rax
movq %rax, 0x80(%rsp)
leaq 0x478(%rbx), %rax
movq %rax, 0x78(%rsp)
leaq 0x490(%rbx), %rax
movq %rax, 0x70(%rsp)
leaq 0x4a8(%rbx), %rax
movq %rax, 0xa0(%rsp)
leaq 0x4c0(%rbx), %rax
movq %rax, 0x98(%rsp)
movl $0x90, %edx
movq %rdi, 0xc0(%rsp)
xorl %esi, %esi
callq 0x51c0
xorps %xmm0, %xmm0
movups %xmm0, 0x3e0(%rbx)
movups %xmm0, 0x3f0(%rbx)
movups %xmm0, 0x400(%rbx)
movups %xmm0, 0x460(%rbx)
movups %xmm0, 0x470(%rbx)
movups %xmm0, 0x480(%rbx)
movups %xmm0, 0x490(%rbx)
movups %xmm0, 0x4a0(%rbx)
movups %xmm0, 0x4b0(%rbx)
andq $0x0, 0x4d0(%rbx)
movups %xmm0, 0x4c0(%rbx)
leaq 0x38031(%rip), %rcx     # 0x3df50
movl 0x1c8(%rcx), %eax
movl %eax, 0x2f0(%rbx)
leaq 0x1d0(%rcx), %rsi
movq %r14, 0xd0(%rsp)
movq %r14, %rdi
callq 0x9bc0
movb $0x0, 0x300(%rbx)
leaq 0x38000(%rip), %rcx     # 0x3df50
cmpl $0x0, 0x40(%rcx)
setne %al
cmpl $0x0, 0x38(%rcx)
setne %cl
andb %al, %cl
movb %cl, 0x338(%rbx)
movq %rbx, %rdi
callq 0x6544
movq 0x3705b(%rip), %rdi     # 0x3cfd0
leaq 0x230a4(%rip), %rsi     # 0x29020
callq 0x52c0
leaq 0x37fc8(%rip), %rax     # 0x3df50
movq 0x1d0(%rax), %r14
movq 0x1d8(%rax), %r15
leaq 0x40(%rsp), %r13
movq 0x3702e(%rip), %r12     # 0x3cfd0
leaq 0x23089(%rip), %rbp     # 0x29032
cmpq %r15, %r14
je 0x5fdd
movq %r13, %rdi
movq %r14, %rsi
callq 0x5410
movq %r12, %rdi
movq %r13, %rsi
callq 0x5290
movq %rax, %rdi
movq %rbp, %rsi
callq 0x52c0
movq %r13, %rdi
callq 0x5618
addq $0x20, %r14
jmp 0x5fa9
movq 0x36fec(%rip), %rdi     # 0x3cfd0
callq 0x5190
movl $0x200, %esi            # imm = 0x200
addq 0x36fbb(%rip), %rsi     # 0x3cfb0
movq 0x38(%rsp), %rdi
callq 0x51b0
leaq 0x2302e(%rip), %rsi     # 0x29034
movq 0x38(%rsp), %rdi
callq 0x9c80
testb %al, %al
je 0x602d
leaq 0x23020(%rip), %rsi     # 0x2903b
movq 0x38(%rsp), %rdi
callq 0x9c80
testb %al, %al
jne 0x63f8
cmpb $0x1, 0x300(%rbx)
jne 0x6079
leaq 0x48(%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 0x40(%rsp), %r14
movq 0x90(%rsp), %rdi
movq %r14, %rsi
callq 0xa19a
movq %r14, %rdi
callq 0xa27e
movq %rbx, %rdi
callq 0x66c0
leaq 0x18(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
pushq $0x3
popq %rsi
leaq 0x17(%rsp), %rcx
callq 0x9c8a
leaq 0x40(%rsp), %rdi
pushq $0x5
popq %rsi
leaq 0x20(%rsp), %rdx
leaq 0x16(%rsp), %rcx
callq 0x9ce0
leaq 0x40(%rsp), %r14
movq 0xc8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xa710
movq %r14, %rdi
callq 0x9d36
leaq 0x20(%rsp), %rdi
callq 0xa49a
leaq 0x37e75(%rip), %rsi     # 0x3df50
movl 0x1f0(%rsi), %eax
movq (%r15), %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)
addq $0xe8, %rsi
movq 0xc0(%rsp), %rdi
callq 0x9d58
leaq 0x3807e(%rip), %rax     # 0x3e1a0
andl $0x0, (%rax)
andq $0x0, 0x2f8(%rbx)
leaq 0x37e1c(%rip), %rax     # 0x3df50
cmpb $0x1, (%rax)
jne 0x614f
leaq 0x37320(%rip), %rdi     # 0x3d460
leaq 0x22faa(%rip), %rsi     # 0x290f1
pushq $0x10
popq %rdx
callq 0x5050
leaq 0x20(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x18(%rsp), %rcx
callq 0x9d90
leaq 0x40(%rsp), %r14
movq 0xb8(%rsp), %rdi
movq %r14, %rsi
callq 0xab1e
movq %r14, %rdi
callq 0xa4a8
leaq 0x20(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x18(%rsp), %rcx
callq 0x9d90
leaq 0x40(%rsp), %r14
movq 0xb0(%rsp), %rdi
movq %r14, %rsi
callq 0xab1e
movq %r14, %rdi
callq 0xa4a8
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
leaq 0x40(%rsp), %r14
movq 0xa8(%rsp), %rdi
movq %r14, %rsi
callq 0xa52e
movq %r14, %rdi
callq 0xa49a
leaq 0x18(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0x17(%rsp), %rcx
callq 0x9c8a
leaq 0x40(%rsp), %rdi
pushq $0x3
popq %rsi
leaq 0x20(%rsp), %rdx
leaq 0x16(%rsp), %rcx
callq 0x9ce0
leaq 0x40(%rsp), %r14
movq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0xa710
movq %r14, %rdi
callq 0x9d36
leaq 0x20(%rsp), %rdi
callq 0xa49a
leaq 0x37d09(%rip), %rax     # 0x3df50
cmpb $0x1, 0x1cc(%rax)
jne 0x6327
movq 0x1d0(%rax), %r15
movq 0x1d8(%rax), %r14
movslq 0x2f0(%rbx), %rsi
leaq 0x18(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x17(%rsp), %rcx
callq 0x9de6
subq %r15, %r14
sarq $0x5, %r14
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x16(%rsp), %rcx
movq %r14, %rsi
callq 0x9e3c
leaq 0x40(%rsp), %r14
movq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0xad80
movq %r14, %rdi
callq 0x9e92
leaq 0x20(%rsp), %rdi
callq 0xab9c
movslq 0x2f0(%rbx), %r14
leaq 0x18(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x17(%rsp), %rcx
movq %r14, %rsi
callq 0x9de6
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x16(%rsp), %rcx
movq %r14, %rsi
callq 0x9e3c
leaq 0x40(%rsp), %r14
movq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0xad80
movq %r14, %rdi
callq 0x9e92
leaq 0x20(%rsp), %rdi
callq 0xab9c
leaq 0x37c29(%rip), %rax     # 0x3df50
cmpb $0x1, 0x1cd(%rax)
jne 0x6382
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %r14
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
movq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0xadd2
movq %r14, %rdi
callq 0xa7d8
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
leaq 0x40(%rsp), %r14
movq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0xadd2
movq %r14, %rdi
callq 0xa7d8
leaq 0x20(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x40(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0x18(%rsp), %rcx
callq 0x9c8a
leaq 0x40(%rsp), %r14
movq 0x98(%rsp), %rdi
movq %r14, %rsi
callq 0xa52e
movq %r14, %rdi
callq 0xa49a
xorps %xmm0, %xmm0
movups %xmm0, 0x3d0(%rbx)
movups %xmm0, 0x410(%rbx)
movups %xmm0, 0x420(%rbx)
movups %xmm0, 0x430(%rbx)
movups %xmm0, 0x440(%rbx)
movups %xmm0, 0x450(%rbx)
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x22c40(%rip), %rdi     # 0x2903f
leaq 0x22c79(%rip), %rsi     # 0x2907f
leaq 0x22c82(%rip), %rcx     # 0x2908f
pushq $0x25
popq %rdx
callq 0x51e0
jmp 0x6419
jmp 0x6447
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0xab9c
jmp 0x6459
jmp 0x6447
jmp 0x6447
jmp 0x6434
jmp 0x6447
jmp 0x6447
jmp 0x6447
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0xa49a
jmp 0x6459
jmp 0x6447
jmp 0x6447
movq %rax, %r15
jmp 0x6459
movq %rax, %r15
leaq 0x40(%rsp), %rdi
callq 0x5618
leaq 0x270(%rbx), %r12
leaq 0x460(%rbx), %r14
leaq 0x288(%rbx), %r13
movq 0x98(%rsp), %rdi
callq 0xa49a
movq 0xa0(%rsp), %rdi
callq 0x9d36
movq 0x70(%rsp), %rdi
callq 0x9e92
movq 0x78(%rsp), %rdi
callq 0x9e92
movq %r14, %rdi
callq 0x9eb4
movq 0x80(%rsp), %rdi
callq 0xa7d8
movq 0x88(%rsp), %rdi
callq 0xa7d8
movq 0xa8(%rsp), %rdi
callq 0xa49a
movq 0xb0(%rsp), %rdi
callq 0xa4a8
movq 0xb8(%rsp), %rdi
callq 0xa4a8
movq 0xc0(%rsp), %rdi
callq 0x9ed6
movq 0x90(%rsp), %rdi
callq 0xa27e
movq 0xc8(%rsp), %rdi
callq 0x9d36
movq 0x38(%rsp), %rdi
callq 0x5618
movq 0xd0(%rsp), %rdi
callq 0x9ef6
movq %r13, %rdi
callq 0x9f18
movq %r12, %rdi
callq 0xa762
movq %rbx, %rdi
callq 0x2087a
movq %r15, %rdi
callq 0x5570
nop