// File: /workspace/github_cpp_makefile_star2_O3/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 $0x88, %rsp
movl %r8d, %r12d
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r14
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
movl %ebp, %ecx
callq 0xfb98
movl %eax, %r10d
movl 0x270(%r15), %eax
movl %eax, 0x38(%r13)
movl 0x338(%r15), %esi
movzbl %bpl, %r9d
testq %rsi, %rsi
je 0xfb08
movq 0x18(%r13), %rcx
movl 0x33c(%r15), %r8d
xorl %edi, %edi
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq 0x2e8(%r15), %rax
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rax
movq (%rax,%rdi,8), %rbp
cmpq %rcx, 0x20(%rbp)
je 0xf827
incq %rdi
cmpq %rdi, %rsi
jne 0xf810
jmp 0xfb08
leaq 0x36722(%rip), %rax     # 0x45f50
movl 0x38(%rax), %ecx
movl 0x40(%rax), %edx
cmpl %edx, %ecx
jle 0xf844
cmpl %r10d, %edx
jg 0xf849
xorl %eax, %eax
cmpl %r10d, %ecx
jmp 0xf852
cmpl %r10d, %ecx
jle 0xf84d
xorl %eax, %eax
jmp 0xf857
xorl %eax, %eax
cmpl %r10d, %edx
setle %al
incl %eax
movl %r10d, 0x3c(%rsp)
movl %r9d, 0x38(%rsp)
movl %eax, 0x40(%rsp)
movq 0x48(%rbp), %rsi
cmpq 0x50(%rbp), %rsi
je 0xf87b
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x48(%rbp)
jmp 0xf889
leaq 0x40(%rbp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x12bee
leaq 0x58(%rbp), %rdi
leaq 0xc0(%rsp), %rax
movl 0x1c(%rax), %eax
cmpl $0x3, %eax
sete %cl
cmpl $0x6, %eax
sete %al
orb %cl, %al
movzbl %al, %esi
callq 0x120dc
cmpb $0x1, 0x148(%r13)
jne 0xf989
cmpl $0x2, 0x28(%rbp)
jne 0xf989
movl %r12d, %r13d
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 0xf91c
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 0x35d45(%rip), %r12     # 0x45668
leaq 0x251d8(%rip), %rsi     # 0x34b02
movl $0xb, %edx
movq %r12, %rdi
callq 0x5360
movl 0x18(%rbp), %esi
movq %r12, %rdi
callq 0x5580
movq %rax, %r12
leaq 0x250b4(%rip), %rsi     # 0x34a00
movl $0x3e, %edx
movq %rax, %rdi
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
movl %r13d, %r12d
jmp 0xfb03
movl %r12d, 0x44(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0xed2c
movb 0x40(%r13), %r12b
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x247c1(%rip), %rsi     # 0x3416e
leaq 0x247c0(%rip), %rdx     # 0x34174
leaq 0x48(%rsp), %rdi
callq 0xcc6c
leaq 0x3658b(%rip), %rax     # 0x45f50
movl 0x38(%rax), %ecx
movl 0x40(%rax), %edx
cmpl %edx, %ecx
jle 0xf9dd
movl 0x3c(%rsp), %esi
cmpl %esi, %edx
jg 0xf9e5
xorl %eax, %eax
cmpl %esi, %ecx
jmp 0xf9ed
movl 0x3c(%rsp), %esi
cmpl %esi, %ecx
jle 0xf9e9
xorl %eax, %eax
jmp 0xf9f3
xorl %eax, %eax
cmpl %esi, %edx
setle %al
incq %rax
leaq 0x35a36(%rip), %rcx     # 0x45430
movq (%rcx,%rax,8), %rsi
leaq 0x68(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x5140
leaq 0xc0(%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 %r12b, %ecx
leaq 0x48(%rsp), %r8
leaq 0x68(%rsp), %r9
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xf054
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfa66
callq 0x52b0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xfa7a
callq 0x52b0
leaq 0x35be7(%rip), %r12     # 0x45668
leaq 0x24fb7(%rip), %rsi     # 0x34a3f
movl $0xc, %edx
movq %r12, %rdi
callq 0x5360
movq %r12, %rdi
movl 0x3c(%rsp), %esi
callq 0x5580
movq %rax, %r12
movq (%rax), %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
leaq 0x3647e(%rip), %rax     # 0x45f50
cmpb $0x1, 0xa9(%rax)
movl 0x44(%rsp), %r12d
movl 0x38(%rsp), %r9d
jne 0xfb08
movl $0x0, (%rsp)
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
movl %r9d, %r8d
movq %rbx, %r9
callq 0xfc98
movl 0x38(%rsp), %r9d
incq 0x270(%r15)
leaq 0xc0(%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 %r12b, %r8d
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl %r9d, %ecx
callq 0x272da
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfb7b
callq 0x52b0
jmp 0xfb7b
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xfb8f
callq 0x52b0
movq %rbx, %rdi
callq 0x55a0
nop