// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movq %rdi, %rbx
movdqa 0x110(%rsp), %xmm0
movdqu %xmm0, (%rsp)
callq 0x25c7c
leaq 0x36bae(%rip), %rax     # 0x44618
movq %rax, (%rbx)
leaq 0x290(%rbx), %rax
movq %rax, 0xb0(%rsp)
movq %rax, 0x280(%rbx)
xorl %eax, %eax
movq %rax, 0x288(%rbx)
movb $0x0, 0x290(%rbx)
leaq 0x2a0(%rbx), %rbp
leaq 0x2e8(%rbx), %r14
leaq 0x310(%rbx), %rcx
movl $0x0, 0x310(%rbx)
movq %rax, 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 %rcx, 0x320(%rbx)
movq %rcx, 0x328(%rbx)
movq %rax, 0x330(%rbx)
leaq 0x340(%rbx), %rcx
movq %rcx, 0x68(%rsp)
movdqu %xmm0, 0x340(%rbx)
movq %rax, 0x350(%rbx)
leaq 0x3a0(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0x3b8(%rbx), %rax
movq %rax, 0x50(%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 0x383d9(%rip), %rax     # 0x45f50
movq 0xac(%rax), %rax
movq %rax, 0x338(%rbx)
movq %r14, %rdi
callq 0x11dbe
movl 0x33c(%rbx), %esi
movq %r14, 0x60(%rsp)
movq %r14, %rdi
callq 0x11e00
cmpl $0x0, 0x33c(%rbx)
je 0xdc3d
xorl %r15d, %r15d
leaq (%r15,%r15,2), %rdi
shlq $0x3, %rdi
addq 0x2e8(%rbx), %rdi
movl 0x338(%rbx), %esi
callq 0x11e82
cmpl $0x0, 0x338(%rbx)
je 0xdc2b
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %r12
xorl %r13d, %r13d
movl $0xc0, %edi
callq 0x52e0
movq %rax, %r14
movq %rax, %rdi
callq 0x11eb4
movq 0x2e8(%rbx), %rax
movq (%rax,%r12), %rax
movq %r14, (%rax,%r13,8)
movq 0x2e8(%rbx), %rax
movq (%rax,%r12), %rax
movq (%rax,%r13,8), %rax
movl %r15d, 0x30(%rax)
movl %r13d, 0x34(%rax)
incq %r13
movl 0x338(%rbx), %eax
cmpq %rax, %r13
jb 0xdbe2
incq %r15
movl 0x33c(%rbx), %eax
cmpq %rax, %r15
jb 0xdbb0
movl $0x130, %edi            # imm = 0x130
addq 0x37357(%rip), %rdi     # 0x44fa0
leaq 0x2774c(%rip), %rsi     # 0x3539c
movl $0x1, %ecx
xorl %edx, %edx
callq 0x5590
cmpq $-0x1, %rax
je 0xddf2
leaq 0xc8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x382d7(%rip), %rax     # 0x45f50
movq 0x130(%rax), %rsi
movq 0x138(%rax), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
movq %rbp, 0x48(%rsp)
callq 0xcc1c
leaq 0x90(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
movl $0x42, %edx
callq 0x2e5ac
movq 0xb8(%rsp), %rdi
cmpq %r14, %rdi
je 0xdcc8
callq 0x52a0
movq 0x90(%rsp), %r15
movq 0x98(%rsp), %rbp
cmpq %r15, %rbp
je 0xdde0
leaq 0x30(%rsp), %r12
leaq 0x20(%rsp), %r14
leaq 0x70(%rsp), %r13
movq %r12, 0x20(%rsp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xcc1c
movq 0x20(%rsp), %rdi
callq 0x54c0
movl %eax, 0x70(%rsp)
movq 0x348(%rbx), %rsi
cmpq 0x350(%rbx), %rsi
je 0xdd34
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x348(%rbx)
jmp 0xdd41
movq 0x68(%rsp), %rdi
movq %r13, %rdx
callq 0x12568
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0xdd50
callq 0x52a0
addq $0x20, %r15
cmpq %rbp, %r15
jne 0xdcf0
movq 0x340(%rbx), %r12
movq 0x348(%rbx), %rbp
cmpq %rbp, %r12
je 0xdde0
movq 0x3725d(%rip), %r13     # 0x44fd0
leaq 0x27622(%rip), %r14     # 0x3539c
movl (%r12), %r15d
movl $0x1a, %edx
movq %r13, %rdi
leaq 0x26c2b(%rip), %rsi     # 0x349b8
callq 0x5350
movq %r13, %rdi
movl %r15d, %esi
callq 0x5580
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x5350
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
addq $0x4, %r12
cmpq %rbp, %r12
jne 0xdd7a
leaq 0x90(%rsp), %rdi
callq 0xc830
movq 0x48(%rsp), %rbp
movl $0x28, %edi
callq 0x52e0
leaq 0x3814d(%rip), %r15     # 0x45f50
leaq 0x368e6(%rip), %rcx     # 0x446f0
movq %rcx, (%rax)
movq 0x60(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x338(%rbx), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, 0x14(%rax)
leaq 0x36859(%rip), %rcx     # 0x44688
movq %rcx, (%rax)
movq $0x1, 0x20(%rax)
movq %rax, 0x300(%rbx)
movq 0x388(%rbx), %rax
cmpq %rax, 0x390(%rbx)
je 0xde58
movq %rax, 0x390(%rbx)
movq 0x58(%rsp), %rdi
callq 0x11f94
pxor %xmm0, %xmm0
movdqa %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
movl $0x3c, %edi
callq 0x52e0
leaq 0x70(%rsp), %rdx
movq %rax, (%rdx)
movq %rax, 0x8(%rdx)
movq %rax, %rcx
addq $0x3c, %rcx
movq %rcx, 0x10(%rdx)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x2c(%rax)
movdqu %xmm0, 0x20(%rax)
movdqu %xmm0, 0x10(%rax)
movdqu %xmm0, (%rax)
movq %rcx, 0x8(%rdx)
leaq 0x90(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
movl $0xf, %esi
callq 0xc5b2
pxor %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movdqa %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movdqu 0x3a0(%rbx), %xmm0
movq 0x3b0(%rbx), %rax
leaq 0x90(%rsp), %r14
movaps (%r14), %xmm1
movups %xmm1, 0x3a0(%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x3b0(%rbx)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movaps (%rdi), %xmm1
movdqa %xmm0, (%rdi)
movaps %xmm1, (%r14)
movq %rcx, 0x10(%r14)
callq 0xc642
movq %r14, %rdi
callq 0xc642
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0xdf40
callq 0x52a0
cmpb $0x1, (%r15)
jne 0xdf5e
leaq 0x3771b(%rip), %rdi     # 0x45668
leaq 0x26a7f(%rip), %rsi     # 0x349d3
movl $0x10, %edx
callq 0x5060
pxor %xmm0, %xmm0
movdqa %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl $0x8, %edi
callq 0x52e0
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
movq %rax, 0x8(%rsi)
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x10(%rsi)
movq $0x0, (%rax)
movq %rcx, 0x8(%rsi)
movq 0x50(%rsp), %rdi
callq 0x1263c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xdfb6
callq 0x52a0
movl $0xe8, %esi
addq 0x36fde(%rip), %rsi     # 0x44fa0
movq %rbp, %rdi
callq 0xca74
leaq 0x2b8(%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
addq 0x36fc3(%rip), %rsi     # 0x44fa0
callq 0xca74
leaq 0x2d0(%rbx), %rdi
movl $0x118, %esi            # imm = 0x118
addq 0x36fab(%rip), %rsi     # 0x44fa0
callq 0xca74
movss 0xe0(%r15), %xmm0
ucomiss 0x26992(%rip), %xmm0    # 0x3499c
jne 0xe00e
jnp 0xe024
movq (%rbp), %rax
xorps %xmm1, %xmm1
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 $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq 0xb8(%rsp), %rdi
cmpq %r14, %rdi
je 0xe0bf
callq 0x52a0
jmp 0xe0bf
movq %rax, %r15
jmp 0xe0bf
movq %rax, %r15
movq 0x20(%rsp), %rdi
jmp 0xe08c
jmp 0xe0c6
movq %rax, %r15
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
jne 0xe0d1
jmp 0xe0d6
jmp 0xe0c6
movq %rax, %r15
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0xe0b2
callq 0x52a0
jmp 0xe0b2
jmp 0xe0c6
jmp 0xe0af
jmp 0xe0c6
movq %rax, %r15
leaq 0x90(%rsp), %rdi
callq 0xc830
movq 0x48(%rsp), %rbp
jmp 0xe0d6
movq %rax, %r15
jmp 0xe0d6
movq %rax, %r15
movq %r14, %rdi
callq 0x52a0
leaq 0x388(%rbx), %r14
leaq 0x3d0(%rbx), %rdi
callq 0x11fd6
movq 0x50(%rsp), %rdi
callq 0xc642
movq 0x58(%rsp), %rdi
callq 0xc642
movq (%r14), %rdi
testq %rdi, %rdi
je 0xe10a
callq 0x52a0
leaq 0x308(%rbx), %r14
movq 0x68(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0xe123
callq 0x52a0
movq %r14, %rdi
callq 0x12202
movq 0x60(%rsp), %rdi
callq 0x1202c
movq %rbp, %rdi
callq 0xc800
movq 0x280(%rbx), %rdi
cmpq 0xb0(%rsp), %rdi
je 0xe153
callq 0x52a0
movq %rbx, %rdi
callq 0x284d2
movq %r15, %rdi
callq 0x55a0
nop