// File: /workspace/github_cpp_makefile_star2_O3/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 0x244e6
incq 0x398(%rbx)
leaq 0x21f72(%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 0x24430
cmpb $0x1, 0x348(%rbx)
jne 0x24430
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x2c0(%rbx), %rax
cmpq 0x2b8(%rbx), %rax
je 0x24322
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 0x1491e
movl %eax, %ebp
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x242f1
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x24300
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x12e2e
addl %ebp, %r12d
movq 0x2c0(%rbx), %rax
subq 0x2b8(%rbx), %rax
movl %r13d, %ebp
sarq $0x3, %rax
incl %r13d
cmpq %rbp, %rax
ja 0x242a0
jmp 0x24325
xorl %r12d, %r12d
leaq 0x21c24(%rip), %r15     # 0x45f50
cmpb $0x0, 0x1cd(%r15)
je 0x243ef
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdx
movq %rdx, %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq %rcx, %xmm0
punpckldq 0x113f5(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x113fd(%rip), %xmm0    # 0x35760
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
xorpd %xmm0, %xmm0
cmpq %rax, %rdx
je 0x243a2
cvtsi2sd %r12d, %xmm3
divsd %xmm1, %xmm3
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm4
subsd %xmm3, %xmm4
mulsd %xmm4, %xmm4
addsd %xmm4, %xmm0
incq %rdx
movl %edx, %esi
cmpq %rsi, %rcx
ja 0x24387
divsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jb 0x243b2
sqrtsd %xmm0, %xmm0
jmp 0x243b7
callq 0x5260
movsd %xmm0, 0x8(%rsp)
movq 0x3b0(%rbx), %rsi
cmpq 0x3b8(%rbx), %rsi
je 0x243de
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x3b0(%rbx)
jmp 0x243ef
leaq 0x3a8(%rbx), %rdi
leaq 0x8(%rsp), %rdx
callq 0xd76a
cmpl 0x1b8(%r15), %r12d
jle 0x2441c
movq 0x358(%rbx), %rax
incq -0x8(%rax)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x24412
callq 0x52b0
movl $0x2, %eax
jmp 0x244b7
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2442b
callq 0x52b0
leaq 0x60(%rsp), %r12
xorl %eax, %eax
cmpb $0x1, 0x349(%rbx)
jne 0x244b7
movq 0x278(%rbx), %rax
cmpq 0x270(%rbx), %rax
je 0x244a3
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 0x1491e
addl %eax, %ebp
movq 0x278(%rbx), %rax
subq 0x270(%rbx), %rax
movl %r12d, %r13d
sarq $0x3, %rax
incl %r12d
cmpq %r13, %rax
ja 0x2445a
jmp 0x244a5
xorl %ebp, %ebp
leaq 0x21aa4(%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 0x244cc
jmp 0x244cc
jmp 0x244cc
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x244de
callq 0x52b0
movq %rbx, %rdi
callq 0x55a0