// File: /workspace/github_cpp_makefile_star2_O3/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), %r14
movl %ecx, 0x8(%rsp)
movl %edx, 0xc(%rsp)
movq 0x10(%rsi), %rax
movq %rax, %xmm1
movl %eax, %eax
shlq $0x6, %rax
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqu %xmm0, 0x10(%rsp)
cmpl $0x0, 0x4(%r14,%rax)
je 0x2fb5b
addq %rax, %r14
xorl %ebp, %ebp
leaq 0x8(%rsp), %r15
movq 0x40(%rbx), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x3d8e0
testb %al, %al
je 0x2fb4f
movl %ebp, 0x1c(%rsp)
movb 0x22(%r14), %r12b
movq 0x38(%rbx), %rdi
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movl 0x10(%rsp), %ecx
movl 0x14(%rsp), %r8d
movl 0x18(%rsp), %r9d
movq (%rdi), %rax
movl %ebp, (%rsp)
callq *0x38(%rax)
movq %rax, %r13
movq 0xa8(%rbx), %rcx
movzwl 0x20(%r14), %eax
movq (%rcx,%rax,8), %rcx
cmpb $0x1, %r12b
jne 0x2facc
movq (%rcx), %rax
movl %r13d, %ecx
shlq $0x4, %rcx
movl (%rax,%rcx), %r12d
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x90(%rax)
cmpq %r12, %rax
je 0x2fb4f
jmp 0x2fb89
movq 0x10(%rcx), %rdi
movq 0x20(%rcx), %rcx
leaq (,%r13,2), %rdx
addq %r13, %rdx
movq (%rcx,%rdx,8), %r12
shlq $0x38, %rax
orq %r13, %rax
movq %rax, 0x20(%rsp)
leaq 0x20(%rsp), %rsi
callq 0x30a0c
testq %rax, %rax
je 0x2fb27
movq 0x10(%rax), %rax
cmpl $0x2, 0x14(%rax)
jne 0x2fb27
movq 0xa8(%rbx), %rax
movzwl 0x20(%r14), %esi
movq (%rax,%rsi,8), %rax
movq 0x10(%rax), %rdi
movq %r13, %rdx
callq 0x293bc
movq %rax, %r12
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x90(%rax)
cmpq %rax, %r12
jne 0x2fb6a
movzwl 0x20(%r14), %esi
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rdx
callq *0xa0(%rax)
incl %ebp
cmpl 0x4(%r14), %ebp
jb 0x2fa47
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3f47f(%rip), %rbx     # 0x6eff0
leaq 0x26a30(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x2918d(%rip), %rsi     # 0x58d14
jmp 0x2fba6
movq 0x3f460(%rip), %rbx     # 0x6eff0
leaq 0x26a11(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x29126(%rip), %rsi     # 0x58ccc
movq %rbx, %rdi
callq 0x7390
movq %rax, %rdi
callq 0x71c0
movq 0x3f413(%rip), %rdi     # 0x6efd0
callq 0x7430
movl $0x1, %edi
callq 0x7440