// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
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, 0x78(%rsp)
movq (%rax,%rdx,8), %rbx
movq 0x160(%rsp), %rcx
movq %rcx, 0x20(%rbx)
movb 0x178(%rsp), %r13b
movl $0x2, %ebp
cmpb $0x1, %r13b
jne 0x7af6
movq 0x48(%rsp), %rax
incq 0x448(%rax)
movl $0x1, %ebp
leaq 0x150(%rsp), %r14
movq 0x48(%rsp), %rsi
movq 0x2f8(%rsi), %rax
leaq 0x1(%rax), %rdx
movq %rdx, 0x2f8(%rsi)
movl %eax, 0x38(%rbx)
cmpb $0x1, 0x149(%rbx)
jne 0x7b5a
movq 0x30(%r14), %rdx
movl 0x1c(%r14), %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 %rbx, %rsi
movl %r12d, %r8d
callq 0x806a
movl %ebp, 0x70(%rsp)
movb %r13b, 0x47(%rsp)
testb %r13b, 0x14a(%rbx)
movq %rbx, 0x60(%rsp)
movq %r12, 0x80(%rsp)
je 0x7d45
movq %rbx, %r13
leaq 0x3d8d9(%rip), %rbx     # 0x45460
leaq 0x2c55a(%rip), %rsi     # 0x340e8
movl $0x26, %edx
movq %rbx, %rdi
callq 0x5360
movq 0x3d8be(%rip), %rax     # 0x45460
movq -0x18(%rax), %rax
movl 0x18(%rax,%rbx), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rax,%rbx)
movq 0x30(%r14), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x51f0
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 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movl %r12d, %edx
callq 0x26dd0
movq %rax, %r14
movq %rbx, %rdi
movq %rbp, 0x58(%rsp)
movq %rbp, %rsi
movl %r12d, %edx
callq 0x26d8a
movl %eax, 0x74(%rsp)
movq %r14, 0x20(%r13)
movq 0x278(%rbx), %rax
movq %rax, %rcx
cmpq 0x270(%rbx), %rax
je 0x7d32
movl $0x1, %ebx
leaq 0xe0(%rsp), %rbp
xorl %r13d, %r13d
movq 0x48(%rsp), %rax
movq 0x288(%rax), %r14
leaq (,%r13,4), %r12
addq %r13, %r12
movq %rbp, 0xd0(%rsp)
movq (%r14,%r12,8), %rsi
movq 0x8(%r14,%r12,8), %rdx
addq %rsi, %rdx
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
callq 0xcbd6
movq 0x20(%r14,%r12,8), %rax
movq %rax, 0xf0(%rsp)
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rdx
movq %r15, %rdi
movq 0x58(%rsp), %rsi
callq 0x159f0
movl %eax, %r14d
movq 0xd0(%rsp), %rdi
movq %rbp, %r12
cmpq %rbp, %rdi
je 0x7ccd
callq 0x52b0
movq 0x48(%rsp), %rax
movq 0x270(%rax), %rax
movq (%rax,%r13,8), %rdi
movl %r14d, %esi
callq 0x149a4
cmpl $0x0, 0x74(%rsp)
je 0x7d04
movq 0x48(%rsp), %rax
movq 0x270(%rax), %rax
movq (%rax,%r13,8), %rdi
movl %r14d, %esi
callq 0x149a4
movl %ebx, %r13d
movq 0x48(%rsp), %rcx
movq 0x270(%rcx), %rax
movq 0x278(%rcx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
incl %ebx
cmpq %r13, %rdx
movq %r12, %rbp
ja 0x7c57
movq 0x48(%rsp), %rdx
incq 0x440(%rdx)
movq 0x60(%rsp), %rbx
jmp 0x7d58
movq 0x48(%rsp), %rcx
movq 0x270(%rcx), %rax
movq 0x278(%rcx), %rcx
cmpq %rax, %rcx
je 0x7e44
leaq 0x98(%rsp), %r13
leaq 0x150(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x58(%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 0xcbd6
movq 0x20(%rbp,%rbx,8), %rax
movq 0x60(%rsp), %rcx
movq %rax, 0xa8(%rsp)
movq %rcx, %rbx
movq 0x20(%rcx), %rdx
leaq 0x88(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x159f0
movl %eax, %ebp
movq 0x88(%rsp), %rdi
cmpq %r13, %rdi
je 0x7df7
callq 0x52b0
movq 0x270(%r15), %rax
movq (%rax,%r14,8), %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x147cc
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 0x7d83
leaq 0x3e105(%rip), %rax     # 0x45f50
cmpb $0x0, 0x226(%rax)
leaq 0x150(%rsp), %r13
jne 0x7ea9
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 0x7ea9
cvtsi2sdl 0x4(%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0x130(%rbx)
movb 0x40(%rbx), %bpl
leaq 0xc0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2c24f(%rip), %rsi     # 0x3410f
leaq 0x2c251(%rip), %rdx     # 0x34118
leaq 0xb0(%rsp), %rdi
callq 0xcc6c
movq %rbx, %r12
movl 0x70(%rsp), %ebx
leaq 0x3d54e(%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 0xb0(%rsp), %r8
leaq 0xf8(%rsp), %r9
movq 0x48(%rsp), %rdi
movq %r12, %rsi
movq 0x80(%rsp), %r12
movl %r12d, %edx
callq 0x8344
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7f64
callq 0x52b0
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
je 0x7f76
callq 0x52b0
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 0x78(%rsp), %rdx
callq 0x26664
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 0x8013
callq 0x52b0
jmp 0x8013
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
jne 0x8044
jmp 0x8049
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x8044
jmp 0x8049
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r13, %rdi
je 0x8049
callq 0x52b0
movq %rbx, %rdi
callq 0x55a0
nop