// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movq %rdi, %rbx
movdqa 0xf0(%rsp), %xmm0
movdqu %xmm0, (%rsp)
callq 0x25a74
leaq 0x36c42(%rip), %rax     # 0x44670
movq %rax, (%rbx)
leaq 0x290(%rbx), %rax
movq %rax, 0x78(%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, 0x38(%rsp)
movdqu %xmm0, 0x340(%rbx)
movq %rax, 0x350(%rbx)
leaq 0x3a0(%rbx), %rax
movq %rax, 0x30(%rsp)
leaq 0x3b8(%rbx), %rax
movq %rax, 0x28(%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 0x38418(%rip), %rax     # 0x45f50
movq 0xac(%rax), %rax
movq %rax, 0x338(%rbx)
movq %r14, %rdi
callq 0x11d04
movl 0x33c(%rbx), %esi
movq %r14, 0x18(%rsp)
movq %r14, %rdi
callq 0x11d46
cmpl $0x0, 0x33c(%rbx)
je 0xdc05
movl 0x338(%rbx), %eax
xorl %r15d, %r15d
leaq (%r15,%r15,2), %rdi
shlq $0x3, %rdi
movq 0x18(%rsp), %rcx
addq (%rcx), %rdi
movl %eax, %esi
callq 0x11dc8
cmpl $0x0, 0x338(%rbx)
je 0xdbf1
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %r12
xorl %r13d, %r13d
movl $0xc0, %edi
callq 0x52f0
movq %rax, %r14
movq %rax, %rdi
callq 0x11dfa
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 0xdba6
jmp 0xdbf3
xorl %eax, %eax
incq %r15
movl 0x33c(%rbx), %ecx
cmpq %rcx, %r15
jb 0xdb77
movl $0x130, %edi            # imm = 0x130
addq 0x3738f(%rip), %rdi     # 0x44fa0
leaq 0x27754(%rip), %rsi     # 0x3536c
movl $0x1, %ecx
xorl %edx, %edx
callq 0x5590
cmpq $-0x1, %rax
je 0xddb7
leaq 0xa8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x3830f(%rip), %rax     # 0x45f50
movq 0x130(%rax), %rsi
movq 0x138(%rax), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
movq %rbp, 0x20(%rsp)
callq 0xcbd6
leaq 0x60(%rsp), %rdi
leaq 0x98(%rsp), %rsi
movl $0x42, %edx
callq 0x2e230
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0xdc8d
callq 0x52b0
movq 0x60(%rsp), %r15
movq 0x68(%rsp), %r13
cmpq %r15, %r13
je 0xdda8
leaq 0x50(%rsp), %rbp
leaq 0x40(%rsp), %r14
movq %rbp, 0x40(%rsp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xcbd6
movq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x54c0
movl %eax, 0x80(%rsp)
movq 0x348(%rbx), %rsi
cmpq 0x350(%rbx), %rsi
je 0xdcf4
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x348(%rbx)
jmp 0xdd0b
movq 0x38(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x124c0
movq 0x40(%rsp), %r12
cmpq %rbp, %r12
je 0xdd18
movq %r12, %rdi
callq 0x52b0
addq $0x20, %r15
cmpq %r13, %r15
jne 0xdcaa
movq 0x340(%rbx), %r15
movq 0x348(%rbx), %rbp
cmpq %rbp, %r15
je 0xdda8
movq 0x37295(%rip), %r13     # 0x44fd0
leaq 0x2762a(%rip), %r14     # 0x3536c
movl (%r15), %r12d
movl $0x1a, %edx
movq %r13, %rdi
leaq 0x26c44(%rip), %rsi     # 0x34998
callq 0x5360
movq %r13, %rdi
movl %r12d, %esi
callq 0x5580
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x5360
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %r12, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
addq $0x4, %r15
cmpq %rbp, %r15
jne 0xdd42
leaq 0x60(%rsp), %rdi
callq 0xc7c2
movq 0x20(%rsp), %rbp
movl $0x28, %edi
callq 0x52f0
leaq 0x38188(%rip), %r15     # 0x45f50
movq 0x18(%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 0x368f6(%rip), %rcx     # 0x446e0
movq %rcx, (%rax)
movq $0x1, 0x20(%rax)
movq %rax, 0x300(%rbx)
movq 0x388(%rbx), %rax
cmpq %rax, 0x390(%rbx)
je 0xde13
movq %rax, 0x390(%rbx)
movq 0x30(%rsp), %rdi
callq 0x11eda
movl $0x3c, %edi
callq 0x52f0
leaq 0x80(%rsp), %rdx
movq %rax, (%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 0x60(%rsp), %rdi
leaq 0x17(%rsp), %rcx
movl $0xf, %esi
callq 0xc524
movq 0x3b0(%rbx), %rax
leaq 0x60(%rsp), %r14
movdqa (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x3b0(%rbx)
movups 0x3a0(%rbx), %xmm1
movdqu %xmm0, 0x3a0(%rbx)
leaq 0x40(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
pxor %xmm0, %xmm0
movdqa %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0xc5b4
movq %r14, %rdi
callq 0xc5b4
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0xded3
callq 0x52b0
cmpb $0x1, (%r15)
jne 0xdef1
leaq 0x37788(%rip), %rdi     # 0x45668
leaq 0x26acc(%rip), %rsi     # 0x349b3
movl $0x10, %edx
callq 0x5060
movl $0x8, %edi
callq 0x52f0
leaq 0x40(%rsp), %rsi
movq %rax, (%rsi)
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x10(%rsi)
movq $0x0, (%rax)
movq %rcx, 0x8(%rsi)
movq 0x28(%rsp), %rdi
callq 0x12594
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xdf32
callq 0x52b0
movl $0xe8, %esi
addq 0x37062(%rip), %rsi     # 0x44fa0
movq %rbp, %rdi
callq 0xca20
leaq 0x2b8(%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
addq 0x37047(%rip), %rsi     # 0x44fa0
callq 0xca20
leaq 0x2d0(%rbx), %rdi
movl $0x118, %esi            # imm = 0x118
addq 0x3702f(%rip), %rsi     # 0x44fa0
callq 0xca20
movss 0xe0(%r15), %xmm0
ucomiss 0x269e6(%rip), %xmm0    # 0x3496c
jne 0xdf8a
jnp 0xdfa0
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 $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0xe03b
callq 0x52b0
jmp 0xe03b
movq %rax, %r15
jmp 0xe03b
movq %rax, %r15
movq 0x40(%rsp), %rdi
jmp 0xe00b
jmp 0xe042
movq %rax, %r15
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
jne 0xe04d
jmp 0xe052
jmp 0xe042
movq %rax, %r15
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0xe031
callq 0x52b0
jmp 0xe031
jmp 0xe042
jmp 0xe02e
jmp 0xe042
movq %rax, %r15
leaq 0x60(%rsp), %rdi
callq 0xc7c2
movq 0x20(%rsp), %rbp
jmp 0xe052
movq %rax, %r15
jmp 0xe052
movq %rax, %r15
movq %r14, %rdi
callq 0x52b0
leaq 0x388(%rbx), %r14
leaq 0x3d0(%rbx), %rdi
callq 0x11f1c
movq 0x28(%rsp), %rdi
callq 0xc5b4
movq 0x30(%rsp), %rdi
callq 0xc5b4
movq (%r14), %rdi
testq %rdi, %rdi
je 0xe086
callq 0x52b0
leaq 0x308(%rbx), %r14
movq 0x38(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0xe09f
callq 0x52b0
movq %r14, %rdi
callq 0x12158
movq 0x18(%rsp), %rdi
callq 0x11f7c
movq %rbp, %rdi
callq 0xc792
movq 0x280(%rbx), %rdi
cmpq 0x78(%rsp), %rdi
je 0xe0cc
callq 0x52b0
movq %rbx, %rdi
callq 0x2819a
movq %r15, %rdi
callq 0x55a0