// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movq %rsi, %rbx
movl %ecx, 0x6c(%rsp)
movl %ecx, %eax
movq %rdi, 0x48(%rsp)
movq 0x8(%rdi,%rax,8), %rax
movq (%rax), %rax
leaq (%rsi,%rsi,2), %rcx
movq (%rax,%rcx,8), %rax
movq %rdx, 0x80(%rsp)
movq (%rax,%rdx,8), %rax
movq 0x160(%rsp), %rcx
movq %rax, 0x58(%rsp)
movq %rcx, 0x20(%rax)
movb 0x178(%rsp), %r12b
movl $0x2, %ebp
cmpb $0x1, %r12b
jne 0x7b8e
movq 0x48(%rsp), %rax
incq 0x448(%rax)
movl $0x1, %ebp
leaq 0x150(%rsp), %rsi
movq 0x48(%rsp), %rdi
movq 0x2f8(%rdi), %rax
leaq 0x1(%rax), %rdx
movq %rdx, 0x2f8(%rdi)
movq 0x58(%rsp), %r14
movl %eax, 0x38(%r14)
cmpb $0x1, 0x149(%r14)
jne 0x7bf8
movq 0x30(%rsi), %rdx
movl 0x1c(%rsi), %eax
cmpl $0x3, %eax
sete %sil
cmpl $0x6, %eax
sete %al
orb %sil, %al
xorl %esi, %esi
movl %esi, 0x18(%rsp)
movl %ebp, 0x10(%rsp)
movl %esi, (%rsp)
movzbl %al, %r9d
movq 0x48(%rsp), %rdi
movq %r14, %rsi
movl %ebx, %r8d
callq 0x80fc
movl %ebp, 0x70(%rsp)
movq %rbx, 0x78(%rsp)
movb 0x14a(%r14), %al
movb %r12b, 0x47(%rsp)
andb %r12b, %al
cmpb $0x1, %al
movq %r14, %rbx
jne 0x7ddd
leaq 0x3d83e(%rip), %rbx     # 0x45460
leaq 0x2c4eb(%rip), %rsi     # 0x34114
movl $0x26, %edx
movq %rbx, %rdi
callq 0x5350
movq 0x3d823(%rip), %rax     # 0x45460
movq -0x18(%rax), %rax
movl 0x18(%rax,%rbx), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rax,%rbx)
leaq 0x150(%rsp), %rax
movq 0x30(%rax), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x51e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rbx,%rcx)
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
movq 0x48(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq 0x78(%rsp), %rbx
movl %ebx, %edx
callq 0x2702a
movq %rax, %r14
movq %r15, %rdi
movq %r12, 0x60(%rsp)
movq %r12, %rsi
movl %ebx, %edx
movq 0x58(%rsp), %rbx
callq 0x26fe4
movl %eax, 0x74(%rsp)
movq %r14, 0x20(%rbx)
movq 0x278(%r15), %rax
cmpq 0x270(%r15), %rax
je 0x7dd1
movl $0x1, %r13d
leaq 0xc0(%rsp), %rbp
xorl %r12d, %r12d
movq 0x48(%rsp), %rax
movq 0x288(%rax), %r14
leaq (%r12,%r12,4), %rbx
movq %rbp, 0xb0(%rsp)
movq (%r14,%rbx,8), %rsi
movq 0x8(%r14,%rbx,8), %rdx
addq %rsi, %rdx
leaq 0xb0(%rsp), %r15
movq %r15, %rdi
callq 0xcc1c
movq 0x20(%r14,%rbx,8), %rax
movq 0x58(%rsp), %rbx
movq %rax, 0xd0(%rsp)
movq 0x20(%rbx), %rdx
movq %r15, %rdi
movq 0x60(%rsp), %rsi
callq 0x15bec
movl %eax, %r14d
movq 0xb0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x7d6c
callq 0x52a0
movq 0x48(%rsp), %rax
movq 0x270(%rax), %rax
movq (%rax,%r12,8), %rdi
movl %r14d, %esi
callq 0x14b12
cmpl $0x0, 0x74(%rsp)
je 0x7da3
movq 0x48(%rsp), %rax
movq 0x270(%rax), %rax
movq (%rax,%r12,8), %rdi
movl %r14d, %esi
callq 0x14b12
movq 0x48(%rsp), %rcx
movq 0x278(%rcx), %rax
subq 0x270(%rcx), %rax
movl %r13d, %r12d
sarq $0x3, %rax
incl %r13d
cmpq %r12, %rax
leaq 0xc0(%rsp), %rbp
ja 0x7d00
movq 0x48(%rsp), %rax
incq 0x440(%rax)
movq 0x48(%rsp), %rcx
movq 0x278(%rcx), %rax
cmpq 0x270(%rcx), %rax
je 0x7ed6
leaq 0x98(%rsp), %r13
leaq 0x150(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x60(%rsp)
movl $0x1, %r12d
xorl %r14d, %r14d
movq 0x48(%rsp), %rax
movq %rax, %r15
movq 0x288(%rax), %rbp
leaq (%r14,%r14,4), %rbx
movq %r13, 0x88(%rsp)
movq (%rbp,%rbx,8), %rsi
movq 0x8(%rbp,%rbx,8), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0xcc1c
movq 0x20(%rbp,%rbx,8), %rax
movq 0x58(%rsp), %rbx
movq %rax, 0xa8(%rsp)
movq 0x20(%rbx), %rdx
leaq 0x88(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x15bec
movl %eax, %ebp
movq 0x88(%rsp), %rdi
cmpq %r13, %rdi
je 0x7e89
callq 0x52a0
movq 0x270(%r15), %rax
movq (%rax,%r14,8), %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x1493e
movq 0xd0(%rbx), %rcx
movl %ebp, (%rcx,%r14,8)
movl %eax, 0x4(%rcx,%r14,8)
movq 0x278(%r15), %rax
subq 0x270(%r15), %rax
movl %r12d, %r14d
sarq $0x3, %rax
incl %r12d
cmpq %r14, %rax
leaq 0x98(%rsp), %r13
ja 0x7e18
leaq 0x3e073(%rip), %rax     # 0x45f50
cmpb $0x0, 0x226(%rax)
leaq 0x150(%rsp), %r13
jne 0x7f3b
movl 0x1c(%r13), %eax
cmpl $0x3, %eax
sete %cl
cmpl $0x6, %eax
sete %al
orb %cl, %al
movzbl %al, %eax
movq 0x48(%rsp), %rcx
movq 0x2d8(%rcx), %rcx
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rax
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0x130(%rbx)
cmpb $0x0, 0x47(%rsp)
je 0x7f3b
cvtsi2sdl 0x4(%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x130(%rbx)
movb 0x40(%rbx), %bpl
leaq 0xe8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2c1e9(%rip), %rsi     # 0x3413b
leaq 0x2c1eb(%rip), %rdx     # 0x34144
leaq 0xd8(%rsp), %rdi
callq 0xccac
movq %rbx, %r12
movl 0x70(%rsp), %ebx
leaq 0x3d4bc(%rip), %rax     # 0x45430
movq (%rax,%rbx,8), %rsi
leaq 0xf8(%rsp), %rdi
leaq 0x57(%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 0xd8(%rsp), %r8
leaq 0xf8(%rsp), %r9
movq 0x48(%rsp), %rdi
movq %r12, %rsi
movq 0x78(%rsp), %r12
movl %r12d, %edx
callq 0x83d6
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7ff3
callq 0x52a0
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x8005
callq 0x52a0
movq 0x48(%rsp), %rdi
incq 0x420(%rdi)
movq 0x4a8(%rdi), %rax
leaq (%rbx,%rbx,2), %rcx
movl 0x1c(%r13), %edx
cmpl $0x3, %edx
sete %sil
cmpl $0x6, %edx
sete %dl
orb %sil, %dl
movq (%rax,%rcx,8), %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 0x6c(%rsp), %ecx
movq %r12, %rsi
movq 0x80(%rsp), %rdx
callq 0x26892
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x80a5
callq 0x52a0
jmp 0x80a5
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
jne 0x80d6
jmp 0x80db
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x80d6
jmp 0x80db
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r13, %rdi
je 0x80db
callq 0x52a0
movq %rbx, %rdi
callq 0x55a0
nop