// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]MQSim/src/ssd/Address_Mapping_Unit_Page_Level.cpp
// Function: SSD_Components::AddressMappingDomain::AddressMappingDomain(unsigned int, unsigned int, unsigned int, SSD_Components::Cached_Mapping_Table*, SSD_Components::Flash_Plane_Allocation_Scheme_Type, unsigned int*, unsigned int, unsigned int*, unsigned int, unsigned int*, unsigned int, unsigned int*, unsigned int, unsigned long, unsigned long, unsigned int)
AddressMappingDomain::AddressMappingDomain(unsigned int cmt_capacity, unsigned int cmt_entry_size, unsigned int no_of_translation_entries_per_page,
		Cached_Mapping_Table* CMT,
		Flash_Plane_Allocation_Scheme_Type PlaneAllocationScheme,
		flash_channel_ID_type* channel_ids, unsigned int channel_no, flash_chip_ID_type* chip_ids, unsigned int chip_no,
		flash_die_ID_type* die_ids, unsigned int die_no, flash_plane_ID_type* plane_ids, unsigned int plane_no,
		PPA_type total_physical_sectors_no, LHA_type total_logical_sectors_no, unsigned int sectors_no_per_page) :
		CMT_entry_size(cmt_entry_size), Translation_entries_per_page(no_of_translation_entries_per_page), No_of_inserted_entries_in_preconditioning(0),
		PlaneAllocationScheme(PlaneAllocationScheme), Channel_no(channel_no), Chip_no(chip_no), Die_no(die_no), Plane_no(plane_no)
	{
		Total_physical_pages_no = total_physical_sectors_no / sectors_no_per_page;
		max_logical_sector_address = total_logical_sectors_no;
		Total_logical_pages_no = (max_logical_sector_address / sectors_no_per_page) + (max_logical_sector_address % sectors_no_per_page == 0? 0 : 1);
		
		Channel_ids = new flash_channel_ID_type[channel_no];
		for (flash_channel_ID_type cid = 0; cid < channel_no; cid++) {
			Channel_ids[cid] = channel_ids[cid];
		}
		
		Chip_ids = new flash_chip_ID_type[chip_no];
		for (flash_chip_ID_type cid = 0; cid < chip_no; cid++) {
			Chip_ids[cid] = chip_ids[cid];
		}
		
		Die_ids = new flash_die_ID_type[die_no];
		for (flash_die_ID_type did = 0; did < die_no; did++) {
			Die_ids[did] = die_ids[did];
		}
		
		Plane_ids = new flash_plane_ID_type[plane_no];
		for (flash_plane_ID_type pid = 0; pid < plane_no; pid++) {
			Plane_ids[pid] = plane_ids[pid];
		}

		GlobalMappingTable = new GMTEntryType[Total_logical_pages_no];
		for (unsigned int i = 0; i < Total_logical_pages_no; i++) {
			GlobalMappingTable[i].PPA = NO_PPA;
			GlobalMappingTable[i].WrittenStateBitmap = UNWRITTEN_LOGICAL_PAGE;
			GlobalMappingTable[i].TimeStamp = 0;
		}

		//If CMT is NULL, then each address mapping domain should create its own CMT
		if (CMT == NULL) {
			//Each flow (address mapping domain) has its own CMT, so CMT is create here in the constructor
			this->CMT = new Cached_Mapping_Table(cmt_capacity);
		} else {
			//The entire CMT space is shared among concurrently running flows (i.e., address mapping domains of all flow)
			this->CMT = CMT;
		}

		Total_translation_pages_no = MVPN_type(Total_logical_pages_no / Translation_entries_per_page);
		GlobalTranslationDirectory = new GTDEntryType[Total_translation_pages_no + 1];
		for (MVPN_type i = 0; i <= Total_translation_pages_no; i++) {
			GlobalTranslationDirectory[i].MPPN = (MPPN_type)NO_MPPN;
			GlobalTranslationDirectory[i].TimeStamp = INVALID_TIME_STAMP;
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r14
movq %rdi, %rbx
movl 0xb0(%rsp), %edi
movl 0x68(%rsp), %r13d
movl 0x98(%rsp), %r11d
movl 0x88(%rsp), %r12d
movl 0x78(%rsp), %ebp
movq 0xa8(%rsp), %r10
movq 0xa0(%rsp), %rax
movl %edx, 0x8(%rbx)
movl %ecx, 0x10(%rsp)
movl %ecx, 0xc(%rbx)
xorl %edx, %edx
movl %edx, 0x18(%rbx)
leaq 0x30(%rbx), %r8
movl %edx, 0x30(%rbx)
movq %rdx, 0x38(%rbx)
movq %r8, 0x40(%rbx)
movq %r8, 0x48(%rbx)
movq %rdx, 0x50(%rbx)
leaq 0x60(%rbx), %r8
movl %edx, 0x60(%rbx)
movq %rdx, 0x68(%rbx)
movq %r8, 0x70(%rbx)
movq %r8, 0x78(%rbx)
movq %rdx, 0x80(%rbx)
leaq 0x90(%rbx), %r8
movl %edx, 0x90(%rbx)
movq %rdx, 0x98(%rbx)
movq %r8, 0xa0(%rbx)
movq %r8, 0xa8(%rbx)
movq %rdx, 0xb0(%rbx)
leaq 0xc0(%rbx), %r8
movl %edx, 0xc0(%rbx)
movq %rdx, 0xc8(%rbx)
movq %r8, 0xd0(%rbx)
movq %r8, 0xd8(%rbx)
movq %rdx, 0xe0(%rbx)
leaq 0xf0(%rbx), %r8
movl %edx, 0xf0(%rbx)
movq %rdx, 0xf8(%rbx)
movq %r8, 0x100(%rbx)
movq %r8, 0x108(%rbx)
movq %rdx, 0x110(%rbx)
leaq 0x120(%rbx), %r8
movl %edx, 0x120(%rbx)
movq %rdx, 0x128(%rbx)
movq %r8, 0x130(%rbx)
movq %r8, 0x138(%rbx)
movq %rdx, 0x140(%rbx)
leaq 0x150(%rbx), %r8
movl %edx, 0x150(%rbx)
movq %rdx, 0x158(%rbx)
movq %r8, 0x160(%rbx)
movq %r8, 0x168(%rbx)
movq %rdx, 0x170(%rbx)
leaq 0x180(%rbx), %r8
movl %edx, 0x180(%rbx)
movq %rdx, 0x188(%rbx)
movq %r8, 0x190(%rbx)
movq %r8, 0x198(%rbx)
movq %rdx, 0x1a0(%rbx)
leaq 0x1b0(%rbx), %r8
movl %edx, 0x1b0(%rbx)
movq %rdx, 0x1b8(%rbx)
movq %r8, 0x1c0(%rbx)
movq %r8, 0x1c8(%rbx)
movq %rdx, 0x1d0(%rbx)
leaq 0x1e0(%rbx), %r8
movl %edx, 0x1e0(%rbx)
movq %rdx, 0x1e8(%rbx)
movq %r8, 0x1f0(%rbx)
movq %r8, 0x1f8(%rbx)
movq %rdx, 0x200(%rbx)
movl %r9d, 0x208(%rbx)
movl %r13d, 0x218(%rbx)
movl %ebp, 0x228(%rbx)
movl %r12d, 0x238(%rbx)
movl %r11d, 0x248(%rbx)
xorl %edx, %edx
divq %rdi
movq %rax, 0x260(%rbx)
movq %r10, 0x250(%rbx)
movq %r10, %rax
xorl %edx, %edx
divq %rdi
movq %rax, %r15
cmpq $0x1, %rdx
sbbq $-0x1, %r15
movl %esi, 0x8(%rsp)
movq %r15, 0x258(%rbx)
movq %r13, %rdi
shlq $0x2, %rdi
callq 0x7030
movq %rax, 0x210(%rbx)
testl %r13d, %r13d
je 0x29fb1
movq 0x60(%rsp), %rsi
movl %r13d, %edx
shlq $0x2, %rdx
movq %rax, %rdi
callq 0x7310
movl %ebp, %r13d
leaq (,%r13,4), %rdi
callq 0x7030
movq %rax, 0x220(%rbx)
testl %ebp, %ebp
je 0x29fe0
movq 0x70(%rsp), %rsi
shlq $0x2, %r13
movq %rax, %rdi
movq %r13, %rdx
callq 0x7310
movl %r12d, %r13d
leaq (,%r13,4), %rdi
callq 0x7030
movq %rax, 0x230(%rbx)
testl %r12d, %r12d
je 0x2a013
movq 0x80(%rsp), %rsi
shlq $0x2, %r13
movq %rax, %rdi
movq %r13, %rdx
callq 0x7310
movl 0x98(%rsp), %r13d
leaq (,%r13,4), %rdi
callq 0x7030
movq %rax, 0x240(%rbx)
cmpl $0x0, 0x98(%rsp)
je 0x2a050
movq 0x90(%rsp), %rsi
shlq $0x2, %r13
movq %rax, %rdi
movq %r13, %rdx
callq 0x7310
movl $0x18, %ecx
movq %r15, %rax
mulq %rcx
movq $-0x1, %rdi
cmovnoq %rax, %rdi
callq 0x7030
movq %rax, 0x20(%rbx)
testq %r15, %r15
je 0x2a098
movl $0x1, %ecx
xorl %edx, %edx
xorps %xmm0, %xmm0
leaq (%rdx,%rdx,2), %rsi
movq $-0x1, (%rax,%rsi,8)
movl %ecx, %edx
incl %ecx
movups %xmm0, 0x8(%rax,%rsi,8)
cmpq %rdx, %r15
ja 0x2a07e
testq %r14, %r14
jne 0x2a0ed
movl $0x58, %edi
callq 0x73a0
movq %rax, %r14
addq $0x30, %rax
movq %rax, (%r14)
movq $0x1, 0x8(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14)
movl $0x3f800000, 0x20(%r14) # imm = 0x3F800000
movups %xmm0, 0x28(%r14)
movq %r14, %rax
addq $0x38, %rax
movq %rax, 0x40(%r14)
movq %rax, 0x38(%r14)
movq $0x0, 0x48(%r14)
movl 0x8(%rsp), %eax
movl %eax, 0x50(%r14)
movq %r14, 0x10(%rbx)
movl 0x10(%rsp), %ecx
movq %r15, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r14
movl %r14d, 0x268(%rbx)
shlq $0x4, %rax
addq $0x10, %rax
movabsq $0xffffffff0, %rdi      # imm = 0xFFFFFFFF0
andq %rax, %rdi
callq 0x7030
movq %rax, (%rbx)
movl %r14d, %ecx
addq $0x8, %rax
movq $-0x1, %rdx
movl $0xffffffff, -0x8(%rax) # imm = 0xFFFFFFFF
movq $-0x1, (%rax)
incq %rdx
addq $0x10, %rax
cmpq %rcx, %rdx
jb 0x2a132
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x10(%rsp)
leaq 0x1d8(%rbx), %rdi
leaq 0x1a8(%rbx), %r13
leaq 0x178(%rbx), %rbp
leaq 0x148(%rbx), %r14
leaq 0x118(%rbx), %r15
leaq 0xe8(%rbx), %r12
leaq 0xb8(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x88(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x58(%rbx), %rax
movq %rax, 0x8(%rsp)
addq $0x28, %rbx
callq 0x30d22
movq %r13, %rdi
callq 0x30d22
movq %rbp, %rdi
callq 0x30d6c
movq %r14, %rdi
callq 0x30d6c
movq %r15, %rdi
callq 0x30d22
movq %r12, %rdi
callq 0x1676e
movq 0x18(%rsp), %rdi
callq 0x30d22
movq 0x20(%rsp), %rdi
callq 0x30db6
movq 0x8(%rsp), %rdi
callq 0x30d6c
movq %rbx, %rdi
callq 0x30d6c
movq 0x10(%rsp), %rdi
callq 0x7620