// File: /workspace/github_cpp_makefile_star2_O1/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 $0x98, %rsp
movl %r8d, 0x44(%rsp)
movl %ecx, %ebx
movq %rdi, %r15
movl %ecx, %eax
movq 0x8(%rdi,%rax,8), %rax
movq (%rax), %rax
leaq (%rsi,%rsi,2), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax,%rdx,8), %r13
movq %rsi, 0x48(%rsp)
movq %rdx, 0x50(%rsp)
movl %ebx, %ecx
callq 0xfbfa
movl %eax, %r12d
movl 0x270(%r15), %eax
movl %eax, 0x38(%r13)
movl 0x338(%r15), %esi
testq %rsi, %rsi
je 0xf892
movq 0x18(%r13), %rcx
movl 0x33c(%r15), %edi
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
movq 0x2e8(%r15), %rax
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rax
xorl %edx, %edx
movq (%rax,%rdx,8), %rbp
cmpq %rcx, 0x20(%rbp)
je 0xf894
incq %rdx
cmpq %rdx, %rsi
jne 0xf880
xorl %ebp, %ebp
leaq 0xd0(%rsp), %r14
movzbl %bl, %ebx
testq %rbp, %rbp
je 0xfb67
leaq 0x366a1(%rip), %rax     # 0x45f50
movl 0x38(%rax), %ecx
movl 0x40(%rax), %edx
cmpl %edx, %ecx
jle 0xf8c5
cmpl %r12d, %edx
jg 0xf8ca
xorl %eax, %eax
cmpl %r12d, %ecx
jmp 0xf8d3
cmpl %r12d, %ecx
jle 0xf8ce
xorl %eax, %eax
jmp 0xf8d8
xorl %eax, %eax
cmpl %r12d, %edx
setle %al
incl %eax
movl %eax, 0x3c(%rsp)
movq 0x48(%rbp), %rsi
cmpq 0x50(%rbp), %rsi
je 0xf8f2
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x48(%rbp)
jmp 0xf900
leaq 0x40(%rbp), %rdi
leaq 0x3c(%rsp), %rdx
callq 0x12c96
leaq 0x58(%rbp), %rdi
movl 0x1c(%r14), %eax
cmpl $0x3, %eax
sete %cl
cmpl $0x6, %eax
sete %al
orb %cl, %al
movzbl %al, %esi
callq 0x12186
cmpb $0x1, 0x148(%r13)
jne 0xf9f8
cmpl $0x2, 0x28(%rbp)
jne 0xf9f8
movl %ebx, %r12d
movslq 0x98(%rbp), %rcx
movslq 0x9c(%rbp), %rax
movl $0x3, 0x28(%rbp)
movabsq $0x200000004, %rdx      # imm = 0x200000004
movq %rdx, 0x98(%rbp)
movl $0x0, 0xb8(%rbp)
cmpb $0x0, 0x81(%r15)
jne 0xf98c
leaq (%rcx,%rcx,2), %rcx
addq %rcx, %rax
movq 0x3a0(%r15), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rax
incl 0x38(%rax)
leaq 0x35cd5(%rip), %rbx     # 0x45668
leaq 0x25188(%rip), %rsi     # 0x34b22
movl $0xb, %edx
movq %rbx, %rdi
callq 0x5350
movl 0x18(%rbp), %esi
movq %rbx, %rdi
callq 0x5580
movq %rax, %rbx
leaq 0x25064(%rip), %rsi     # 0x34a20
movl $0x3e, %edx
movq %rax, %rdi
callq 0x5350
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movl %r12d, %ebx
jmp 0xfb67
movl %ebx, 0x40(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0xedc2
movb 0x40(%r13), %bl
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2477f(%rip), %rsi     # 0x3419a
leaq 0x2477e(%rip), %rdx     # 0x341a0
leaq 0x58(%rsp), %rdi
callq 0xccac
leaq 0x3651d(%rip), %rax     # 0x45f50
movl 0x38(%rax), %ecx
movl 0x40(%rax), %edx
cmpl %edx, %ecx
jle 0xfa49
cmpl %r12d, %edx
jg 0xfa4e
xorl %eax, %eax
cmpl %r12d, %ecx
jmp 0xfa57
cmpl %r12d, %ecx
jle 0xfa52
xorl %eax, %eax
jmp 0xfa5d
xorl %eax, %eax
cmpl %r12d, %edx
setle %al
incq %rax
leaq 0x359cc(%rip), %rcx     # 0x45430
movq (%rcx,%rax,8), %rsi
leaq 0x78(%rsp), %rdi
leaq 0x3c(%rsp), %rdx
callq 0x5140
movq 0x30(%r14), %rax
movq %rax, 0x30(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movzbl %bl, %ecx
leaq 0x58(%rsp), %r8
leaq 0x78(%rsp), %r9
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xf0f6
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfacd
callq 0x52a0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xfae1
callq 0x52a0
leaq 0x35b80(%rip), %rbx     # 0x45668
leaq 0x24f70(%rip), %rsi     # 0x34a5f
movl $0xc, %edx
movq %rbx, %rdi
callq 0x5350
movq %rbx, %rdi
movl %r12d, %esi
callq 0x5580
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
leaq 0x36418(%rip), %rax     # 0x45f50
cmpb $0x1, 0xa9(%rax)
movl 0x40(%rsp), %ebx
jne 0xfb67
movl $0x0, (%rsp)
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq 0x48(%rsp), %rcx
movl %ebx, %r8d
movq 0x50(%rsp), %r9
callq 0xfcfa
incq 0x270(%r15)
movq 0x30(%r14), %rax
movq %rax, 0x30(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movzbl 0x44(%rsp), %r8d
movq %r15, %rdi
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movl %ebx, %ecx
callq 0x275be
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfbdd
callq 0x52a0
jmp 0xfbdd
movq %rax, %r14
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xfbf1
callq 0x52a0
movq %r14, %rdi
callq 0x55a0
nop