// File: /workspace/github_cpp_makefile_star2_O1/estwings57[P]CasHMC/sources/HMCController.cpp
// Function: CasHMC::HMCController::LinkPowerStateManager()
void HMCController::LinkPowerStateManager()
{
	switch(LINK_POWER) {
		case NO_MANAGEMENT:
		case QUIESCE_SLEEP:{
			break;
		}
		case MSHR:{
			linkEpochCycle--;
			//control the number of active link in every one epoch
			if(linkEpochCycle == 0) {
				//The average allocated MSHR size
				double aveMSHR = accuMSHR/((double)LINK_EPOCH*1000000/CPU_CLK_PERIOD);
				aveMSHR *= MSHR_SCALING;
				
				if(aveMSHR >= 4) {
					sleepLink = 0;
				}
				else if(aveMSHR >= 3) {
					sleepLink = 1;
				}
				else if(aveMSHR >= 2) {
					sleepLink = 2;
				}
				else {
					sleepLink = 3;
				}
				DEBUG(ALI(33)<<header<<"Down) epoch average MSHR size : "<<aveMSHR);
				
				//link epoch cycle reset
				accuMSHR = 0;
				linkEpochCycle = ceil((double)LINK_EPOCH*1000000/CPU_CLK_PERIOD);
			}
			break;
		}
		case LINK_MONITOR:{
			linkEpochCycle--;
			//control the number of active link in every one epoch
			if(linkEpochCycle == 0) {
				//( ( total FLIT length * 16 bytes) / one epoch time ) * 1000 ms / 1000000000 B = [GB/s]
				double epochDownBandwidth = LINK_SCALING*((requestAccLNG*16)/LINK_EPOCH)/1000000;
				double epochUpBandwidth = LINK_SCALING*((responseAccLNG*16)/LINK_EPOCH)/1000000;
				if(epochDownBandwidth >= maxLinkBand*3 || epochUpBandwidth >= maxLinkBand*3) {
					sleepLink = 0;
				}
				else if(epochDownBandwidth >= maxLinkBand*2 || epochUpBandwidth >= maxLinkBand*2) {
					sleepLink = 1;
				}
				else if(epochDownBandwidth >= maxLinkBand || epochUpBandwidth >= maxLinkBand) {
					sleepLink = 2;
				}
				else {
					sleepLink = 3;
				}

				DEBUG(ALI(33)<<header<<"Down) epoch link BANDWIDTH downstream : "<<epochDownBandwidth<<" GB/s | upstream : "<<epochUpBandwidth<<" GB/s (sleepLink : "<<sleepLink<<")");
				
				//packet accumulated length and link epoch cycle reset
				requestAccLNG = 0;
				responseAccLNG = 0;
				linkEpochCycle = ceil((double)LINK_EPOCH*1000000/CPU_CLK_PERIOD);
			}
			break;
		}
		case AUTONOMOUS:{
			linkEpochCycle--;
			//control the number of active link in every one epoch
			if(linkEpochCycle == 0) {
				//The average MSHR size
				double aveMSHR = accuMSHR/((double)LINK_EPOCH*1000000/CPU_CLK_PERIOD);
				aveMSHR *= MSHR_SCALING;
				//( ( total FLIT length * 16 bytes) / one epoch time ) * 1000 ms / 1000000000 B = [GB/s]
				double epochDownBandwidth = LINK_SCALING*((requestAccLNG*16)/LINK_EPOCH)/1000000;
				double epochUpBandwidth = LINK_SCALING*((responseAccLNG*16)/LINK_EPOCH)/1000000;
				if(aveMSHR >= 4 || epochDownBandwidth >= maxLinkBand*3 || epochUpBandwidth >= maxLinkBand*3) {
					sleepLink = 0;
				}
				else if(aveMSHR >= 3 || epochDownBandwidth >= maxLinkBand*2 || epochUpBandwidth >= maxLinkBand*2) {
					sleepLink = 1;
				}
				else if(aveMSHR >= 2 || epochDownBandwidth >= maxLinkBand || epochUpBandwidth >= maxLinkBand) {
					sleepLink = 2;
				}
				else {
					sleepLink = 3;
				}
				
				DEBUG(ALI(33)<<header<<"Down) epoch average MSHR size : "<<aveMSHR);
				DEBUG(ALI(33)<<header<<"Down) epoch link BANDWIDTH downstream : "<<epochDownBandwidth<<" GB/s | upstream : "<<epochUpBandwidth<<" GB/s (sleepLink : "<<sleepLink<<")");

				//packet accumulated length and link epoch cycle reset
				accuMSHR = 0;
				requestAccLNG = 0;
				responseAccLNG = 0;
				linkEpochCycle = ceil((double)LINK_EPOCH*1000000/CPU_CLK_PERIOD);
			}
			break;
		}
		default:{
			ERROR(header<<"   == Error - WRONG LINK_POWER parameter  (LINK_POWER : "<<LINK_POWER<<")");
			exit(0);
			break;
		}
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0x1c08d(%rip), %r14     # 0x3c4e8
movl (%r14), %eax
cmpq $0x4, %rax
ja 0x20bd4
leaq 0x12e89(%rip), %rcx     # 0x332f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
decl 0x240(%rbx)
jne 0x20bc8
movsd 0x260(%rbx), %xmm0
unpcklps 0x10c6d(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x10c55(%rip), %xmm0    # 0x310f0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
leaq 0x1c046(%rip), %rax     # 0x3c4f0
movsd (%rax), %xmm1
mulsd 0x12d2a(%rip), %xmm1    # 0x331e0
addsd %xmm0, %xmm2
leaq 0x1bfd7(%rip), %rax     # 0x3c498
divsd (%rax), %xmm1
divsd %xmm1, %xmm2
leaq 0x1c028(%rip), %rax     # 0x3c4f8
mulsd (%rax), %xmm2
ucomisd 0x12d14(%rip), %xmm2    # 0x331f0
jae 0x2095c
ucomisd 0x12d0e(%rip), %xmm2    # 0x331f8
jae 0x20977
ucomisd 0x12d08(%rip), %xmm2    # 0x33200
jae 0x20992
movl $0x3, 0x258(%rbx)
jmp 0x2099c
decl 0x240(%rbx)
jne 0x20bc8
movsd 0x260(%rbx), %xmm0
movsd 0x10bd7(%rip), %xmm1    # 0x31100
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x10bbc(%rip), %xmm2    # 0x310f0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm6
unpckhpd %xmm0, %xmm6            # xmm6 = xmm6[1],xmm0[1]
addsd %xmm0, %xmm6
leaq 0x1bfa5(%rip), %rax     # 0x3c4f0
movsd (%rax), %xmm3
movsd 0x12c89(%rip), %xmm0    # 0x331e0
movq 0x248(%rbx), %rax
movq 0x250(%rbx), %rcx
shlq $0x4, %rax
movq %rax, %xmm4
punpckldq %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
subpd %xmm2, %xmm4
movapd %xmm4, %xmm5
unpckhpd %xmm4, %xmm5            # xmm5 = xmm5[1],xmm4[1]
addsd %xmm4, %xmm5
divsd %xmm3, %xmm5
shlq $0x4, %rcx
movq %rcx, %xmm4
punpckldq %xmm1, %xmm4    # xmm4 = xmm4[0],xmm1[0],xmm4[1],xmm1[1]
subpd %xmm2, %xmm4
movapd %xmm4, %xmm2
unpckhpd %xmm4, %xmm2            # xmm2 = xmm2[1],xmm4[1]
addsd %xmm4, %xmm2
divsd %xmm3, %xmm2
mulsd %xmm0, %xmm3
leaq 0x1bee6(%rip), %rax     # 0x3c498
divsd (%rax), %xmm3
divsd %xmm3, %xmm6
leaq 0x1bf37(%rip), %rax     # 0x3c4f8
mulsd (%rax), %xmm6
leaq 0x1bf34(%rip), %rax     # 0x3c500
movsd (%rax), %xmm1
mulsd %xmm1, %xmm5
divsd %xmm0, %xmm5
mulsd %xmm1, %xmm2
divsd %xmm0, %xmm2
xorl %eax, %eax
ucomisd 0x12c06(%rip), %xmm6    # 0x331f0
jae 0x20665
movl 0x23c(%rbx), %ecx
leal (%rcx,%rcx,2), %edx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
ucomisd %xmm0, %xmm5
jae 0x20665
ucomisd %xmm0, %xmm2
jae 0x20665
movl $0x1, %eax
ucomisd 0x12be2(%rip), %xmm6    # 0x331f8
jae 0x20665
leal (%rcx,%rcx), %edx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
ucomisd %xmm0, %xmm5
jae 0x20665
ucomisd %xmm0, %xmm2
jae 0x20665
movl $0x2, %eax
ucomisd 0x12bc4(%rip), %xmm6    # 0x33200
jae 0x20665
movl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movapd %xmm0, %xmm1
cmpnlepd %xmm2, %xmm1
cmpnlepd %xmm5, %xmm0
andpd %xmm1, %xmm0
movd %xmm0, %ecx
movl $0x2, %eax
subl %ecx, %eax
movl %eax, 0x258(%rbx)
leaq 0x1be16(%rip), %r12     # 0x3c488
cmpb $0x1, (%r12)
jne 0x20737
leaq 0x1be05(%rip), %rax     # 0x3c489
cmpb $0x0, (%rax)
jne 0x20737
movapd %xmm6, 0x20(%rsp)
movapd %xmm2, 0x10(%rsp)
movapd %xmm5, (%rsp)
movq 0x1b92b(%rip), %rax     # 0x3bfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x21, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r14
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x206e3
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x1b8d6(%rip), %rdi     # 0x3bfd0
callq 0x4340
movq %rax, %r14
leaq 0x12ebc(%rip), %rsi     # 0x335c5
movl $0x20, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movapd 0x20(%rsp), %xmm0
callq 0x4460
movq %rax, %rdi
callq 0x4170
movapd (%rsp), %xmm5
movapd 0x10(%rsp), %xmm2
leaq 0x248(%rbx), %r15
cmpb $0x1, (%r12)
jne 0x20851
leaq 0x1bd39(%rip), %rax     # 0x3c489
cmpb $0x0, (%rax)
jne 0x20851
movapd %xmm2, 0x10(%rsp)
movapd %xmm5, (%rsp)
movq 0x1b865(%rip), %rax     # 0x3bfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x21, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r14
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x207a9
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x1b810(%rip), %rdi     # 0x3bfd0
callq 0x4340
movq %rax, %r14
leaq 0x12e17(%rip), %rsi     # 0x335e6
movl $0x28, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movaps (%rsp), %xmm0
callq 0x4460
movq %rax, %r14
leaq 0x12e1d(%rip), %rsi     # 0x3360f
movl $0x13, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movapd 0x10(%rsp), %xmm0
callq 0x4460
movq %rax, %r14
leaq 0x12e0c(%rip), %rsi     # 0x33623
movl $0x13, %edx
movq %rax, %rdi
callq 0x4340
movl 0x258(%rbx), %esi
movq %r14, %rdi
callq 0x41e0
movq %rax, %r14
leaq 0x13c25(%rip), %rsi     # 0x34461
movl $0x1, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
callq 0x4170
movq $0x0, 0x260(%rbx)
jmp 0x20b8e
decl 0x240(%rbx)
jne 0x20bc8
leaq 0x1bc8c(%rip), %rax     # 0x3c500
movsd (%rax), %xmm0
movq 0x248(%rbx), %rax
shlq $0x4, %rax
movq %rax, %xmm1
movq 0x10870(%rip), %xmm2    # 0x31100
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x10854(%rip), %xmm3    # 0x310f0
subpd %xmm3, %xmm1
movapd %xmm1, %xmm6
unpckhpd %xmm1, %xmm6            # xmm6 = xmm6[1],xmm1[1]
addsd %xmm1, %xmm6
leaq 0x1bc3d(%rip), %rax     # 0x3c4f0
movsd (%rax), %xmm1
divsd %xmm1, %xmm6
mulsd %xmm0, %xmm6
movsd 0x12919(%rip), %xmm4    # 0x331e0
divsd %xmm4, %xmm6
movq 0x250(%rbx), %rax
shlq $0x4, %rax
movq %rax, %xmm5
punpckldq %xmm2, %xmm5    # xmm5 = xmm5[0],xmm2[0],xmm5[1],xmm2[1]
subpd %xmm3, %xmm5
movapd %xmm5, %xmm2
unpckhpd %xmm5, %xmm2            # xmm2 = xmm2[1],xmm5[1]
addsd %xmm5, %xmm2
divsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
divsd %xmm4, %xmm2
movl 0x23c(%rbx), %eax
leal (%rax,%rax,2), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
ucomisd %xmm0, %xmm6
jae 0x20968
ucomisd %xmm0, %xmm2
jae 0x20968
leal (%rax,%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
ucomisd %xmm0, %xmm6
jae 0x20983
ucomisd %xmm0, %xmm2
jae 0x20983
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
ucomisd %xmm0, %xmm6
jae 0x20a65
ucomisd %xmm0, %xmm2
jae 0x20a65
movl $0x3, 0x258(%rbx)
jmp 0x20a6f
movl $0x0, 0x258(%rbx)
jmp 0x2099c
movl $0x0, 0x258(%rbx)
jmp 0x20a6f
movl $0x1, 0x258(%rbx)
jmp 0x2099c
movl $0x1, 0x258(%rbx)
jmp 0x20a6f
movl $0x2, 0x258(%rbx)
leaq 0x1bae5(%rip), %rax     # 0x3c488
cmpb $0x1, (%rax)
jne 0x20a4e
leaq 0x1bad6(%rip), %rax     # 0x3c489
cmpb $0x0, (%rax)
jne 0x20a4e
movapd %xmm2, (%rsp)
movq 0x1b608(%rip), %rax     # 0x3bfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x21, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r14
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x20a06
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x1b5b3(%rip), %rdi     # 0x3bfd0
callq 0x4340
movq %rax, %r14
leaq 0x12b99(%rip), %rsi     # 0x335c5
movl $0x20, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movapd (%rsp), %xmm0
callq 0x4460
movq %rax, %rdi
callq 0x4170
movq $0x0, 0x260(%rbx)
addq $0x240, %rbx            # imm = 0x240
jmp 0x20b9e
movl $0x2, 0x258(%rbx)
leaq 0x248(%rbx), %r15
leaq 0x1ba0b(%rip), %rax     # 0x3c488
cmpb $0x1, (%rax)
jne 0x20b8e
leaq 0x1b9fc(%rip), %rax     # 0x3c489
cmpb $0x0, (%rax)
jne 0x20b8e
movapd %xmm2, 0x10(%rsp)
movapd %xmm6, (%rsp)
movq 0x1b528(%rip), %rax     # 0x3bfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x21, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %r14
cmpb $0x0, 0xe1(%rax,%rcx)
jne 0x20ae6
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x1b4d3(%rip), %rdi     # 0x3bfd0
callq 0x4340
movq %rax, %r14
leaq 0x12ada(%rip), %rsi     # 0x335e6
movl $0x28, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movaps (%rsp), %xmm0
callq 0x4460
movq %rax, %r14
leaq 0x12ae0(%rip), %rsi     # 0x3360f
movl $0x13, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movapd 0x10(%rsp), %xmm0
callq 0x4460
movq %rax, %r14
leaq 0x12acf(%rip), %rsi     # 0x33623
movl $0x13, %edx
movq %rax, %rdi
callq 0x4340
movl 0x258(%rbx), %esi
movq %r14, %rdi
callq 0x41e0
movq %rax, %r14
leaq 0x138e8(%rip), %rsi     # 0x34461
movl $0x1, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
callq 0x4170
addq $0x240, %rbx            # imm = 0x240
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
leaq 0x1b94b(%rip), %rax     # 0x3c4f0
movsd (%rax), %xmm0
mulsd 0x1262f(%rip), %xmm0    # 0x331e0
leaq 0x1b8e0(%rip), %rax     # 0x3c498
divsd (%rax), %xmm0
callq 0x4090
cvttsd2si %xmm0, %rax
movl %eax, (%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x1b415(%rip), %rdi     # 0x3bff0
leaq 0x10440(%rip), %rsi     # 0x31022
callq 0x42e0
leaq 0x127b1(%rip), %rsi     # 0x3339f
movq %rax, %rdi
callq 0x42e0
leaq 0x10c3a(%rip), %rsi     # 0x31837
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x254, %esi            # imm = 0x254
callq 0x4500
leaq 0x10428(%rip), %rsi     # 0x31041
movq %rax, %rdi
callq 0x42e0
addq $0x20, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4290
leaq 0x12955(%rip), %rsi     # 0x3358c
movq %rax, %rdi
callq 0x42e0
movl (%r14), %esi
movq %rax, %rdi
callq 0x4500
leaq 0x13810(%rip), %rsi     # 0x34461
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
xorl %edi, %edi
callq 0x4360