// File: /workspace/github_cpp_makefile_star2_O1/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 0x17976
leaq 0x1e66b(%rip), %rax     # 0x3baf0
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 0x1efb4(%rip), %r15     # 0x3c4a8
movslq (%r15), %rsi
movq %rdi, 0x20(%rsp)
callq 0x1db16
movslq (%r15), %rsi
movq 0x18(%rsp), %rdi
callq 0x1dbac
cmpl $0x0, (%r15)
jle 0x1d58d
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 0x2663c
movq %r12, 0x8(%rsp)
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x1dd8a
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 0x22bd8
movq %r12, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x1deda
incl %ebp
cmpl (%r15), %ebp
jl 0x1d51b
movl $0x270, %edi            # imm = 0x270
callq 0x42f0
movq %rax, %r14
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %rax, %rdi
callq 0x18f1c
movq %r14, 0x200(%rbx)
leaq 0x1efc4(%rip), %r15     # 0x3c57c
movslq (%r15), %rsi
movq 0x10(%rsp), %rdi
callq 0x1dc42
movslq (%r15), %rsi
movq %r13, %rdi
callq 0x1dcd8
movl (%r15), %ecx
testl %ecx, %ecx
jle 0x1d654
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 0x2d490
movq %r12, 0x8(%rsp)
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x1e062
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 0x1af10
movq %r12, 0x8(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x1e1b2
incq %rbp
movslq (%r15), %rcx
cmpq %rcx, %rbp
jl 0x1d5de
movl %ecx, %eax
testl %ecx, %ecx
je 0x1d6b0
leaq 0x1ef3b(%rip), %rdx     # 0x3c59c
xorps %xmm0, %xmm0
cvtsi2sdl (%rdx), %xmm0
leaq 0x1ef31(%rip), %rdx     # 0x3c5a0
divsd (%rdx), %xmm0
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
movq 0x10(%rsp), %rdx
movq (%rdx), %rdx
xorl %esi, %esi
leaq 0x1(%rsi), %rdi
movl %edi, %r8d
xorps %xmm1, %xmm1
cvtsi2sd %r8, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r8
movq (%rdx,%rsi,8), %rsi
movl %r8d, 0x208(%rsi)
movq %rdi, %rsi
cmpq %rdi, %rax
jne 0x1d685
testl %ecx, %ecx
jle 0x1d70a
xorl %ecx, %ecx
movq 0x200(%rbx), %rdx
movq 0x208(%rbx), %rsi
movq (%rsi,%rcx,8), %rsi
movq 0x208(%rdx), %rdx
movq %rsi, (%rdx,%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), %rdx
movq %rsi, 0x250(%rdx)
incq %rcx
cmpq %rcx, %rax
jne 0x1d6b6
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 0x1d751
jmp 0x1d75e
movq %rax, %rbp
movl $0x2a8, %esi            # imm = 0x2A8
jmp 0x1d74e
movq %rax, %rbp
movl $0x248, %esi            # imm = 0x248
jmp 0x1d74e
movq %rax, %rbp
movl $0x230, %esi            # imm = 0x230
jmp 0x1d74e
movq %rax, %rbp
movl $0x288, %esi            # imm = 0x288
movq %r12, %rdi
callq 0x4300
jmp 0x1d761
jmp 0x1d75e
jmp 0x1d75e
jmp 0x1d75e
movq %rax, %rbp
movq (%r13), %rdi
testq %rdi, %rdi
je 0x1d779
movq 0x230(%rbx), %rsi
subq %rdi, %rsi
callq 0x4300
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x1d795
movq 0x218(%rbx), %rsi
subq %rdi, %rsi
callq 0x4300
movq 0x18(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x1d7b1
movq 0x1f8(%rbx), %rsi
subq %rdi, %rsi
callq 0x4300
movq 0x20(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x1d7cd
movq 0x1e0(%rbx), %rsi
subq %rdi, %rsi
callq 0x4300
movq %rbx, %rdi
callq 0x17d50
movq %rbp, %rdi
callq 0x4540
nop