// File: gvaumour[P]cache-simulator/src/Hierarchy.cc
// Function: Hierarchy::prefetchAddress(Access)
void 
Hierarchy::prefetchAddress(Access element)
{
	uint64_t addr = element.m_address;
	uint64_t block_addr = bitRemove(addr , 0 , m_start_index+1);
	

	DPRINTF(DebugHierarchy, "HIERARCHY::Prefetching of block %#lx\n", block_addr);

		
	DirectoryEntry* entry = m_directory->getEntry(block_addr);
	if(entry == NULL){
		entry = m_directory->addEntry(block_addr, element.isInstFetch());
	}
	assert(entry != NULL);

	DirectoryState dir_state = m_directory->getEntry(block_addr)->coherence_state;

	entry->print();
	
	if(dir_state == NOT_PRESENT)
	{
		m_LLC->handleAccess(element);
		m_directory->updateEntry(block_addr);
		m_directory->setCoherenceState(block_addr, CLEAN_LLC);	
		stats_issuedPrefetchs++;
	}
	else
	{
		DPRINTF(DebugHierarchy, "HIERARCHY::Prefetcher Block %#lx already present\n", block_addr);
	}
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
leaq 0x150(%rsp), %rcx
movq %rcx, 0x70(%rsp)
movq %rdi, 0x140(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0x78(%rsp)
movq (%rcx), %rcx
movq %rcx, 0x138(%rsp)
movq 0x138(%rsp), %rdi
movl 0x60(%rax), %edx
incl %edx
xorl %esi, %esi
callq 0x655b0
movq %rax, 0x130(%rsp)
leaq 0x10f(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x56a0
movq 0x80(%rsp), %rdx
leaq 0x3fec4(%rip), %rsi     # 0x72358
leaq 0x110(%rsp), %rdi
callq 0x5530
jmp 0x324a3
leaq 0x61b46(%rip), %rdi     # 0x93ff0
addq $0x8, %rdi
leaq 0x110(%rsp), %rsi
callq 0x33a00
movq %rax, 0x68(%rsp)
jmp 0x324c2
leaq 0x110(%rsp), %rdi
callq 0x5768
leaq 0x10f(%rsp), %rdi
callq 0x53e0
movq 0x68(%rsp), %rax
cmpq $0x0, %rax
je 0x32548
movq 0x130(%rsp), %rsi
leaq 0x400b9(%rip), %rdi     # 0x725af
movb $0x0, %al
callq 0x5060
jmp 0x32548
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x32536
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x5768
leaq 0x10f(%rsp), %rdi
callq 0x53e0
jmp 0x327a1
movq 0x78(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x130(%rsp), %rsi
callq 0x27b00
movq %rax, 0xf0(%rsp)
cmpq $0x0, 0xf0(%rsp)
jne 0x325b3
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0x60(%rsp)
callq 0x20960
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
movzbl %al, %edx
andl $0x1, %edx
callq 0x279e0
movq %rax, 0xf0(%rsp)
cmpq $0x0, 0xf0(%rsp)
je 0x325c0
jmp 0x325df
leaq 0x41597(%rip), %rdi     # 0x73b5e
leaq 0x3ff00(%rip), %rsi     # 0x724ce
movl $0xfa, %edx
leaq 0x3fffb(%rip), %rcx     # 0x725d5
callq 0x5260
movq 0x78(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x130(%rsp), %rsi
callq 0x27b00
movl 0x38(%rax), %eax
movl %eax, 0xec(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x27720
cmpl $0x8, 0xec(%rsp)
jne 0x326c8
movq 0x78(%rsp), %rax
movq 0x70(%rsp), %rsi
movq 0x18(%rax), %rax
movq %rax, 0x50(%rsp)
leaq 0xb0(%rsp), %rdi
movl $0x38, %edx
callq 0x52f0
movq 0x50(%rsp), %rdi
movq 0xe0(%rsp), %rcx
movq %rsp, %rax
movq %rcx, 0x30(%rax)
movups 0xb0(%rsp), %xmm0
movups 0xc0(%rsp), %xmm1
movups 0xd0(%rsp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x46b30
movq 0x78(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x130(%rsp), %rsi
callq 0x28300
movq 0x78(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x130(%rsp), %rsi
movl $0x6, %edx
callq 0x27f50
movq 0x78(%rsp), %rax
movq 0x90(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x90(%rax)
jmp 0x32799
leaq 0x8f(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x56a0
movq 0x48(%rsp), %rdx
leaq 0x3fc72(%rip), %rsi     # 0x72358
leaq 0x90(%rsp), %rdi
callq 0x5530
jmp 0x326f5
leaq 0x618f4(%rip), %rdi     # 0x93ff0
addq $0x8, %rdi
leaq 0x90(%rsp), %rsi
callq 0x33a00
movq %rax, 0x40(%rsp)
jmp 0x32714
leaq 0x90(%rsp), %rdi
callq 0x5768
leaq 0x8f(%rsp), %rdi
callq 0x53e0
movq 0x40(%rsp), %rax
cmpq $0x0, %rax
je 0x32797
movq 0x130(%rsp), %rsi
leaq 0x3feb5(%rip), %rdi     # 0x725fd
movb $0x0, %al
callq 0x5060
jmp 0x32797
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x32788
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x5768
leaq 0x8f(%rsp), %rdi
callq 0x53e0
jmp 0x327a1
jmp 0x32799
addq $0x148, %rsp            # imm = 0x148
retq
movq 0x100(%rsp), %rdi
callq 0x5690
nop