// File: /workspace/github_cpp_makefile_star2_O2/gvaumour[P]cache-simulator/src/Cerebron.cc
// Function: CerebronPredictor::recordAccess(CacheEntry*, unsigned long, unsigned long, int, bool, bool, int, RD_TYPE, bool)
void
CerebronPredictor::recordAccess(CacheEntry* entry,uint64_t block_addr, uint64_t missPC, int set,\
			bool isWrite , bool inNVM, int index, RD_TYPE rd , bool isUpdate)
{
	if(simu_parameters.Cerebron_RDmodel)
	{
		bool hitSRAM = false, hitNVM = false;
		hitNVM = getHitPerDataArray( block_addr , set , true);
		hitSRAM = getHitPerDataArray( block_addr , set , false);
		/*
		if( !inNVM && isUpdate)
			hitSRAM = true;
		else
			hitSRAM = getHitPerDataArray( block_addr , set , false);
				
	
		if( inNVM && isUpdate)
			hitNVM = true;
		else 
			hitNVM = getHitPerDataArray( block_addr , set , true);
		*/
		/*
		string hitSRAM_str = hitSRAM ? "TRUE" : "FALSE";
		string hitNVM_str = hitNVM ? "TRUE" : "FALSE";		
		//debug_file << "hitSRAM = " << hitSRAM_str << " , hitNVM = " << hitNVM_str << endl;
		//debug_file << "BEFORE : entry->e_sram = " << entry->e_sram << endl;
		*/
		entry->e_sram += m_costParameters.costSRAM[isWrite];
		entry->e_sram +=  !hitSRAM ? m_costParameters.costDRAM[isWrite] : 0;

		entry->e_nvm += m_costParameters.costNVM[isWrite];
		entry->e_nvm += !hitNVM ? m_costParameters.costDRAM[isWrite] : 0;
		//debug_file << "END: entry->e_sram = " << entry->e_sram << endl;
	
		if(entry->isLearning_policy)
		{
			for(unsigned i = 0 ; i < m_features.size() ; i++)
			{
				int hash = hashing_function1( m_features_hash[i] , block_addr , missPC);
				m_features[i]->recordAccess(hash, isWrite , hitSRAM , hitNVM);
			}		
		}
	}
	else
	{
		if(entry->isLearning_policy)
		{
			for(unsigned i = 0 ; i < m_features.size() ; i++)
			{
				int hash = hashing_function1( m_features_hash[i] , block_addr , missPC);
				m_features[i]->recordAccess(hash, isWrite , rd);	
			}
		}
	}	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, %r13d
movq %rcx, 0x10(%rsp)
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
leaq 0x36d90(%rip), %rax     # 0x3df50
cmpb $0x1, 0x226(%rax)
jne 0x7269
movl %r8d, %ebp
pushq $0x1
popq %rcx
movq %r15, %rdi
movq %r14, %rsi
movl %r8d, %edx
callq 0x20196
movb %al, 0xf(%rsp)
xorl %ebx, %ebx
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x20196
movzbl %r13b, %esi
movq 0x358(%r15), %rcx
movslq (%rcx,%rsi,4), %rcx
addq 0x138(%r12), %rcx
movq %rcx, 0x138(%r12)
testb %al, %al
jne 0x7224
movq 0x370(%r15), %rdx
movslq (%rdx,%rsi,4), %rbx
addq %rcx, %rbx
movq %rbx, 0x138(%r12)
movq 0x340(%r15), %rcx
movslq (%rcx,%rsi,4), %rcx
addq 0x140(%r12), %rcx
movq %rcx, 0x140(%r12)
movb 0xf(%rsp), %dil
testb %dil, %dil
movq %r14, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
je 0x72f3
xorl %edx, %edx
jmp 0x72fe
cmpb $0x1, 0x149(%r12)
jne 0x738d
movq %r14, %rbp
xorl %eax, %eax
leaq 0x28(%rsp), %r12
movzbl %r13b, %r13d
movl %eax, %r14d
movq 0x278(%r15), %rax
subq 0x270(%r15), %rax
sarq $0x3, %rax
cmpq %r14, %rax
jbe 0x738d
imulq $0x28, %r14, %rsi
addq 0x288(%r15), %rsi
movq %r12, %rdi
callq 0x9f3a
movq %r12, %rdi
movq %rbp, %rsi
movq 0x10(%rsp), %rdx
callq 0x11de8
movl %eax, %ebx
movq %r12, %rdi
callq 0x5618
movq 0x270(%r15), %rax
movq (%rax,%r14,8), %rdi
movl %ebx, %esi
movl %r13d, %edx
movl 0xc0(%rsp), %ecx
callq 0x10ed2
leal 0x1(%r14), %eax
jmp 0x7286
movq 0x370(%r15), %rdx
movslq (%rdx,%rsi,4), %rdx
addq %rcx, %rdx
movq %rdx, 0x140(%r12)
cmpb $0x1, 0x149(%r12)
jne 0x738d
xorl %ecx, %ecx
leaq 0x50(%rsp), %r12
movzbl %al, %ebp
movzbl %dil, %r13d
movl %ecx, %r14d
movq 0x278(%r15), %rax
subq 0x270(%r15), %rax
sarq $0x3, %rax
cmpq %r14, %rax
jbe 0x738d
imulq $0x28, %r14, %rsi
addq 0x288(%r15), %rsi
movq %r12, %rdi
callq 0x9f3a
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x11de8
movl %eax, %ebx
movq %r12, %rdi
callq 0x5618
movq 0x270(%r15), %rax
movq (%rax,%r14,8), %rdi
movl %ebx, %esi
movq 0x18(%rsp), %rdx
movl %ebp, %ecx
movl %r13d, %r8d
callq 0x10fa2
leal 0x1(%r14), %ecx
jmp 0x7322
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x739e
movq %rax, %rbx
movq %r12, %rdi
callq 0x5618
movq %rbx, %rdi
callq 0x5570
nop