// File: 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:
subq $0x2d8, %rsp            # imm = 0x2D8
movq 0x2e8(%rsp), %rax
movq 0x2e0(%rsp), %rax
movq %rdi, 0x2d0(%rsp)
movl %esi, 0x2cc(%rsp)
movl %edx, 0x2c8(%rsp)
movl %ecx, 0x2c4(%rsp)
movl %r8d, 0x2c0(%rsp)
movq %r9, 0x2b8(%rsp)
movq 0x2d0(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
movl 0x2cc(%rsp), %esi
movl 0x2c8(%rsp), %edx
movl 0x2c4(%rsp), %ecx
movl 0x2c0(%rsp), %r8d
movq 0x2b8(%rsp), %r9
movq 0x2e0(%rsp), %r10
movq 0x2e8(%rsp), %r11
movq %rsp, %rax
movq %r11, 0x8(%rax)
movq %r10, (%rax)
callq 0x537e0
movq 0xa0(%rsp), %rdi
leaq 0x42d61(%rip), %rax     # 0x928f8
movq %rax, (%rdi)
addq $0x270, %rdi            # imm = 0x270
movq %rdi, 0xb0(%rsp)
callq 0xe830
movq 0xa0(%rsp), %rdi
addq $0x288, %rdi            # imm = 0x288
movq %rdi, 0x58(%rsp)
callq 0x4d5f0
movq 0xa0(%rsp), %rdi
addq $0x2a0, %rdi            # imm = 0x2A0
movq %rdi, 0x60(%rsp)
callq 0xe850
movq 0xa0(%rsp), %rdi
addq $0x2b8, %rdi            # imm = 0x2B8
movq %rdi, 0xa8(%rsp)
callq 0xe830
movq 0xa0(%rsp), %rdi
addq $0x2d0, %rdi            # imm = 0x2D0
movq %rdi, 0x68(%rsp)
callq 0x4d5f0
movq 0xa0(%rsp), %rdi
addq $0x2e8, %rdi            # imm = 0x2E8
movq %rdi, 0xc0(%rsp)
callq 0xe850
movq 0xa0(%rsp), %rdi
addq $0x318, %rdi            # imm = 0x318
movq %rdi, 0x70(%rsp)
callq 0xe870
movq 0xa0(%rsp), %rdi
addq $0x350, %rdi            # imm = 0x350
movq %rdi, 0x78(%rsp)
callq 0xe8c0
movq 0xa0(%rsp), %rdi
addq $0x368, %rdi            # imm = 0x368
movq %rdi, 0x80(%rsp)
callq 0xe8c0
movq 0xa0(%rsp), %rdi
addq $0x380, %rdi            # imm = 0x380
movq %rdi, 0x88(%rsp)
callq 0xe8d0
movq 0xa0(%rsp), %rdi
addq $0x3a8, %rdi            # imm = 0x3A8
movq %rdi, 0x90(%rsp)
callq 0xe8e0
movq 0xa0(%rsp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
movq %rdi, 0x98(%rsp)
callq 0xe8e0
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rdi
leaq 0x44306(%rip), %rcx     # 0x93ff0
movq %rcx, 0xb8(%rsp)
movl 0x1c8(%rcx), %ecx
movl %ecx, 0x300(%rax)
callq 0xe910
movq 0xb0(%rsp), %rdi
callq 0xe910
movq 0xb8(%rsp), %rsi
movq 0xc0(%rsp), %rdi
addq $0x180, %rsi            # imm = 0x180
callq 0xe930
jmp 0x4fd2e
movq 0xa0(%rsp), %rdi
addq $0x2a0, %rdi            # imm = 0x2A0
leaq 0x442ac(%rip), %rsi     # 0x93ff0
addq $0x198, %rsi            # imm = 0x198
callq 0xe930
jmp 0x4fd52
movq 0xa0(%rsp), %rax
movb $0x0, 0x310(%rax)
leaq 0x44288(%rip), %rcx     # 0x93ff0
movb 0x1ce(%rcx), %cl
andb $0x1, %cl
movb %cl, 0x348(%rax)
movb $0x1, 0x349(%rax)
leaq 0x4426b(%rip), %rax     # 0x93ff0
cmpl $0x0, 0x40(%rax)
je 0x4fd98
leaq 0x4425e(%rip), %rax     # 0x93ff0
cmpl $0x0, 0x38(%rax)
jne 0x4fdc2
movq 0xa0(%rsp), %rax
movb $0x0, 0x349(%rax)
jmp 0x4fdc2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
jmp 0x50416
movq 0x43207(%rip), %rdi     # 0x92fd0
leaq 0x2366b(%rip), %rsi     # 0x7343b
callq 0x5380
jmp 0x4fdd7
leaq 0x44212(%rip), %rax     # 0x93ff0
addq $0x180, %rax            # imm = 0x180
movq %rax, 0x2a0(%rsp)
leaq 0x441fd(%rip), %rdi     # 0x93ff0
addq $0x180, %rdi            # imm = 0x180
callq 0xebf0
movq %rax, 0x298(%rsp)
leaq 0x441e2(%rip), %rdi     # 0x93ff0
addq $0x180, %rdi            # imm = 0x180
callq 0xec20
movq %rax, 0x290(%rsp)
leaq 0x298(%rsp), %rdi
leaq 0x290(%rsp), %rsi
callq 0xec50
testb $0x1, %al
jne 0x4fe40
jmp 0x4fed2
leaq 0x298(%rsp), %rdi
callq 0xec90
movq %rax, %rsi
leaq 0x270(%rsp), %rdi
callq 0x51b0
jmp 0x4fe5f
movq 0x4316a(%rip), %rdi     # 0x92fd0
leaq 0x270(%rsp), %rsi
callq 0x5330
movq %rax, 0x50(%rsp)
jmp 0x4fe7a
movq 0x50(%rsp), %rdi
leaq 0x211bc(%rip), %rsi     # 0x71042
callq 0x5380
jmp 0x4fe8d
leaq 0x270(%rsp), %rdi
callq 0x5768
leaq 0x298(%rsp), %rdi
callq 0xeca0
jmp 0x4fe22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x270(%rsp), %rdi
callq 0x5768
jmp 0x50416
movq 0x430f7(%rip), %rdi     # 0x92fd0
movq 0x430d8(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x4fee7
movq 0x430e2(%rip), %rdi     # 0x92fd0
leaq 0x2355b(%rip), %rsi     # 0x73450
callq 0x5380
jmp 0x4fefc
leaq 0x440ed(%rip), %rax     # 0x93ff0
addq $0x198, %rax            # imm = 0x198
movq %rax, 0x268(%rsp)
leaq 0x440d8(%rip), %rdi     # 0x93ff0
addq $0x198, %rdi            # imm = 0x198
callq 0xebf0
movq %rax, 0x260(%rsp)
leaq 0x440bd(%rip), %rdi     # 0x93ff0
addq $0x198, %rdi            # imm = 0x198
callq 0xec20
movq %rax, 0x258(%rsp)
leaq 0x260(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0xec50
testb $0x1, %al
jne 0x4ff65
jmp 0x4fff7
leaq 0x260(%rsp), %rdi
callq 0xec90
movq %rax, %rsi
leaq 0x238(%rsp), %rdi
callq 0x51b0
jmp 0x4ff84
movq 0x43045(%rip), %rdi     # 0x92fd0
leaq 0x238(%rsp), %rsi
callq 0x5330
movq %rax, 0x48(%rsp)
jmp 0x4ff9f
movq 0x48(%rsp), %rdi
leaq 0x21097(%rip), %rsi     # 0x71042
callq 0x5380
jmp 0x4ffb2
leaq 0x238(%rsp), %rdi
callq 0x5768
leaq 0x260(%rsp), %rdi
callq 0xeca0
jmp 0x4ff47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x238(%rsp), %rdi
callq 0x5768
jmp 0x50416
movq 0x42fd2(%rip), %rdi     # 0x92fd0
movq 0x42fb3(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x5000c
movq 0xa0(%rsp), %rax
testb $0x1, 0x348(%rax)
je 0x50033
movq 0xa0(%rsp), %rdi
movl $0x1, %esi
callq 0x504c0
jmp 0x50031
jmp 0x50033
movq 0xa0(%rsp), %rdi
xorl %esi, %esi
callq 0x504c0
jmp 0x50044
movq 0xa0(%rsp), %rax
testb $0x1, 0x310(%rax)
je 0x500b6
xorps %xmm0, %xmm0
movaps %xmm0, 0x220(%rsp)
movaps %xmm0, 0x210(%rsp)
movaps %xmm0, 0x200(%rsp)
leaq 0x200(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xe870
movq 0x40(%rsp), %rsi
movq 0xa0(%rsp), %rdi
addq $0x318, %rdi            # imm = 0x318
callq 0xecf0
movq 0x40(%rsp), %rdi
callq 0xed20
movq 0xa0(%rsp), %rdi
callq 0x50bd0
jmp 0x500b4
jmp 0x500b6
movq 0xa0(%rsp), %rax
leaq 0x4417b(%rip), %rcx     # 0x94240
movl $0x0, (%rcx)
movq $0x0, 0x308(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x1f0(%rsp)
movaps %xmm0, 0x1e0(%rsp)
movaps %xmm0, 0x1d0(%rsp)
movaps %xmm0, 0x1c0(%rsp)
movaps %xmm0, 0x1b0(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x4d570
jmp 0x50110
leaq 0x43b41(%rip), %rdi     # 0x93c58
leaq 0x1b0(%rsp), %rsi
movq %rsi, 0x38(%rsp)
callq 0x4d600
movq 0x38(%rsp), %rdi
callq 0x4d580
xorps %xmm0, %xmm0
movaps %xmm0, 0x1a0(%rsp)
movaps %xmm0, 0x190(%rsp)
movaps %xmm0, 0x180(%rsp)
movaps %xmm0, 0x170(%rsp)
movaps %xmm0, 0x160(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x4d570
jmp 0x5016d
leaq 0x43b34(%rip), %rdi     # 0x93ca8
leaq 0x160(%rsp), %rsi
movq %rsi, 0x28(%rsp)
callq 0x4d600
movq 0x28(%rsp), %rdi
callq 0x4d580
movq $0x0, 0x140(%rsp)
leaq 0x13f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xf010
movq 0x30(%rsp), %rcx
leaq 0x148(%rsp), %rdi
movl $0x1, %esi
leaq 0x140(%rsp), %rdx
callq 0xf020
jmp 0x501cf
movq 0xa0(%rsp), %rdi
addq $0x350, %rdi            # imm = 0x350
leaq 0x148(%rsp), %rsi
movq %rsi, 0x18(%rsp)
callq 0xf0a0
movq 0x18(%rsp), %rdi
callq 0xf0e0
leaq 0x13f(%rsp), %rdi
callq 0xf140
movq $0x0, 0x118(%rsp)
leaq 0x117(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0xf010
movq 0x20(%rsp), %rcx
leaq 0x120(%rsp), %rdi
movl $0x1, %esi
leaq 0x118(%rsp), %rdx
callq 0xf020
jmp 0x50246
movq 0xa0(%rsp), %rdi
addq $0x368, %rdi            # imm = 0x368
leaq 0x120(%rsp), %rsi
callq 0xf0a0
leaq 0x120(%rsp), %rdi
callq 0xf0e0
leaq 0x117(%rsp), %rdi
callq 0xf140
leaq 0xf8(%rsp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x5210
leaq 0xf8(%rsp), %rdi
callq 0xe8d0
movq 0xa0(%rsp), %rdi
addq $0x380, %rdi            # imm = 0x380
leaq 0xf8(%rsp), %rsi
callq 0xf150
leaq 0xf8(%rsp), %rdi
callq 0xef00
leaq 0x43d23(%rip), %rax     # 0x93ff0
testb $0x1, 0x1cd(%rax)
je 0x503b9
leaq 0xe0(%rsp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x5210
leaq 0xe0(%rsp), %rdi
callq 0xe8e0
movq 0xa0(%rsp), %rdi
addq $0x3a8, %rdi            # imm = 0x3A8
leaq 0xe0(%rsp), %rsi
callq 0xf420
leaq 0xe0(%rsp), %rdi
callq 0xf460
leaq 0xc8(%rsp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x5210
leaq 0xc8(%rsp), %rdi
callq 0xe8e0
movq 0xa0(%rsp), %rdi
addq $0x3c0, %rdi            # imm = 0x3C0
leaq 0xc8(%rsp), %rsi
callq 0xf420
leaq 0xc8(%rsp), %rdi
callq 0xf460
jmp 0x503b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x13f(%rsp), %rdi
callq 0xf140
jmp 0x50416
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2b0(%rsp)
movl %eax, 0x2ac(%rsp)
leaq 0x117(%rsp), %rdi
callq 0xf140
jmp 0x50416
movq 0xa0(%rsp), %rax
movq $0x0, 0x3e8(%rax)
movq $0x0, 0x398(%rax)
movq $0x0, 0x3a0(%rax)
movq $0x0, 0x3e0(%rax)
movq $0x0, 0x3d8(%rax)
movq $0x0, 0x3e8(%rax)
movq $0x0, 0x3f0(%rax)
addq $0x2d8, %rsp            # imm = 0x2D8
retq
movq 0x98(%rsp), %rdi
callq 0xf460
movq 0x90(%rsp), %rdi
callq 0xf460
movq 0x88(%rsp), %rdi
callq 0xef00
movq 0x80(%rsp), %rdi
callq 0xf0e0
movq 0x78(%rsp), %rdi
callq 0xf0e0
movq 0x70(%rsp), %rdi
callq 0xed20
movq 0xc0(%rsp), %rdi
callq 0xf560
movq 0x68(%rsp), %rdi
callq 0x4d6f0
movq 0xa8(%rsp), %rdi
callq 0xf620
movq 0x60(%rsp), %rdi
callq 0xf560
movq 0x58(%rsp), %rdi
callq 0x4d6f0
movq 0xb0(%rsp), %rdi
callq 0xf620
movq 0xa0(%rsp), %rdi
callq 0x549b0
movq 0x2b0(%rsp), %rdi
callq 0x5690
nopl (%rax)