// File: sopanpatra160[P]OOO_Superscalar_Processor_Simulator/cache.cc
// Function: cache::swap(unsigned int, unsigned int)
unsigned int cache::swap(unsigned int found_loc,unsigned int writeorread){
	//LRU policy
	if(rp==2){
		ev_blk= lru_block2evict(ind);
	}
	//LFU policy
	else if(rp==3){
		ev_blk= lfu_block2evict(ind);
	}
	
	unsigned int temp_tag = tag_store[ind][ev_blk];
	unsigned int temp_dirty = dirty_store[ind][ev_blk];
	unsigned int reconstr_addr_to_vc = ev_blk_addr(ind,temp_tag);	
	unsigned int reconstr_tag_to_vc = vptr->calc_tag(reconstr_addr_to_vc);

	tag_store[ind][ev_blk] = tag;
	if(writeorread)
		dirty_store[ind][ev_blk] = 1; 
	else
		dirty_store[ind][ev_blk] = vptr->dirty_store[0][found_loc];
	vptr->tag_store[0][found_loc] = reconstr_tag_to_vc;
	vptr->dirty_store[0][found_loc] = temp_dirty;
	//Update Victim Cache counters
	if(vptr->rp==2)
		vptr->lru_update(0,found_loc);
	//Update L1 Cache counters
	if(rp==2)
		lru_update(ind,ev_blk);
	else if(rp==3){
		lfu_update_set(ind,ev_blk);
		lfu_update_block(ind,ev_blk,0);
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0x2, 0x1c(%rax)
jne 0x2327
movq -0x28(%rbp), %rdi
movl 0x68(%rdi), %esi
callq 0x2490
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x6c(%rax)
jmp 0x2348
movq -0x28(%rbp), %rax
cmpl $0x3, 0x1c(%rax)
jne 0x2346
movq -0x28(%rbp), %rdi
movl 0x68(%rdi), %esi
callq 0x2500
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x6c(%rax)
jmp 0x2348
movq -0x28(%rbp), %rdi
movq 0x28(%rdi), %rax
movl 0x68(%rdi), %ecx
movq (%rax,%rcx,8), %rax
movl 0x6c(%rdi), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x14(%rbp)
movq 0x38(%rdi), %rax
movl 0x68(%rdi), %ecx
movq (%rax,%rcx,8), %rax
movl 0x6c(%rdi), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x18(%rbp)
movl 0x68(%rdi), %esi
movl -0x14(%rbp), %edx
callq 0x2570
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, -0x1c(%rbp)
movq 0x8(%rax), %rdi
movl -0x1c(%rbp), %esi
callq 0x22c0
movq -0x28(%rbp), %rcx
movl %eax, -0x20(%rbp)
movl 0x64(%rcx), %edx
movq 0x28(%rcx), %rax
movl 0x68(%rcx), %esi
movq (%rax,%rsi,8), %rax
movl 0x6c(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
cmpl $0x0, -0x10(%rbp)
je 0x23d0
movq -0x28(%rbp), %rcx
movq 0x38(%rcx), %rax
movl 0x68(%rcx), %edx
movq (%rax,%rdx,8), %rax
movl 0x6c(%rcx), %ecx
movl $0x1, (%rax,%rcx,4)
jmp 0x23f6
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movl -0xc(%rbp), %edx
movl (%rax,%rdx,4), %edx
movq 0x38(%rcx), %rax
movl 0x68(%rcx), %esi
movq (%rax,%rsi,8), %rax
movl 0x6c(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl -0x20(%rbp), %esi
movq 0x8(%rax), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx), %rcx
movl -0xc(%rbp), %edx
movl %esi, (%rcx,%rdx,4)
movl -0x18(%rbp), %esi
movq 0x8(%rax), %rcx
movq 0x38(%rcx), %rcx
movq (%rcx), %rcx
movl -0xc(%rbp), %edx
movl %esi, (%rcx,%rdx,4)
movq 0x8(%rax), %rax
cmpl $0x2, 0x1c(%rax)
jne 0x243e
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0xc(%rbp), %edx
xorl %esi, %esi
callq 0x21b0
movq -0x28(%rbp), %rax
cmpl $0x2, 0x1c(%rax)
jne 0x2459
movq -0x28(%rbp), %rdi
movl 0x68(%rdi), %esi
movl 0x6c(%rdi), %edx
callq 0x21b0
jmp 0x2485
movq -0x28(%rbp), %rax
cmpl $0x3, 0x1c(%rax)
jne 0x2483
movq -0x28(%rbp), %rdi
movl 0x68(%rdi), %esi
movl 0x6c(%rdi), %edx
callq 0x2fe0
movq -0x28(%rbp), %rdi
movl 0x68(%rdi), %esi
movl 0x6c(%rdi), %edx
xorl %ecx, %ecx
callq 0x2250
jmp 0x2485
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)