// File: /workspace/github_cpp_makefile_star2_O2/gvaumour[P]cache-simulator/src/DBAMBPredictor.cc
// Function: DBAMBPredictor::DBAMBPredictor(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*)
DBAMBPredictor::DBAMBPredictor(int id, int nbAssoc , int nbSet, int nbNVMways, DataArray& SRAMtable, DataArray& NVMtable, HybridCache* cache) : \
	Predictor(id, nbAssoc, nbSet, nbNVMways, SRAMtable, NVMtable, cache) {

	m_cpt = 1;
	m_RAP_assoc = simu_parameters.rap_assoc;
	m_RAP_sets = simu_parameters.rap_sets;

	m_DHPTable.clear();
	m_DHPTable.resize(m_RAP_sets);
	
	for(unsigned i = 0 ; i < m_RAP_sets ; i++)
	{
		m_DHPTable[i].resize(m_RAP_assoc);
		
		
		for(unsigned j = 0 ; j < m_RAP_assoc ; j++)
		{
			m_DHPTable[i][j] = new DHPEntry();
			m_DHPTable[i][j]->index = i;
			m_DHPTable[i][j]->assoc = j;
		}
	}
	/*
	if(simu_parameters.enableReuseErrorComputation)
		stats_history_SRAM.resize(nbSet);
	*/

	if(simu_parameters.DBAMB_signature.find("B") != std::string::npos)
	{	
		vector<string> split_line = split(simu_parameters.DBAMB_signature , 'B');
	
		if(split_line.size() != 0)
		{
			for(auto byte : split_line)
				m_hashingBytes.push_back(atoi(byte.c_str()));
			
			for(auto byte : m_hashingBytes)
				cout << "Hashing Function - Byte : " << byte << "B" << endl;
	
		}

	}

	
	//DPRINTF("RAPPredictor::Constructor m_DHPTable.size() = %lu , m_DHPTable[0].size() = %lu\n" , m_DHPTable.size() , m_DHPTable[0].size());

	m_rap_policy = new DBAMBLRUPolicy(m_RAP_assoc , m_RAP_sets , m_DHPTable);

	/* Stats init*/ 
	stats_nbSwitchDst.clear();
	stats_ClassErrors.clear();
	stats_ClassErrors = vector< vector<int> >(NUM_RW_TYPE*NUM_RD_TYPE, vector<int>(NUM_RD_TYPE*NUM_RW_TYPE, 0));	
	

	if(simu_parameters.printDebug)
		dataset_file.open(RAP_TEST_OUTPUT_DATASETS);
	
	stats_nbMigrationsFromNVM.push_back(vector<int>(2,0));

	m_costParameters = simu_parameters.optTarget;
	
	if(simu_parameters.ratio_RWcost != -1)
		m_costParameters.costNVM[WRITE_ACCESS] = m_costParameters.costNVM[READ_ACCESS]*simu_parameters.ratio_RWcost;
	
	stats_error_wrongallocation = 0;
	stats_error_learning = 0;
	stats_error_wrongpolicy = 0;	

	stats_error_SRAMwrongallocation = 0;
	stats_error_SRAMlearning = 0;
	stats_error_SRAMwrongpolicy = 0;

	stats_allocate_NVM = 0, stats_allocate_SRAM = 0;
	stats_busyness_alloc_change = 0, stats_busyness_migrate_change = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
movdqa 0xd0(%rsp), %xmm0
movdqu %xmm0, (%rsp)
callq 0x1e8c0
leaq 0x30f2a(%rip), %rax     # 0x3c688
movq %rax, (%rbx)
leaq 0x290(%rbx), %rax
movq %rax, 0x280(%rbx)
andq $0x0, 0x288(%rbx)
movb $0x0, 0x290(%rbx)
leaq 0x2a0(%rbx), %r12
leaq 0x2e8(%rbx), %r15
leaq 0x310(%rbx), %rax
andl $0x0, 0x310(%rbx)
andq $0x0, 0x318(%rbx)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x2a0(%rbx)
movdqu %xmm0, 0x2b0(%rbx)
movdqu %xmm0, 0x2c0(%rbx)
movdqu %xmm0, 0x2d0(%rbx)
movdqu %xmm0, 0x2e0(%rbx)
movdqu %xmm0, 0x2f0(%rbx)
movq %rax, 0x320(%rbx)
movq %rax, 0x328(%rbx)
andq $0x0, 0x330(%rbx)
leaq 0x340(%rbx), %rax
movq %rax, 0x50(%rsp)
movdqu %xmm0, 0x340(%rbx)
andq $0x0, 0x350(%rbx)
leaq 0x3a0(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x3b8(%rbx), %rax
movq %rax, 0x40(%rsp)
movdqu %xmm0, 0x388(%rbx)
movdqu %xmm0, 0x398(%rbx)
movdqu %xmm0, 0x3a8(%rbx)
movdqu %xmm0, 0x3b8(%rbx)
movdqu %xmm0, 0x3c8(%rbx)
movdqu %xmm0, 0x3d8(%rbx)
movq $0x1, 0x270(%rbx)
leaq 0x326ee(%rip), %rax     # 0x3df50
movq 0xac(%rax), %rax
movq %rax, 0x338(%rbx)
movq %r15, %rdi
callq 0xe678
movl 0x33c(%rbx), %esi
movq %r15, %rdi
movq %r12, 0x48(%rsp)
callq 0xe680
xorl %r12d, %r12d
movl 0x33c(%rbx), %eax
cmpq %rax, %r12
jae 0xb8fb
imulq $0x18, %r12, %r13
movq 0x2e8(%rbx), %rdi
addq %r13, %rdi
movl 0x338(%rbx), %esi
callq 0xe6b6
xorl %ebp, %ebp
movl 0x338(%rbx), %eax
cmpq %rax, %rbp
jae 0xb8f6
movl $0xc0, %edi
callq 0x52e0
movq %rax, %r14
movq %rax, %rdi
callq 0xe6e8
movq (%r15), %rax
movq (%rax,%r13), %rax
movq %r14, (%rax,%rbp,8)
movq (%r15), %rax
movq (%rax,%r13), %rax
movq (%rax,%rbp,8), %rax
movl %r12d, 0x30(%rax)
movl %ebp, 0x34(%rax)
incq %rbp
jmp 0xb8b4
incq %r12
jmp 0xb88e
movl $0x130, %r14d           # imm = 0x130
addq 0x316a8(%rip), %r14     # 0x3cfb0
leaq 0x1ea09(%rip), %rsi     # 0x2a318
movq %r14, %rdi
xorl %edx, %edx
callq 0x5600
cmpq $-0x1, %rax
je 0xba01
leaq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0x5410
leaq 0x28(%rsp), %rdi
leaq 0x78(%rsp), %rsi
pushq $0x42
popq %rdx
callq 0x24e58
leaq 0x78(%rsp), %rdi
callq 0x5618
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %r12
cmpq %r14, %r12
je 0xb9f7
leaq 0x58(%rsp), %r13
leaq 0x18(%rsp), %rbp
cmpq %r12, %r14
je 0xb9a2
movq %r13, %rdi
movq %r14, %rsi
callq 0x5410
movq 0x58(%rsp), %rdi
callq 0x5490
movl %eax, 0x18(%rsp)
movq 0x50(%rsp), %rdi
movq %rbp, %rsi
callq 0xeef4
movq %r13, %rdi
callq 0x5618
addq $0x20, %r14
jmp 0xb969
movq 0x340(%rbx), %rbp
movq 0x348(%rbx), %r14
leaq 0x1e961(%rip), %r13     # 0x2a318
cmpq %r14, %rbp
je 0xb9f7
movl (%rbp), %r12d
movq 0x31609(%rip), %rdi     # 0x3cfd0
leaq 0x1dfaa(%rip), %rsi     # 0x29978
callq 0x52c0
movq %rax, %rdi
movl %r12d, %esi
callq 0x5560
movq %rax, %rdi
movq %r13, %rsi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
addq $0x4, %rbp
jmp 0xb9b7
leaq 0x28(%rsp), %rdi
callq 0x9ef6
pushq $0x28
popq %rdi
movq 0x48(%rsp), %r12
callq 0x52e0
movq %r15, 0x8(%rax)
movq 0x338(%rbx), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x14(%rax)
leaq 0x30ccd(%rip), %rcx     # 0x3c6f8
movq %rcx, (%rax)
movq $0x1, 0x20(%rax)
movq %rax, 0x300(%rbx)
movq 0x388(%rbx), %rax
cmpq %rax, 0x390(%rbx)
je 0xba54
movq %rax, 0x390(%rbx)
movq 0x20(%rsp), %rdi
callq 0xe7c6
leaq 0x18(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x28(%rsp), %rdi
pushq $0xf
popq %rsi
leaq 0x1f(%rsp), %rcx
callq 0x9c8a
leaq 0x58(%rsp), %rdi
pushq $0xf
popq %rsi
leaq 0x28(%rsp), %rdx
leaq 0x1e(%rsp), %rcx
callq 0x9ce0
leaq 0x58(%rsp), %r14
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0xa710
movq %r14, %rdi
callq 0x9d36
leaq 0x28(%rsp), %rdi
callq 0xa49a
leaq 0x32496(%rip), %rax     # 0x3df50
cmpb $0x1, (%rax)
jne 0xbad5
leaq 0x31ba2(%rip), %rdi     # 0x3d668
leaq 0x1dec6(%rip), %rsi     # 0x29993
pushq $0x10
popq %rdx
callq 0x5050
leaq 0x28(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x58(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0x18(%rsp), %rcx
callq 0x9c8a
leaq 0x58(%rsp), %rsi
movq 0x40(%rsp), %rdi
callq 0xf004
leaq 0x58(%rsp), %rdi
callq 0xa49a
movl $0xe8, %esi
addq 0x3149c(%rip), %rsi     # 0x3cfb0
movq %r12, %rdi
callq 0x9d58
leaq 0x3242d(%rip), %rax     # 0x3df50
movss 0xe0(%rax), %xmm0
ucomiss 0x1de2a(%rip), %xmm0    # 0x2995c
jne 0xbb36
jnp 0xbb49
movq (%r12), %rax
cvtsi2ssl (%rax), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %ecx
movl %ecx, 0x4(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x360(%rbx)
movups %xmm0, 0x378(%rbx)
movups %xmm0, 0x3e8(%rbx)
movups %xmm0, 0x3f8(%rbx)
movups %xmm0, 0x408(%rbx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbp
leaq 0x78(%rsp), %rdi
callq 0x5618
jmp 0xbbe3
jmp 0xbbe0
movq %rax, %rbp
leaq 0x58(%rsp), %rdi
jmp 0xbba6
jmp 0xbbe0
movq %rax, %rbp
leaq 0x28(%rsp), %rdi
callq 0xa49a
jmp 0xbbe3
jmp 0xbbe0
jmp 0xbbe0
jmp 0xbbc4
movq %rax, %rbp
leaq 0x58(%rsp), %rdi
callq 0x5618
jmp 0xbbc7
jmp 0xbbe0
movq %rax, %rbp
leaq 0x28(%rsp), %rdi
callq 0x9ef6
jmp 0xbbe3
movq %rax, %rbp
movq %r14, %rdi
callq 0x52a0
jmp 0xbbe3
movq %rax, %rbp
leaq 0x280(%rbx), %r14
leaq 0x388(%rbx), %r12
leaq 0x3d0(%rbx), %rdi
leaq 0x308(%rbx), %r13
callq 0xe7ce
movq 0x40(%rsp), %rdi
callq 0x9d36
movq 0x20(%rsp), %rdi
callq 0x9d36
movq %r12, %rdi
callq 0xa7d8
movq 0x50(%rsp), %rdi
callq 0xa49a
movq %r13, %rdi
callq 0xea0a
movq %r15, %rdi
callq 0xe7f0
movq 0x48(%rsp), %rdi
callq 0x9ed6
movq %r14, %rdi
callq 0x5618
movq %rbx, %rdi
callq 0x2087a
movq %rbp, %rdi
callq 0x5570