// File: gvaumour[P]cache-simulator/src/SimplePerceptron.cc
// Function: SimplePerceptronPredictor::doLearning(CacheEntry*)
void 
SimplePerceptronPredictor::doLearning(CacheEntry* entry)
{
	allocDecision correct_des =  entry->e_sram > entry->e_nvm ? ALLOCATE_IN_NVM : ALLOCATE_IN_SRAM;

	if(simu_parameters.simple_perceptron_independantLearning)
	{
	
		for(unsigned i = 0 ; i < m_features.size() ; i++)
		{
			int hash = entry->simple_perceptron_hash[i];
			//if(entry->simple_perceptron_pred[i] != correct_des)
			//{
				if( correct_des == ALLOCATE_IN_NVM)
					m_features[i]->increaseCounter(hash);
				else
					m_features[i]->decreaseCounter(hash);
			//}
			/*
			else
				m_features[i]->increaseCounter(hash);
			*/
		}		
	}
	else
	{
		//allocDecision des = entry->simple_perceptron_pred[0];
		//if( des != correct_des)
		//{
			if( correct_des == ALLOCATE_IN_NVM)
			{
				for(unsigned i = 0 ; i < m_features.size() ; i++)
				{
					int hash = entry->simple_perceptron_hash[i];
					m_features[i]->increaseCounter(hash);
				}

			}
			else
			{			
				for(unsigned i = 0 ; i < m_features.size() ; i++)
				{
					int hash = entry->simple_perceptron_hash[i];
					m_features[i]->decreaseCounter(hash);
				}
			}
		//}
		/*
		else
		{
			for(unsigned i = 0 ; i < m_features.size() ; i++)
			{
				int hash = entry->simple_perceptron_hash[i];
				m_features[i]->increaseCounter(hash);
			}		
		}*/
	}
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rax
movq 0x138(%rax), %rdx
movq 0x48(%rsp), %rax
movq 0x140(%rax), %rsi
xorl %eax, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmoval %ecx, %eax
movl %eax, 0x44(%rsp)
leaq 0x32cc8(%rip), %rax     # 0x93ff0
testb $0x1, 0x24d(%rax)
je 0x613e7
movl $0x0, 0x40(%rsp)
movq 0x20(%rsp), %rdi
movl 0x40(%rsp), %eax
movq %rax, 0x18(%rsp)
addq $0x270, %rdi            # imm = 0x270
callq 0x64a70
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x613e2
movq 0x48(%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
movl 0x40(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl (%rax), %eax
movl %eax, 0x3c(%rsp)
cmpl $0x1, 0x44(%rsp)
jne 0x613ad
movq 0x20(%rsp), %rdi
addq $0x270, %rdi            # imm = 0x270
movl 0x40(%rsp), %eax
movl %eax, %esi
callq 0x64a90
movq (%rax), %rdi
movl 0x3c(%rsp), %esi
callq 0x5e680
jmp 0x613d0
movq 0x20(%rsp), %rdi
addq $0x270, %rdi            # imm = 0x270
movl 0x40(%rsp), %eax
movl %eax, %esi
callq 0x64a90
movq (%rax), %rdi
movl 0x3c(%rsp), %esi
callq 0x5e620
jmp 0x613d2
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x6133d
jmp 0x614ec
cmpl $0x1, 0x44(%rsp)
jne 0x6146c
movl $0x0, 0x38(%rsp)
movq 0x20(%rsp), %rdi
movl 0x38(%rsp), %eax
movq %rax, 0x10(%rsp)
addq $0x270, %rdi            # imm = 0x270
callq 0x64a70
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x6146a
movq 0x48(%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
movl 0x38(%rsp), %eax
movl %eax, %esi
callq 0xef90
movq 0x20(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x34(%rsp)
addq $0x270, %rdi            # imm = 0x270
movl 0x38(%rsp), %eax
movl %eax, %esi
callq 0x64a90
movq (%rax), %rdi
movl 0x34(%rsp), %esi
callq 0x5e680
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x613f6
jmp 0x614ea
movl $0x0, 0x30(%rsp)
movq 0x20(%rsp), %rdi
movl 0x30(%rsp), %eax
movq %rax, 0x8(%rsp)
addq $0x270, %rdi            # imm = 0x270
callq 0x64a70
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0x614e8
movq 0x48(%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
movl 0x30(%rsp), %eax
movl %eax, %esi
callq 0xef90
movq 0x20(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x2c(%rsp)
addq $0x270, %rdi            # imm = 0x270
movl 0x30(%rsp), %eax
movl %eax, %esi
callq 0x64a90
movq (%rax), %rdi
movl 0x2c(%rsp), %esi
callq 0x5e620
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x61474
jmp 0x614ea
jmp 0x614ec
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)