// File: /workspace/github_cpp_makefile_star2_O3/sopanpatra160[P]OOO_Superscalar_Processor_Simulator/cache.cc
// Function: cache::cache(unsigned int, unsigned int, unsigned int, double, unsigned int, unsigned int)
cache::cache(unsigned int bs, unsigned int cs, unsigned int a, double rp, unsigned int wp, unsigned int lev){


	//printf("Initialization done\n");
	this->cs = cs;							//IF CACHE SIZE = 0 , SIMPLY RETURN TO NEXT INSTANTIATION AS THAT LEVEL IS UNDEFINED
	num_r=0;
	num_miss_r=0;
	num_w=0;
	num_miss_w=0;
	num_wb=0;
	num_wb_v=0;
	num_swap=0;
	mr=0;
	hit_time=0;
	mp=0;
	next = NULL;
	vptr = NULL;
	hit=0;
	miss=0;
	if(cs==0)return ;


	num_set = cs/(bs*a);
	num_bo= log2 (bs);
	num_ind= log2 (num_set);
	num_tag= 32-num_bo-num_ind; 
	
	this->bs = bs;
	this->a = a;
	this->rp = rp;
	this->wp = wp;
	this->lev= lev;

	//printf("num_set:%d",num_set);	
	//MEMORY ALLOCATION
	//(1)TAG
	tag_store = new unsigned int *[num_set];
	for (unsigned int i=0; i<num_set; i++){
		tag_store[i] = new unsigned int [a];			
	}
	for (unsigned int i=0; i<num_set; i++){
		for (unsigned int j=0; j<a; j++){
			tag_store[i][j]= 0;
		}
	}
	//(2)VALID
	valid_store = new unsigned int *[num_set];
	for (unsigned int i=0; i<num_set; i++){
		valid_store[i] = new unsigned int [a];			
	}
	for (unsigned int i=0; i<num_set; i++){
		for (unsigned int j=0; j<a; j++){
			valid_store[i][j]= 0;
		}
	}
	//LRU_STORE
	if(rp==2){
		lru_store = new unsigned int *[num_set];
		for (unsigned int i=0; i<num_set; i++){
			lru_store[i] = new unsigned int [a];			
		}
		for (unsigned int i=0; i<num_set; i++){
			for (unsigned int j=0; j<a; j++){
				lru_store[i][j]= a-j-1;
			}
		}
	}

	//LFU_BLOCK_STORE & LFU_SET_STORE
	if (rp==3){
		lfu_block_store = new unsigned int *[num_set];
		for (unsigned int i=0; i<num_set; i++){
			lfu_block_store[i] = new unsigned int [a];			
		}
		for (unsigned int i=0; i<num_set; i++){
			for (unsigned int j=0; j<a; j++){
				lfu_block_store[i][j]= 0;
			}
		}
		lfu_set_store = new unsigned int [num_set];
		for (unsigned int i=0; i<num_set; i++){
				lfu_set_store[i]= 0;
		}
	}
	//DIRTY_STORE
	if(wp==0){
		num_wb=0;
		dirty_store = new unsigned int *[num_set];
		for (unsigned int i=0; i<num_set; i++){
			dirty_store[i] = new unsigned int [a];			
		}
		for (unsigned int i=0; i<num_set; i++){
			for (unsigned int j=0; j<a; j++){
				dirty_store[i][j]= 0;
			}
		}
	}

}

// Assembly:
movdqa %xmm0, %xmm1
movl %edx, 0x14(%rdi)
pxor %xmm0, %xmm0
movdqu %xmm0, (%rdi)
movdqu %xmm0, 0x74(%rdi)
movdqu %xmm0, 0x84(%rdi)
movdqu %xmm0, 0x94(%rdi)
testl %edx, %edx
je 0x17b8
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r15d
movl %r8d, %ebp
movl %ecx, %ebx
movl %esi, %r12d
movq %rdi, %r14
imull %esi, %ecx
movl %edx, %eax
xorl %edx, %edx
divl %ecx
movl %eax, 0x70(%rdi)
movl %esi, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq %xmm1, 0x10(%rsp)
callq 0x1150
cvttsd2si %xmm0, %rax
movl %eax, 0x58(%r14)
movl 0x70(%r14), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
callq 0x1150
cvttsd2si %xmm0, %rax
movl %eax, 0x5c(%r14)
addl 0x58(%r14), %eax
movl $0x20, %ecx
subl %eax, %ecx
movl %ecx, 0x60(%r14)
movl %r12d, 0x10(%r14)
movl %ebx, 0x18(%r14)
cvttsd2si 0x10(%rsp), %rax
movl %eax, 0x1c(%r14)
movl %ebp, 0x1c(%rsp)
movl %ebp, 0x20(%r14)
movl %r15d, 0x24(%r14)
movl 0x70(%r14), %r15d
leaq (,%r15,8), %rdi
callq 0x1030
movq %rax, 0x28(%r14)
movl %ebx, %eax
movq %rax, 0x8(%rsp)
movl $0x0, %ebp
testq %r15, %r15
je 0x14de
movq 0x8(%rsp), %rax
leaq (,%rax,4), %r12
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x1030
movq 0x28(%r14), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
cmpq %r13, %r15
jne 0x147c
testl %r15d, %r15d
je 0x14dc
movq 0x28(%r14), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %rax
leaq (,%rax,4), %r12
xorl %r13d, %r13d
movl %r15d, %ebp
testl %ebx, %ebx
je 0x14d0
movq 0x20(%rsp), %rax
movq (%rax,%r13,8), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x1070
movl 0x70(%r14), %ebp
incq %r13
movl %ebp, %eax
cmpq %rax, %r13
jb 0x14b5
jmp 0x14de
xorl %ebp, %ebp
movl %ebp, %r15d
leaq (,%r15,8), %rdi
callq 0x1030
movq %rax, 0x30(%r14)
testl %ebp, %ebp
movsd 0x10(%rsp), %xmm9
movl $0x0, %r8d
je 0x1581
movq 0x8(%rsp), %rax
leaq (,%rax,4), %r12
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x1030
movq 0x30(%r14), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
cmpq %r13, %r15
jne 0x1513
testl %ebp, %ebp
je 0x1577
movq 0x30(%r14), %r15
movq 0x8(%rsp), %rax
leaq (,%rax,4), %r12
xorl %r13d, %r13d
movl %ebp, %r8d
movsd 0x10(%rsp), %xmm9
testl %ebx, %ebx
je 0x156a
movq (%r15,%r13,8), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x1070
movsd 0x10(%rsp), %xmm9
movl 0x70(%r14), %r8d
incq %r13
movl %r8d, %eax
cmpq %rax, %r13
jb 0x154d
jmp 0x1581
xorl %r8d, %r8d
movsd 0x10(%rsp), %xmm9
ucomisd 0x3a7e(%rip), %xmm9     # 0x5008
jne 0x16ce
jp 0x16ce
movl %r8d, %r15d
leaq (,%r15,8), %rdi
movl %r8d, %ebp
callq 0x1030
movq %rax, 0x40(%r14)
testl %ebp, %ebp
je 0x16c4
movq 0x8(%rsp), %rax
leaq (,%rax,4), %r12
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x1030
movq 0x40(%r14), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
cmpq %r13, %r15
jne 0x15c5
testl %ebp, %ebp
je 0x16c4
movl %ebp, %r8d
movq 0x40(%r14), %rax
movq 0x8(%rsp), %rdx
leaq 0x1(%rdx), %rcx
andq $-0x2, %rcx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leal -0x1(%rbx), %edx
xorl %esi, %esi
movdqa 0x3a0d(%rip), %xmm1     # 0x5020
movdqa 0x3a15(%rip), %xmm2     # 0x5030
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x3a15(%rip), %xmm4     # 0x5040
movsd 0x10(%rsp), %xmm9
testl %ebx, %ebx
je 0x16b3
movq (%rax,%rsi,8), %rdi
movl %edx, %r8d
xorl %r9d, %r9d
movdqa %xmm1, %xmm5
movdqa %xmm5, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %r10d
notl %r10d
testb $0x1, %r10b
je 0x167f
movl %r8d, (%rdi,%r9,4)
pxor %xmm3, %xmm6
pextrw $0x4, %xmm6, %r10d
testb $0x1, %r10b
je 0x169e
movl %r9d, %r10d
xorl $-0x2, %r10d
addl %ebx, %r10d
movl %r10d, 0x4(%rdi,%r9,4)
addq $0x2, %r9
paddq %xmm4, %xmm5
addl $-0x2, %r8d
cmpq %r9, %rcx
jne 0x1644
movl 0x70(%r14), %r8d
incq %rsi
movl %r8d, %edi
cmpq %rdi, %rsi
jb 0x1632
jmp 0x16ce
xorl %r8d, %r8d
movsd 0x10(%rsp), %xmm9
ucomisd 0x3939(%rip), %xmm9     # 0x5010
jne 0x176f
jp 0x176f
movl %r8d, %r13d
leaq (,%r13,8), %rdi
movl %r8d, 0x10(%rsp)
callq 0x1030
movq %rax, 0x48(%r14)
movl $0x0, %ebp
cmpl $0x0, 0x10(%rsp)
je 0x1776
movq 0x8(%rsp), %rax
leaq (,%rax,4), %r12
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x1030
movq 0x48(%r14), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
cmpq %r15, %r13
jne 0x1718
movl 0x10(%rsp), %ebp
testl %ebp, %ebp
je 0x1774
movq 0x48(%r14), %r13
movq 0x8(%rsp), %rax
leaq (,%rax,4), %r12
xorl %r15d, %r15d
testl %ebx, %ebx
je 0x1763
movq (%r13,%r15,8), %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x1070
movl 0x70(%r14), %ebp
incq %r15
movl %ebp, %eax
cmpq %rax, %r15
jb 0x174c
jmp 0x1776
movl %r8d, %r13d
jmp 0x17a3
xorl %ebp, %ebp
movl %ebp, %r12d
shlq $0x2, %r12
movq %r12, %rdi
callq 0x1030
movq %rax, 0x50(%r14)
testl %ebp, %ebp
movl $0x0, %r13d
je 0x17a3
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x1070
movl %ebp, %r13d
cmpl $0x0, 0x1c(%rsp)
je 0x17b9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, 0x74(%r14)
movl %r13d, %r15d
leaq (,%r15,8), %rdi
callq 0x1030
movq %rax, 0x38(%r14)
testl %r13d, %r13d
je 0x17aa
movl %r13d, %ebp
movq 0x8(%rsp), %rax
leaq (,%rax,4), %r12
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x1030
movq 0x38(%r14), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
cmpq %r13, %r15
jne 0x17ed
testl %ebp, %ebp
je 0x17aa
movl %ebp, %ecx
movq 0x38(%r14), %r12
shlq $0x2, 0x8(%rsp)
xorl %r15d, %r15d
testl %ebx, %ebx
je 0x1830
movq (%r12,%r15,8), %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x1070
movl 0x70(%r14), %ecx
incq %r15
movl %ecx, %eax
cmpq %rax, %r15
jb 0x1818
jmp 0x17aa
nop