// File: /workspace/github_cpp_makefile_star2_O2/gvaumour[P]cache-simulator/src/DBAMBPredictor.cc
// Function: DBAMBPredictor::updatePolicy(unsigned long, unsigned long, bool, Access, bool)
void
DBAMBPredictor::updatePolicy(uint64_t set, uint64_t index, bool inNVM, Access element, bool isWBrequest = false)
{

	//DPRINTF("DBAMBPredictor::updatePolicy set %ld , index %ld\n" , set, index);

	CacheEntry* current = NULL;
	if(inNVM)
		current = m_tableNVM[set][index];
	else 
		current = m_tableSRAM[set][index];
	
	int rd = computeRd(set, index , inNVM);

	current->policyInfo = m_cpt;

	DHPEntry* rap_current = lookup(current->signature);

	if(rap_current)
	{

//			//DPRINTF("DBAMBPredictor::updatePolicy Reuse distance of the pc %lx, RD = %d\n", current->m_pc , rd );
		rap_current->rd_history.push_back(convertRD(rd));
		rap_current->rw_history.push_back(element.isWrite());		
		
		//A learning cl shows some reuse so we quit dead state 
		if(current->isLearning && rap_current->des == BYPASS_CACHE)
		{
			// Reset the window 
			RW_TYPE old_rw = rap_current->state_rw;
			RD_TYPE old_rd = rap_current->state_rd;
			
			rap_current->des = ALLOCATE_PREEMPTIVELY;
			rap_current->state_rd = RD_NOT_ACCURATE;
			rap_current->state_rw = RW_NOT_ACCURATE;
			rap_current->dead_counter = 0;

			if(!m_isWarmup)
				stats_ClassErrors[old_rd + NUM_RD_TYPE*old_rw][rap_current->state_rd + NUM_RD_TYPE*rap_current->state_rw]++;
			
			dataset_file << "Dataset n°" << rap_current->id << ": Reuse detected on a learning Cl, switching to learning state" << endl;
		}
		else
		{
			updateWindow(rap_current);
		
			reportAccess(rap_current , element, current, current->isNVM, string("UPDATE"), string(str_RD_status[convertRD(rd)]));
			dataset_file << "Position is " << rd << endl;
			if(simu_parameters.enableMigration )
				current = checkLazyMigration(rap_current , current , set , inNVM , index, element.isWrite());
		}
	}
	
	m_cpt++;
	Predictor::updatePolicy(set , index , inNVM , element , isWBrequest);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r8d, 0x50(%rsp)
movl %ecx, %ebx
movq %rdi, %r15
leaq 0xe0(%rsp), %r12
movl %ecx, %eax
movq 0x8(%rdi,%rax,8), %rax
movq (%rax), %rax
imulq $0x18, %rsi, %rcx
movq (%rax,%rcx), %rax
movq (%rax,%rdx,8), %rbp
movq %rsi, 0x58(%rsp)
movq %rdx, 0x60(%rsp)
movl %ebx, %ecx
callq 0xcf4a
movl %eax, %r14d
movl 0x270(%r15), %eax
movl %eax, 0x38(%rbp)
movq 0x18(%rbp), %rsi
movq %r15, %rdi
callq 0xc1d8
movzbl %bl, %r9d
testq %rax, %rax
je 0xcec5
movq %rax, %r13
movl %r9d, 0x44(%rsp)
leaq 0x40(%rax), %rbx
movl %r14d, 0x4c(%rsp)
movl %r14d, %esi
callq 0xd006
leaq 0x54(%rsp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0xf728
movq %r13, %rdi
addq $0x58, %rdi
movl 0x1c(%r12), %eax
cmpl $0x3, %eax
sete %cl
cmpl $0x6, %eax
sete %al
orb %cl, %al
movzbl %al, %esi
callq 0xe94a
cmpb $0x1, 0x148(%rbp)
jne 0xcdaf
cmpl $0x2, 0x28(%r13)
jne 0xcdaf
movslq 0x98(%r13), %rcx
movslq 0x9c(%r13), %rax
movl $0x3, 0x28(%r13)
movabsq $0x200000004, %rdx      # imm = 0x200000004
movq %rdx, 0x98(%r13)
andl $0x0, 0xb8(%r13)
cmpb $0x0, 0x81(%r15)
jne 0xcd6c
leaq (%rcx,%rcx,2), %rcx
addq %rcx, %rax
movq 0x3a0(%r15), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rax
incl 0x38(%rax)
leaq 0x308f5(%rip), %rdi     # 0x3d668
leaq 0x1cd68(%rip), %rsi     # 0x29ae2
callq 0x52c0
movl 0x18(%r13), %esi
movq %rax, %rdi
callq 0x5560
leaq 0x1cc4e(%rip), %rsi     # 0x299e0
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
leaq 0xe0(%rsp), %r12
jmp 0xcec0
movq %r15, %rdi
movq %r13, %rsi
callq 0xc584
movb 0x40(%rbp), %bl
leaq 0x1c3c6(%rip), %rsi     # 0x2918a
leaq 0x88(%rsp), %rdi
leaq 0x54(%rsp), %rdx
callq 0x5140
movl 0x4c(%rsp), %r12d
movl %r12d, %esi
callq 0xd006
movl %eax, %eax
leaq 0x30644(%rip), %rcx     # 0x3d430
movq (%rcx,%rax,8), %rsi
leaq 0x68(%rsp), %rdi
leaq 0x4b(%rsp), %rdx
callq 0x5140
leaq 0xe0(%rsp), %rcx
movq 0x30(%rcx), %rax
movq %rax, 0x30(%rsp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movzbl %bl, %ecx
leaq 0x88(%rsp), %r8
leaq 0x68(%rsp), %r9
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xc7a6
leaq 0x68(%rsp), %rdi
callq 0x5618
leaq 0x88(%rsp), %rdi
callq 0x5618
leaq 0x30803(%rip), %rdi     # 0x3d668
leaq 0x1cbb3(%rip), %rsi     # 0x29a1f
callq 0x52c0
movq %rax, %rdi
movl %r12d, %esi
callq 0x5560
movq %rax, %rdi
callq 0x5190
leaq 0x310c5(%rip), %rax     # 0x3df50
cmpb $0x1, 0xa9(%rax)
leaq 0xe0(%rsp), %r12
movl 0x44(%rsp), %r9d
jne 0xcec5
andl $0x0, (%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq 0x58(%rsp), %rcx
movl %r9d, %r8d
movq 0x60(%rsp), %r9
callq 0xd032
movl 0x44(%rsp), %r9d
incq 0x270(%r15)
movq 0x30(%r12), %rax
movq %rax, 0x30(%rsp)
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movzbl 0x50(%rsp), %r8d
movq %r15, %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movl %r9d, %ecx
callq 0x1fe44
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x5618
jmp 0xcf34
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x5618
movq %rbx, %rdi
callq 0x5570
nop