// File: /workspace/github_cpp_makefile_star2_O3/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 0x25a74
leaq 0x21700(%rip), %rax     # 0x44910
movq %rax, (%r15)
leaq 0x270(%r15), %rdi
leaq 0x2a0(%r15), %rax
movq %rax, 0x38(%rsp)
leaq 0x2e8(%r15), %r14
leaq 0x318(%r15), %rax
movq %rax, 0x28(%rsp)
leaq 0x320(%r15), %r12
movl $0x0, 0x320(%r15)
xorl %ebx, %ebx
movq %rbx, 0x328(%r15)
movl $0x90, %edx
movq %rdi, 0x98(%rsp)
xorl %esi, %esi
callq 0x51b0
movq %r12, 0x330(%r15)
movq %r12, 0xa0(%rsp)
movq %r12, 0x338(%r15)
movq %rbx, 0x340(%r15)
leaq 0x380(%r15), %rax
movq %rax, 0x30(%rsp)
leaq 0x3a8(%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0x3c0(%r15), %rax
movq %rax, 0x20(%rsp)
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 0x22c5e(%rip), %rbx     # 0x45f50
movl 0x1c8(%rbx), %eax
movl %eax, 0x300(%r15)
leaq 0x180(%rbx), %rsi
movq %r14, 0x90(%rsp)
movq %r14, %rdi
callq 0xc3b4
movl $0x198, %esi            # imm = 0x198
addq 0x21c7e(%rip), %rsi     # 0x44fa0
movq 0x38(%rsp), %rdi
callq 0xc3b4
movb $0x0, 0x310(%r15)
movb 0x1ce(%rbx), %al
movb %al, 0x348(%r15)
cmpl $0x0, 0x40(%rbx)
setne %al
cmpl $0x0, 0x38(%rbx)
setne %cl
andb %al, %cl
movb %cl, 0x349(%r15)
movq 0x21c71(%rip), %rdi     # 0x44fd0
leaq 0x1312d(%rip), %rsi     # 0x36493
movl $0x14, %edx
callq 0x5360
movq %r15, 0x10(%rsp)
movq 0x180(%rbx), %r12
movq 0x188(%rbx), %rbx
cmpq %rbx, %r12
je 0x233f3
leaq 0x50(%rsp), %rbp
leaq 0x40(%rsp), %r13
movq 0x21c37(%rip), %r14     # 0x44fd0
leaq 0x10c76(%rip), %r15     # 0x34016
movq %rbp, 0x40(%rsp)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xcbd6
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %r14, %rdi
callq 0x5360
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x5360
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x233ea
callq 0x52b0
addq $0x20, %r12
cmpq %rbx, %r12
jne 0x233a0
movq 0x21bd6(%rip), %rdi     # 0x44fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
movq 0x10(%rsp), %r15
callq 0x52c0
leaq 0x22b39(%rip), %rbx     # 0x45f50
movsbl %al, %esi
movq 0x21baf(%rip), %rdi     # 0x44fd0
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq 0x21b9b(%rip), %rdi     # 0x44fd0
leaq 0x1306c(%rip), %rsi     # 0x364a8
movl $0x17, %edx
callq 0x5360
movq 0x198(%rbx), %r12
movq 0x1a0(%rbx), %rbx
cmpq %rbx, %r12
je 0x234c4
leaq 0x50(%rsp), %rbp
leaq 0x40(%rsp), %r13
movq 0x21b66(%rip), %r14     # 0x44fd0
leaq 0x10ba5(%rip), %r15     # 0x34016
movq %rbp, 0x40(%rsp)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xcbd6
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %r14, %rdi
callq 0x5360
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x5360
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x234bb
callq 0x52b0
addq $0x20, %r12
cmpq %rbx, %r12
jne 0x23471
movq 0x21b05(%rip), %rdi     # 0x44fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
movq 0x10(%rsp), %r15
callq 0x52c0
leaq 0x22a68(%rip), %r12     # 0x45f50
movsbl %al, %esi
movq 0x21ade(%rip), %rdi     # 0x44fd0
callq 0x5030
movq %rax, %rdi
callq 0x5200
cmpb $0x1, 0x348(%r15)
jne 0x23516
movq %r15, %rdi
movl $0x1, %esi
callq 0x2386c
movq %r15, %rdi
xorl %esi, %esi
callq 0x2386c
cmpb $0x1, 0x310(%r15)
jne 0x235be
leaq 0x48(%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 0x28(%rsp), %rdi
callq 0xc9a8
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x235ac
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 0xca0c
movq %r15, %rdi
callq 0x23dee
leaq 0x22bdb(%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 0x22bac
leaq 0x225b9(%rip), %rdi     # 0x45bb8
leaq 0x40(%rsp), %r14
movq %r14, %rsi
callq 0x22d5e
movq %r14, %rdi
callq 0x22d14
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 0x22bac
leaq 0x225c6(%rip), %rdi     # 0x45c08
leaq 0x40(%rsp), %r14
movq %r14, %rsi
callq 0x22d5e
movq %r14, %rdi
callq 0x22d14
movl $0x8, %edi
callq 0x52f0
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 0x23695
callq 0x52b0
movl $0x8, %edi
callq 0x52f0
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 0x236d3
callq 0x52b0
movq 0x30(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x236f3
callq 0x52b0
cmpb $0x1, 0x1cd(%r12)
jne 0x2373e
movq 0x18(%rsp), %rax
movq (%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x23721
callq 0x52b0
xorps %xmm0, %xmm0
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x2373e
callq 0x52b0
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 0x23773
jmp 0x23773
jmp 0x23773
jmp 0x23773
movq %rax, %r14
jmp 0x23798
jmp 0x2377a
movq %rax, %r14
jmp 0x23793
jmp 0x23781
movq %rax, %r14
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x23793
callq 0x52b0
movq 0x10(%rsp), %r15
movq 0x20(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x237aa
callq 0x52b0
movq 0x18(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x237bc
callq 0x52b0
movq 0x30(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x237ce
callq 0x52b0
leaq 0x350(%r15), %rbx
movq 0x368(%r15), %rdi
testq %rdi, %rdi
je 0x237e6
callq 0x52b0
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x237f3
callq 0x52b0
movq 0x28(%rsp), %rdi
callq 0xca0c
movq 0x90(%rsp), %rdi
callq 0xc7c2
movq 0x2d0(%r15), %rdi
testq %rdi, %rdi
je 0x2381b
callq 0x52b0
movq 0x2b8(%r15), %rdi
testq %rdi, %rdi
je 0x2382c
callq 0x52b0
movq 0x38(%rsp), %rdi
callq 0xc7c2
movq 0x288(%r15), %rdi
testq %rdi, %rdi
je 0x23847
callq 0x52b0
movq 0x98(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2385c
callq 0x52b0
movq %r15, %rdi
callq 0x2819a
movq %r14, %rdi
callq 0x55a0