// File: /workspace/github_cpp_makefile_star2_O1/gvaumour[P]cache-simulator/src/Perceptron.cc
// Function: PerceptronPredictor::PerceptronPredictor(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*)
PerceptronPredictor::PerceptronPredictor(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_BP_features.clear();
	m_Allocation_features.clear();

	m_BP_criterias_names = simu_parameters.perceptron_BP_features;
	m_Allocation_criterias_names = simu_parameters.perceptron_Allocation_features;

	m_need_callee_file = false;
	m_enableBP = simu_parameters.perceptron_enableBypass;
	
	m_enableAllocation = true;
	if(simu_parameters.nvm_assoc == 0 || simu_parameters.sram_assoc == 0)
		m_enableAllocation = false;
	
	
	cout <<  "\tBP Features used : ";
	for(auto p : simu_parameters.perceptron_BP_features)
		cout << p << ",";
	cout << endl;
	cout <<  "\tAlloc Features used : ";
	for(auto p : simu_parameters.perceptron_Allocation_features)
		cout << p << ",";
	cout << endl;

	
	if(m_enableBP)
		initFeatures(true);
	initFeatures(false);
	
	if(m_need_callee_file)
	{
		m_callee_map = map<uint64_t,int>();
		load_callee_file();
	}
		
	
	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>();
	
	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;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %r15
movaps 0xe0(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x25c7c
leaq 0x2151c(%rip), %rax     # 0x448e0
movq %rax, (%r15)
leaq 0x270(%r15), %rdi
leaq 0x320(%r15), %r14
movl $0x0, 0x320(%r15)
xorl %ebx, %ebx
movq %rbx, 0x328(%r15)
movl $0x90, %edx
movq %rdi, 0x98(%rsp)
xorl %esi, %esi
callq 0x51b0
movq %r14, 0x330(%r15)
movq %r14, 0xa0(%rsp)
movq %r14, 0x338(%r15)
movq %rbx, 0x340(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x350(%r15)
movups %xmm0, 0x360(%r15)
movups %xmm0, 0x370(%r15)
movups %xmm0, 0x380(%r15)
movq %rbx, 0x390(%r15)
movups %xmm0, 0x3a8(%r15)
movups %xmm0, 0x3b8(%r15)
movups %xmm0, 0x3c8(%r15)
leaq 0x22aed(%rip), %rbx     # 0x45f50
movl 0x1c8(%rbx), %eax
movl %eax, 0x300(%r15)
movq 0x2b8(%r15), %rax
cmpq %rax, 0x2c0(%r15)
je 0x23487
movq %rax, 0x2c0(%r15)
leaq 0x2e8(%r15), %rdi
movq 0x270(%r15), %rax
cmpq %rax, 0x278(%r15)
je 0x234a5
movq %rax, 0x278(%r15)
leaq 0x2a0(%r15), %rax
movq %rax, 0x38(%rsp)
leaq 0x318(%r15), %rax
movq %rax, 0x28(%rsp)
leaq 0x380(%r15), %rax
movq %rax, 0x30(%rsp)
leaq 0x3a8(%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0x3c0(%r15), %rax
movq %rax, 0x20(%rsp)
movl $0x180, %esi            # imm = 0x180
addq 0x21ab3(%rip), %rsi     # 0x44fa0
movq %rdi, 0x90(%rsp)
callq 0xc46a
movl $0x198, %esi            # imm = 0x198
addq 0x21a9a(%rip), %rsi     # 0x44fa0
movq 0x38(%rsp), %rdi
callq 0xc46a
movb $0x0, 0x310(%r15)
movb 0x1ce(%rbx), %al
movb %al, 0x348(%r15)
movb $0x1, 0x349(%r15)
cmpl $0x0, 0x40(%rbx)
setne %al
cmpl $0x0, 0x38(%rbx)
setne %cl
andb %al, %cl
movb %cl, 0x349(%r15)
movq 0x21a85(%rip), %rdi     # 0x44fd0
leaq 0x12f49(%rip), %rsi     # 0x3649b
movl $0x14, %edx
callq 0x5350
movq %r15, 0x10(%rsp)
movq 0x180(%rbx), %r12
movq 0x188(%rbx), %rbx
cmpq %rbx, %r12
je 0x235df
leaq 0x50(%rsp), %rbp
leaq 0x40(%rsp), %r13
movq 0x21a4b(%rip), %r14     # 0x44fd0
leaq 0x10ab6(%rip), %r15     # 0x34042
movq %rbp, 0x40(%rsp)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xcc1c
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %r14, %rdi
callq 0x5350
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x5350
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x235d6
callq 0x52a0
addq $0x20, %r12
cmpq %rbx, %r12
jne 0x2358c
movq 0x219ea(%rip), %rdi     # 0x44fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
movq 0x10(%rsp), %r15
callq 0x52b0
leaq 0x2294d(%rip), %rbx     # 0x45f50
movsbl %al, %esi
movq 0x219c3(%rip), %rdi     # 0x44fd0
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq 0x219af(%rip), %rdi     # 0x44fd0
leaq 0x12e88(%rip), %rsi     # 0x364b0
movl $0x17, %edx
callq 0x5350
movq 0x198(%rbx), %r12
movq 0x1a0(%rbx), %rbx
cmpq %rbx, %r12
je 0x236b0
leaq 0x50(%rsp), %rbp
leaq 0x40(%rsp), %r13
movq 0x2197a(%rip), %r14     # 0x44fd0
leaq 0x109e5(%rip), %r15     # 0x34042
movq %rbp, 0x40(%rsp)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xcc1c
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %r14, %rdi
callq 0x5350
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x5350
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x236a7
callq 0x52a0
addq $0x20, %r12
cmpq %rbx, %r12
jne 0x2365d
movq 0x21919(%rip), %rdi     # 0x44fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
movq 0x10(%rsp), %r15
callq 0x52b0
leaq 0x2287c(%rip), %r12     # 0x45f50
movsbl %al, %esi
movq 0x218f2(%rip), %rdi     # 0x44fd0
callq 0x5030
movq %rax, %rdi
callq 0x51f0
cmpb $0x1, 0x348(%r15)
jne 0x23702
movq %r15, %rdi
movl $0x1, %esi
callq 0x23a5e
movq %r15, %rdi
xorl %esi, %esi
callq 0x23a5e
cmpb $0x1, 0x310(%r15)
jne 0x237b0
leaq 0x48(%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 0x28(%rsp), %rdi
callq 0xc9fc
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x2379e
movl 0x48(%rsp), %ecx
movl %ecx, 0x320(%r15)
movq %rax, 0x328(%r15)
movups 0x58(%rsp), %xmm0
movups %xmm0, 0x330(%r15)
movq 0xa0(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x68(%rsp), %rax
movq %rax, 0x340(%r15)
xorl %eax, %eax
movq %rax, 0x50(%rsp)
movq %rbx, 0x58(%rsp)
movq %rbx, 0x60(%rsp)
movq %rax, 0x68(%rsp)
leaq 0x40(%rsp), %rdi
callq 0xca60
movq %r15, %rdi
callq 0x23ff2
leaq 0x229e9(%rip), %rax     # 0x461a0
movl $0x0, (%rax)
movq $0x0, 0x308(%r15)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdi
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 0x223c7(%rip), %rdi     # 0x45bb8
leaq 0x40(%rsp), %r14
movq %r14, %rsi
callq 0x22f14
movq %r14, %rdi
callq 0x22ed0
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%r14)
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x22d68
leaq 0x223d4(%rip), %rdi     # 0x45c08
leaq 0x40(%rsp), %r14
movq %r14, %rsi
callq 0x22f14
movq %r14, %rdi
callq 0x22ed0
movl $0x8, %edi
callq 0x52e0
movq $0x0, (%rax)
movq %rax, %rcx
addq $0x8, %rcx
movq 0x350(%r15), %rdi
movq %rax, 0x350(%r15)
movq %rcx, 0x358(%r15)
movq %rcx, 0x360(%r15)
testq %rdi, %rdi
je 0x23887
callq 0x52a0
movl $0x8, %edi
callq 0x52e0
movq $0x0, (%rax)
movq %rax, %rcx
addq $0x8, %rcx
movq 0x368(%r15), %rdi
movq %rax, 0x368(%r15)
movq %rcx, 0x370(%r15)
movq %rcx, 0x378(%r15)
testq %rdi, %rdi
je 0x238c5
callq 0x52a0
movq 0x30(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x238e5
callq 0x52a0
cmpb $0x1, 0x1cd(%r12)
jne 0x23930
movq 0x18(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x23913
callq 0x52a0
xorps %xmm0, %xmm0
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x23930
callq 0x52a0
xorps %xmm0, %xmm0
movups %xmm0, 0x398(%r15)
movups %xmm0, 0x3d8(%r15)
movups %xmm0, 0x3e8(%r15)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x23965
jmp 0x23965
jmp 0x23965
jmp 0x23965
movq %rax, %r14
jmp 0x2398a
jmp 0x2396c
movq %rax, %r14
jmp 0x23985
jmp 0x23973
movq %rax, %r14
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x23985
callq 0x52a0
movq 0x10(%rsp), %r15
movq 0x20(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2399c
callq 0x52a0
movq 0x18(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x239ae
callq 0x52a0
movq 0x30(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x239c0
callq 0x52a0
leaq 0x350(%r15), %rbx
movq 0x368(%r15), %rdi
testq %rdi, %rdi
je 0x239d8
callq 0x52a0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x239e5
callq 0x52a0
movq 0x28(%rsp), %rdi
callq 0xca60
movq 0x90(%rsp), %rdi
callq 0xc830
movq 0x2d0(%r15), %rdi
testq %rdi, %rdi
je 0x23a0d
callq 0x52a0
movq 0x2b8(%r15), %rdi
testq %rdi, %rdi
je 0x23a1e
callq 0x52a0
movq 0x38(%rsp), %rdi
callq 0xc830
movq 0x288(%r15), %rdi
testq %rdi, %rdi
je 0x23a39
callq 0x52a0
movq 0x98(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x23a4e
callq 0x52a0
movq %r15, %rdi
callq 0x284d2
movq %r14, %rdi
callq 0x55a0