// File: estwings57[P]CasHMC/sources/HMCController.cpp
// Function: CasHMC::HMCController::HMCController(std::basic_ofstream<char, std::char_traits<char>>&, std::basic_ofstream<char, std::char_traits<char>>&)
HMCController::HMCController(ofstream &debugOut_, ofstream &stateOut_):
	DualVectorObject<Transaction, Packet>(debugOut_, stateOut_, MAX_REQ_BUF, MAX_LINK_BUF),
	readDone(NULL),
	writeDone(NULL)
{
	header = " (HC)";
	
	inServiceLink = -1;
	maxLinkBand = LINK_WIDTH * LINK_SPEED / 8;
	linkEpochCycle = ceil((double)LINK_EPOCH*1000000/CPU_CLK_PERIOD);
	requestAccLNG = 0;
	responseAccLNG = 0;
	sleepLink = 0;
	alloMSHR = 0;
	accuMSHR = 0;
	returnTransCnt = 0;
	quiesceClk = ceil((double)tQUIESCE/CPU_CLK_PERIOD);
	staggerSleep = 0;
	staggerActive = 0;
	staySREF = 0;
	stayActive = vector<uint64_t>(NUM_LINKS, ceil((double)tOP/CPU_CLK_PERIOD));
	quiesceLink = vector<uint64_t>(NUM_LINKS, quiesceClk);
	staggeringSleep = vector<bool>(NUM_LINKS, false);
	staggeringActive = vector<bool>(NUM_LINKS, false);
	modeTransition = vector<uint64_t>(NUM_LINKS, 0);
	
	linkSleepTime = vector<uint64_t>(NUM_LINKS, 0);
	linkDownTime = vector<uint64_t>(NUM_LINKS, 0);
	
	//Make class objects
	downLinkMasters.reserve(NUM_LINKS);
	upLinkSlaves.reserve(NUM_LINKS);
	for(int l=0; l<NUM_LINKS; l++) {
		downLinkMasters.push_back(new LinkMaster(debugOut, stateOut, l, true));
		upLinkSlaves.push_back(new LinkSlave(debugOut, stateOut, l, false));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x168(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x312b3(%rip), %rax     # 0x66544
movl (%rax), %ecx
leaq 0x312be(%rip), %rax     # 0x66558
movl (%rax), %r8d
callq 0x3a6a0
movq -0x168(%rbp), %rdi
leaq 0x30890(%rip), %rax     # 0x65b40
movq %rax, (%rdi)
addq $0x208, %rdi            # imm = 0x208
movq %rdi, -0x1b0(%rbp)
callq 0x295a0
movq -0x168(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
movq %rdi, -0x1a8(%rbp)
callq 0x324a0
movq -0x168(%rbp), %rdi
addq $0x288, %rdi            # imm = 0x288
movq %rdi, -0x1a0(%rbp)
callq 0x172c0
movq -0x168(%rbp), %rdi
addq $0x2a0, %rdi            # imm = 0x2A0
movq %rdi, -0x198(%rbp)
callq 0x172c0
movq -0x168(%rbp), %rdi
addq $0x2b8, %rdi            # imm = 0x2B8
movq %rdi, -0x190(%rbp)
callq 0x172c0
movq -0x168(%rbp), %rdi
addq $0x2d0, %rdi            # imm = 0x2D0
movq %rdi, -0x188(%rbp)
callq 0x22080
movq -0x168(%rbp), %rdi
addq $0x2f8, %rdi            # imm = 0x2F8
movq %rdi, -0x180(%rbp)
callq 0x22080
movq -0x168(%rbp), %rdi
addq $0x320, %rdi            # imm = 0x320
movq %rdi, -0x178(%rbp)
callq 0x172c0
movq -0x168(%rbp), %rdi
addq $0x338, %rdi            # imm = 0x338
movq %rdi, -0x170(%rbp)
callq 0x172c0
movq -0x168(%rbp), %rdi
movq $0x0, 0x350(%rdi)
movq $0x0, 0x358(%rdi)
addq $0x20, %rdi
leaq 0x1c50a(%rip), %rsi     # 0x518c8
callq 0x44e0
jmp 0x353c5
movq -0x168(%rbp), %rax
movl $0xffffffff, 0x238(%rax) # imm = 0xFFFFFFFF
leaq 0x3116f(%rip), %rcx     # 0x6654c
cvtsi2sdl (%rcx), %xmm0
leaq 0x31168(%rip), %rcx     # 0x66550
movsd (%rcx), %xmm1
mulsd %xmm1, %xmm0
movsd 0x1ddf0(%rip), %xmm1    # 0x531e8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
movl %ecx, 0x23c(%rax)
leaq 0x31182(%rip), %rax     # 0x66590
movsd (%rax), %xmm0
movsd 0x1ddd6(%rip), %xmm1    # 0x531f0
mulsd %xmm1, %xmm0
leaq 0x31113(%rip), %rax     # 0x66538
movq %rax, -0x1c8(%rbp)
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movq -0x168(%rbp), %rcx
movq -0x1c8(%rbp), %rax
cvttsd2si %xmm0, %rdx
movl %edx, 0x240(%rcx)
movq $0x0, 0x248(%rcx)
movq $0x0, 0x250(%rcx)
movl $0x0, 0x258(%rcx)
movl $0x0, 0x25c(%rcx)
movq $0x0, 0x260(%rcx)
movl $0x0, 0x268(%rcx)
leaq 0x31158(%rip), %rcx     # 0x665f0
movsd (%rcx), %xmm0
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movq -0x168(%rbp), %rcx
movq -0x1c8(%rbp), %rax
cvttsd2si %xmm0, %rdx
movl %edx, 0x26c(%rcx)
movq $0x0, 0x270(%rcx)
movq $0x0, 0x278(%rcx)
movq $0x0, 0x280(%rcx)
leaq 0x3105e(%rip), %rcx     # 0x66548
movslq (%rcx), %rcx
movq %rcx, -0x1c0(%rbp)
leaq 0x310ed(%rip), %rcx     # 0x665e8
movsd (%rcx), %xmm0
movsd (%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x40a0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x1dcd5(%rip), %xmm1    # 0x531f8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x48(%rbp)
leaq -0x49(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x17820
movq -0x1c0(%rbp), %rsi
movq -0x1b8(%rbp), %rcx
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x17840
jmp 0x35563
movq -0x168(%rbp), %rdi
addq $0x288, %rdi            # imm = 0x288
leaq -0x40(%rbp), %rsi
movq %rsi, -0x1e0(%rbp)
callq 0x178c0
movq -0x1e0(%rbp), %rdi
callq 0x178f0
leaq -0x49(%rbp), %rdi
callq 0x17950
movq -0x168(%rbp), %rax
leaq 0x30fa4(%rip), %rcx     # 0x66548
movslq (%rcx), %rcx
movq %rcx, -0x1d8(%rbp)
movl 0x26c(%rax), %eax
movq %rax, -0x70(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x17820
movq -0x1d8(%rbp), %rsi
movq -0x1d0(%rbp), %rcx
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x17840
jmp 0x355e5
movq -0x168(%rbp), %rdi
addq $0x2a0, %rdi            # imm = 0x2A0
leaq -0x68(%rbp), %rsi
movq %rsi, -0x1f8(%rbp)
callq 0x178c0
movq -0x1f8(%rbp), %rdi
callq 0x178f0
leaq -0x71(%rbp), %rdi
callq 0x17950
leaq 0x30f29(%rip), %rax     # 0x66548
movslq (%rax), %rax
movq %rax, -0x1f0(%rbp)
movb $0x0, -0xa1(%rbp)
leaq -0xa2(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x220e0
movq -0x1f0(%rbp), %rsi
movq -0x1e8(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
leaq -0xa1(%rbp), %rdx
callq 0x22100
jmp 0x35666
movq -0x168(%rbp), %rdi
addq $0x2d0, %rdi            # imm = 0x2D0
leaq -0xa0(%rbp), %rsi
movq %rsi, -0x210(%rbp)
callq 0x22180
movq -0x210(%rbp), %rdi
callq 0x221f0
leaq -0xa2(%rbp), %rdi
callq 0x22210
leaq 0x30ea2(%rip), %rax     # 0x66548
movslq (%rax), %rax
movq %rax, -0x208(%rbp)
movb $0x0, -0xd1(%rbp)
leaq -0xd2(%rbp), %rdi
movq %rdi, -0x200(%rbp)
callq 0x220e0
movq -0x208(%rbp), %rsi
movq -0x200(%rbp), %rcx
leaq -0xd0(%rbp), %rdi
leaq -0xd1(%rbp), %rdx
callq 0x22100
jmp 0x356ed
movq -0x168(%rbp), %rdi
addq $0x2f8, %rdi            # imm = 0x2F8
leaq -0xd0(%rbp), %rsi
movq %rsi, -0x228(%rbp)
callq 0x22180
movq -0x228(%rbp), %rdi
callq 0x221f0
leaq -0xd2(%rbp), %rdi
callq 0x22210
leaq 0x30e1b(%rip), %rax     # 0x66548
movslq (%rax), %rax
movq %rax, -0x220(%rbp)
movq $0x0, -0xf8(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x17820
movq -0x220(%rbp), %rsi
movq -0x218(%rbp), %rcx
leaq -0xf0(%rbp), %rdi
leaq -0xf8(%rbp), %rdx
callq 0x17840
jmp 0x35778
movq -0x168(%rbp), %rdi
addq $0x2b8, %rdi            # imm = 0x2B8
leaq -0xf0(%rbp), %rsi
movq %rsi, -0x240(%rbp)
callq 0x178c0
movq -0x240(%rbp), %rdi
callq 0x178f0
leaq -0xf9(%rbp), %rdi
callq 0x17950
leaq 0x30d90(%rip), %rax     # 0x66548
movslq (%rax), %rax
movq %rax, -0x238(%rbp)
movq $0x0, -0x120(%rbp)
leaq -0x121(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x17820
movq -0x238(%rbp), %rsi
movq -0x230(%rbp), %rcx
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rdx
callq 0x17840
jmp 0x35803
movq -0x168(%rbp), %rdi
addq $0x320, %rdi            # imm = 0x320
leaq -0x118(%rbp), %rsi
movq %rsi, -0x258(%rbp)
callq 0x178c0
movq -0x258(%rbp), %rdi
callq 0x178f0
leaq -0x121(%rbp), %rdi
callq 0x17950
leaq 0x30d05(%rip), %rax     # 0x66548
movslq (%rax), %rax
movq %rax, -0x250(%rbp)
movq $0x0, -0x148(%rbp)
leaq -0x149(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x17820
movq -0x250(%rbp), %rsi
movq -0x248(%rbp), %rcx
leaq -0x140(%rbp), %rdi
leaq -0x148(%rbp), %rdx
callq 0x17840
jmp 0x3588e
movq -0x168(%rbp), %rdi
addq $0x338, %rdi            # imm = 0x338
leaq -0x140(%rbp), %rsi
movq %rsi, -0x260(%rbp)
callq 0x178c0
movq -0x260(%rbp), %rdi
callq 0x178f0
leaq -0x149(%rbp), %rdi
callq 0x17950
movq -0x168(%rbp), %rdi
addq $0x208, %rdi            # imm = 0x208
leaq 0x30c6c(%rip), %rax     # 0x66548
movslq (%rax), %rsi
callq 0x32600
jmp 0x358e6
movq -0x168(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
leaq 0x30c4d(%rip), %rax     # 0x66548
movslq (%rax), %rsi
callq 0x32500
jmp 0x35905
movl $0x0, -0x150(%rbp)
movl -0x150(%rbp), %eax
leaq 0x30c2c(%rip), %rcx     # 0x66548
cmpl (%rcx), %eax
jge 0x35b28
movq -0x168(%rbp), %rax
addq $0x208, %rax            # imm = 0x208
movq %rax, -0x270(%rbp)
movl $0x288, %edi            # imm = 0x288
callq 0x4390
movq %rax, -0x268(%rbp)
jmp 0x3594b
movq -0x268(%rbp), %rdi
movq -0x168(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
movl -0x150(%rbp), %ecx
movl $0x1, %r8d
callq 0x3c270
jmp 0x35974
movq -0x270(%rbp), %rdi
movq -0x268(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0x158(%rbp), %rsi
callq 0x32730
jmp 0x35997
movq -0x168(%rbp), %rax
addq $0x220, %rax            # imm = 0x220
movq %rax, -0x280(%rbp)
movl $0x230, %edi            # imm = 0x230
callq 0x4390
movq %rax, -0x278(%rbp)
jmp 0x359be
movq -0x278(%rbp), %rdi
movq -0x168(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
movl -0x150(%rbp), %ecx
xorl %r8d, %r8d
callq 0x40d50
jmp 0x359e4
movq -0x280(%rbp), %rdi
movq -0x278(%rbp), %rax
movq %rax, -0x160(%rbp)
leaq -0x160(%rbp), %rsi
callq 0x32700
jmp 0x35a07
jmp 0x35a09
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
jmp 0x3590f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x35b31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x49(%rbp), %rdi
callq 0x17950
jmp 0x35b31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x17950
jmp 0x35b31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xa2(%rbp), %rdi
callq 0x22210
jmp 0x35b31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xd2(%rbp), %rdi
callq 0x22210
jmp 0x35b31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xf9(%rbp), %rdi
callq 0x17950
jmp 0x35b31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x121(%rbp), %rdi
callq 0x17950
jmp 0x35b31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x149(%rbp), %rdi
callq 0x17950
jmp 0x35b31
movq -0x268(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x288, %esi            # imm = 0x288
callq 0x43a0
jmp 0x35b31
movq -0x278(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x230, %esi            # imm = 0x230
callq 0x43a0
jmp 0x35b31
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
movq -0x170(%rbp), %rdi
callq 0x178f0
movq -0x178(%rbp), %rdi
callq 0x178f0
movq -0x180(%rbp), %rdi
callq 0x221f0
movq -0x188(%rbp), %rdi
callq 0x221f0
movq -0x190(%rbp), %rdi
callq 0x178f0
movq -0x198(%rbp), %rdi
callq 0x178f0
movq -0x1a0(%rbp), %rdi
callq 0x178f0
movq -0x1a8(%rbp), %rdi
callq 0x32ac0
movq -0x1b0(%rbp), %rdi
callq 0x29800
movq -0x168(%rbp), %rdi
callq 0x3aa30
movq -0x20(%rbp), %rdi
callq 0x4630
nopw %cs:(%rax,%rax)