// File: gvaumour[P]cache-simulator/src/DBAMBPredictor.cc
// Function: DBAMBPredictor::insertionPolicy(unsigned long, unsigned long, bool, Access)
void
DBAMBPredictor::insertionPolicy(uint64_t set, uint64_t index, bool inNVM, Access element)
{
	CacheEntry* current = NULL;
	if(inNVM)
		current = m_tableNVM[set][index];
	else 
		current = m_tableSRAM[set][index];
		
	current->policyInfo = m_cpt;
	current->signature = hashingSignature(element);
		
	
	RD_TYPE reuse_class = RD_NOT_ACCURATE;
	DHPEntry* rap_current;

	if(inNVM)
		stats_allocate_NVM++;			
	else
		stats_allocate_SRAM++;			


	if( (rap_current= lookup(current->signature) ) != NULL )
	{

		/* Set the flag of learning cache line when bypassing */
		if(rap_current->des == BYPASS_CACHE)
		{
			current->isLearning = true;
		}
		else
		{
		
			if(element.isSRAMerror)
				reuse_class = RD_MEDIUM; 

			rap_current->rd_history.push_back(reuse_class); 
			rap_current->rw_history.push_back(element.isWrite());

			updateWindow(rap_current);		
		}
	
		reportAccess(rap_current, element, current, inNVM, "INSERTION",  str_RD_status[reuse_class]);
	}
	
	Predictor::insertionPolicy(set , index , inNVM , element);
	m_cpt++;
}

// Assembly:
subq $0x1d8, %rsp            # imm = 0x1D8
movb %cl, %al
leaq 0x1e0(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq %rdi, 0x1d0(%rsp)
movq %rsi, 0x1c8(%rsp)
movq %rdx, 0x1c0(%rsp)
andb $0x1, %al
movb %al, 0x1bf(%rsp)
movq 0x1d0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq $0x0, 0x1b0(%rsp)
testb $0x1, 0x1bf(%rsp)
je 0x1b5c6
movq 0x90(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x1c8(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movq 0x1c0(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movq %rax, 0x1b0(%rsp)
jmp 0x1b5fa
movq 0x90(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x1c8(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movq 0x1c0(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movq %rax, 0x1b0(%rsp)
movq 0x90(%rsp), %rax
movq 0x88(%rsp), %rsi
movq 0x270(%rax), %rax
movl %eax, %ecx
movq 0x1b0(%rsp), %rax
movl %ecx, 0x38(%rax)
leaq 0x178(%rsp), %rdi
movl $0x38, %edx
callq 0x52f0
movq 0x90(%rsp), %rdi
movq 0x1a8(%rsp), %rcx
movq %rsp, %rax
movq %rcx, 0x30(%rax)
movups 0x178(%rsp), %xmm0
movups 0x188(%rsp), %xmm1
movups 0x198(%rsp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x1aff0
movq %rax, %rcx
movq 0x1b0(%rsp), %rax
movq %rcx, 0x18(%rax)
movl $0x2, 0x174(%rsp)
testb $0x1, 0x1bf(%rsp)
je 0x1b6af
movq 0x90(%rsp), %rax
movq 0x360(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x360(%rax)
jmp 0x1b6c9
movq 0x90(%rsp), %rax
movq 0x368(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x368(%rax)
movq 0x90(%rsp), %rdi
movq 0x1b0(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0x1b150
movq %rax, 0x168(%rsp)
cmpq $0x0, %rax
je 0x1b96f
movq 0x168(%rsp), %rax
cmpl $0x2, 0x28(%rax)
jne 0x1b713
movq 0x1b0(%rsp), %rax
movb $0x1, 0x148(%rax)
jmp 0x1b78e
movq 0x88(%rsp), %rax
testb $0x1, 0x28(%rax)
je 0x1b72c
movl $0x1, 0x174(%rsp)
movq 0x168(%rsp), %rdi
addq $0x40, %rdi
leaq 0x174(%rsp), %rsi
callq 0x20ad0
movq 0x88(%rsp), %rdi
movq 0x168(%rsp), %rax
addq $0x58, %rax
movq %rax, 0x80(%rsp)
callq 0xf7c0
movq 0x80(%rsp), %rdi
movzbl %al, %esi
andl $0x1, %esi
callq 0x20b40
movq 0x90(%rsp), %rdi
movq 0x168(%rsp), %rsi
callq 0x1ba30
movq 0x88(%rsp), %rax
movq 0x168(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movq 0x30(%rax), %rcx
movq %rcx, 0x160(%rsp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movaps %xmm2, 0x150(%rsp)
movaps %xmm1, 0x140(%rsp)
movaps %xmm0, 0x130(%rsp)
movq 0x1b0(%rsp), %rax
movq %rax, 0x68(%rsp)
movb 0x1bf(%rsp), %al
movb %al, 0x77(%rsp)
leaq 0x10f(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x56a0
movq 0x78(%rsp), %rdx
leaq 0x55933(%rip), %rsi     # 0x7113b
leaq 0x110(%rsp), %rdi
callq 0x5530
jmp 0x1b817
movl 0x174(%rsp), %eax
movl %eax, %ecx
leaq 0x77ca9(%rip), %rax     # 0x934d0
movq (%rax,%rcx,8), %rax
movq %rax, 0x50(%rsp)
leaq 0xd7(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x56a0
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
leaq 0xd8(%rsp), %rdi
callq 0x5530
jmp 0x1b85b
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rsi
movq 0x90(%rsp), %rdi
movb 0x77(%rsp), %al
movq 0x160(%rsp), %r8
movq %rsp, %rcx
movq %r8, 0x30(%rcx)
movaps 0x130(%rsp), %xmm0
movaps 0x140(%rsp), %xmm1
movaps 0x150(%rsp), %xmm2
movups %xmm2, 0x20(%rcx)
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
movzbl %al, %ecx
andl $0x1, %ecx
leaq 0x110(%rsp), %r8
leaq 0xd8(%rsp), %r9
callq 0x1bd50
jmp 0x1b8c0
leaq 0xd8(%rsp), %rdi
callq 0x5768
leaq 0xd7(%rsp), %rdi
callq 0x53e0
leaq 0x110(%rsp), %rdi
callq 0x5768
leaq 0x10f(%rsp), %rdi
callq 0x53e0
jmp 0x1b96f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x1b95d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x1b943
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x5768
leaq 0xd7(%rsp), %rdi
callq 0x53e0
leaq 0x110(%rsp), %rdi
callq 0x5768
leaq 0x10f(%rsp), %rdi
callq 0x53e0
jmp 0x1ba23
movq 0x88(%rsp), %rsi
movq 0x1c8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x1c0(%rsp), %rax
movq %rax, 0x48(%rsp)
movb 0x1bf(%rsp), %al
movb %al, 0x3f(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x38, %edx
callq 0x52f0
movb 0x3f(%rsp), %al
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x90(%rsp), %rdi
movq 0xc8(%rsp), %r8
movq %rsp, %rcx
movq %r8, 0x30(%rcx)
movups 0x98(%rsp), %xmm0
movups 0xa8(%rsp), %xmm1
movups 0xb8(%rsp), %xmm2
movups %xmm2, 0x20(%rcx)
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
movzbl %al, %ecx
andl $0x1, %ecx
callq 0x55140
movq 0x90(%rsp), %rax
movq 0x270(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x270(%rax)
addq $0x1d8, %rsp            # imm = 0x1D8
retq
movq 0x100(%rsp), %rdi
callq 0x5690