// File: 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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x68(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x21ff0
movq -0x68(%rbp), %rdi
leaq 0x34039(%rip), %rax     # 0x65b00
movq %rax, (%rdi)
addq $0x1d0, %rdi            # imm = 0x1D0
movq %rdi, -0x60(%rbp)
callq 0x324a0
movq -0x68(%rbp), %rdi
addq $0x1e8, %rdi            # imm = 0x1E8
movq %rdi, -0x80(%rbp)
callq 0x295a0
movq -0x68(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movq %rdi, -0x78(%rbp)
callq 0x324c0
movq -0x68(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
movq %rdi, -0x70(%rbp)
callq 0x324e0
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rdi
movq $0x1, 0x1c8(%rax)
leaq 0x34a18(%rip), %rax     # 0x66548
movslq (%rax), %rsi
callq 0x32500
jmp 0x31b3a
movq -0x68(%rbp), %rdi
addq $0x1e8, %rdi            # imm = 0x1E8
leaq 0x349fc(%rip), %rax     # 0x66548
movslq (%rax), %rsi
callq 0x32600
jmp 0x31b56
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
leaq 0x349e1(%rip), %rcx     # 0x66548
cmpl (%rcx), %eax
jge 0x31c99
movq -0x68(%rbp), %rax
addq $0x1d0, %rax            # imm = 0x1D0
movq %rax, -0x90(%rbp)
movl $0x230, %edi            # imm = 0x230
callq 0x4390
movq %rax, -0x88(%rbp)
jmp 0x31b93
movq -0x88(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
movl -0x28(%rbp), %ecx
movl $0x1, %r8d
callq 0x40d50
jmp 0x31bb6
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rsi
callq 0x32700
jmp 0x31bd3
movq -0x68(%rbp), %rax
addq $0x1e8, %rax            # imm = 0x1E8
movq %rax, -0xa0(%rbp)
movl $0x288, %edi            # imm = 0x288
callq 0x4390
movq %rax, -0x98(%rbp)
jmp 0x31bf7
movq -0x98(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
movl -0x28(%rbp), %ecx
xorl %r8d, %r8d
callq 0x3c270
jmp 0x31c17
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x38(%rbp), %rsi
callq 0x32730
jmp 0x31c34
jmp 0x31c36
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x31b5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x32003
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x230, %esi            # imm = 0x230
callq 0x43a0
jmp 0x32003
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x288, %esi            # imm = 0x288
callq 0x43a0
jmp 0x32003
movl $0x270, %edi            # imm = 0x270
callq 0x4390
movq %rax, -0xa8(%rbp)
jmp 0x31cac
movq -0xa8(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
callq 0x27370
jmp 0x31cc6
movq -0x68(%rbp), %rdi
movq -0xa8(%rbp), %rax
movq %rax, 0x200(%rdi)
addq $0x208, %rdi            # imm = 0x208
leaq 0x34936(%rip), %rax     # 0x6661c
movslq (%rax), %rsi
callq 0x32760
jmp 0x31cf0
movq -0x68(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
leaq 0x3491a(%rip), %rax     # 0x6661c
movslq (%rax), %rsi
callq 0x32860
jmp 0x31d0c
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
leaq 0x348ff(%rip), %rcx     # 0x6661c
cmpl (%rcx), %eax
jge 0x31e91
movq -0x68(%rbp), %rax
addq $0x208, %rax            # imm = 0x208
movq %rax, -0xb8(%rbp)
movl $0x2a8, %edi            # imm = 0x2A8
callq 0x4390
movq %rax, -0xb0(%rbp)
jmp 0x31d49
movq -0xb0(%rbp), %rdi
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
movl -0x3c(%rbp), %ecx
callq 0x4bdd0
jmp 0x31d66
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x32960
jmp 0x31d83
movq -0x68(%rbp), %rax
addq $0x220, %rax            # imm = 0x220
movq %rax, -0xc8(%rbp)
movl $0x248, %edi            # imm = 0x248
callq 0x4390
movq %rax, -0xc0(%rbp)
jmp 0x31da7
movq -0x68(%rbp), %rdi
movq 0x10(%rdi), %rax
movq %rax, -0xe0(%rbp)
movq 0x18(%rdi), %rax
movq %rax, -0xd8(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0xcc(%rbp)
addq $0x208, %rdi            # imm = 0x208
movslq %eax, %rsi
callq 0x329c0
movq -0xc0(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movl -0xcc(%rbp), %ecx
movq (%rax), %r8
callq 0x2cc10
jmp 0x31dfe
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rsi
callq 0x32990
jmp 0x31e1b
jmp 0x31e1d
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x31d13
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x270, %esi            # imm = 0x270
callq 0x43a0
jmp 0x32003
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x2a8, %esi            # imm = 0x2A8
callq 0x43a0
jmp 0x32003
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x248, %esi            # imm = 0x248
callq 0x43a0
jmp 0x32003
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
leaq 0x3477a(%rip), %rcx     # 0x6661c
cmpl (%rcx), %eax
jae 0x31f17
movq -0x68(%rbp), %rdi
leaq 0x3478b(%rip), %rax     # 0x6663c
cvtsi2sdl (%rax), %xmm0
leaq 0x34784(%rip), %rax     # 0x66640
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
leaq 0x34751(%rip), %rax     # 0x6661c
cvtsi2sdl (%rax), %xmm1
divsd %xmm1, %xmm0
movl -0x54(%rbp), %eax
incl %eax
cvtsi2sd %rax, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0xe4(%rbp)
addq $0x208, %rdi            # imm = 0x208
movl -0x54(%rbp), %eax
movl %eax, %esi
callq 0x329c0
movl -0xe4(%rbp), %ecx
movq (%rax), %rax
movl %ecx, 0x208(%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x31e98
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
leaq 0x346f4(%rip), %rcx     # 0x6661c
cmpl (%rcx), %eax
jge 0x31ffa
movq -0x68(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x58(%rbp), %rsi
callq 0x329c0
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x100(%rbp)
movq 0x200(%rax), %rdi
addq $0x208, %rdi            # imm = 0x208
movslq -0x58(%rbp), %rsi
callq 0x29d40
movq -0x100(%rbp), %rcx
movq -0x68(%rbp), %rdi
movq %rcx, (%rax)
addq $0x220, %rdi            # imm = 0x220
movslq -0x58(%rbp), %rsi
callq 0x329e0
movq -0x68(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
addq $0x208, %rdi            # imm = 0x208
movslq -0x58(%rbp), %rsi
callq 0x329c0
movq -0xf8(%rbp), %rcx
movq -0x68(%rbp), %rdi
movq (%rax), %rax
movq %rcx, 0x210(%rax)
movq 0x200(%rdi), %rax
movq %rax, -0xf0(%rbp)
addq $0x208, %rdi            # imm = 0x208
movslq -0x58(%rbp), %rsi
callq 0x329c0
movq -0xf0(%rbp), %rcx
movq (%rax), %rax
movq %rcx, 0x250(%rax)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x31f1e
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x32a00
movq -0x78(%rbp), %rdi
callq 0x32a60
movq -0x80(%rbp), %rdi
callq 0x29800
movq -0x60(%rbp), %rdi
callq 0x32ac0
movq -0x68(%rbp), %rdi
callq 0x22e30
movq -0x20(%rbp), %rdi
callq 0x4630
nopl (%rax)