// File: /workspace/github_cpp_makefile_star2_O2/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, 0x1c(%rsp)
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x60(%rsp), %r14
movq 0x10(%r14), %rsi
callq 0x1d9e2
incq 0x3d8(%r15)
movl %ebp, %eax
movq 0x8(%r15,%rax,8), %rax
movq (%rax), %rax
movq %rbx, 0x10(%rsp)
imulq $0x18, %rbx, %rcx
movq (%rax,%rcx), %rax
movq (%rax,%r12,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 0x1dc23
cmpb $0x1, 0x348(%r15)
jne 0x1db82
movq %r12, 0x20(%rsp)
incq 0x3e0(%r15)
leaq 0xa8(%r13), %r12
xorl %ebx, %ebx
leaq 0x2043c(%rip), %r14     # 0x3df50
movl %ebx, %ebx
movq 0x2b8(%r15), %rax
movq 0x2c0(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
jbe 0x1db6d
movq 0x48(%r13), %rcx
xorl %edx, %edx
subl 0x1bc(%r14), %edx
cmpl %edx, (%rcx,%rbx,4)
jg 0x1db59
movq %r12, %rdi
movq %rbx, %rsi
callq 0x9f66
testq %rdx, (%rax)
jne 0x1db69
movq 0x2b8(%r15), %rax
movq (%rax,%rbx,8), %rdi
movq 0x78(%r13), %rax
movl (%rax,%rbx,4), %esi
callq 0x11188
incl %ebx
jmp 0x1db14
movq %r15, %rdi
movq %r13, %rsi
callq 0x1dd00
movq 0x20(%rsp), %r12
leaq 0x60(%rsp), %r14
cmpb $0x1, 0x349(%r15)
jne 0x1dc23
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movl %r12d, %edx
movl 0xc(%rsp), %ecx
callq 0x1ddb6
testl %eax, %eax
jne 0x1dc13
leaq 0x60(%rsp), %rax
movl 0x1c(%rax), %eax
cmpl $0x3, %eax
sete %cl
cmpl $0x6, %eax
sete %al
orb %cl, %al
andb %bpl, %al
cmpb $0x1, %al
jne 0x1dc13
xorl %ebx, %ebx
leaq 0x20382(%rip), %r14     # 0x3df50
movl %ebx, %ebx
movq 0x270(%r15), %rax
movq 0x278(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
jbe 0x1dc13
movq 0x60(%r13), %rcx
xorl %edx, %edx
subl 0x1bc(%r14), %edx
cmpl %edx, (%rcx,%rbx,4)
jle 0x1dc0f
movq (%rax,%rbx,8), %rdi
movq 0x90(%r13), %rax
movl (%rax,%rbx,4), %esi
callq 0x11188
incl %ebx
jmp 0x1dbce
movq %r15, %rdi
movq %r13, %rsi
callq 0x1de98
leaq 0x60(%rsp), %r14
cmpb $0x1, 0x349(%r15)
jne 0x1dca3
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movl %r12d, %edx
movl 0xc(%rsp), %ecx
callq 0x1ddb6
movl %eax, %ebx
movl 0x1c(%r14), %eax
cmpl $0x3, %eax
sete %cl
cmpl $0x6, %eax
sete %dl
orb %cl, %dl
xorl %eax, %eax
movzbl %dl, %ebp
movl %eax, %r14d
movq 0x278(%r15), %rax
subq 0x270(%r15), %rax
sarq $0x3, %rax
cmpq %r14, %rax
jbe 0x1dca3
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 %ebp, %edx
movl %ebx, %ecx
callq 0x10ed2
leal 0x1(%r14), %eax
jmp 0x1dc5a
incq 0x3a0(%r15)
leaq 0x204ef(%rip), %rax     # 0x3e1a0
movl (%rax), %ecx
cmpl $0x2, %ecx
pushq $0x1
popq %rdx
cmovgel %ecx, %edx
decl %edx
movl %edx, (%rax)
movzbl 0x1c(%rsp), %r8d
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
movl 0xc(%rsp), %ecx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1fe44