// File: /workspace/github_cpp_makefile_star2_O3/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 0x25a74
leaq 0x3e0a0(%rip), %rax     # 0x445e8
movq %rax, (%r14)
leaq 0x2a0(%r14), %r15
leaq 0x2b8(%r14), %rax
movq %rax, 0xb8(%rsp)
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)
leaq 0x2d8(%r14), %rax
movq %rax, 0xb0(%rsp)
movups %xmm0, 0x2d8(%r14)
movq %rbx, 0x2e8(%r14)
leaq 0x308(%r14), %rax
movq %rax, 0x98(%rsp)
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
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 $0x90, %edx
movq %rdi, 0xa8(%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 0x3f892(%rip), %rbx     # 0x45f50
movl 0x1c8(%rbx), %eax
movl %eax, 0x2f0(%r14)
leaq 0x1d0(%rbx), %rsi
movq %r15, 0xe8(%rsp)
movq %r15, %rdi
movq %r14, 0x40(%rsp)
callq 0xc3b4
movb $0x0, 0x300(%r14)
cmpl $0x0, 0x40(%rbx)
setne %al
cmpl $0x0, 0x38(%rbx)
setne %cl
andb %al, %cl
movb %cl, 0x338(%r14)
movq %r14, %rdi
callq 0x6f62
movq 0x3e8bb(%rip), %rdi     # 0x44fd0
leaq 0x2d8e8(%rip), %rsi     # 0x34004
movl $0x11, %edx
callq 0x5360
movq 0x1d0(%rbx), %r15
movq 0x1d8(%rbx), %rbx
cmpq %rbx, %r15
je 0x67a2
leaq 0x60(%rsp), %r13
leaq 0x50(%rsp), %r14
movq 0x3e886(%rip), %r12     # 0x44fd0
leaq 0x2d8c5(%rip), %rbp     # 0x34016
movq %r13, 0x50(%rsp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xcbd6
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq %r12, %rdi
callq 0x5360
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x5360
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x6799
callq 0x52b0
addq $0x20, %r15
cmpq %rbx, %r15
jne 0x6751
movq 0x3e827(%rip), %rdi     # 0x44fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
movq 0x40(%rsp), %r15
movq 0xb8(%rsp), %rbx
callq 0x52c0
leaq 0x3f782(%rip), %r12     # 0x45f50
movsbl %al, %esi
movq 0x3e7f8(%rip), %rdi     # 0x44fd0
callq 0x5030
movq %rax, %rdi
callq 0x5200
movl $0x200, %esi            # imm = 0x200
addq 0x3e7af(%rip), %rsi     # 0x44fa0
movq %rbx, %rdi
callq 0x51a0
leaq 0x2d818(%rip), %rsi     # 0x34018
movq %rbx, %rdi
callq 0x50f0
testl %eax, %eax
je 0x6823
leaq 0x2d80c(%rip), %rsi     # 0x3401f
movq %rbx, %rdi
callq 0x50f0
testl %eax, %eax
jne 0x6dcb
cmpb $0x1, 0x300(%r15)
jne 0x68c4
leaq 0x58(%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 0x98(%rsp), %rdi
callq 0xc9a8
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x68b2
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 0xca0c
movq %r15, %rdi
callq 0x7186
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 0xc0(%rsp), %rdi
leaq 0x48(%rsp), %rcx
movl $0x5, %esi
callq 0xc524
movq 0x2e8(%r15), %rax
leaq 0xc0(%rsp), %r14
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x2e8(%r15)
movups 0x2d8(%r15), %xmm1
movups %xmm0, 0x2d8(%r15)
leaq 0x50(%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 0x6980
callq 0x52b0
movl 0x1f0(%r12), %eax
movq 0xb0(%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 0xa8(%rsp), %rdi
callq 0xca20
leaq 0x358(%r15), %rdi
movl $0x100, %esi            # imm = 0x100
addq 0x3e5bc(%rip), %rsi     # 0x44fa0
callq 0xca20
leaq 0x370(%r15), %rdi
movl $0x118, %esi            # imm = 0x118
addq 0x3e5a4(%rip), %rsi     # 0x44fa0
callq 0xca20
leaq 0x3f798(%rip), %rax     # 0x461a0
movl $0x0, (%rax)
movq $0x0, 0x2f8(%r15)
cmpb $0x1, (%r12)
jne 0x6a38
leaq 0x3ea39(%rip), %rdi     # 0x45460
leaq 0x2d6a7(%rip), %rsi     # 0x340d5
movl $0x10, %edx
callq 0x5060
movl $0x8, %edi
callq 0x52f0
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 0x6a76
callq 0x52b0
movl $0x8, %edi
callq 0x52f0
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 0x6ab4
callq 0x52b0
movq 0xa0(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x6ada
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 0xc0(%rsp), %rdi
leaq 0x48(%rsp), %rcx
movl $0x3, %esi
callq 0xc524
movq 0x4b8(%r15), %rax
leaq 0xc0(%rsp), %r14
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x4b8(%r15)
movups 0x4a8(%r15), %xmm1
movups %xmm0, 0x4a8(%r15)
leaq 0x50(%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 0x6b8c
callq 0x52b0
cmpb $0x1, 0x1cc(%r12)
jne 0x6cf7
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 0xc5fa
subq %rbx, %r14
sarq $0x5, %r14
leaq 0xc0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
movq %r14, %rsi
callq 0xc67c
movq 0x488(%r15), %rax
leaq 0xc0(%rsp), %r14
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x488(%r15)
movups 0x478(%r15), %xmm1
movups %xmm0, 0x478(%r15)
leaq 0x50(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0xc70c
movq %r14, %rdi
callq 0xc70c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x6c53
callq 0x52b0
movslq 0x2f0(%r15), %r14
leaq 0x48(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
movq %r14, %rsi
callq 0xc5fa
leaq 0xc0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
movq %r14, %rsi
callq 0xc67c
movq 0x4a0(%r15), %rax
leaq 0xc0(%rsp), %r14
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x4a0(%r15)
movups 0x490(%r15), %xmm1
movups %xmm0, 0x490(%r15)
leaq 0x50(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0xc70c
movq %r14, %rdi
callq 0xc70c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x6cf7
callq 0x52b0
cmpb $0x1, 0x1cd(%r12)
jne 0x6d48
movq 0x90(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x6d28
callq 0x52b0
xorps %xmm0, %xmm0
movq 0x88(%rsp), %rax
movq (%rax), %rdi
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x6d48
callq 0x52b0
movl $0x8, %edi
callq 0x52f0
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 0x6d86
callq 0x52b0
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 0x2d251(%rip), %rdi     # 0x34023
leaq 0x2d28a(%rip), %rsi     # 0x34063
leaq 0x2d293(%rip), %rcx     # 0x34073
movl $0x25, %edx
callq 0x51d0
jmp 0x6dfc
jmp 0x6e0f
jmp 0x6dfc
jmp 0x6e0f
jmp 0x6e0f
jmp 0x6dfc
jmp 0x6e0f
jmp 0x6e0f
jmp 0x6e0f
movq %rax, %r15
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
jne 0x6e21
jmp 0x6e26
jmp 0x6e0f
jmp 0x6e0f
movq %rax, %r15
jmp 0x6e26
movq %rax, %r15
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x6e26
callq 0x52b0
movq 0x40(%rsp), %rax
leaq 0x460(%rax), %r14
leaq 0x478(%rax), %r12
leaq 0x490(%rax), %r13
leaq 0x4a8(%rax), %rbp
movq 0x4c0(%rax), %rdi
testq %rdi, %rdi
je 0x6e58
callq 0x52b0
movq %rbp, %rdi
callq 0xc5b4
movq %r13, %rdi
callq 0xc70c
movq %r12, %rdi
callq 0xc70c
movq %r14, %rdi
callq 0xc752
movq 0x88(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6e8d
callq 0x52b0
movq 0x90(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6ea2
callq 0x52b0
movq 0xa0(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6eb7
callq 0x52b0
movq 0x40(%rsp), %r14
movq 0x3a0(%r14), %rdi
testq %rdi, %rdi
je 0x6ecd
callq 0x52b0
movq 0x388(%r14), %rdi
testq %rdi, %rdi
je 0x6ede
callq 0x52b0
leaq 0x270(%r14), %rbx
addq $0x288, %r14            # imm = 0x288
movq 0xa8(%rsp), %rdi
callq 0xc792
movq 0x98(%rsp), %rdi
callq 0xca0c
movq 0xb0(%rsp), %rdi
callq 0xc5b4
movq 0xb8(%rsp), %rax
movq (%rax), %rdi
cmpq 0xe0(%rsp), %rdi
je 0x6f2d
callq 0x52b0
movq 0xe8(%rsp), %rdi
callq 0xc7c2
movq %r14, %rdi
callq 0xc80c
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x6f4f
callq 0x52b0
movq 0x40(%rsp), %rdi
callq 0x2819a
movq %r15, %rdi
callq 0x55a0
nop