// File: /workspace/github_cpp_makefile_star2_O2/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:
movl %edx, 0x14(%rdi)
xorps %xmm1, %xmm1
movups %xmm1, (%rdi)
movups %xmm1, 0x74(%rdi)
movups %xmm1, 0x84(%rdi)
movups %xmm1, 0x94(%rdi)
testl %edx, %edx
je 0x15fb
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %r13d
movl %r8d, %r15d
movl %esi, %r12d
movq %rdi, %rbx
movl %ecx, %esi
imull %r12d, %esi
movl %ecx, %r14d
xorl %ebp, %ebp
movl %edx, %eax
xorl %edx, %edx
divl %esi
movl %eax, 0x70(%rdi)
movl %r12d, %edi
movsd %xmm0, 0x8(%rsp)
callq 0x25cb
cvttsd2si %xmm0, %rax
movl %eax, 0x58(%rbx)
movl 0x70(%rbx), %edi
callq 0x25cb
cvttsd2si %xmm0, %rax
movl %eax, 0x5c(%rbx)
addl 0x58(%rbx), %eax
pushq $0x20
popq %rcx
subl %eax, %ecx
movl %ecx, 0x60(%rbx)
movl %r12d, 0x10(%rbx)
movl %r14d, 0x18(%rbx)
cvttsd2si 0x8(%rsp), %rax
movl %eax, 0x1c(%rbx)
movl %r15d, 0x14(%rsp)
movl %r15d, 0x20(%rbx)
movl %r13d, 0x24(%rbx)
movl 0x70(%rbx), %r13d
leaq (,%r13,8), %rdi
callq 0x1030
movq %rax, 0x28(%rbx)
movl %r14d, 0x10(%rsp)
movl %r14d, %r12d
leaq (,%r12,4), %r14
cmpq %rbp, %r13
je 0x145c
movq %r14, %rdi
callq 0x1030
movq 0x28(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
incq %rbp
jmp 0x1442
xorl %eax, %eax
movl %r13d, %ebp
cmpq %rbp, %rax
jae 0x1487
movq 0x28(%rbx), %rcx
xorl %edx, %edx
cmpq %rdx, %r12
je 0x147e
movq (%rcx,%rax,8), %rsi
andl $0x0, (%rsi,%rdx,4)
incq %rdx
jmp 0x146c
incq %rax
movl 0x70(%rbx), %r13d
jmp 0x145e
leaq (,%rbp,8), %rdi
callq 0x1030
movq %rax, 0x30(%rbx)
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0x14b5
movq %r14, %rdi
callq 0x1030
movq 0x30(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0x149b
xorl %eax, %eax
movsd 0x8(%rsp), %xmm0
movl %r13d, %ebp
cmpq %rbp, %rax
jae 0x14e6
movq 0x30(%rbx), %rcx
xorl %edx, %edx
cmpq %rdx, %r12
je 0x14dd
movq (%rcx,%rax,8), %rsi
andl $0x0, (%rsi,%rdx,4)
incq %rdx
jmp 0x14cb
incq %rax
movl 0x70(%rbx), %r13d
jmp 0x14bd
ucomisd 0x2b1a(%rip), %xmm0     # 0x4008
jne 0x155e
jp 0x155e
leaq (,%rbp,8), %rdi
callq 0x1030
movq %rax, 0x40(%rbx)
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0x1520
movq %r14, %rdi
callq 0x1030
movq 0x40(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0x1506
movl 0x10(%rsp), %r8d
decl %r8d
xorl %eax, %eax
movsd 0x8(%rsp), %xmm0
movl %r13d, %ecx
cmpq %rcx, %rax
jae 0x155e
movq 0x40(%rbx), %rcx
movl %r8d, %edx
xorl %esi, %esi
cmpq %rsi, %r14
je 0x1555
movq (%rcx,%rax,8), %rdi
movl %edx, (%rdi,%rsi)
addq $0x4, %rsi
decl %edx
jmp 0x1541
incq %rax
movl 0x70(%rbx), %r13d
jmp 0x1530
ucomisd 0x2aaa(%rip), %xmm0     # 0x4010
jne 0x15e6
jp 0x15e6
movl %r13d, %r15d
leaq (,%r15,8), %rdi
callq 0x1030
movq %rax, 0x48(%rbx)
xorl %ebp, %ebp
cmpq %rbp, %r15
je 0x159a
movq %r14, %rdi
callq 0x1030
movq 0x48(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
incq %rbp
jmp 0x1580
xorl %eax, %eax
movl %r13d, %r15d
cmpq %r15, %rax
jae 0x15c5
movq 0x48(%rbx), %rcx
xorl %edx, %edx
cmpq %rdx, %r12
je 0x15bc
movq (%rcx,%rax,8), %rsi
andl $0x0, (%rsi,%rdx,4)
incq %rdx
jmp 0x15aa
incq %rax
movl 0x70(%rbx), %r13d
jmp 0x159c
leaq (,%r15,4), %rdi
callq 0x1030
movq %rax, 0x50(%rbx)
xorl %ecx, %ecx
cmpq %rcx, %r15
je 0x15e6
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x15d8
cmpl $0x0, 0x14(%rsp)
je 0x15fc
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andl $0x0, 0x74(%rbx)
movl %r13d, %r15d
leaq (,%r15,8), %rdi
callq 0x1030
movq %rax, 0x38(%rbx)
xorl %ebp, %ebp
cmpq %rbp, %r15
je 0x1630
movq %r14, %rdi
callq 0x1030
movq 0x38(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
incq %rbp
jmp 0x1616
xorl %eax, %eax
movl %r13d, %ecx
cmpq %rcx, %rax
jae 0x15ed
movq 0x38(%rbx), %rcx
xorl %edx, %edx
cmpq %rdx, %r12
je 0x1652
movq (%rcx,%rax,8), %rsi
andl $0x0, (%rsi,%rdx,4)
incq %rdx
jmp 0x1640
incq %rax
movl 0x70(%rbx), %r13d
jmp 0x1632
nop