// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
movl %ecx, %r14d
movl %edx, %r15d
movl %esi, %r12d
movq %rdi, %rbx
callq 0x1529c
leaq 0x14463(%rip), %rsi     # 0x2a84d
leaq 0x78(%rsp), %r13
leaq 0x3f(%rsp), %rdx
movq %r13, %rdi
callq 0x5140
leaq 0x27b4d(%rip), %rdi     # 0x3df50
addq $0x8, %rdi
movq %r13, %rsi
callq 0x138f8
movq %rax, %r13
leaq 0x78(%rsp), %rdi
callq 0x5618
testq %r13, %r13
je 0x16438
leaq 0x14657(%rip), %rdi     # 0x2aa7f
movl %r12d, %esi
movl %r15d, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x5040
movslq %r12d, %rax
imulq $0x18, %rax, %rax
testb %bpl, %bpl
movl %r15d, %ecx
cmovnel %r14d, %ecx
leaq 0x20(%rbx), %rdx
movl %r14d, %esi
cmovnel %r15d, %esi
leaq 0x8(%rbx), %rdi
movq %rdx, %r8
cmovneq %rdi, %r8
movq (%r8), %r8
movslq %ecx, %rcx
cmovneq %rdx, %rdi
movq (%r8,%rax), %rdx
movq (%rdi), %rdi
movslq %esi, %rsi
movq (%rdi,%rax), %rax
movq (%rdx,%rcx,8), %r12
movq (%rax,%rsi,8), %r13
cmpb $0x0, 0x91(%rbx)
jne 0x16497
movq 0x170(%rbx), %rax
movzbl %bpl, %ecx
incq (%rax,%rcx,8)
cmpb $0x0, (%r12)
je 0x165ae
cmpb $0x1, (%r13)
jne 0x16511
movq 0x8(%r13), %rax
movq 0x10(%r13), %rcx
movzbl 0x1(%r13), %edx
addl $0x5, %edx
movq %rax, 0x40(%rsp)
movl $0x4, 0x48(%rsp)
movq %rcx, 0x50(%rsp)
movl %edx, 0x5c(%rsp)
andl $0x0, 0x60(%rsp)
movb $0x0, 0x68(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x30(%rsp)
movups 0x40(%rsp), %xmm0
movups 0x50(%rsp), %xmm1
movups 0x60(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x15fb2
incq 0x100(%rbx)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x16096
movq %r13, %rdi
movq %r12, %rsi
callq 0x17834
movb $0x1, %al
movb %al, 0x14c(%r13)
leaq 0x279e1(%rip), %rcx     # 0x3df18
movl (%rcx), %ecx
movl %ecx, 0x38(%r13)
movb %al, (%r13)
leaq 0x38(%rbx), %rdi
addq $0x8, %r13
movq %r13, %rsi
callq 0x1817e
leaq 0x40(%rbx), %rcx
cmpq %rcx, %rax
je 0x1656d
movl %ebp, %ecx
xorb $0x1, %cl
movb %cl, 0x2c(%rax)
testb %bpl, %bpl
cmovnel %r15d, %r14d
movl %r14d, 0x28(%rax)
movb $0x0, (%r12)
movq 0x128(%rbx), %rax
testb %bpl, %bpl
je 0x1658e
incq (%rax)
movq 0xd8(%rbx), %rax
addq $0x8, %rax
jmp 0x16599
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 0x14506(%rip), %rdi     # 0x2aabb
leaq 0x14175(%rip), %rsi     # 0x2a731
leaq 0x1450c(%rip), %rcx     # 0x2aacf
movl $0x263, %edx            # imm = 0x263
callq 0x51e0
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x5618
movq %rbx, %rdi
callq 0x5570