// File: MPSLab-ASU[P]DiRAC/./src/baseAccelSim.cc
// Function: baseAccelSim::readConfig(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void baseAccelSim::readConfig(string configFileName) {
	string key, value, line;
	map <string, string> configs;

	ifstream inFile(configFileName.c_str());
	if(!inFile)
	{
		cout << "Cannot open and read file: " << configFileName.c_str() << endl;
		exit (EXIT_FAILURE);
	}

	while(getline(inFile, line)) {
		istringstream tokenStream(line);
		tokenStream >> key >> value;
		// Skip comments beginning with #
		// Skip empty lines
		if ( (key.find("#") != std::string::npos) || (line.empty()) )
			continue;
		configs[key] = value;
	}
	inFile.close();

	RF_passes 			= stoi(configs["RF_passes_in_SPM_pass"]);
	SPM_passes 			= stoi(configs["total_SPM_pass"]);
	total_cycles_RF_pass 		= stoi(configs["total_cycles_RF_pass"]);
	total_compute_cycles_RF_pass = stoi(configs["total_compute_cycles_RF_pass"]);

	regs_buf1_startIdx_Op = new uint16_t[total_operands]();
	regs_buf2_startIdx_Op = new uint16_t[total_operands]();
	uint8_t count_nonZero_reg_startIdx = 0;

	for(uint8_t i=0; i < total_operands; i++)
	{
		regs_buf1_startIdx_Op[i] = stoi(configs["regs_buf1_startIdx_Op"+ std::to_string(i+1)]);
		regs_buf2_startIdx_Op[i] = stoi(configs["regs_buf2_startIdx_Op"+ std::to_string(i+1)]);

		if(regs_buf1_startIdx_Op[i] > 0) count_nonZero_reg_startIdx++;
	}
	// no need to do for buf2; double buffering of RF may not be needed.
	// We need to work with at least two tensors: one for input, one for output.
	// So, at least one tensor out of the two should start at non-zero reg. idx.
	assert(count_nonZero_reg_startIdx >= 1 && "Incorrect startIdx for RegFile");

	assert(RF_passes >= 1 && "Total RF passes must be 1 or more for a kernel execution.");
	assert(SPM_passes >= 1 && "Total SPM passes must be 1 or more for a kernel execution.");
	assert(total_cycles_RF_pass > 0 && "Total cycles for processing data from RF in one RF pass must be greater than zero.");
	assert(total_compute_cycles_RF_pass > 0 && total_compute_cycles_RF_pass <= total_cycles_RF_pass &&
		"Total cycles for computation on PEs should be greater than zero and not more than cycles for an RF pass.");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x650, %rsp            # imm = 0x650
movq %rsi, -0x568(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x4a2620
leaq -0x50(%rbp), %rdi
callq 0x4a2620
leaq -0x70(%rbp), %rdi
callq 0x4a2620
leaq -0xa0(%rbp), %rdi
callq 0x40ed40
movq -0x568(%rbp), %rdi
callq 0x4a4170
movq %rax, %rsi
leaq -0x2a8(%rbp), %rdi
movl $0x8, %edx
callq 0x46e8c0
jmp 0x406c33
movq -0x2a8(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2a8(%rbp,%rax), %rdi
callq 0x472d80
movb %al, -0x569(%rbp)
jmp 0x406c53
movb -0x569(%rbp), %al
testb $0x1, %al
jne 0x406c62
jmp 0x406cef
movq $0x61f900, %rdi         # imm = 0x61F900
leaq 0x19a3a0(%rip), %rsi    # 0x5a1010
callq 0x492450
movq %rax, -0x578(%rbp)
jmp 0x406c7e
movq -0x568(%rbp), %rdi
callq 0x4a4170
movq -0x578(%rbp), %rdi
movq %rax, %rsi
callq 0x492450
movq %rax, -0x580(%rbp)
jmp 0x406ca2
movq -0x580(%rbp), %rdi
movq $0x491d30, %rsi         # imm = 0x491D30
callq 0x490f40
jmp 0x406cb7
movl $0x1, %edi
callq 0x4ec1e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x407602
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x4075f6
jmp 0x406cf1
leaq -0x2a8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4a5170
movq %rax, -0x588(%rbp)
jmp 0x406d0a
movq -0x588(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x472d70
movb %al, -0x589(%rbp)
jmp 0x406d28
movb -0x589(%rbp), %al
testb $0x1, %al
jne 0x406d37
jmp 0x406e28
leaq -0x438(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x8, %edx
callq 0x49a120
jmp 0x406d4e
leaq -0x438(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4277f0
movq %rax, -0x598(%rbp)
jmp 0x406d67
movq -0x598(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4277f0
jmp 0x406d79
leaq -0x30(%rbp), %rdi
leaq 0x1a1f4c(%rip), %rsi    # 0x5a8cd0
xorl %eax, %eax
movl %eax, %edx
callq 0x4a4290
cmpq $-0x1, %rax
jne 0x406da2
leaq -0x70(%rbp), %rdi
callq 0x4a2c50
testb $0x1, %al
jne 0x406da2
jmp 0x406dd1
movl $0x2, -0x43c(%rbp)
jmp 0x406e06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x438(%rbp), %rdi
callq 0x497a10
jmp 0x4075f6
leaq -0xa0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x40ed60
movq %rax, -0x5a0(%rbp)
jmp 0x406dea
movq -0x5a0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x4a2760
jmp 0x406dfc
movl $0x0, -0x43c(%rbp)
leaq -0x438(%rbp), %rdi
callq 0x497a10
movl -0x43c(%rbp), %eax
testl %eax, %eax
je 0x406e23
jmp 0x406e1e
jmp 0x406cf1
jmp 0x406cf1
leaq -0x2a8(%rbp), %rdi
callq 0x46ee70
jmp 0x406e36
leaq -0x461(%rbp), %rdi
movq %rdi, -0x5a8(%rbp)
callq 0x426c50
movq -0x5a8(%rbp), %rdx
leaq 0x19ad6e(%rip), %rsi    # 0x5a1bc5
leaq -0x460(%rbp), %rdi
callq 0x40ef60
jmp 0x406e65
leaq -0xa0(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x40ee80
movq %rax, -0x5b0(%rbp)
jmp 0x406e81
movq -0x5b0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x40ee40
movl %eax, -0x5b4(%rbp)
jmp 0x406e9e
movl -0x5b4(%rbp), %eax
movw %ax, 0x2176a7(%rip)     # 0x61e552
leaq -0x460(%rbp), %rdi
callq 0x4a2730
leaq -0x461(%rbp), %rdi
callq 0x426c70
leaq -0x489(%rbp), %rdi
movq %rdi, -0x5c0(%rbp)
callq 0x426c50
movq -0x5c0(%rbp), %rdx
leaq 0x19acf7(%rip), %rsi    # 0x5a1bdb
leaq -0x488(%rbp), %rdi
callq 0x40ef60
jmp 0x406ef2
leaq -0xa0(%rbp), %rdi
leaq -0x488(%rbp), %rsi
callq 0x40ee80
movq %rax, -0x5c8(%rbp)
jmp 0x406f0e
movq -0x5c8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x40ee40
movl %eax, -0x5cc(%rbp)
jmp 0x406f2b
movl -0x5cc(%rbp), %eax
movw %ax, 0x21761c(%rip)     # 0x61e554
leaq -0x488(%rbp), %rdi
callq 0x4a2730
leaq -0x489(%rbp), %rdi
callq 0x426c70
leaq -0x4b1(%rbp), %rdi
movq %rdi, -0x5d8(%rbp)
callq 0x426c50
movq -0x5d8(%rbp), %rdx
leaq 0x19ac79(%rip), %rsi    # 0x5a1bea
leaq -0x4b0(%rbp), %rdi
callq 0x40ef60
jmp 0x406f7f
leaq -0xa0(%rbp), %rdi
leaq -0x4b0(%rbp), %rsi
callq 0x40ee80
movq %rax, -0x5e0(%rbp)
jmp 0x406f9b
movq -0x5e0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x40ee40
movl %eax, -0x5e4(%rbp)
jmp 0x406fb8
movl -0x5e4(%rbp), %eax
movw %ax, 0x21761b(%rip)     # 0x61e5e0
leaq -0x4b0(%rbp), %rdi
callq 0x4a2730
leaq -0x4b1(%rbp), %rdi
callq 0x426c70
leaq -0x4d9(%rbp), %rdi
movq %rdi, -0x5f0(%rbp)
callq 0x426c50
movq -0x5f0(%rbp), %rdx
leaq 0x19ac01(%rip), %rsi    # 0x5a1bff
leaq -0x4d8(%rbp), %rdi
callq 0x40ef60
jmp 0x40700c
leaq -0xa0(%rbp), %rdi
leaq -0x4d8(%rbp), %rsi
callq 0x40ee80
movq %rax, -0x5f8(%rbp)
jmp 0x407028
movq -0x5f8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x40ee40
movl %eax, -0x5fc(%rbp)
jmp 0x407045
movl -0x5fc(%rbp), %eax
movw %ax, 0x217590(%rip)     # 0x61e5e2
leaq -0x4d8(%rbp), %rdi
callq 0x4a2730
leaq -0x4d9(%rbp), %rdi
callq 0x426c70
movzbl 0x2174e5(%rip), %eax    # 0x61e556
movl %eax, %edi
addq %rdi, %rdi
movq %rdi, -0x610(%rbp)
callq 0x425dd0
movq %rax, -0x608(%rbp)
jmp 0x40708b
movq -0x608(%rbp), %rdi
movq -0x610(%rbp), %rdx
xorl %esi, %esi
callq 0x401080
movq -0x608(%rbp), %rax
movq %rax, 0x217522(%rip)    # 0x61e5d0
movzbl 0x2174a1(%rip), %eax    # 0x61e556
movl %eax, %edi
addq %rdi, %rdi
movq %rdi, -0x620(%rbp)
callq 0x425dd0
movq %rax, -0x618(%rbp)
jmp 0x4070cf
movq -0x618(%rbp), %rdi
movq -0x620(%rbp), %rdx
xorl %esi, %esi
callq 0x401080
movq -0x618(%rbp), %rax
movq %rax, 0x2174e6(%rip)    # 0x61e5d8
movb $0x0, -0x4da(%rbp)
movb $0x0, -0x4db(%rbp)
movzbl -0x4db(%rbp), %eax
movzbl 0x217448(%rip), %ecx    # 0x61e556
cmpl %ecx, %eax
jge 0x407429
movzbl -0x4db(%rbp), %esi
incl %esi
leaq -0x520(%rbp), %rdi
callq 0x40f0c0
jmp 0x40712d
leaq 0x19aae8(%rip), %rsi    # 0x5a1c1c
leaq -0x500(%rbp), %rdi
leaq -0x520(%rbp), %rdx
callq 0x40f070
jmp 0x407149
leaq -0xa0(%rbp), %rdi
leaq -0x500(%rbp), %rsi
callq 0x40ee80
movq %rax, -0x628(%rbp)
jmp 0x407165
movq -0x628(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x40ee40
movl %eax, -0x62c(%rbp)
jmp 0x407182
movl -0x62c(%rbp), %eax
movw %ax, %dx
movq 0x21743e(%rip), %rax    # 0x61e5d0
movzbl -0x4db(%rbp), %ecx
movw %dx, (%rax,%rcx,2)
leaq -0x500(%rbp), %rdi
callq 0x4a2730
leaq -0x520(%rbp), %rdi
callq 0x4a2730
movzbl -0x4db(%rbp), %esi
incl %esi
leaq -0x560(%rbp), %rdi
callq 0x40f0c0
jmp 0x4071cc
leaq 0x19aa5f(%rip), %rsi    # 0x5a1c32
leaq -0x540(%rbp), %rdi
leaq -0x560(%rbp), %rdx
callq 0x40f070
jmp 0x4071e8
leaq -0xa0(%rbp), %rdi
leaq -0x540(%rbp), %rsi
callq 0x40ee80
movq %rax, -0x638(%rbp)
jmp 0x407204
movq -0x638(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x40ee40
movl %eax, -0x63c(%rbp)
jmp 0x407221
movl -0x63c(%rbp), %eax
movw %ax, %dx
movq 0x2173a7(%rip), %rax    # 0x61e5d8
movzbl -0x4db(%rbp), %ecx
movw %dx, (%rax,%rcx,2)
leaq -0x540(%rbp), %rdi
callq 0x4a2730
leaq -0x560(%rbp), %rdi
callq 0x4a2730
movq 0x217375(%rip), %rax    # 0x61e5d0
movzbl -0x4db(%rbp), %ecx
movzwl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jle 0x407414
movb -0x4da(%rbp), %al
addb $0x1, %al
movb %al, -0x4da(%rbp)
jmp 0x407414
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x4072b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x460(%rbp), %rdi
callq 0x4a2730
leaq -0x461(%rbp), %rdi
callq 0x426c70
jmp 0x4075f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x4072f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x488(%rbp), %rdi
callq 0x4a2730
leaq -0x489(%rbp), %rdi
callq 0x426c70
jmp 0x4075f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x40733a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x4b0(%rbp), %rdi
callq 0x4a2730
leaq -0x4b1(%rbp), %rdi
callq 0x426c70
jmp 0x4075f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x40737d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x4d8(%rbp), %rdi
callq 0x4a2730
leaq -0x4d9(%rbp), %rdi
callq 0x426c70
jmp 0x4075f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x4073c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x500(%rbp), %rdi
callq 0x4a2730
leaq -0x520(%rbp), %rdi
callq 0x4a2730
jmp 0x4075f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
jmp 0x407403
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2b0(%rbp)
movl %eax, -0x2b4(%rbp)
leaq -0x540(%rbp), %rdi
callq 0x4a2730
leaq -0x560(%rbp), %rdi
callq 0x4a2730
jmp 0x4075f6
jmp 0x407416
movb -0x4db(%rbp), %al
addb $0x1, %al
movb %al, -0x4db(%rbp)
jmp 0x407100
movzbl -0x4da(%rbp), %ecx
xorl %eax, %eax
cmpl $0x1, %ecx
movb %al, -0x63d(%rbp)
jl 0x407447
movb $0x1, %al
movb %al, -0x63d(%rbp)
jmp 0x407447
movb -0x63d(%rbp), %al
testb $0x1, %al
jne 0x407453
jmp 0x407455
jmp 0x407474
leaq 0x19a80b(%rip), %rdi    # 0x5a1c67
leaq 0x199c2b(%rip), %rsi    # 0x5a108e
movl $0xaf, %edx
leaq 0x19a83c(%rip), %rcx    # 0x5a1cab
callq 0x4e53d0
movzwl 0x2170d7(%rip), %ecx    # 0x61e552
xorl %eax, %eax
cmpl $0x1, %ecx
movb %al, -0x63e(%rbp)
jl 0x407492
movb $0x1, %al
movb %al, -0x63e(%rbp)
jmp 0x407492
movb -0x63e(%rbp), %al
testb $0x1, %al
jne 0x40749e
jmp 0x4074a0
jmp 0x4074bf
leaq 0x19a864(%rip), %rdi    # 0x5a1d0b
leaq 0x199be0(%rip), %rsi    # 0x5a108e
movl $0xb1, %edx
leaq 0x19a7f1(%rip), %rcx    # 0x5a1cab
callq 0x4e53d0
movzwl 0x21708e(%rip), %ecx    # 0x61e554
xorl %eax, %eax
cmpl $0x1, %ecx
movb %al, -0x63f(%rbp)
jl 0x4074dd
movb $0x1, %al
movb %al, -0x63f(%rbp)
jmp 0x4074dd
movb -0x63f(%rbp), %al
testb $0x1, %al
jne 0x4074e9
jmp 0x4074eb
jmp 0x40750a
leaq 0x19a8a2(%rip), %rdi    # 0x5a1d94
leaq 0x199b95(%rip), %rsi    # 0x5a108e
movl $0xb2, %edx
leaq 0x19a7a6(%rip), %rcx    # 0x5a1cab
callq 0x4e53d0
movzwl 0x2170cf(%rip), %ecx    # 0x61e5e0
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x640(%rbp)
jle 0x407528
movb $0x1, %al
movb %al, -0x640(%rbp)
jmp 0x407528
movb -0x640(%rbp), %al
testb $0x1, %al
jne 0x407534
jmp 0x407536
jmp 0x407555
leaq 0x19a8fa(%rip), %rdi    # 0x5a1e37
leaq 0x199b4a(%rip), %rsi    # 0x5a108e
movl $0xb3, %edx
leaq 0x19a75b(%rip), %rcx    # 0x5a1cab
callq 0x4e53d0
movzwl 0x217086(%rip), %ecx    # 0x61e5e2
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x641(%rbp)
jle 0x40758d
movzwl 0x217072(%rip), %ecx    # 0x61e5e2
movzwl 0x217069(%rip), %edx    # 0x61e5e0
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x641(%rbp)
jg 0x40758d
movb $0x1, %al
movb %al, -0x641(%rbp)
jmp 0x40758d
movb -0x641(%rbp), %al
testb $0x1, %al
jne 0x407599
jmp 0x40759b
jmp 0x4075ba
leaq 0x19a96f(%rip), %rdi    # 0x5a1f11
leaq 0x199ae5(%rip), %rsi    # 0x5a108e
movl $0xb5, %edx
leaq 0x19a6f6(%rip), %rcx    # 0x5a1cab
callq 0x4e53d0
leaq -0x2a8(%rbp), %rdi
callq 0x46f220
leaq -0xa0(%rbp), %rdi
callq 0x40f050
leaq -0x70(%rbp), %rdi
callq 0x4a2730
leaq -0x50(%rbp), %rdi
callq 0x4a2730
leaq -0x30(%rbp), %rdi
callq 0x4a2730
addq $0x650, %rsp            # imm = 0x650
popq %rbp
retq
leaq -0x2a8(%rbp), %rdi
callq 0x46f220
leaq -0xa0(%rbp), %rdi
callq 0x40f050
leaq -0x70(%rbp), %rdi
callq 0x4a2730
leaq -0x50(%rbp), %rdi
callq 0x4a2730
leaq -0x30(%rbp), %rdi
callq 0x4a2730
movq -0x2b0(%rbp), %rdi
callq 0x4d0770
nopw %cs:(%rax,%rax)