// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
leaq 0x1b877(%rip), %r14     # 0x3b4e8
movl (%r14), %eax
cmpq $0x4, %rax
ja 0x203cf
leaq 0x126fb(%rip), %rcx     # 0x32380
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
decl 0x240(%rbx)
jne 0x203c1
movsd 0x260(%rbx), %xmm1
unpcklps 0x10477(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1045f(%rip), %xmm1    # 0x30110
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
leaq 0x1b830(%rip), %r15     # 0x3b4f0
movsd (%r15), %xmm0
mulsd 0x12583(%rip), %xmm0    # 0x32250
addsd %xmm1, %xmm2
leaq 0x1b7c0(%rip), %r12     # 0x3b498
divsd (%r12), %xmm0
divsd %xmm0, %xmm2
leaq 0x1b80f(%rip), %rax     # 0x3b4f8
mulsd (%rax), %xmm2
ucomisd 0x1256b(%rip), %xmm2    # 0x32260
jae 0x20157
ucomisd 0x12565(%rip), %xmm2    # 0x32268
jae 0x20172
ucomisd 0x1255f(%rip), %xmm2    # 0x32270
jae 0x2018d
movl $0x3, 0x258(%rbx)
jmp 0x20197
decl 0x240(%rbx)
jne 0x203c1
movsd 0x260(%rbx), %xmm0
unpcklps 0x103df(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x103c7(%rip), %xmm0    # 0x30110
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
leaq 0x1b794(%rip), %r15     # 0x3b4f0
movsd (%r15), %xmm0
movsd 0x124e7(%rip), %xmm1    # 0x32250
mulsd %xmm0, %xmm1
leaq 0x1b724(%rip), %r12     # 0x3b498
divsd (%r12), %xmm1
divsd %xmm1, %xmm3
leaq 0x1b773(%rip), %rax     # 0x3b4f8
mulsd (%rax), %xmm3
leaq 0x1b770(%rip), %rax     # 0x3b500
movdqu 0x248(%rbx), %xmm1
psllq $0x4, %xmm1
movdqa 0x1038b(%rip), %xmm2    # 0x30130
pand %xmm1, %xmm2
por 0x1038f(%rip), %xmm2    # 0x30140
psrlq $0x20, %xmm1
por 0x10392(%rip), %xmm1    # 0x30150
subpd 0x1039a(%rip), %xmm1    # 0x30160
addpd %xmm2, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
divpd %xmm0, %xmm1
movsd (%rax), %xmm2
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm1, %xmm2
divpd 0x1249a(%rip), %xmm2    # 0x32280
xorl %eax, %eax
ucomisd 0x12470(%rip), %xmm3    # 0x32260
jae 0x1fe6e
movl 0x23c(%rbx), %ecx
leal (%rcx,%rcx,2), %edx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
ucomisd %xmm1, %xmm2
jae 0x1fe6e
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
ucomisd %xmm1, %xmm0
jae 0x1fe6e
movl $0x1, %eax
ucomisd 0x12444(%rip), %xmm3    # 0x32268
jae 0x1fe6e
leal (%rcx,%rcx), %edx
xorps %xmm1, %xmm1
cvtsi2sd %rdx, %xmm1
ucomisd %xmm1, %xmm2
jae 0x1fe6e
ucomisd %xmm1, %xmm0
jae 0x1fe6e
movl $0x2, %eax
ucomisd 0x12426(%rip), %xmm3    # 0x32270
jae 0x1fe6e
movl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
cmpnlepd %xmm2, %xmm0
movmskpd %xmm0, %ecx
xorl %eax, %eax
cmpl $0x3, %ecx
sete %al
orl $0x2, %eax
movl %eax, 0x258(%rbx)
leaq 0x1b60d(%rip), %r13     # 0x3b488
movb (%r13), %al
cmpb $0x1, %al
jne 0x1ff32
leaq 0x1b5fb(%rip), %rcx     # 0x3b489
cmpb $0x0, (%rcx)
jne 0x1ff32
movapd %xmm3, 0x10(%rsp)
movapd %xmm2, (%rsp)
movq 0x1b127(%rip), %rax     # 0x3afd0
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 0x1fee0
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x1b0d9(%rip), %rdi     # 0x3afd0
callq 0x4340
movq %rax, %r14
leaq 0x12747(%rip), %rsi     # 0x3264d
movl $0x20, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movapd 0x10(%rsp), %xmm0
callq 0x4460
movq %rax, %rdi
callq 0x4170
movb (%r13), %al
movapd (%rsp), %xmm2
leaq 0x248(%rbx), %r13
testb $0x1, %al
je 0x2003f
leaq 0x1b541(%rip), %rax     # 0x3b489
cmpb $0x0, (%rax)
jne 0x2003f
movapd %xmm2, (%rsp)
movq 0x1b073(%rip), %rax     # 0x3afd0
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 0x1ff94
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x1b025(%rip), %rdi     # 0x3afd0
callq 0x4340
movq %rax, %r14
leaq 0x126b4(%rip), %rsi     # 0x3266e
movl $0x28, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movaps (%rsp), %xmm0
callq 0x4460
movq %rax, %r14
leaq 0x126ba(%rip), %rsi     # 0x32697
movl $0x13, %edx
movq %rax, %rdi
callq 0x4340
movapd (%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movq %r14, %rdi
callq 0x4460
movq %rax, %r14
leaq 0x126a6(%rip), %rsi     # 0x326ab
movl $0x13, %edx
movq %rax, %rdi
callq 0x4340
movl 0x258(%rbx), %esi
movq %r14, %rdi
callq 0x41e0
movq %rax, %r14
leaq 0x134b7(%rip), %rsi     # 0x334e1
movl $0x1, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
callq 0x4170
movq $0x0, 0x260(%rbx)
addq $0x240, %rbx            # imm = 0x240
xorpd %xmm0, %xmm0
movupd %xmm0, (%r13)
movsd (%r15), %xmm0
mulsd 0x121e8(%rip), %xmm0    # 0x32250
divsd (%r12), %xmm0
jmp 0x203b5
decl 0x240(%rbx)
jne 0x203c1
leaq 0x1b47a(%rip), %rax     # 0x3b500
movdqu 0x248(%rbx), %xmm1
psllq $0x4, %xmm1
movdqa 0x10095(%rip), %xmm2    # 0x30130
pand %xmm1, %xmm2
por 0x10099(%rip), %xmm2    # 0x30140
leaq 0x1b442(%rip), %r15     # 0x3b4f0
psrlq $0x20, %xmm1
por 0x10095(%rip), %xmm1    # 0x30150
movsd (%r15), %xmm0
subpd 0x10098(%rip), %xmm1    # 0x30160
addpd %xmm2, %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
divpd %xmm2, %xmm1
movsd (%rax), %xmm3
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd %xmm1, %xmm3
divpd 0x12194(%rip), %xmm3    # 0x32280
movl 0x23c(%rbx), %eax
leal (%rax,%rax,2), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm3
movapd %xmm3, %xmm2
unpckhpd %xmm3, %xmm2            # xmm2 = xmm2[1],xmm3[1]
jae 0x20163
ucomisd %xmm1, %xmm2
jae 0x20163
leal (%rax,%rax), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
ucomisd %xmm1, %xmm3
jae 0x2017e
ucomisd %xmm1, %xmm2
jae 0x2017e
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
cmpnlepd %xmm3, %xmm1
movmskpd %xmm1, %eax
cmpl $0x3, %eax
jne 0x2026b
movl $0x3, 0x258(%rbx)
jmp 0x20275
movl $0x0, 0x258(%rbx)
jmp 0x20197
movl $0x0, 0x258(%rbx)
jmp 0x20275
movl $0x1, 0x258(%rbx)
jmp 0x20197
movl $0x1, 0x258(%rbx)
jmp 0x20275
movl $0x2, 0x258(%rbx)
leaq 0x1b2ea(%rip), %rax     # 0x3b488
cmpb $0x1, (%rax)
jne 0x20254
leaq 0x1b2db(%rip), %rax     # 0x3b489
cmpb $0x0, (%rax)
jne 0x20254
movapd %xmm2, (%rsp)
movq 0x1ae0d(%rip), %rax     # 0x3afd0
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 0x201fa
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x1adbf(%rip), %rdi     # 0x3afd0
callq 0x4340
movq %rax, %r14
leaq 0x1242d(%rip), %rsi     # 0x3264d
movl $0x20, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movaps (%rsp), %xmm0
callq 0x4460
movq %rax, %rdi
callq 0x4170
movsd (%r15), %xmm0
mulsd 0x12002(%rip), %xmm0    # 0x32250
divsd (%r12), %xmm0
movq $0x0, 0x260(%rbx)
addq $0x240, %rbx            # imm = 0x240
jmp 0x203b5
movl $0x2, 0x258(%rbx)
leaq 0x248(%rbx), %r12
leaq 0x1b205(%rip), %rax     # 0x3b488
cmpb $0x1, (%rax)
jne 0x20391
leaq 0x1b1f6(%rip), %rax     # 0x3b489
cmpb $0x0, (%rax)
jne 0x20391
movapd %xmm3, 0x10(%rsp)
movapd %xmm2, (%rsp)
movq 0x1ad22(%rip), %rax     # 0x3afd0
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 0x202e5
movq %r14, %rdi
movl $0x20, %esi
callq 0x42d0
movb $0x1, 0xe1(%r14)
movb $0x20, 0xe0(%r14)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
movq 0x1acd4(%rip), %rdi     # 0x3afd0
callq 0x4340
movq %rax, %r14
leaq 0x12363(%rip), %rsi     # 0x3266e
movl $0x28, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movaps 0x10(%rsp), %xmm0
callq 0x4460
movq %rax, %r14
leaq 0x12368(%rip), %rsi     # 0x32697
movl $0x13, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
movaps (%rsp), %xmm0
callq 0x4460
movq %rax, %r14
leaq 0x12359(%rip), %rsi     # 0x326ab
movl $0x13, %edx
movq %rax, %rdi
callq 0x4340
movl 0x258(%rbx), %esi
movq %r14, %rdi
callq 0x41e0
movq %rax, %r14
leaq 0x1316a(%rip), %rsi     # 0x334e1
movl $0x1, %edx
movq %rax, %rdi
callq 0x4340
movq %r14, %rdi
callq 0x4170
movsd (%r15), %xmm0
addq $0x240, %rbx            # imm = 0x240
mulsd 0x11eb0(%rip), %xmm0    # 0x32250
xorpd %xmm1, %xmm1
movupd %xmm1, (%r12)
leaq 0x1b0e7(%rip), %rax     # 0x3b498
divsd (%rax), %xmm0
callq 0x4090
cvttsd2si %xmm0, %rax
movl %eax, (%rbx)
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x1ac1a(%rip), %rdi     # 0x3aff0
leaq 0xfc45(%rip), %rsi      # 0x30022
callq 0x42e0
leaq 0x1203e(%rip), %rsi     # 0x32427
movq %rax, %rdi
callq 0x42e0
leaq 0x1049f(%rip), %rsi     # 0x30897
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
movl $0x254, %esi            # imm = 0x254
callq 0x4500
leaq 0xfc2d(%rip), %rsi      # 0x30041
movq %rax, %rdi
callq 0x42e0
addq $0x20, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4290
leaq 0x121e2(%rip), %rsi     # 0x32614
movq %rax, %rdi
callq 0x42e0
movl (%r14), %esi
movq %rax, %rdi
callq 0x4500
leaq 0x13095(%rip), %rsi     # 0x334e1
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
callq 0x4170
xorl %edi, %edi
callq 0x4360
nop