// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movq %rdi, %rbx
movaps 0x100(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1e8c0
leaq 0x1fde4(%rip), %rax     # 0x3c928
movq %rax, (%rbx)
leaq 0x270(%rbx), %rdi
leaq 0x2a0(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0x2e8(%rbx), %r15
leaq 0x318(%rbx), %rax
movq %rax, 0x38(%rsp)
andl $0x0, 0x320(%rbx)
leaq 0x320(%rbx), %r14
andq $0x0, 0x328(%rbx)
movl $0x90, %edx
movq %rdi, 0x20(%rsp)
xorl %esi, %esi
callq 0x51c0
movq %r14, 0x330(%rbx)
movq %r14, 0x338(%rbx)
andq $0x0, 0x340(%rbx)
leaq 0x350(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x368(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x380(%rbx), %rax
movq %rax, 0x48(%rsp)
leaq 0x3a8(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x3c0(%rbx), %rax
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x350(%rbx)
movups %xmm0, 0x360(%rbx)
andq $0x0, 0x390(%rbx)
movups %xmm0, 0x370(%rbx)
movups %xmm0, 0x380(%rbx)
movups %xmm0, 0x3a8(%rbx)
movups %xmm0, 0x3b8(%rbx)
movups %xmm0, 0x3c8(%rbx)
leaq 0x21327(%rip), %rcx     # 0x3df50
movl 0x1c8(%rcx), %eax
movl %eax, 0x300(%rbx)
leaq 0x180(%rcx), %rsi
movq %r15, 0x60(%rsp)
movq %r15, %rdi
callq 0x9bc0
movl $0x198, %esi            # imm = 0x198
addq 0x2035b(%rip), %rsi     # 0x3cfb0
movq 0x58(%rsp), %rdi
callq 0x9bc0
movb $0x0, 0x310(%rbx)
leaq 0x212e3(%rip), %rcx     # 0x3df50
movb 0x1ce(%rcx), %al
movb %al, 0x348(%rbx)
cmpl $0x0, 0x40(%rcx)
setne %al
cmpl $0x0, 0x38(%rcx)
setne %cl
andb %al, %cl
movb %cl, 0x349(%rbx)
movq 0x2033a(%rip), %rdi     # 0x3cfd0
leaq 0xe7a6(%rip), %rsi      # 0x2b443
callq 0x52c0
leaq 0x212a7(%rip), %rax     # 0x3df50
movq 0x180(%rax), %r15
movq 0x188(%rax), %r14
leaq 0x70(%rsp), %r12
movq 0x2030d(%rip), %rbp     # 0x3cfd0
leaq 0xc368(%rip), %r13      # 0x29032
cmpq %r14, %r15
je 0x1ccfe
movq %r12, %rdi
movq %r15, %rsi
callq 0x5410
movq %rbp, %rdi
movq %r12, %rsi
callq 0x5290
movq %rax, %rdi
movq %r13, %rsi
callq 0x52c0
movq %r12, %rdi
callq 0x5618
addq $0x20, %r15
jmp 0x1ccca
movq 0x202cb(%rip), %rdi     # 0x3cfd0
callq 0x5190
movq 0x202bf(%rip), %rdi     # 0x3cfd0
leaq 0xe740(%rip), %rsi      # 0x2b458
callq 0x52c0
leaq 0x2122c(%rip), %rax     # 0x3df50
movq 0x198(%rax), %r15
movq 0x1a0(%rax), %r14
leaq 0x70(%rsp), %r12
movq 0x20292(%rip), %rbp     # 0x3cfd0
leaq 0xc2ed(%rip), %r13      # 0x29032
cmpq %r14, %r15
je 0x1cd79
movq %r12, %rdi
movq %r15, %rsi
callq 0x5410
movq %rbp, %rdi
movq %r12, %rsi
callq 0x5290
movq %rax, %rdi
movq %r13, %rsi
callq 0x52c0
movq %r12, %rdi
callq 0x5618
addq $0x20, %r15
jmp 0x1cd45
movq 0x20250(%rip), %rdi     # 0x3cfd0
callq 0x5190
cmpb $0x1, 0x348(%rbx)
jne 0x1cd99
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x1d04c
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1d04c
cmpb $0x1, 0x310(%rbx)
jne 0x1cdec
leaq 0x78(%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 0x70(%rsp), %r15
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0xa19a
movq %r15, %rdi
callq 0xa27e
movq %rbx, %rdi
callq 0x1d47c
leaq 0x213ad(%rip), %rax     # 0x3e1a0
andl $0x0, (%rax)
andq $0x0, 0x308(%rbx)
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
callq 0x1c334
leaq 0x20d93(%rip), %rdi     # 0x3dbb8
leaq 0x70(%rsp), %r15
movq %r15, %rsi
callq 0x1c534
movq %r15, %rdi
callq 0x1c500
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
leaq 0x70(%rsp), %rdi
callq 0x1c334
leaq 0x20da2(%rip), %rdi     # 0x3dc08
leaq 0x70(%rsp), %r15
movq %r15, %rsi
callq 0x1c534
movq %r15, %rdi
callq 0x1c500
leaq 0x68(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x70(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x1f(%rsp), %rcx
callq 0x9d90
leaq 0x70(%rsp), %r15
movq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0xab1e
movq %r15, %rdi
callq 0xa4a8
leaq 0x68(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x70(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x1f(%rsp), %rcx
callq 0x9d90
leaq 0x70(%rsp), %r15
movq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0xab1e
movq %r15, %rdi
callq 0xa4a8
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
leaq 0x70(%rsp), %r14
movq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0xa52e
movq %r14, %rdi
callq 0xa49a
leaq 0x2103e(%rip), %rax     # 0x3df50
cmpb $0x1, 0x1cd(%rax)
jne 0x1cf67
leaq 0x70(%rsp), %r14
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
movq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0xadd2
movq %r14, %rdi
callq 0xa7d8
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
leaq 0x70(%rsp), %r14
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0xadd2
movq %r14, %rdi
callq 0xa7d8
xorps %xmm0, %xmm0
movups %xmm0, 0x398(%rbx)
movups %xmm0, 0x3d8(%rbx)
movups %xmm0, 0x3e8(%rbx)
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1cf9d
jmp 0x1cf9d
jmp 0x1cf9d
jmp 0x1cf9d
jmp 0x1cf9d
jmp 0x1cf9d
movq %rax, %rbp
jmp 0x1cfb1
jmp 0x1cfa4
movq %rax, %rbp
leaq 0x70(%rsp), %rdi
callq 0x5618
movq 0x20(%rsp), %r14
leaq 0x2d0(%rbx), %r13
leaq 0x2b8(%rbx), %r12
leaq 0x288(%rbx), %r15
movq 0x30(%rsp), %rdi
callq 0xa7d8
movq 0x28(%rsp), %rdi
callq 0xa7d8
movq 0x48(%rsp), %rdi
callq 0xa49a
movq 0x40(%rsp), %rdi
callq 0xa4a8
movq 0x50(%rsp), %rdi
callq 0xa4a8
movq 0x38(%rsp), %rdi
callq 0xa27e
movq 0x60(%rsp), %rdi
callq 0x9ef6
movq %r13, %rdi
callq 0x1c526
movq %r12, %rdi
callq 0xa762
movq 0x58(%rsp), %rdi
callq 0x9ef6
movq %r15, %rdi
callq 0x1c526
movq %r14, %rdi
callq 0xa762
movq %rbx, %rdi
callq 0x2087a
movq %rbp, %rdi
callq 0x5570
nop