// File: /workspace/github_cpp_makefile_star2_O2/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 0x10de6
leaq 0x1b3bb(%rip), %rax     # 0x30b08
movq %rax, (%rbx)
leaq 0x1d0(%rbx), %rdi
leaq 0x1e8(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x208(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x220(%rbx), %rax
movq %rax, 0x10(%rsp)
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 0x1bce7(%rip), %r13     # 0x314a8
movslq (%r13), %rsi
movq %rdi, 0x20(%rsp)
callq 0x15d38
movslq (%r13), %rsi
movq 0x18(%rsp), %rdi
callq 0x15dce
xorl %ebp, %ebp
pushq $0x1
popq %r15
movq %rsp, %r12
cmpl (%r13), %ebp
jge 0x15856
movl $0x230, %edi            # imm = 0x230
callq 0x4310
movq %rax, %r14
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %rax, %rdi
movl %ebp, %ecx
movl %r15d, %r8d
callq 0x1c81c
movq %r14, (%rsp)
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x16068
movl $0x288, %edi            # imm = 0x288
callq 0x4310
movq %rax, %r14
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %rax, %rdi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x19ef4
movq %r14, (%rsp)
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x161a8
incl %ebp
jmp 0x157e6
movl $0x270, %edi            # imm = 0x270
callq 0x4310
movq %rax, %r14
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %rax, %rdi
callq 0x122a4
movq %r14, 0x200(%rbx)
leaq 0x1bcfb(%rip), %r13     # 0x3157c
movslq (%r13), %rsi
movq 0x8(%rsp), %rdi
callq 0x15e64
movslq (%r13), %rsi
movq 0x10(%rsp), %rdi
callq 0x15efa
xorl %ebp, %ebp
movq %rsp, %r15
movslq (%r13), %rax
cmpq %rax, %rbp
jge 0x1591b
movl $0x2a8, %edi            # imm = 0x2A8
callq 0x4310
movq %rax, %r14
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq %rax, %rdi
movl %ebp, %ecx
callq 0x214a4
movq %r14, (%rsp)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x16360
movl $0x248, %edi            # imm = 0x248
callq 0x4310
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 0x13bfc
movq %r12, (%rsp)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x164a0
incq %rbp
jmp 0x158a2
movl %eax, %eax
leaq 0x1bc78(%rip), %rcx     # 0x3159c
cvtsi2sdl (%rcx), %xmm0
leaq 0x1bc71(%rip), %rcx     # 0x315a0
divsd (%rcx), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x15969
movq (%rcx,%rdx,8), %rsi
incq %rdx
movl %edx, %edi
cvtsi2sd %rdi, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rdi
movl %edi, 0x208(%rsi)
jmp 0x15945
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
cmpq %rcx, %rax
je 0x159c6
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
jmp 0x15970
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbp
movl $0x270, %esi            # imm = 0x270
jmp 0x15a0a
jmp 0x15a1a
movq %rax, %rbp
movl $0x2a8, %esi            # imm = 0x2A8
jmp 0x15a0a
movq %rax, %rbp
movl $0x248, %esi            # imm = 0x248
movq %r12, %rdi
jmp 0x15a0d
movq %rax, %rbp
movl $0x230, %esi            # imm = 0x230
jmp 0x15a0a
movq %rax, %rbp
movl $0x288, %esi            # imm = 0x288
movq %r14, %rdi
callq 0x4320
jmp 0x15a1d
jmp 0x15a1a
jmp 0x15a1a
jmp 0x15a1a
movq %rax, %rbp
movq 0x10(%rsp), %rdi
callq 0x15ff8
movq 0x8(%rsp), %rdi
callq 0x15fc4
movq 0x18(%rsp), %rdi
callq 0x136ac
movq 0x20(%rsp), %rdi
callq 0x15f90
movq %rbx, %rdi
callq 0x11246
movq %rbp, %rdi
callq 0x4520
nop