// File: /workspace/github_cpp_makefile_star2_O1/gvaumour[P]cache-simulator/src/Perceptron.cc
// Function: PerceptronPredictor::allocateInNVM(unsigned long, Access)
allocDecision
PerceptronPredictor::allocateInNVM(uint64_t set, Access element)
{
//	if(element.isInstFetch())
//		return ALLOCATE_IN_NVM;
	
	update_globalPChistory(element.m_pc);
	stats_nbMiss++;
	miss_counter++;
	if(miss_counter > 255)
		miss_counter = 255;
	
	// All the set is a learning/sampled set independantly of its way or SRAM/NVM alloc
	bool isLearning = m_tableSRAM[set][0]->isLearning; 
	
	if(!isLearning && m_enableBP)
	{
		//Predict if we should bypass
		int sum_prediction = 0;
		vector<double> samples;
		for(unsigned i = 0 ; i < m_BP_features.size(); i++)
		{
			int hash = m_BP_features_hash[i](element.m_address , element.m_pc);
			int pred = m_BP_features[i]->getConfidence(hash,true);
			samples.push_back(pred);
			sum_prediction += pred;
		}

		if(simu_parameters.perceptron_compute_variance)
		{	//Compute Variance of the sample
			double variance = 0, avg = (double)sum_prediction / (double) samples.size();
			for(unsigned i = 0 ; i < samples.size(); i++)
				variance += (samples[i] - avg) * (samples[i] - avg);

			variance = sqrt( variance / (double) samples.size());
			stats_variances_buffer.push_back(variance);
		}		
		
		if(sum_prediction > simu_parameters.perceptron_bypass_threshold)
		{
			stats_nbBPrequests[stats_nbBPrequests.size()-1]++;
			return BYPASS_CACHE;
		}
	}

	if(m_enableAllocation)
	{
		//Bypass decision is done, we do not bypass
		//Decide NVM/SRAM allocation
		int sum_prediction = 0;
		for(unsigned i = 0 ; i < m_Allocation_features.size(); i++)
		{
			int hash = m_Allocation_features_hash[i](element.m_address , element.m_pc);
			int pred = m_Allocation_features[i]->getConfidence(hash, true);
			sum_prediction += pred;
		}	
	
		if(sum_prediction > simu_parameters.perceptron_allocation_threshold)
			return ALLOCATE_IN_NVM;
		else
			return ALLOCATE_IN_SRAM;
	}
	else 
		return ALLOCATE_IN_SRAM;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x60(%rsp), %r12
movq 0x10(%r12), %r14
movq %r14, %rsi
callq 0x24704
incq 0x398(%rbx)
leaq 0x21d6e(%rip), %rax     # 0x461a0
movl (%rax), %ecx
movl $0xfe, %edx
cmpl %edx, %ecx
cmovll %ecx, %edx
incl %edx
movl %edx, (%rax)
movq 0x8(%rbx), %rax
movq (%rax), %rax
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
cmpb $0x0, 0x148(%rax)
jne 0x2464e
cmpb $0x1, 0x348(%rbx)
jne 0x2464e
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x2c0(%rbx), %rax
cmpq 0x2b8(%rbx), %rax
je 0x24526
movq (%r12), %r15
xorl %ebp, %ebp
movl $0x1, %r13d
xorl %r12d, %r12d
movq 0x2d0(%rbx), %rax
movq %r15, %rdi
movq %r14, %rsi
callq *(%rax,%rbp,8)
movq 0x2b8(%rbx), %rcx
movq (%rcx,%rbp,8), %rdi
movl %eax, %esi
movl $0x1, %edx
callq 0x14a94
movl %eax, %ebp
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x244f5
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x24504
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x12ed6
addl %ebp, %r12d
movq 0x2c0(%rbx), %rax
subq 0x2b8(%rbx), %rax
movl %r13d, %ebp
sarq $0x3, %rax
incl %r13d
cmpq %rbp, %rax
ja 0x244a4
jmp 0x24529
xorl %r12d, %r12d
leaq 0x21a20(%rip), %r15     # 0x45f50
cmpb $0x0, 0x1cd(%r15)
je 0x2460d
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdx
movq %rdx, %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq $0x0, 0x8(%rsp)
movq %rcx, %xmm0
punpckldq 0xfaa8(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xfab0(%rip), %xmm0     # 0x34020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
cmpq %rax, %rdx
je 0x245b6
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm2
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm3
subsd %xmm0, %xmm3
mulsd %xmm3, %xmm3
addsd %xmm3, %xmm2
movsd %xmm2, 0x8(%rsp)
incq %rdx
movl %edx, %esi
cmpq %rsi, %rcx
ja 0x24595
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x245d0
sqrtsd %xmm0, %xmm0
jmp 0x245d5
callq 0x5250
movsd %xmm0, 0x8(%rsp)
movq 0x3b0(%rbx), %rsi
cmpq 0x3b8(%rbx), %rsi
je 0x245fc
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x3b0(%rbx)
jmp 0x2460d
leaq 0x3a8(%rbx), %rdi
leaq 0x8(%rsp), %rdx
callq 0xd7a4
cmpl 0x1b8(%r15), %r12d
jle 0x2463a
movq 0x358(%rbx), %rax
incq -0x8(%rax)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x24630
callq 0x52a0
movl $0x2, %eax
jmp 0x246d5
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x24649
callq 0x52a0
leaq 0x60(%rsp), %r12
xorl %eax, %eax
cmpb $0x1, 0x349(%rbx)
jne 0x246d5
movq 0x278(%rbx), %rax
cmpq 0x270(%rbx), %rax
je 0x246c1
movq (%r12), %r15
xorl %r13d, %r13d
movl $0x1, %r12d
xorl %ebp, %ebp
movq 0x288(%rbx), %rax
movq %r15, %rdi
movq %r14, %rsi
callq *(%rax,%r13,8)
movq 0x270(%rbx), %rcx
movq (%rcx,%r13,8), %rdi
movl %eax, %esi
movl $0x1, %edx
callq 0x14a94
addl %eax, %ebp
movq 0x278(%rbx), %rax
subq 0x270(%rbx), %rax
movl %r12d, %r13d
sarq $0x3, %rax
incl %r12d
cmpq %r13, %rax
ja 0x24678
jmp 0x246c3
xorl %ebp, %ebp
leaq 0x21886(%rip), %rcx     # 0x45f50
xorl %eax, %eax
cmpl 0x1c0(%rcx), %ebp
setg %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x246ea
jmp 0x246ea
jmp 0x246ea
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x246fc
callq 0x52a0
movq %rbx, %rdi
callq 0x55a0