// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]MQSim/src/ssd/Address_Mapping_Unit_Page_Level.cpp
// Function: SSD_Components::Address_Mapping_Unit_Page_Level::Set_barrier_for_accessing_physical_block(NVM::FlashMemory::Physical_Page_Address const&)
inline void Address_Mapping_Unit_Page_Level::Set_barrier_for_accessing_physical_block(const NVM::FlashMemory::Physical_Page_Address& block_address)
	{
		//The LPAs are actually not known until they are read one-by-one from flash storage. But, to reduce MQSim's complexity, we assume that LPAs are stored in DRAM and thus no read from flash storage is needed.
		Block_Pool_Slot_Type* block = &(block_manager->plane_manager[block_address.ChannelID][block_address.ChipID][block_address.DieID][block_address.PlaneID].Blocks[block_address.BlockID]);
		NVM::FlashMemory::Physical_Page_Address addr(block_address);
		for (flash_page_ID_type pageID = 0; pageID < block->Current_page_write_index; pageID++) {
			if (block_manager->Is_page_valid(block, pageID)) {
				addr.PageID = pageID;
				if (block->Holds_mapping_data) {
					MVPN_type mpvn = (MVPN_type)flash_controller->Get_metadata(addr.ChannelID, addr.ChipID, addr.DieID, addr.PlaneID, addr.BlockID, addr.PageID);
					if (domains[block->Stream_id]->GlobalTranslationDirectory[mpvn].MPPN != Convert_address_to_ppa(addr)) {
						PRINT_ERROR("Inconsistency in the global translation directory when locking an MPVN!")
						Set_barrier_for_accessing_mvpn(block->Stream_id, mpvn);
					}
				} else {
					LPA_type lpa = flash_controller->Get_metadata(addr.ChannelID, addr.ChipID, addr.DieID, addr.PlaneID, addr.BlockID, addr.PageID);
					LPA_type ppa = domains[block->Stream_id]->GlobalMappingTable[lpa].PPA;
					if (domains[block->Stream_id]->CMT->Exists(block->Stream_id, lpa)) {
						ppa = domains[block->Stream_id]->CMT->Retrieve_ppa(block->Stream_id, lpa);
					}
					if (ppa != Convert_address_to_ppa(addr)) {
						PRINT_ERROR("Inconsistency in the global mapping table when locking an LPA!")
					}
					Set_barrier_for_accessing_lpa(block->Stream_id, lpa);
				}
			}
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %rax
movl (%rsi), %ecx
movl 0x4(%rsi), %edx
movq (%rax,%rcx,8), %rax
movq (%rax,%rdx,8), %rax
movq 0x8(%rsi), %rdi
movq %rdi, %xmm0
movl %edi, %edi
movq (%rax,%rdi,8), %rax
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
movd %xmm1, %edi
imulq $0xe0, %rdi, %rdi
movq 0x10(%rax,%rdi), %rax
leaq 0x10(%rsp), %r14
movl %ecx, (%r14)
movl %edx, 0x4(%r14)
movq 0x10(%rsi), %rcx
movq %rcx, %xmm1
movl %ecx, %r15d
shlq $0x6, %r15
addq %rax, %r15
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqu %xmm0, 0x8(%r14)
xorl %ebp, %ebp
cmpl 0x4(%r15), %ebp
jae 0x26946
movq 0x40(%rbx), %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x31c92
testb %al, %al
je 0x2693f
movl %ebp, 0x24(%rsp)
movb 0x22(%r15), %r13b
movq 0x38(%rbx), %rdi
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movl 0x18(%rsp), %ecx
movl 0x1c(%rsp), %r8d
movl 0x20(%rsp), %r9d
movq (%rdi), %rax
movl %ebp, (%rsp)
callq *0x38(%rax)
movq %rax, %r12
movq 0xa8(%rbx), %rcx
movzwl 0x20(%r15), %eax
movq (%rcx,%rax,8), %rcx
cmpb $0x1, %r13b
jne 0x268d9
movq (%rcx), %rax
movl %r12d, %ecx
shlq $0x4, %rcx
movl (%rax,%rcx), %r12d
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x90(%rax)
cmpq %r12, %rax
je 0x2693f
jmp 0x26955
movq 0x10(%rcx), %rdi
movq 0x20(%rcx), %rcx
imulq $0x18, %r12, %rdx
movq (%rcx,%rdx), %r13
movzwl %ax, %esi
movq %r12, %rdx
callq 0x264a2
testb %al, %al
je 0x26917
movq 0xa8(%rbx), %rax
movzwl 0x20(%r15), %esi
movq (%rax,%rsi,8), %rax
movq 0x10(%rax), %rdi
movq %r12, %rdx
callq 0x20a46
movq %rax, %r13
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x90(%rax)
cmpq %rax, %r13
jne 0x26974
movzwl 0x20(%r15), %esi
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rdx
callq *0xa0(%rax)
incl %ebp
jmp 0x26851
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3b694(%rip), %rbx     # 0x61ff0
leaq 0x1dc25(%rip), %rsi     # 0x44588
movq %rbx, %rdi
callq 0x7360
leaq 0x2022a(%rip), %rsi     # 0x46b9c
jmp 0x26991
movq 0x3b675(%rip), %rbx     # 0x61ff0
leaq 0x1dc06(%rip), %rsi     # 0x44588
movq %rbx, %rdi
callq 0x7360
leaq 0x20253(%rip), %rsi     # 0x46be4
movq %rbx, %rdi
callq 0x7360
movq %rax, %rdi
callq 0x71a0
movq 0x3b628(%rip), %rdi     # 0x61fd0
callq 0x73d0
pushq $0x1
popq %rdi
callq 0x73e0
nop