// File: /workspace/github_cpp_makefile_star2_O3/gvaumour[P]cache-simulator/src/HybridCache.cc
// Function: HybridCache::triggerMigration(int, int, int, bool)
void HybridCache::triggerMigration(int set, int id_assocSRAM, int id_assocNVM , bool fromNVM)
{
	entete_debug();
	DPRINTF(DebugCache , "TriggerMigration set %d , id_assocSRAM %d , id_assocNVM %d\n" , set , id_assocSRAM , id_assocNVM);
	
	CacheEntry* from_entry = fromNVM ? m_tableNVM[set][id_assocNVM] : m_tableSRAM[set][id_assocSRAM];
	CacheEntry* destination_entry = fromNVM ? m_tableSRAM[set][id_assocSRAM] : m_tableNVM[set][id_assocNVM];
	
	if(!m_isWarmup)
		stats_migration[fromNVM]++;
	
	assert(from_entry->isValid);
	
	if(destination_entry->isValid)
	{
		//WB this cache line to the lower levels 			
		Access wb_request;
		wb_request.m_address = destination_entry->address;
		wb_request.m_pc = destination_entry->m_pc;
		wb_request.m_size = 4;
		if(destination_entry->isDirty)
			wb_request.m_type = MemCmd::DIRTY_WRITEBACK;
		else
			wb_request.m_type = MemCmd::CLEAN_WRITEBACK;
		signalWB(wb_request, false);
		stats_evict++;	
	}
	
	deallocate(destination_entry);
	destination_entry->copyCL(from_entry);
	destination_entry->justMigrate = true;
	destination_entry->policyInfo = cpt_time;
	destination_entry->isValid = true;
	
	map<uint64_t,HybridLocation>::iterator p1 = m_tag_index.find(destination_entry->address);
	if(p1 != m_tag_index.end())
	{
 		p1->second.m_inNVM = !fromNVM;
		p1->second.m_way = fromNVM ? id_assocSRAM : id_assocNVM;
	}
	
	from_entry->isValid = false;
	
	
	if(fromNVM)
	{
		//One read NVM , one write SRAM 
		stats_hitsNVM[0]++;
		stats_hitsSRAM[1]++;
	}
	else
	{
		//One read SRAM , one write NVM  
		stats_hitsNVM[1]++;
		stats_hitsSRAM[0]++;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %r8d, 0x3c(%rsp)
movl %ecx, %r14d
movl %edx, %ebp
movl %esi, %r12d
movq %rdi, %rbx
callq 0x19e2a
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1a255(%rip), %rsi     # 0x3589d
leaq 0x1a258(%rip), %rdx     # 0x358a7
leaq 0x40(%rsp), %r13
movq %r13, %rdi
callq 0xcc6c
leaq 0x2a8ed(%rip), %r15     # 0x45f50
leaq 0x8(%r15), %rdi
movq %r13, %rsi
callq 0x1800c
movq %rax, %r13
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x1b686
callq 0x52b0
addq $0x10, %r15
cmpq %r15, %r13
movl 0x3c(%rsp), %r13d
movl %r14d, %r15d
je 0x1b6ad
leaq 0x1a431(%rip), %rdi     # 0x35acf
movl %r12d, %esi
movl %ebp, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x5050
movslq %r12d, %rax
leaq 0x20(%rbx), %rcx
shlq $0x3, %rax
movl %r13d, %r14d
testb %r14b, %r14b
movl %ebp, %edx
cmovnel %r15d, %edx
leaq 0x8(%rbx), %rsi
movl %r15d, %edi
cmovnel %ebp, %edi
movq %rcx, %r8
cmovneq %rsi, %r8
movq (%r8), %r8
leaq (%rax,%rax,2), %rax
movslq %edx, %rdx
cmovneq %rcx, %rsi
movq (%r8,%rax), %rcx
movq (%rsi), %rsi
movslq %edi, %rdi
movq (%rsi,%rax), %rax
movq (%rcx,%rdx,8), %r12
movq (%rax,%rdi,8), %r13
cmpb $0x0, 0x91(%rbx)
jne 0x1b711
movq 0x170(%rbx), %rax
movzbl %r14b, %ecx
incq (%rax,%rcx,8)
cmpb $0x0, (%r12)
je 0x1b856
cmpb $0x1, (%r13)
jne 0x1b79a
movq 0x8(%r13), %rax
movq 0x10(%r13), %rcx
movzbl 0x1(%r13), %edx
addl $0x5, %edx
movq %rax, 0x60(%rsp)
movl $0x4, 0x68(%rsp)
movq %rcx, 0x70(%rsp)
movl %edx, 0x7c(%rsp)
movl $0x0, 0x80(%rsp)
movb $0x0, 0x88(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x30(%rsp)
movups 0x60(%rsp), %xmm0
movups 0x70(%rsp), %xmm1
movups 0x80(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1b0ec
incq 0x100(%rbx)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1b1ea
movq %r13, %rdi
movq %r12, %rsi
callq 0x1d1c2
movb $0x1, %al
movb %al, 0x14c(%r13)
leaq 0x2a758(%rip), %rcx     # 0x45f18
movl (%rcx), %ecx
movl %ecx, 0x38(%r13)
movb %al, (%r13)
movq 0x48(%rbx), %rcx
testq %rcx, %rcx
je 0x1b815
leaq 0x40(%rbx), %rsi
movq 0x8(%r13), %rdx
movq %rsi, %rax
xorl %edi, %edi
cmpq %rdx, 0x20(%rcx)
setb %dil
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rdi,8), %rcx
testq %rcx, %rcx
jne 0x1b7de
cmpq %rsi, %rax
je 0x1b815
cmpq 0x20(%rax), %rdx
jb 0x1b815
movl %r14d, %ecx
xorb $0x1, %cl
movb %cl, 0x2c(%rax)
testb %r14b, %r14b
cmovnel %ebp, %r15d
movl %r15d, 0x28(%rax)
movb $0x0, (%r12)
movq 0x128(%rbx), %rax
testb %r14b, %r14b
je 0x1b836
incq (%rax)
movq 0xd8(%rbx), %rax
addq $0x8, %rax
jmp 0x1b841
incq 0x8(%rax)
movq 0xd8(%rbx), %rax
incq (%rax)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a2ae(%rip), %rdi     # 0x35b0b
leaq 0x19f1d(%rip), %rsi     # 0x35781
leaq 0x1a2b4(%rip), %rcx     # 0x35b1f
movl $0x263, %edx            # imm = 0x263
callq 0x51d0
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x1b88c
callq 0x52b0
movq %rbx, %rdi
callq 0x55a0