// File: /workspace/github_cpp_makefile_star2_O2/gvaumour[P]cache-simulator/src/Cerebron.cc
// Function: CerebronPredictor::insertionPolicy(unsigned long, unsigned long, bool, Access)
void
CerebronPredictor::insertionPolicy(uint64_t set, uint64_t index, bool inNVM, Access element)
{
	CacheEntry* entry = get_entry(set , index , inNVM);
	entry->missPC = element.m_pc;
	RD_TYPE rd = RD_NOT_ACCURATE;
	if( element.isSRAMerror)
	{
		stats_cptSRAMerror++;
		rd = RD_MEDIUM;	
	}
	entry->policyInfo = m_cpt++;
			

	if(entry->isLearning_policy)
		recordAccess(entry, element.block_addr, entry->missPC, set , element.isWrite() , inNVM, index, rd , false);

	if(entry->isLearning_weight)
	{
		if( element.isSRAMerror)
		{
			debug_file << "SRAM error detected on Block Addr = 0x" \
					<< std::hex << element.block_addr << std::dec << endl;
			
			uint64_t missPC = missingTagMissPC(element.block_addr , set);
			uint64_t cost_value = missingTagCostValue(element.block_addr , set);
			entry->missPC = missPC;
			for(unsigned i = 0 ; i < m_features.size() ; i++)
			{
				int hash = hashing_function1(m_features_hash[i] , element.block_addr , entry->missPC);
				m_features[i]->decreaseConfidence(hash);
				if(cost_value > 0)
					m_features[i]->decreaseConfidence(hash);
			}
			stats_cptLearningSRAMerror++;
		}
	}
	
	for(unsigned i = 0 ; i < m_features.size() ; i++)
	{
		pair<int , allocDecision> dummy;
		dummy.first = hashing_function1(m_features_hash[i] , element.block_addr , entry->missPC);
		dummy.second = m_features[i]->getAllocDecision(dummy.first, false);
		entry->PHC_allocation_pred[i] = dummy;
	}		
	
	if( !simu_parameters.Cerebron_RDmodel)
	{
		entry->cost_value = m_costAccess[element.isWrite()][RD_SHORT];
		if( element.isSRAMerror)
			entry->cost_value += m_costAccess[element.isWrite()][RD_MEDIUM];		

	}

	reportAccess( element, entry , set,  entry->isNVM, string("INSERTION"), string(str_RD_status[rd]));
				
	stats_allocate++;
	stats_access_class[rd][element.isWrite()]++;
	Predictor::insertionPolicy(set , index , inNVM , element);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r15
movl %ecx, %eax
movq 0x8(%rdi,%rax,8), %rax
movq (%rax), %rax
imulq $0x18, %rsi, %rcx
movq (%rax,%rcx), %rax
movq (%rax,%rdx,8), %r12
movq 0x130(%rsp), %rcx
movq %rcx, 0x20(%r12)
movb 0x148(%rsp), %al
movb %al, 0x39(%rsp)
cmpb $0x1, %al
movq %rdx, 0x48(%rsp)
jne 0x6dbb
incq 0x448(%r15)
pushq $0x1
jmp 0x6dbd
pushq $0x2
popq %r13
leaq 0x120(%rsp), %r14
movq 0x2f8(%r15), %rax
leaq 0x1(%rax), %rdx
movq %rdx, 0x2f8(%r15)
movl %eax, 0x38(%r12)
cmpb $0x1, 0x149(%r12)
jne 0x6e21
movq 0x30(%r14), %rdx
movl 0x1c(%r14), %eax
cmpl $0x3, %eax
sete %sil
cmpl $0x6, %eax
sete %al
orb %sil, %al
andl $0x0, 0x18(%rsp)
andl $0x0, (%rsp)
movl %r13d, 0x10(%rsp)
movzbl %al, %r9d
movq %r15, %rdi
movq %r12, %rsi
movl %ebx, %r8d
callq 0x719a
movl %r13d, 0x40(%rsp)
movb 0x39(%rsp), %al
testb %al, 0x14a(%r12)
movq %rbx, 0x50(%rsp)
movl %ebp, 0x3c(%rsp)
je 0x6f3d
leaq 0x36618(%rip), %rdi     # 0x3d460
leaq 0x222b5(%rip), %rsi     # 0x29104
callq 0x52c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq 0x30(%r14), %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x5200
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
callq 0x5190
movq %r15, %rdi
movq %r13, %rsi
movl %ebx, %edx
callq 0x1fa36
movq %rax, %r14
movq %r15, %rdi
movq %r13, %rsi
movl %ebx, %edx
callq 0x1f9f4
movl %eax, 0x44(%rsp)
movq %r14, 0x20(%r12)
xorl %ebx, %ebx
leaq 0xc0(%rsp), %rbp
movl %ebx, %ebx
movq 0x278(%r15), %rax
subq 0x270(%r15), %rax
sarq $0x3, %rax
cmpq %rbx, %rax
jbe 0x6f43
imulq $0x28, %rbx, %rsi
addq 0x288(%r15), %rsi
movq %rbp, %rdi
callq 0x9f3a
movq 0x20(%r12), %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x11de8
movl %eax, %r14d
movq %rbp, %rdi
callq 0x5618
movq 0x270(%r15), %rax
movq (%rax,%rbx,8), %rdi
movl %r14d, %esi
callq 0x11188
cmpl $0x0, 0x44(%rsp)
je 0x6f39
movq 0x270(%r15), %rax
movq (%rax,%rbx,8), %rdi
movl %r14d, %esi
callq 0x11188
incl %ebx
jmp 0x6ec5
movq 0x30(%r14), %r13
jmp 0x6f4a
incq 0x440(%r15)
xorl %eax, %eax
leaq 0x98(%rsp), %rbx
movl %eax, %r14d
movq 0x278(%r15), %rax
subq 0x270(%r15), %rax
sarq $0x3, %rax
cmpq %r14, %rax
jbe 0x6fc6
imulq $0x28, %r14, %rsi
addq 0x288(%r15), %rsi
movq %rbx, %rdi
callq 0x9f3a
movq 0x20(%r12), %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x11de8
movl %eax, %ebp
movq %rbx, %rdi
callq 0x5618
movq 0x270(%r15), %rax
movq (%rax,%r14,8), %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x11088
movq 0xd0(%r12), %rcx
movl %ebp, (%rcx,%r14,8)
movl %eax, 0x4(%rcx,%r14,8)
leal 0x1(%r14), %eax
jmp 0x6f54
leaq 0x36f83(%rip), %rax     # 0x3df50
cmpb $0x0, 0x226(%rax)
movq 0x50(%rsp), %r14
leaq 0x120(%rsp), %r13
jne 0x702f
movl 0x1c(%r13), %eax
cmpl $0x3, %eax
sete %cl
cmpl $0x6, %eax
sete %al
orb %cl, %al
movzbl %al, %eax
movq 0x2d8(%r15), %rcx
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rax
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0x130(%r12)
cmpb $0x0, 0x39(%rsp)
je 0x702f
cvtsi2sdl 0x4(%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x130(%r12)
movb 0x40(%r12), %bpl
leaq 0x220f0(%rip), %rsi     # 0x2912b
leaq 0x78(%rsp), %rdi
leaq 0x3b(%rsp), %rdx
callq 0x5140
movl 0x40(%rsp), %ebx
leaq 0x363db(%rip), %rax     # 0x3d430
movq (%rax,%rbx,8), %rsi
leaq 0x58(%rsp), %rdi
leaq 0x3a(%rsp), %rdx
callq 0x5140
movq 0x30(%r13), %rax
movq %rax, 0x30(%rsp)
movupd (%r13), %xmm0
movupd 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movzbl %bpl, %ecx
leaq 0x78(%rsp), %r8
leaq 0x58(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
callq 0x73b2
leaq 0x58(%rsp), %rdi
callq 0x5618
leaq 0x78(%rsp), %rdi
callq 0x5618
incq 0x420(%r15)
movq 0x4a8(%r15), %rax
imulq $0x18, %rbx, %rcx
movl 0x1c(%r13), %edx
cmpl $0x3, %edx
sete %sil
cmpl $0x6, %edx
sete %dl
orb %sil, %dl
movq (%rax,%rcx), %rax
movzbl %dl, %ecx
incl (%rax,%rcx,4)
movq 0x30(%r13), %rax
movq %rax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movzbl 0x3c(%rsp), %ecx
movq %r15, %rdi
movq %r14, %rsi
movq 0x48(%rsp), %rdx
callq 0x1f3a2
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x5618
jmp 0x7151
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x7175
movq %rax, %rbx
jmp 0x717a
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
jmp 0x7175
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x5618
movq %rbx, %rdi
callq 0x5570