// File: gvaumour[P]cache-simulator/src/PHC.cc
// Function: PHCPredictor::updatePolicy(unsigned long, unsigned long, bool, Access, bool)
void
PHCPredictor::updatePolicy(uint64_t set, uint64_t index, bool inNVM, Access element, bool isWBrequest)
{
	update_globalPChistory(element.m_pc);
	
	stats_update++;
	
	CacheEntry *entry = get_entry(set , index , inNVM);
	entry->policyInfo = m_cpt++;


	RD_TYPE rd_type = classifyRD( set , index , inNVM );
	stats_access_class[rd_type][element.isWrite()]++;

	if(entry->isLearning)
	{
		entry->cost_value += m_costAccess[element.isWrite()][rd_type];
//		cout << "UpdatePolicy Learning Cache line 0x" << std::hex << element.block_addr
//			<< std::dec << " Cost Value " << entry->cost_value << endl;

	}

	stats_nbHits++;
	miss_counter--;
	if(miss_counter < 0)
		miss_counter = 0;

	Predictor::updatePolicy(set , index , inNVM , element , isWBrequest);
}

// Assembly:
subq $0xf8, %rsp
movl %r8d, 0x64(%rsp)
movl %ecx, %eax
movl 0x64(%rsp), %ecx
movq %rdx, 0x68(%rsp)
movq %rsi, %rdx
movq 0x68(%rsp), %rsi
movq %rdx, 0x70(%rsp)
movq %rdi, %r8
movq 0x70(%rsp), %rdi
movb %al, %dl
leaq 0x100(%rsp), %rax
movq %rax, 0x80(%rsp)
movq %r8, 0xf0(%rsp)
movq %rdi, 0xe8(%rsp)
movq %rsi, 0xe0(%rsp)
andb $0x1, %dl
movb %dl, 0xdf(%rsp)
andb $0x1, %cl
movb %cl, 0xde(%rsp)
movq 0xf0(%rsp), %rdi
movq %rdi, 0x78(%rsp)
movq 0x10(%rax), %rsi
callq 0x4ab00
movq 0x78(%rsp), %rdi
movq 0x3a8(%rdi), %rax
addq $0x1, %rax
movq %rax, 0x3a8(%rdi)
movq 0xe8(%rsp), %rsi
movq 0xe0(%rsp), %rdx
movb 0xdf(%rsp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x4ae70
movq 0x78(%rsp), %rdi
movq %rax, 0xd0(%rsp)
movq 0x2d8(%rdi), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x2d8(%rdi)
movl %eax, %ecx
movq 0xd0(%rsp), %rax
movl %ecx, 0x38(%rax)
movq 0xe8(%rsp), %rax
movl %eax, %esi
movq 0xe0(%rsp), %rax
movl %eax, %edx
movb 0xdf(%rsp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x4af00
movq 0x78(%rsp), %rdi
movl %eax, 0xcc(%rsp)
addq $0x430, %rdi            # imm = 0x430
movl 0xcc(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq 0x80(%rsp), %rdi
movq %rax, 0x88(%rsp)
callq 0xf7c0
movq 0x88(%rsp), %rdi
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
callq 0xef90
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq 0xd0(%rsp), %rax
testb $0x1, 0x148(%rax)
je 0x4ad79
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rax
addq $0x2b8, %rax            # imm = 0x2B8
movq %rax, 0x58(%rsp)
callq 0xf7c0
movq 0x58(%rsp), %rdi
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
movl 0xcc(%rsp), %eax
movl %eax, %esi
callq 0xef90
cvtsi2sdl (%rax), %xmm0
movq 0xd0(%rsp), %rax
addsd 0x130(%rax), %xmm0
movsd %xmm0, 0x130(%rax)
movq 0x78(%rsp), %rax
movq 0x370(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x370(%rax)
leaq 0x494a9(%rip), %rax     # 0x94240
movl (%rax), %ecx
addl $-0x1, %ecx
leaq 0x4949d(%rip), %rax     # 0x94240
movl %ecx, (%rax)
leaq 0x49494(%rip), %rax     # 0x94240
cmpl $0x0, (%rax)
jge 0x4adbe
leaq 0x49488(%rip), %rax     # 0x94240
movl $0x0, (%rax)
movq 0x80(%rsp), %rsi
movq 0xe8(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x50(%rsp)
movb 0xdf(%rsp), %al
movb %al, 0x47(%rsp)
leaq 0x90(%rsp), %rdi
movl $0x38, %edx
callq 0x52f0
movb 0x47(%rsp), %cl
movq 0x78(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movb 0xde(%rsp), %al
movq 0xc0(%rsp), %r9
movq %rsp, %r8
movq %r9, 0x30(%r8)
movups 0x90(%rsp), %xmm0
movups 0xa0(%rsp), %xmm1
movups 0xb0(%rsp), %xmm2
movups %xmm2, 0x20(%r8)
movups %xmm1, 0x10(%r8)
movups %xmm0, (%r8)
movzbl %cl, %ecx
andl $0x1, %ecx
movzbl %al, %r8d
andl $0x1, %r8d
callq 0x56ed0
addq $0xf8, %rsp
retq
nopw (%rax,%rax)