// File: 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:
subq $0xf8, %rsp
movb %sil, %al
movq %rdi, 0xe8(%rsp)
andb $0x1, %al
movb %al, 0xe7(%rsp)
movq %rdx, 0xd8(%rsp)
movq %rcx, 0xd0(%rsp)
movq 0xe8(%rsp), %rdi
movq %rdi, 0x38(%rsp)
addq $0x2b8, %rdi            # imm = 0x2B8
leaq 0x690fe(%rip), %rsi     # 0x71044
callq 0xfa60
testb $0x1, %al
jne 0x7f54
jmp 0x8191
movl $0x0, 0xcc(%rsp)
movl $0x0, 0xc8(%rsp)
movq 0x38(%rsp), %rdi
movl 0xc8(%rsp), %eax
movq %rax, 0x30(%rsp)
addq $0x270, %rdi            # imm = 0x270
callq 0xf840
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x8168
movq 0x38(%rsp), %rdi
addq $0x288, %rdi            # imm = 0x288
movl 0xc8(%rsp), %eax
movl %eax, %esi
callq 0xf860
movq %rax, %rsi
leaq 0x98(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0xf880
movq 0x20(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
callq 0x2ff40
movl %eax, 0x2c(%rsp)
jmp 0x7fe7
leaq 0x98(%rsp), %rdi
callq 0xf7b0
movl 0x2c(%rsp), %eax
movq 0x38(%rsp), %rdi
movl %eax, 0xc4(%rsp)
addq $0x270, %rdi            # imm = 0x270
movl 0xc8(%rsp), %eax
movl %eax, %esi
callq 0xf8c0
movq (%rax), %rdi
movl 0xc4(%rsp), %esi
movl $0x1, %edx
callq 0x2d520
movq 0x38(%rsp), %rdi
movl %eax, 0x88(%rsp)
addq $0x270, %rdi            # imm = 0x270
movl 0xc8(%rsp), %eax
movl %eax, %esi
callq 0xf8c0
movq (%rax), %rdi
movl 0xc4(%rsp), %esi
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0x2d360
movl %eax, 0x84(%rsp)
leaq 0x8bf79(%rip), %rax     # 0x93ff0
testb $0x1, (%rax)
je 0x8116
leaq 0x8b479(%rip), %rdi     # 0x93500
leaq 0x691c4(%rip), %rsi     # 0x71252
callq 0x5380
movq %rax, %rdi
movl 0xc8(%rsp), %esi
callq 0x5510
movq %rax, %rdi
leaq 0x691af(%rip), %rsi     # 0x7125b
callq 0x5380
movq %rax, %rdi
movl 0xc4(%rsp), %esi
callq 0x5680
movq %rax, %rdi
leaq 0x6ab99(%rip), %rsi     # 0x72c63
callq 0x5380
movq %rax, %rdi
movq 0xd0(%rsp), %rsi
callq 0x50f0
movq %rax, %rdi
movq 0x8aecf(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x8116
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x98(%rsp), %rdi
callq 0xf7b0
jmp 0x832b
cmpl $0x0, 0x84(%rsp)
jne 0x813b
imull $0xffffffff, 0x88(%rsp), %eax # imm = 0xFFFFFFFF
addl 0xcc(%rsp), %eax
movl %eax, 0xcc(%rsp)
jmp 0x8150
movl 0x88(%rsp), %eax
addl 0xcc(%rsp), %eax
movl %eax, 0xcc(%rsp)
jmp 0x8152
movl 0xc8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc8(%rsp)
jmp 0x7f6a
movq 0x38(%rsp), %rdi
movl 0xcc(%rsp), %esi
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0xc0e0
movl %eax, 0xf4(%rsp)
jmp 0x831c
movq 0x38(%rsp), %rdi
addq $0x2b8, %rdi            # imm = 0x2B8
leaq 0x68ea7(%rip), %rsi     # 0x7104b
callq 0xfa60
testb $0x1, %al
jne 0x81b2
jmp 0x82fb
movl $0x0, 0x80(%rsp)
movl $0x0, 0x7c(%rsp)
movl $0x0, 0x78(%rsp)
movq 0x38(%rsp), %rdi
movl 0x78(%rsp), %eax
movq %rax, 0x18(%rsp)
addq $0x270, %rdi            # imm = 0x270
callq 0xf840
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x82f9
movq 0x38(%rsp), %rdi
addq $0x288, %rdi            # imm = 0x288
movl 0x78(%rsp), %eax
movl %eax, %esi
callq 0xf860
movq %rax, %rsi
leaq 0x48(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xf880
movq 0x8(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
callq 0x2ff40
movl %eax, 0x14(%rsp)
jmp 0x8241
leaq 0x48(%rsp), %rdi
callq 0xf7b0
movl 0x14(%rsp), %eax
movq 0x38(%rsp), %rdi
movl %eax, 0x74(%rsp)
addq $0x270, %rdi            # imm = 0x270
movl 0x78(%rsp), %eax
movl %eax, %esi
callq 0xf8c0
movq (%rax), %rdi
movl 0x74(%rsp), %esi
movl $0x1, %edx
callq 0x2d520
movl %eax, 0x44(%rsp)
movl 0x7c(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x82e9
movq 0x38(%rsp), %rdi
movl 0x44(%rsp), %eax
movl %eax, 0x7c(%rsp)
addq $0x270, %rdi            # imm = 0x270
movl 0x78(%rsp), %eax
movl %eax, %esi
callq 0xf8c0
movq (%rax), %rdi
movl 0x74(%rsp), %esi
movb 0xe7(%rsp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0x2d360
movl %eax, 0x80(%rsp)
jmp 0x82e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0xf7b0
jmp 0x832b
movl 0x80(%rsp), %eax
movl %eax, 0xf4(%rsp)
jmp 0x831c
jmp 0x82fb
jmp 0x82fd
leaq 0x68f67(%rip), %rdi     # 0x7126b
leaq 0x68d84(%rip), %rsi     # 0x7108f
movl $0x1f9, %edx            # imm = 0x1F9
leaq 0x68f80(%rip), %rcx     # 0x71297
callq 0x5260
movl 0xf4(%rsp), %eax
addq $0xf8, %rsp
retq
movq 0x90(%rsp), %rdi
callq 0x5690
nopl (%rax,%rax)