// File: gvaumour[P]cache-simulator/src/SimplePerceptron.cc
// Function: SimplePerceptronPredictor::insertionPolicy(unsigned long, unsigned long, bool, Access)
void
SimplePerceptronPredictor::insertionPolicy(uint64_t set, uint64_t index, bool inNVM, Access element)
{
	CacheEntry* entry = inNVM ? m_tableNVM[set][index] : m_tableSRAM[set][index];
	entry->missPC = element.m_pc;
		
	if(isHitInBPtags(element.block_addr , set))
	{
		entry->missPC = getMissPCfromBPtags(element.block_addr , set);
		correctBPerror(entry , element , set );
			/*
		debug_file_simple_perceptron << "Insertion + detected SRAM error on line 0x" << std::hex << element.block_addr \
			 << " , Retified MissPC from 0x" << element.m_pc << " to " << entry->missPC << endl;
		*/
	}

	entry->policyInfo = m_cpt++;

	if(entry->isLearning)
	{		
		updateCostModel(entry, entry->address , set , element.isWrite());		

		if(simu_parameters.simple_perceptron_fastLearning)
			doLearning(entry);

		setPrediction(entry , element);	
	}	
	reportAccess( element, entry , set , inNVM, string("INSERTION") );
	
//	stats_access_class[rd][element.isWrite()]++;
	Predictor::insertionPolicy(set , index , inNVM , element);
}

// Assembly:
subq $0x1f8, %rsp            # imm = 0x1F8
movb %cl, %al
leaq 0x200(%rsp), %rcx
movq %rcx, 0xa0(%rsp)
movq %rdi, 0x1f0(%rsp)
movq %rsi, 0x1e8(%rsp)
movq %rdx, 0x1e0(%rsp)
andb $0x1, %al
movb %al, 0x1df(%rsp)
movq 0x1f0(%rsp), %rax
movq %rax, 0xa8(%rsp)
testb $0x1, 0x1df(%rsp)
je 0x60b7a
movq 0xa8(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x1e8(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movq 0x1e0(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movq %rax, 0x98(%rsp)
jmp 0x60bae
movq 0xa8(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x1e8(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movq 0x1e0(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movq %rax, 0x98(%rsp)
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rax
movq 0x98(%rsp), %rcx
movq %rcx, 0x1d0(%rsp)
movq 0x10(%rax), %rdx
movq 0x1d0(%rsp), %rcx
movq %rdx, 0x20(%rcx)
movq 0x30(%rax), %rsi
movq 0x1e8(%rsp), %rax
movl %eax, %edx
callq 0x573f0
testb $0x1, %al
jne 0x60bfa
jmp 0x60ca7
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rax
movq 0x30(%rax), %rsi
movq 0x1e8(%rsp), %rax
movl %eax, %edx
callq 0x574e0
movq 0xa0(%rsp), %rsi
movq %rax, %rcx
movq 0x1d0(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x1d0(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x198(%rsp), %rdi
movl $0x38, %edx
callq 0x52f0
movq 0xa8(%rsp), %rdi
movq 0x90(%rsp), %rsi
movq 0x1e8(%rsp), %rax
movl %eax, %edx
movq 0x1c8(%rsp), %rcx
movq %rsp, %rax
movq %rcx, 0x30(%rax)
movups 0x198(%rsp), %xmm0
movups 0x1a8(%rsp), %xmm1
movups 0x1b8(%rsp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x60fd0
movq 0xa8(%rsp), %rcx
movq 0x2c0(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x2c0(%rcx)
movl %eax, %ecx
movq 0x1d0(%rsp), %rax
movl %ecx, 0x38(%rax)
movq 0x1d0(%rsp), %rax
testb $0x1, 0x148(%rax)
je 0x60ddc
movq 0xa0(%rsp), %rdi
movq 0x1d0(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x1d0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x80(%rsp)
movq 0x1e8(%rsp), %rax
movl %eax, 0x8c(%rsp)
callq 0xf7c0
movq 0xa8(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
movl 0x8c(%rsp), %ecx
movzbl %al, %r8d
andl $0x1, %r8d
callq 0x61160
leaq 0x3329d(%rip), %rax     # 0x93ff0
testb $0x1, 0x24c(%rax)
je 0x60d71
movq 0xa8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
callq 0x612e0
movq 0xa0(%rsp), %rsi
movq 0x1d0(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x160(%rsp), %rdi
movl $0x38, %edx
callq 0x52f0
movq 0xa8(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq 0x190(%rsp), %rcx
movq %rsp, %rax
movq %rcx, 0x30(%rax)
movups 0x160(%rsp), %xmm0
movups 0x170(%rsp), %xmm1
movups 0x180(%rsp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x61500
movq 0xa0(%rsp), %rax
movq 0x30(%rax), %rcx
movq %rcx, 0x150(%rsp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movaps %xmm2, 0x140(%rsp)
movaps %xmm1, 0x130(%rsp)
movaps %xmm0, 0x120(%rsp)
movq 0x1d0(%rsp), %rax
movq %rax, 0x58(%rsp)
movl 0x1e8(%rsp), %eax
movl %eax, 0x60(%rsp)
movb 0x1df(%rsp), %al
movb %al, 0x67(%rsp)
leaq 0xff(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x56a0
movq 0x68(%rsp), %rdx
leaq 0x102e7(%rip), %rsi     # 0x7113b
leaq 0x100(%rsp), %rdi
callq 0x5530
jmp 0x60e63
movl 0x60(%rsp), %edx
movq 0x58(%rsp), %rsi
movq 0xa8(%rsp), %rdi
movb 0x67(%rsp), %al
movq 0x150(%rsp), %r8
movq %rsp, %rcx
movq %r8, 0x30(%rcx)
movaps 0x120(%rsp), %xmm0
movaps 0x130(%rsp), %xmm1
movaps 0x140(%rsp), %xmm2
movups %xmm2, 0x20(%rcx)
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
movzbl %al, %ecx
andl $0x1, %ecx
leaq 0x100(%rsp), %r8
callq 0x61740
jmp 0x60ebf
leaq 0x100(%rsp), %rdi
callq 0x5768
leaq 0xff(%rsp), %rdi
callq 0x53e0
movq 0xa0(%rsp), %rsi
movq 0x1e8(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x1e0(%rsp), %rax
movq %rax, 0x50(%rsp)
movb 0x1df(%rsp), %al
movb %al, 0x47(%rsp)
leaq 0xb0(%rsp), %rdi
movl $0x38, %edx
callq 0x52f0
movb 0x47(%rsp), %al
movq 0xa8(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0xe0(%rsp), %r8
movq %rsp, %rcx
movq %r8, 0x30(%rcx)
movups 0xb0(%rsp), %xmm0
movups 0xc0(%rsp), %xmm1
movups 0xd0(%rsp), %xmm2
movups %xmm2, 0x20(%rcx)
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
movzbl %al, %ecx
andl $0x1, %ecx
callq 0x55140
addq $0x1f8, %rsp            # imm = 0x1F8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0x60faa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x5768
leaq 0xff(%rsp), %rdi
callq 0x53e0
movq 0xf0(%rsp), %rdi
callq 0x5690
nopw %cs:(%rax,%rax)