// File: gvaumour[P]cache-simulator/src/HybridCache.cc
// Function: HybridCache::allocate(unsigned long, int, int, bool, unsigned long, bool)
void 
HybridCache::allocate(uint64_t address , int id_set , int id_assoc, bool inNVM, uint64_t pc, bool isPrefetch)
{

	uint64_t block_addr = bitRemove(address , 0 , m_start_index+1);
	
	if(inNVM){
	 	assert(!m_tableNVM[id_set][id_assoc]->isValid);

		m_tableNVM[id_set][id_assoc]->isValid = true;	
		m_tableNVM[id_set][id_assoc]->address = block_addr;
		m_tableNVM[id_set][id_assoc]->policyInfo = 0;
		m_tableNVM[id_set][id_assoc]->m_pc = pc;
		m_tableNVM[id_set][id_assoc]->isPrefetch = isPrefetch;
	}
	else
	{
	 	assert(!m_tableSRAM[id_set][id_assoc]->isValid);

		m_tableSRAM[id_set][id_assoc]->isValid = true;	
		m_tableSRAM[id_set][id_assoc]->address = block_addr;
		m_tableSRAM[id_set][id_assoc]->policyInfo = 0;		
		m_tableSRAM[id_set][id_assoc]->m_pc = pc;		
		m_tableSRAM[id_set][id_assoc]->isPrefetch = isPrefetch;
	}
	
	if(!m_isWarmup)
		stats_nbFetchedLines++;	
		
	HybridLocation loc(id_assoc, inNVM);
	m_tag_index.insert(pair<uint64_t , HybridLocation>(block_addr , loc));
}

// Assembly:
subq $0xb8, %rsp
movl %r8d, %eax
movl %ecx, 0x40(%rsp)
movl %edx, %ecx
movl 0x40(%rsp), %edx
movl %ecx, 0x44(%rsp)
movq %rsi, %rcx
movl 0x44(%rsp), %esi
movq %rcx, 0x48(%rsp)
movq %rdi, %r8
movq 0x48(%rsp), %rdi
movb %al, %cl
movb 0xc0(%rsp), %al
movq %r8, 0xb0(%rsp)
movq %rdi, 0xa8(%rsp)
movl %esi, 0xa4(%rsp)
movl %edx, 0xa0(%rsp)
andb $0x1, %cl
movb %cl, 0x9f(%rsp)
movq %r9, 0x90(%rsp)
andb $0x1, %al
movb %al, 0x8f(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0xa8(%rsp), %rdi
movl 0x94(%rax), %edx
addl $0x1, %edx
xorl %esi, %esi
callq 0x655b0
movq %rax, 0x80(%rsp)
testb $0x1, 0x9f(%rsp)
je 0x3a5fd
movq 0x50(%rsp), %rdi
addq $0x8, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movb (%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3a4bc
jmp 0x3a4be
jmp 0x3a4dd
leaq 0x38566(%rip), %rdi     # 0x72a2b
leaq 0x38286(%rip), %rsi     # 0x72752
movl $0x23d, %edx            # imm = 0x23D
leaq 0x3857a(%rip), %rcx     # 0x72a52
callq 0x5260
movq 0x50(%rsp), %rdi
addq $0x8, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movq 0x50(%rsp), %rdi
movq (%rax), %rax
movb $0x1, (%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x28(%rsp)
addq $0x8, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movq 0x28(%rsp), %rcx
movq 0x50(%rsp), %rdi
movq (%rax), %rax
movq %rcx, 0x8(%rax)
addq $0x8, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movq 0x50(%rsp), %rdi
movq (%rax), %rax
movl $0x0, 0x38(%rax)
movq 0x90(%rsp), %rax
movq %rax, 0x30(%rsp)
addq $0x8, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movq 0x30(%rsp), %rcx
movq 0x50(%rsp), %rdi
movq (%rax), %rax
movq %rcx, 0x10(%rax)
movb 0x8f(%rsp), %al
movb %al, 0x3f(%rsp)
addq $0x8, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movb 0x3f(%rsp), %cl
movq (%rax), %rax
andb $0x1, %cl
movb %cl, 0x14b(%rax)
jmp 0x3a76c
movq 0x50(%rsp), %rdi
addq $0x20, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movq (%rax), %rax
movb (%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3a630
jmp 0x3a632
jmp 0x3a651
leaq 0x3845e(%rip), %rdi     # 0x72a97
leaq 0x38112(%rip), %rsi     # 0x72752
movl $0x247, %edx            # imm = 0x247
leaq 0x38406(%rip), %rcx     # 0x72a52
callq 0x5260
movq 0x50(%rsp), %rdi
addq $0x20, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movq 0x50(%rsp), %rdi
movq (%rax), %rax
movb $0x1, (%rax)
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
addq $0x20, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movq 0x10(%rsp), %rcx
movq 0x50(%rsp), %rdi
movq (%rax), %rax
movq %rcx, 0x8(%rax)
addq $0x20, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movq 0x50(%rsp), %rdi
movq (%rax), %rax
movl $0x0, 0x38(%rax)
movq 0x90(%rsp), %rax
movq %rax, 0x18(%rsp)
addq $0x20, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movq 0x18(%rsp), %rcx
movq 0x50(%rsp), %rdi
movq (%rax), %rax
movq %rcx, 0x10(%rax)
movb 0x8f(%rsp), %al
movb %al, 0x27(%rsp)
addq $0x20, %rdi
movslq 0xa4(%rsp), %rsi
callq 0xf9a0
movq %rax, %rdi
movslq 0xa0(%rsp), %rsi
callq 0xf9c0
movb 0x27(%rsp), %cl
movq (%rax), %rax
andb $0x1, %cl
movb %cl, 0x14b(%rax)
movq 0x50(%rsp), %rax
testb $0x1, 0x91(%rax)
jne 0x3a791
movq 0x50(%rsp), %rax
movq 0x1a0(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x1a0(%rax)
movl 0xa0(%rsp), %esi
movb 0x9f(%rsp), %al
leaq 0x78(%rsp), %rdi
andb $0x1, %al
movzbl %al, %edx
callq 0x3de60
movq 0x50(%rsp), %rax
addq $0x38, %rax
movq %rax, 0x8(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0x3dee0
movq 0x8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3de90
movq %rax, 0x58(%rsp)
movb %dl, 0x60(%rsp)
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)