// File: /workspace/github_cpp_makefile_star2_O3/gvaumour[P]cache-simulator/src/Perceptron.cc
// Function: PerceptronPredictor::updatePolicy(unsigned long, unsigned long, bool, Access, bool)
void
PerceptronPredictor::updatePolicy(uint64_t set, uint64_t index, bool inNVM, Access element, bool isWBrequest)
{
	update_globalPChistory(element.m_pc);
	
	stats_update++;
	
	CacheEntry *entry = get_entry(set , index , inNVM);
	entry->policyInfo = m_cpt++;

	if(entry->isLearning)
	{
		if(m_enableBP)
		{
			stats_update_learning++;
			for(unsigned i = 0 ; i < m_BP_features.size() ; i++)
			{
				if( entry->perceptron_BPpred[i] > -simu_parameters.perceptron_bypass_learning || !entry->predictedReused[i])
					m_BP_features[i]->decreaseConfidence(entry->perceptron_BPHash[i]);
			}
			setBPPrediction(entry);
		}
		
		if(m_enableAllocation)
		{
			RD_TYPE rd_type = classifyRD(set , index , inNVM);
			
		
			if(rd_type == RD_SHORT && element.isWrite() && inNVM)
			{
				for(unsigned i = 0 ; i < m_Allocation_features.size() ; i++)
				{
					if( entry->perceptron_Allocpred[i] > - simu_parameters.perceptron_bypass_learning)
						m_Allocation_features[i]->decreaseConfidence(entry->perceptron_AllocHash[i]);
				}		
			}
			setAllocPrediction(entry);

		}
	}
	
	if(m_enableAllocation)
	{
		RD_TYPE rd_type = classifyRD(set , index , inNVM);
	
		for(unsigned i = 0 ; i < m_Allocation_features.size() ; i++)
		{
			int hash = m_Allocation_features_hash[i](entry->address , entry->m_pc);
			m_Allocation_features[i]->recordAccess( hash  , element.isWrite() , rd_type);
		}
	}

	
	stats_nbHits++;
	miss_counter--;
	if(miss_counter < 0)
		miss_counter = 0;


	Predictor::updatePolicy(set , index , inNVM , element , isWBrequest);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, 0x24(%rsp)
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x60(%rsp), %r12
movq 0x10(%r12), %rsi
callq 0x244e6
incq 0x3d8(%r15)
movl %ebp, %eax
movq 0x8(%r15,%rax,8), %rax
movq (%rax), %rax
movq %r14, 0x10(%rsp)
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
movq %rbx, 0x18(%rsp)
movq (%rax,%rbx,8), %r13
movq 0x308(%r15), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x308(%r15)
movl %eax, 0x38(%r13)
cmpb $0x1, 0x148(%r13)
movzbl %bpl, %eax
movl %eax, 0xc(%rsp)
jne 0x24865
cmpb $0x1, 0x348(%r15)
jne 0x247a3
movq %r12, %r14
incq 0x3e0(%r15)
movq 0x2b8(%r15), %rax
movq 0x2c0(%r15), %rcx
cmpq %rax, %rcx
je 0x24795
leaq 0x2182a(%rip), %r12     # 0x45f50
movl 0x1bc(%r12), %edx
movl $0x1, %ebx
xorl %esi, %esi
movq 0x48(%r13), %rdi
movl %edx, %r8d
negl %r8d
cmpl %r8d, (%rdi,%rsi,4)
jg 0x2475c
leal -0x1(%rbx), %edi
movq 0xa8(%r13), %r8
shrl $0x6, %edi
movq (%r8,%rdi,8), %rdi
btq %rsi, %rdi
jb 0x24782
movq (%rax,%rsi,8), %rdi
movq 0x78(%r13), %rax
movl (%rax,%rsi,4), %esi
callq 0x149a4
movl 0x1bc(%r12), %edx
movq 0x2b8(%r15), %rax
movq 0x2c0(%r15), %rcx
movl %ebx, %esi
movq %rcx, %rdi
subq %rax, %rdi
sarq $0x3, %rdi
incl %ebx
cmpq %rsi, %rdi
ja 0x24735
movq %r15, %rdi
movq %r13, %rsi
callq 0x24962
movq %r14, %r12
cmpb $0x1, 0x349(%r15)
jne 0x24865
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl 0xc(%rsp), %ecx
callq 0x24a38
testl %eax, %eax
jne 0x2485a
movl 0x1c(%r12), %eax
cmpl $0x3, %eax
sete %cl
cmpl $0x6, %eax
sete %al
orb %cl, %al
andb %bpl, %al
cmpb $0x1, %al
jne 0x2485a
movq 0x270(%r15), %rax
movq 0x278(%r15), %rcx
cmpq %rax, %rcx
je 0x2485a
leaq 0x2174d(%rip), %rbx     # 0x45f50
movl 0x1bc(%rbx), %edx
movl $0x1, %ebp
xorl %esi, %esi
movq 0x60(%r13), %rdi
movl %edx, %r8d
negl %r8d
cmpl %r8d, (%rdi,%rsi,4)
jle 0x24847
movq (%rax,%rsi,8), %rdi
movq 0x90(%r13), %rax
movl (%rax,%rsi,4), %esi
callq 0x149a4
movl 0x1bc(%rbx), %edx
movq 0x270(%r15), %rax
movq 0x278(%r15), %rcx
movl %ebp, %esi
movq %rcx, %rdi
subq %rax, %rdi
sarq $0x3, %rdi
incl %ebp
cmpq %rsi, %rdi
ja 0x24810
movq %r15, %rdi
movq %r13, %rsi
callq 0x24b3e
cmpb $0x1, 0x349(%r15)
jne 0x24900
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl 0xc(%rsp), %ecx
callq 0x24a38
movl %eax, %ebp
movq 0x278(%r15), %rax
cmpq 0x270(%r15), %rax
je 0x24900
movl 0x1c(%r12), %eax
cmpl $0x3, %eax
sete %cl
cmpl $0x6, %eax
sete %al
orb %cl, %al
movl $0x1, %ebx
xorl %r14d, %r14d
movzbl %al, %r12d
movq 0x288(%r15), %rax
movq 0x8(%r13), %rdi
movq 0x10(%r13), %rsi
callq *(%rax,%r14,8)
movq 0x270(%r15), %rcx
movq (%rcx,%r14,8), %rdi
movl %eax, %esi
movl %r12d, %edx
movl %ebp, %ecx
callq 0x14524
movq 0x278(%r15), %rax
subq 0x270(%r15), %rax
movl %ebx, %r14d
sarq $0x3, %rax
incl %ebx
cmpq %r14, %rax
ja 0x248ba
incq 0x3a0(%r15)
leaq 0x21892(%rip), %rax     # 0x461a0
movl (%rax), %ecx
cmpl $0x2, %ecx
movl $0x1, %edx
cmovgel %ecx, %edx
decl %edx
movl %edx, (%rax)
movzbl 0x24(%rsp), %r8d
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl 0xc(%rsp), %ecx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x272da
nop