// File: /workspace/github_cpp_makefile_star2_O1/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, %r15d
movl %esi, %r12d
movq %rdi, %rbx
callq 0x1a158
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x19ff4(%rip), %rsi     # 0x358a5
leaq 0x19ff7(%rip), %rdx     # 0x358af
leaq 0x40(%rsp), %r13
movq %r13, %rdi
callq 0xccac
leaq 0x2a684(%rip), %rbp     # 0x45f50
leaq 0x8(%rbp), %rdi
movq %r13, %rsi
callq 0x182c0
movq %rax, %r13
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x1b8ef
callq 0x52a0
addq $0x10, %rbp
cmpq %rbp, %r13
je 0x1b90f
leaq 0x1a1d8(%rip), %rdi     # 0x35ad7
movl %r12d, %esi
movl %r15d, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x5050
movslq %r12d, %rax
leaq 0x20(%rbx), %rcx
shlq $0x3, %rax
movl 0x3c(%rsp), %ebp
testb %bpl, %bpl
movl %r15d, %edx
cmovnel %r14d, %edx
leaq 0x8(%rbx), %rsi
movq %rcx, %rdi
cmovneq %rsi, %rdi
movq (%rdi), %rdi
leaq (%rax,%rax,2), %rax
movslq %edx, %rdx
movq (%rdi,%rax), %rdi
movq (%rdi,%rdx,8), %r12
movl %r14d, %edx
cmovnel %r15d, %edx
cmovneq %rcx, %rsi
movq (%rsi), %rcx
movslq %edx, %rdx
movq (%rcx,%rax), %rax
movq (%rax,%rdx,8), %r13
cmpb $0x0, 0x91(%rbx)
jne 0x1b976
movq 0x170(%rbx), %rax
movzbl %bpl, %ecx
incq (%rax,%rcx,8)
cmpb $0x0, (%r12)
je 0x1bacd
cmpb $0x1, (%r13)
jne 0x1b9ff
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 0x1b344
incq 0x100(%rbx)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1b442
movq %r13, %rdi
movq %r12, %rsi
callq 0x1d300
movb $0x1, %al
movb %al, 0x14c(%r13)
leaq 0x2a4f3(%rip), %rcx     # 0x45f18
movl (%rcx), %ecx
movl %ecx, 0x38(%r13)
movb %al, (%r13)
movq 0x48(%rbx), %rdx
leaq 0x40(%rbx), %rax
movq %rax, %rcx
testq %rdx, %rdx
je 0x1ba5e
movq 0x8(%r13), %rsi
movq %rax, %rcx
xorl %edi, %edi
cmpq %rsi, 0x20(%rdx)
setb %dil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rdi,8), %rdx
testq %rdx, %rdx
jne 0x1ba46
movq %rax, %rdx
cmpq %rax, %rcx
je 0x1ba75
movq 0x8(%r13), %rdx
cmpq 0x20(%rcx), %rdx
cmovbq %rax, %rcx
movq %rcx, %rdx
cmpq %rax, %rdx
je 0x1ba8c
movl %ebp, %eax
xorb $0x1, %al
movb %al, 0x2c(%rdx)
testb %bpl, %bpl
cmovnel %r15d, %r14d
movl %r14d, 0x28(%rdx)
movb $0x0, (%r12)
movq 0x128(%rbx), %rax
testb %bpl, %bpl
je 0x1baad
incq (%rax)
movq 0xd8(%rbx), %rax
addq $0x8, %rax
jmp 0x1bab8
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 0x1a03f(%rip), %rdi     # 0x35b13
leaq 0x19cae(%rip), %rsi     # 0x35789
leaq 0x1a045(%rip), %rcx     # 0x35b27
movl $0x263, %edx            # imm = 0x263
callq 0x51d0
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x1bb03
callq 0x52a0
movq %rbx, %rdi
callq 0x55a0
nop