// File: /workspace/github_cpp_makefile_star2_O3/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, %ebx
movq %rcx, 0x18(%rsp)
movq %rsi, %r13
movq %rdi, %r15
leaq 0x3dec3(%rip), %rax     # 0x45f50
cmpb $0x1, 0x226(%rax)
movq %rdx, 0x10(%rsp)
jne 0x8131
movl %r8d, %ebp
movq %rdx, %r12
movq %r15, %rdi
movq %rdx, %rsi
movl %r8d, %edx
movl $0x1, %ecx
callq 0x2771a
movb %al, 0x8(%rsp)
xorl %r14d, %r14d
movq %r15, %rdi
movq %r12, %rsi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x2771a
movzbl %bl, %ebx
movq 0x358(%r15), %rcx
movslq (%rcx,%rbx,4), %rcx
addq 0x138(%r13), %rcx
movq %rcx, 0x138(%r13)
testb %al, %al
jne 0x80f9
movq 0x370(%r15), %rdx
movslq (%rdx,%rbx,4), %r14
addq %rcx, %r14
movq %r14, 0x138(%r13)
movq 0x340(%r15), %rcx
movslq (%rcx,%rbx,4), %rcx
addq 0x140(%r13), %rcx
movq %rcx, 0x140(%r13)
movb 0x8(%rsp), %sil
testb %sil, %sil
je 0x820d
xorl %edx, %edx
jmp 0x8218
cmpb $0x1, 0x149(%r13)
jne 0x830c
movq 0x278(%r15), %rax
cmpq 0x270(%r15), %rax
je 0x830c
movl $0x1, %ebp
leaq 0x60(%rsp), %r12
xorl %r13d, %r13d
movzbl %bl, %ecx
movl %ecx, 0xc(%rsp)
movq 0x288(%r15), %r14
leaq (,%r13,4), %rbx
addq %r13, %rbx
movq %r12, 0x50(%rsp)
movq (%r14,%rbx,8), %rsi
movq 0x8(%r14,%rbx,8), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0xcbd6
movq 0x20(%r14,%rbx,8), %rax
movq %rax, 0x70(%rsp)
leaq 0x50(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x159f0
movl %eax, %r14d
movq 0x50(%rsp), %rdi
movq %r12, %rbx
cmpq %r12, %rdi
je 0x81c7
callq 0x52b0
movq 0x270(%r15), %rax
movq (%rax,%r13,8), %rdi
movl %r14d, %esi
movl 0xc(%rsp), %edx
movl 0xc0(%rsp), %ecx
callq 0x14524
movq 0x278(%r15), %rax
subq 0x270(%r15), %rax
movl %ebp, %r13d
sarq $0x3, %rax
incl %ebp
cmpq %r13, %rax
movq %rbx, %r12
ja 0x8167
jmp 0x830c
movq 0x370(%r15), %rdx
movslq (%rdx,%rbx,4), %rdx
addq %rcx, %rdx
movq %rdx, 0x140(%r13)
cmpb $0x1, 0x149(%r13)
jne 0x830c
movq 0x278(%r15), %rcx
cmpq 0x270(%r15), %rcx
je 0x830c
movl $0x1, %r12d
leaq 0x38(%rsp), %rbp
xorl %r13d, %r13d
movzbl %al, %eax
movl %eax, 0xc(%rsp)
movzbl %sil, %eax
movl %eax, 0x8(%rsp)
movq %r15, 0x20(%rsp)
movq 0x288(%r15), %r14
leaq (,%r13,4), %r15
addq %r13, %r15
movq %rbp, 0x28(%rsp)
movq (%r14,%r15,8), %rsi
movq 0x8(%r14,%r15,8), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0xcbd6
movq 0x20(%r14,%r15,8), %rax
movq %rax, 0x48(%rsp)
leaq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x159f0
movl %eax, %r14d
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x82c3
callq 0x52b0
movq 0x20(%rsp), %r15
movq 0x270(%r15), %rax
movq (%rax,%r13,8), %rdi
movl %r14d, %esi
movl %ebx, %edx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
callq 0x1466a
movq 0x278(%r15), %rax
subq 0x270(%r15), %rax
movl %r12d, %r13d
sarq $0x3, %rax
incl %r12d
cmpq %r13, %rax
leaq 0x38(%rsp), %rbp
ja 0x8266
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x8337
jmp 0x833c
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x833c
callq 0x52b0
movq %rbx, %rdi
callq 0x55a0