// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]MQSim/src/host/IO_Flow_Base.cpp
// Function: Host_Components::IO_Flow_Base::IO_Flow_Base(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned short, unsigned long, unsigned long, unsigned short, unsigned short, unsigned short, IO_Flow_Priority_Class::Priority, unsigned long, double, unsigned int, HostInterface_Types, Host_Components::PCIe_Root_Complex*, Host_Components::SATA_HBA*, bool, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
IO_Flow_Base::IO_Flow_Base(const sim_object_id_type &name, uint16_t flow_id, LHA_type start_lsa_on_device, LHA_type end_lsa_on_device, uint16_t io_queue_id,
						   uint16_t nvme_submission_queue_size, uint16_t nvme_completion_queue_size,
						   IO_Flow_Priority_Class::Priority priority_class, sim_time_type stop_time, double initial_occupancy_ratio, unsigned int total_requets_to_be_generated,
						   HostInterface_Types SSD_device_type, PCIe_Root_Complex *pcie_root_complex, SATA_HBA *sata_hba,
						   bool enabled_logging, sim_time_type logging_period, std::string logging_file_path) : MQSimEngine::Sim_Object(name), flow_id(flow_id), start_lsa_on_device(start_lsa_on_device), end_lsa_on_device(end_lsa_on_device), io_queue_id(io_queue_id),
																												priority_class(priority_class), stop_time(stop_time), initial_occupancy_ratio(initial_occupancy_ratio), total_requests_to_be_generated(total_requets_to_be_generated), SSD_device_type(SSD_device_type), pcie_root_complex(pcie_root_complex), sata_hba(sata_hba),
																												STAT_generated_request_count(0), STAT_generated_read_request_count(0), STAT_generated_write_request_count(0),
																												STAT_ignored_request_count(0),
																												STAT_serviced_request_count(0), STAT_serviced_read_request_count(0), STAT_serviced_write_request_count(0),
																												STAT_sum_device_response_time(0), STAT_sum_device_response_time_read(0), STAT_sum_device_response_time_write(0),
																												STAT_min_device_response_time(MAXIMUM_TIME), STAT_min_device_response_time_read(MAXIMUM_TIME), STAT_min_device_response_time_write(MAXIMUM_TIME),
																												STAT_max_device_response_time(0), STAT_max_device_response_time_read(0), STAT_max_device_response_time_write(0),
																												STAT_sum_request_delay(0), STAT_sum_request_delay_read(0), STAT_sum_request_delay_write(0),
																												STAT_min_request_delay(MAXIMUM_TIME), STAT_min_request_delay_read(MAXIMUM_TIME), STAT_min_request_delay_write(MAXIMUM_TIME),
																												STAT_max_request_delay(0), STAT_max_request_delay_read(0), STAT_max_request_delay_write(0),
																												STAT_transferred_bytes_total(0), STAT_transferred_bytes_read(0), STAT_transferred_bytes_write(0), progress(0), next_progress_step(0),
																												enabled_logging(enabled_logging), logging_period(logging_period), logging_file_path(logging_file_path)
{
	Host_IO_Request *t = NULL;

	switch (SSD_device_type)
	{
	case HostInterface_Types::NVME:
		for (uint16_t cmdid = 0; cmdid < (uint16_t)(0xffffffff); cmdid++)
		{
			available_command_ids.insert(cmdid);
		}
		for (uint16_t cmdid = 0; cmdid < nvme_submission_queue_size; cmdid++)
		{
			request_queue_in_memory.push_back(t);
		}
		nvme_queue_pair.Submission_queue_size = nvme_submission_queue_size;
		nvme_queue_pair.Submission_queue_head = 0;
		nvme_queue_pair.Submission_queue_tail = 0;
		nvme_queue_pair.Completion_queue_size = nvme_completion_queue_size;
		nvme_queue_pair.Completion_queue_head = 0;
		nvme_queue_pair.Completion_queue_tail = 0;

		//id = 0: admin queues, id = 1 to 8, normal I/O queues
		switch (io_queue_id)
		{
		case 0:
			throw std::logic_error("I/O queue id 0 is reserved for NVMe admin queues and should not be used for I/O flows");
			/*
						nvme_queue_pair.Submission_queue_memory_base_address = SUBMISSION_QUEUE_MEMORY_0;
						nvme_queue_pair.Submission_tail_register_address_on_device = SUBMISSION_QUEUE_REGISTER_0;
						nvme_queue_pair.Completion_queue_tail = COMPLETION_QUEUE_REGISTER_0;*/
			nvme_queue_pair.Completion_queue_memory_base_address = COMPLETION_QUEUE_REGISTER_0;
			break;
		case 1:
			nvme_queue_pair.Submission_queue_memory_base_address = SUBMISSION_QUEUE_MEMORY_1;
			nvme_queue_pair.Submission_tail_register_address_on_device = SUBMISSION_QUEUE_REGISTER_1;
			nvme_queue_pair.Completion_queue_memory_base_address = COMPLETION_QUEUE_MEMORY_1;
			nvme_queue_pair.Completion_head_register_address_on_device = COMPLETION_QUEUE_REGISTER_1;
			break;
		case 2:
			nvme_queue_pair.Submission_queue_memory_base_address = SUBMISSION_QUEUE_MEMORY_2;
			nvme_queue_pair.Submission_tail_register_address_on_device = SUBMISSION_QUEUE_REGISTER_2;
			nvme_queue_pair.Completion_queue_memory_base_address = COMPLETION_QUEUE_MEMORY_2;
			nvme_queue_pair.Completion_head_register_address_on_device = COMPLETION_QUEUE_REGISTER_2;
			break;
		case 3:
			nvme_queue_pair.Submission_queue_memory_base_address = SUBMISSION_QUEUE_MEMORY_3;
			nvme_queue_pair.Submission_tail_register_address_on_device = SUBMISSION_QUEUE_REGISTER_3;
			nvme_queue_pair.Completion_queue_memory_base_address = COMPLETION_QUEUE_MEMORY_3;
			nvme_queue_pair.Completion_head_register_address_on_device = COMPLETION_QUEUE_REGISTER_3;
			break;
		case 4:
			nvme_queue_pair.Submission_queue_memory_base_address = SUBMISSION_QUEUE_MEMORY_4;
			nvme_queue_pair.Submission_tail_register_address_on_device = SUBMISSION_QUEUE_REGISTER_4;
			nvme_queue_pair.Completion_queue_memory_base_address = COMPLETION_QUEUE_MEMORY_4;
			nvme_queue_pair.Completion_head_register_address_on_device = COMPLETION_QUEUE_REGISTER_4;
			break;
		case 5:
			nvme_queue_pair.Submission_queue_memory_base_address = SUBMISSION_QUEUE_MEMORY_5;
			nvme_queue_pair.Submission_tail_register_address_on_device = SUBMISSION_QUEUE_REGISTER_5;
			nvme_queue_pair.Completion_queue_memory_base_address = COMPLETION_QUEUE_MEMORY_5;
			nvme_queue_pair.Completion_head_register_address_on_device = COMPLETION_QUEUE_REGISTER_5;
			break;
		case 6:
			nvme_queue_pair.Submission_queue_memory_base_address = SUBMISSION_QUEUE_MEMORY_6;
			nvme_queue_pair.Submission_tail_register_address_on_device = SUBMISSION_QUEUE_REGISTER_6;
			nvme_queue_pair.Completion_queue_memory_base_address = COMPLETION_QUEUE_MEMORY_6;
			nvme_queue_pair.Completion_head_register_address_on_device = COMPLETION_QUEUE_REGISTER_6;
			break;
		case 7:
			nvme_queue_pair.Submission_queue_memory_base_address = SUBMISSION_QUEUE_MEMORY_7;
			nvme_queue_pair.Submission_tail_register_address_on_device = SUBMISSION_QUEUE_REGISTER_7;
			nvme_queue_pair.Completion_queue_memory_base_address = COMPLETION_QUEUE_MEMORY_7;
			nvme_queue_pair.Completion_head_register_address_on_device = COMPLETION_QUEUE_REGISTER_7;
			break;
		case 8:
			nvme_queue_pair.Submission_queue_memory_base_address = SUBMISSION_QUEUE_MEMORY_8;
			nvme_queue_pair.Submission_tail_register_address_on_device = SUBMISSION_QUEUE_REGISTER_8;
			nvme_queue_pair.Completion_queue_memory_base_address = COMPLETION_QUEUE_MEMORY_8;
			nvme_queue_pair.Completion_head_register_address_on_device = COMPLETION_QUEUE_REGISTER_8;
			break;
		default:
			break;
		}
		break;
	default:
		break;
	}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movsd %xmm0, 0x8(%rsp)
movl %r9d, %ebp
movq %r8, %r14
movq %rcx, %r15
movl %edx, %r12d
movq %rdi, %rbx
movq 0x78(%rsp), %r13
callq 0x11bca
leaq 0x49698(%rip), %rax     # 0x60b70
movq %rax, (%rbx)
leaq 0x496e6(%rip), %rax     # 0x60bc8
movq %rax, 0x30(%rbx)
movw %r12w, 0x38(%rbx)
movl 0x88(%rsp), %r12d
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x40(%rbx)
movq %r13, 0x48(%rbx)
movl 0x80(%rsp), %eax
movl %eax, 0x50(%rbx)
movl %r12d, 0x54(%rbx)
movaps 0x90(%rsp), %xmm0
movups %xmm0, 0x58(%rbx)
movq %r15, 0x68(%rbx)
movq %r14, 0x70(%rbx)
movl 0x70(%rsp), %eax
movl %eax, 0x78(%rbx)
movl %ebp, 0x8(%rsp)
movw %bp, 0xb0(%rbx)
leaq 0xb8(%rbx), %r14
leaq 0xc0(%rbx), %rax
andl $0x0, 0xc0(%rbx)
andq $0x0, 0xc8(%rbx)
movq %rax, 0xd0(%rbx)
movq %rax, 0xd8(%rbx)
leaq 0xe8(%rbx), %r15
leaq 0x100(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0xe0(%rbx)
movups %xmm0, 0xf0(%rbx)
movq %rax, 0x108(%rbx)
movq %rax, 0x18(%rsp)
movq %rax, 0x100(%rbx)
andq $0x0, 0x110(%rbx)
leaq 0x148(%rbx), %rax
movq %rax, 0x118(%rbx)
movq $0x1, 0x120(%rbx)
movups %xmm0, 0x128(%rbx)
movl $0x3f800000, 0x138(%rbx) # imm = 0x3F800000
movups %xmm0, 0x140(%rbx)
movups %xmm0, 0x150(%rbx)
movups %xmm0, 0x15c(%rbx)
movups %xmm0, 0x170(%rbx)
andq $0x0, 0x180(%rbx)
pcmpeqd %xmm1, %xmm1
movdqu %xmm1, 0x188(%rbx)
orq $-0x1, 0x198(%rbx)
movups %xmm0, 0x1c0(%rbx)
movups %xmm0, 0x1b0(%rbx)
movups %xmm0, 0x1a0(%rbx)
movdqu %xmm1, 0x1d0(%rbx)
orq $-0x1, 0x1e0(%rbx)
movups %xmm0, 0x208(%rbx)
movups %xmm0, 0x1f8(%rbx)
andq $0x0, 0x218(%rbx)
movups %xmm0, 0x1e8(%rbx)
movb 0xa0(%rsp), %al
movb %al, 0x220(%rbx)
movq 0xa8(%rsp), %rax
movq %rax, 0x228(%rbx)
leaq 0x238(%rbx), %rdi
movq %rdi, 0x10(%rsp)
movq 0xb0(%rsp), %rsi
callq 0x7480
leaq 0x258(%rbx), %rdi
movq %rdi, %rbp
callq 0x7580
andq $0x0, 0x20(%rsp)
cmpl $0x1, %r12d
jne 0x177b4
xorl %eax, %eax
leaq 0x6(%rsp), %r13
movw %ax, 0x6(%rsp)
cmpw $-0x1, %ax
je 0x176b9
movq %r14, %rdi
movq %r13, %rsi
callq 0x19a84
movzwl 0x6(%rsp), %eax
incl %eax
jmp 0x1769a
leaq 0x20(%rsp), %r13
movzwl 0x60(%rsp), %r12d
subw $0x1, %r12w
jb 0x176d8
movq %r15, %rdi
movq %r13, %rsi
callq 0x1993a
jmp 0x176c4
movzwl 0x60(%rsp), %eax
movw %ax, 0x84(%rbx)
andl $0x0, 0x80(%rbx)
movzwl 0x68(%rsp), %eax
movw %ax, 0x9c(%rbx)
andl $0x0, 0x98(%rbx)
cmpw $0x8, 0x8(%rsp)
ja 0x177b4
movzwl 0x8(%rsp), %eax
leaq 0x2e0da(%rip), %rcx     # 0x457f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movaps 0x2dfaa(%rip), %xmm0    # 0x456d0
movdqa 0x2dfb2(%rip), %xmm1    # 0x456e0
jmp 0x177a5
movaps 0x2e019(%rip), %xmm0    # 0x45750
movdqa 0x2e021(%rip), %xmm1    # 0x45760
jmp 0x177a5
movaps 0x2e068(%rip), %xmm0    # 0x457b0
movdqa 0x2e070(%rip), %xmm1    # 0x457c0
jmp 0x177a5
movaps 0x2e017(%rip), %xmm0    # 0x45770
movdqa 0x2e01f(%rip), %xmm1    # 0x45780
jmp 0x177a5
movaps 0x2e026(%rip), %xmm0    # 0x45790
movdqa 0x2e02e(%rip), %xmm1    # 0x457a0
jmp 0x177a5
movaps 0x2df75(%rip), %xmm0    # 0x456f0
movdqa 0x2df7d(%rip), %xmm1    # 0x45700
jmp 0x177a5
movaps 0x2dfa4(%rip), %xmm0    # 0x45730
movdqa 0x2dfac(%rip), %xmm1    # 0x45740
jmp 0x177a5
movaps 0x2df73(%rip), %xmm0    # 0x45710
movdqa 0x2df7b(%rip), %xmm1    # 0x45720
movdqu %xmm1, 0x88(%rbx)
movups %xmm0, 0xa0(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x71b0
movq %rax, %r13
leaq 0x2e06b(%rip), %rsi     # 0x45840
movq %rax, %rdi
callq 0x74b0
movq 0x4a7dc(%rip), %rsi     # 0x61fc0
movq 0x4a785(%rip), %rdx     # 0x61f70
movq %r13, %rdi
callq 0x7590
jmp 0x1780e
movq %rax, %r12
movq %r13, %rdi
callq 0x72a0
jmp 0x17811
movq %rax, %r12
jmp 0x17819
movq %rax, %r12
jmp 0x17823
jmp 0x1780e
movq %rax, %r12
movq %rbp, %rdi
callq 0x74e0
movq 0x10(%rsp), %rdi
callq 0x7678
leaq 0x118(%rbx), %rdi
callq 0x19984
movq 0x18(%rsp), %rdi
callq 0x19a0a
movq %r15, %rdi
callq 0x19a76
movq %r14, %rdi
callq 0x19a2e
movq %rbx, %rdi
callq 0x11c8c
movq %r12, %rdi
callq 0x75d0
nop