// File: /workspace/github_cpp_makefile_star2_O3/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), %ebp
movl 0x98(%rsp), %r11d
movl 0x88(%rsp), %r15d
movl 0x78(%rsp), %r12d
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 %ebp, 0x218(%rbx)
movl %r12d, 0x228(%rbx)
movl %r15d, 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 %rbp, %r13
shlq $0x2, %r13
movq %r13, %rdi
callq 0x7030
movq %rax, 0x210(%rbx)
testl %ebp, %ebp
je 0x29af7
movq 0x60(%rsp), %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0x7310
movl %r12d, %r13d
shlq $0x2, %r13
movq %r13, %rdi
callq 0x7030
movq %rax, 0x220(%rbx)
testl %r12d, %r12d
je 0x29b22
movq 0x70(%rsp), %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0x7310
movl 0x88(%rsp), %r13d
shlq $0x2, %r13
movq %r13, %rdi
callq 0x7030
movq %rax, 0x230(%rbx)
cmpl $0x0, 0x88(%rsp)
je 0x29b5a
movq 0x80(%rsp), %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0x7310
movl 0x98(%rsp), %r13d
shlq $0x2, %r13
movq %r13, %rdi
callq 0x7030
movq %rax, 0x240(%rbx)
cmpl $0x0, 0x98(%rsp)
je 0x29b92
movq 0x90(%rsp), %rsi
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 0x29bda
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 0x29bc0
testq %r14, %r14
jne 0x29c2f
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 %r15d, %eax
xorl %edx, %edx
divl 0x10(%rsp)
movl %eax, %r14d
movl %eax, 0x268(%rbx)
movq %r14, %rax
shlq $0x4, %rax
addq $0x10, %rax
movabsq $0xffffffff0, %rdi      # imm = 0xFFFFFFFF0
andq %rax, %rdi
callq 0x7030
movq %rax, (%rbx)
addq $0x8, %rax
movq $-0x1, %rcx
movl $0xffffffff, -0x8(%rax) # imm = 0xFFFFFFFF
movq $-0x1, (%rax)
incq %rcx
addq $0x10, %rax
cmpq %r14, %rcx
jb 0x29c70
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 0x304fe
movq %r13, %rdi
callq 0x304fe
movq %rbp, %rdi
callq 0x30548
movq %r14, %rdi
callq 0x30548
movq %r15, %rdi
callq 0x304fe
movq %r12, %rdi
callq 0x16674
movq 0x18(%rsp), %rdi
callq 0x304fe
movq 0x20(%rsp), %rdi
callq 0x30592
movq 0x8(%rsp), %rdi
callq 0x30548
movq %rbx, %rdi
callq 0x30548
movq 0x10(%rsp), %rdi
callq 0x7620