// File: /workspace/github_cpp_makefile_star2_O1/gvaumour[P]cache-simulator/src/Cerebron.cc
// Function: CerebronPredictor::activationFunction(bool, unsigned long, unsigned long)
allocDecision
CerebronPredictor::activationFunction( bool isWrite , uint64_t block_addr , uint64_t missPC)
{

	if(m_activation_function == "linear")
	{
	
		int sum_pred = 0;
		for(unsigned i = 0 ; i < m_features.size() ; i++)
		{
			int hash = hashing_function1 ( m_features_hash[i] , block_addr , missPC);
			int confidence = m_features[i]->getConfidence(hash, true);
			allocDecision des = m_features[i]->getAllocDecision(hash, isWrite );

			if(simu_parameters.printDebug)
				debug_file << "Feature " << i << " -- ID Dataset:" << hash << "\t" << missPC << endl;

		
			if( des == ALLOCATE_IN_SRAM )
				sum_pred += (-1) * confidence;
			else
				sum_pred += confidence;
		}
		return convertToAllocDecision(sum_pred, isWrite );
	}
	else if(m_activation_function == "max")
	{
		allocDecision des = ALLOCATE_IN_SRAM;
		int max_confidence = 0;
		for(unsigned i = 0 ; i < m_features.size() ; i++)
		{
			int hash = hashing_function1( m_features_hash[i] , block_addr , missPC);
			int confidence = m_features[i]->getConfidence(hash, true);
			
			if(max_confidence < confidence)
			{
				max_confidence = confidence;
				des = m_features[i]->getAllocDecision(hash, isWrite );
			}
			return des;
		}
	}
	
	assert(false && "Error, should have return before");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, (%rsp)
movq %rdx, 0x20(%rsp)
movl %esi, %ebp
movq %rdi, %r12
leaq 0x2b8(%rdi), %rbx
leaq 0x2c838(%rip), %rsi     # 0x34044
movq %rbx, %rdi
callq 0x50f0
testl %eax, %eax
movq %r12, 0x8(%rsp)
je 0x78e4
leaq 0x2c823(%rip), %rsi     # 0x3404b
movq %rbx, %rdi
callq 0x50f0
testl %eax, %eax
jne 0x7a95
movq 0x270(%r12), %r14
movq 0x278(%r12), %r15
cmpq %r14, %r15
je 0x7a8c
movq 0x288(%r12), %r13
leaq 0x60(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0xcc1c
movq 0x20(%r13), %rax
movq %rax, 0x20(%rbx)
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq (%rsp), %rdx
callq 0x15bec
movl %eax, %ebx
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x78a5
callq 0x52a0
movq 0x8(%rsp), %r12
movq 0x270(%r12), %rax
movq (%rax), %rdi
movl %ebx, %esi
movl $0x1, %edx
callq 0x14a94
testl %eax, %eax
jle 0x7a8e
movq 0x270(%r12), %rax
movq (%rax), %rdi
movzbl %bpl, %edx
movl %ebx, %esi
callq 0x1493e
jmp 0x7a90
movq 0x278(%r12), %rax
cmpq 0x270(%r12), %rax
movl %ebp, 0x14(%rsp)
je 0x7ab4
xorl %ebx, %ebx
movl $0x1, %r14d
leaq 0x38(%rsp), %r15
movzbl %bpl, %ecx
movl %ecx, 0x18(%rsp)
xorl %edx, %edx
movl %edx, 0x1c(%rsp)
movq 0x288(%r12), %r12
leaq (%rbx,%rbx,4), %r13
movq %r15, 0x28(%rsp)
movq (%r12,%r13,8), %rsi
movq 0x8(%r12,%r13,8), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
callq 0xcc1c
movq 0x20(%r12,%r13,8), %rax
movq %rax, 0x48(%rsp)
movq %rbp, %rdi
movq 0x20(%rsp), %rsi
movq (%rsp), %rdx
callq 0x15bec
movl %eax, %ebp
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x796f
callq 0x52a0
movq 0x8(%rsp), %r13
movq 0x270(%r13), %rax
movq (%rax,%rbx,8), %rdi
movl %ebp, %esi
movl $0x1, %edx
callq 0x14a94
movl %eax, %r12d
movq 0x270(%r13), %rax
movq (%rax,%rbx,8), %rdi
movl %ebp, %esi
movl 0x18(%rsp), %edx
callq 0x1493e
movl %eax, %r13d
leaq 0x3e5a2(%rip), %rax     # 0x45f50
cmpb $0x1, (%rax)
jne 0x7a4b
movl $0x8, %edx
leaq 0x3da9d(%rip), %r15     # 0x45460
movq %r15, %rdi
leaq 0x2c885(%rip), %rsi     # 0x34252
callq 0x5350
movq %r15, %rdi
movq %rbx, %rsi
callq 0x51e0
movq %rax, %rbx
movl $0xf, %edx
movq %rax, %rdi
leaq 0x2c86c(%rip), %rsi     # 0x3425b
callq 0x5350
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5580
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2e26b(%rip), %rsi     # 0x35c7b
callq 0x5350
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x51e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movl %r12d, %eax
negl %eax
testl %r13d, %r13d
cmovnel %r12d, %eax
movl 0x1c(%rsp), %edx
addl %eax, %edx
movq 0x8(%rsp), %r12
movq 0x278(%r12), %rax
subq 0x270(%r12), %rax
movl %r14d, %ebx
sarq $0x3, %rax
incl %r14d
cmpq %rbx, %rax
leaq 0x38(%rsp), %r15
ja 0x7915
jmp 0x7ab6
jmp 0x7a90
xorl %eax, %eax
cmpq %r14, %r15
jne 0x7ae5
leaq 0x2c7cf(%rip), %rdi     # 0x3426b
leaq 0x2c5ec(%rip), %rsi     # 0x3408f
leaq 0x2c7ed(%rip), %rcx     # 0x34297
movl $0x1f9, %edx            # imm = 0x1F9
callq 0x51d0
xorl %edx, %edx
leaq 0x3e493(%rip), %rax     # 0x45f50
cmpb $0x1, 0x221(%rax)
jne 0x7add
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
cmpl 0x1c0(%rax), %ecx
jge 0x7add
movl 0x14(%rsp), %eax
xorb $0x1, %al
jmp 0x7ae2
testl %edx, %edx
setns %al
movzbl %al, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
jne 0x7b10
jmp 0x7b15
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x7b15
callq 0x52a0
movq %rbx, %rdi
callq 0x55a0
nop