// File: /workspace/github_cpp_makefile_star2_O3/estwings57[P]CasHMC/sources/HMC.cpp
// Function: CasHMC::HMC::HMC(std::basic_ofstream<char, std::char_traits<char>>&, std::basic_ofstream<char, std::char_traits<char>>&)
HMC::HMC(ofstream &debugOut_, ofstream &stateOut_):
	SimulatorObject(debugOut_, stateOut_)
{
	clockTuner = 1;
	
	//Make class objects
	downLinkSlaves.reserve(NUM_LINKS);
	upLinkMasters.reserve(NUM_LINKS);
	for(int l=0; l<NUM_LINKS; l++) {
		downLinkSlaves.push_back(new LinkSlave(debugOut, stateOut, l, true));
		upLinkMasters.push_back(new LinkMaster(debugOut, stateOut, l, false));
	}
	crossbarSwitch = new CrossbarSwitch(debugOut, stateOut);
	vaultControllers.reserve(NUM_VAULTS);
	drams.reserve(NUM_VAULTS);
	for(int v=0; v<NUM_VAULTS; v++) {
		vaultControllers.push_back(new VaultController(debugOut, stateOut, v));
		drams.push_back(new DRAM(debugOut, stateOut, v, vaultControllers[v]));
	}
	
	//initialize refresh counters
	for(unsigned v=0; v<NUM_VAULTS; v++) {
		vaultControllers[v]->refreshCountdown = ((REFRESH_PERIOD/tCK)/NUM_VAULTS)*(v+1);
	}
	
	//Crossbar switch, and vault are linked each other by respective lanes
	for(int v=0; v<NUM_VAULTS; v++) {
		//Downstream
		crossbarSwitch->downBufferDest[v] = vaultControllers[v];
		vaultControllers[v]->dramP = drams[v];
		//Upstream
		vaultControllers[v]->upBufferDest = crossbarSwitch;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
callq 0x16fc6
leaq 0x1ddfb(%rip), %rax     # 0x3aaf0
movq %rax, (%rbx)
leaq 0x1d0(%rbx), %rdi
leaq 0x1e8(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x208(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x220(%rbx), %r13
xorpd %xmm0, %xmm0
movupd %xmm0, 0x1d0(%rbx)
movupd %xmm0, 0x1e0(%rbx)
movupd %xmm0, 0x1f0(%rbx)
movupd %xmm0, 0x208(%rbx)
movupd %xmm0, 0x218(%rbx)
movupd %xmm0, 0x228(%rbx)
movq $0x1, 0x1c8(%rbx)
leaq 0x1e744(%rip), %r15     # 0x3b4a8
movslq (%r15), %rsi
movq %rdi, 0x20(%rsp)
callq 0x1d386
movslq (%r15), %rsi
movq 0x18(%rsp), %rdi
callq 0x1d422
cmpl $0x0, (%r15)
jle 0x1cdfd
xorl %ebp, %ebp
leaq 0x8(%rsp), %r14
movl $0x230, %edi            # imm = 0x230
callq 0x42f0
movq %rax, %r12
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %rax, %rdi
movl %ebp, %ecx
movl $0x1, %r8d
callq 0x25ebc
movq %r12, 0x8(%rsp)
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x1d612
movl $0x288, %edi            # imm = 0x288
callq 0x42f0
movq %rax, %r12
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %rax, %rdi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x22498
movq %r12, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x1d76a
incl %ebp
cmpl (%r15), %ebp
jl 0x1cd8b
movl $0x270, %edi            # imm = 0x270
callq 0x42f0
movq %rax, %r14
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %rax, %rdi
callq 0x18718
movq %r14, 0x200(%rbx)
leaq 0x1e754(%rip), %r15     # 0x3b57c
movslq (%r15), %rsi
movq 0x10(%rsp), %rdi
callq 0x1d4be
movslq (%r15), %rsi
movq %r13, %rdi
callq 0x1d55a
movl (%r15), %eax
testl %eax, %eax
jle 0x1cec4
xorl %ebp, %ebp
leaq 0x8(%rsp), %r14
movl $0x2a8, %edi            # imm = 0x2A8
callq 0x42f0
movq %rax, %r12
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %rax, %rdi
movl %ebp, %ecx
callq 0x2cb5c
movq %r12, 0x8(%rsp)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x1d8fa
movl $0x248, %edi            # imm = 0x248
callq 0x42f0
movq %rax, %r12
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq 0x208(%rbx), %rax
movq (%rax,%rbp,8), %r8
movq %r12, %rdi
movl %ebp, %ecx
callq 0x1a720
movq %r12, 0x8(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x1da52
incq %rbp
movslq (%r15), %rax
cmpq %rax, %rbp
jl 0x1ce4e
testl %eax, %eax
je 0x1cf7c
movl %eax, %eax
leaq 0x1e6c7(%rip), %rcx     # 0x3b59c
xorps %xmm0, %xmm0
cvtsi2sdl (%rcx), %xmm0
leaq 0x1e6bd(%rip), %rcx     # 0x3b5a0
divsd (%rcx), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
xorl %edx, %edx
leaq 0x1(%rdx), %rsi
movl %esi, %edi
xorps %xmm1, %xmm1
cvtsi2sd %rdi, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rdi
movq (%rcx,%rdx,8), %rdx
movl %edi, 0x208(%rdx)
movq %rsi, %rdx
cmpq %rsi, %rax
jne 0x1cef9
testl %eax, %eax
jle 0x1cf7c
movq 0x200(%rbx), %rsi
movq 0x208(%rbx), %rdx
xorl %ecx, %ecx
movq (%rdx,%rcx,8), %rdx
movq 0x208(%rsi), %rsi
movq %rdx, (%rsi,%rcx,8)
movq 0x208(%rbx), %rdx
movq 0x220(%rbx), %rsi
movq (%rsi,%rcx,8), %rsi
movq (%rdx,%rcx,8), %rdi
movq %rsi, 0x210(%rdi)
movq 0x200(%rbx), %rsi
movq (%rdx,%rcx,8), %rdi
movq %rsi, 0x250(%rdi)
incq %rcx
cmpq %rcx, %rax
jne 0x1cf36
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbp
movl $0x270, %esi            # imm = 0x270
movq %r14, %rdi
jmp 0x1cfc3
jmp 0x1cfd0
movq %rax, %rbp
movl $0x2a8, %esi            # imm = 0x2A8
jmp 0x1cfc0
movq %rax, %rbp
movl $0x248, %esi            # imm = 0x248
jmp 0x1cfc0
movq %rax, %rbp
movl $0x230, %esi            # imm = 0x230
jmp 0x1cfc0
movq %rax, %rbp
movl $0x288, %esi            # imm = 0x288
movq %r12, %rdi
callq 0x4300
jmp 0x1cfd3
jmp 0x1cfd0
jmp 0x1cfd0
jmp 0x1cfd0
movq %rax, %rbp
movq (%r13), %rdi
testq %rdi, %rdi
je 0x1cfeb
movq 0x230(%rbx), %rsi
subq %rdi, %rsi
callq 0x4300
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x1d007
movq 0x218(%rbx), %rsi
subq %rdi, %rsi
callq 0x4300
movq 0x18(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x1d023
movq 0x1f8(%rbx), %rsi
subq %rdi, %rsi
callq 0x4300
movq 0x20(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x1d03f
movq 0x1e0(%rbx), %rsi
subq %rdi, %rsi
callq 0x4300
movq %rbx, %rdi
callq 0x175ae
movq %rbp, %rdi
callq 0x4540
nop