// File: /workspace/github_cpp_makefile_star2_O2/gvaumour[P]cache-simulator/src/DBAMBPredictor.cc
// Function: DBAMBPredictor::updateWindow(DHPEntry*)
void
DBAMBPredictor::updateWindow(DHPEntry* rap_current)
{

	if(rap_current->cptWindow < simu_parameters.window_size)
		rap_current->cptWindow++;
	else
	{
		RW_TYPE old_rw = rap_current->state_rw;
		RD_TYPE old_rd = rap_current->state_rd;
		allocDecision old_alloc = rap_current->des;
		
		determineStatus(rap_current);
		
		dataset_file << "Window:Dataset n°" << rap_current->id << ": NewWindow [" << str_RW_status[rap_current->state_rw] << "," \
		  	     << str_RD_status[rap_current->state_rd] << "]"  << endl;	
	

	
		if(!m_isWarmup)
			stats_ClassErrors[old_rd + NUM_RD_TYPE*old_rw][rap_current->state_rd + NUM_RD_TYPE*rap_current->state_rw]++;

		if(old_rd != rap_current->state_rd || old_rw != rap_current->state_rw)
		{
			HistoEntry current = {rap_current->state_rw , rap_current->state_rd, rap_current->nbKeepState};

			if(!m_isWarmup)
				rap_current->stats_history.push_back(current);

			rap_current->nbSwitchState++;
			rap_current->nbKeepState = 0;					

			rap_current->des = convertState(rap_current);
			if(old_alloc == ALLOCATE_PREEMPTIVELY &&  simu_parameters.writeDatasetFile)
			{	
				firstAlloc_dataset_file << std::hex << "0x" << rap_current->signature << std::dec << "\t" << rap_current->des << endl;	
			}
		}
		else{
			rap_current->nbKeepState++;
			rap_current->nbKeepCurrentState++;			
		}

		/* Reset the window */			
		rap_current->rd_history.clear();
		rap_current->rw_history.clear();
		rap_current->cptWindow = 0;		
	}	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movl 0x84(%rsi), %eax
leaq 0x319ae(%rip), %r15     # 0x3df50
cmpl 0xa0(%r15), %eax
jge 0xc5b2
incl %eax
jmp 0xc791
movq %rdi, %r14
movl 0x28(%rbx), %ebp
movl 0x98(%rbx), %r12d
movl 0x9c(%rbx), %r13d
movq %rbx, %rsi
callq 0xd658
leaq 0x31093(%rip), %rdi     # 0x3d668
leaq 0x1d5c7(%rip), %rsi     # 0x29ba3
callq 0x52c0
movl 0x18(%rbx), %esi
movq %rax, %rdi
callq 0x5560
leaq 0x1d5c3(%rip), %rsi     # 0x29bb6
movq %rax, %rdi
callq 0x52c0
movl 0x98(%rbx), %ecx
leaq 0x30df8(%rip), %rdx     # 0x3d400
movq (%rdx,%rcx,8), %rsi
movq %rax, %rdi
callq 0x52c0
leaq 0x1ca17(%rip), %rsi     # 0x29032
movq %rax, %rdi
callq 0x52c0
movl 0x9c(%rbx), %ecx
leaq 0x30e00(%rip), %rdx     # 0x3d430
movq (%rdx,%rcx,8), %rsi
movq %rax, %rdi
callq 0x52c0
leaq 0x1f8b7(%rip), %rsi     # 0x2befa
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
movb 0x81(%r14), %al
movl 0x98(%rbx), %edx
movl 0x9c(%rbx), %ecx
testb %al, %al
jne 0xc691
leal (%r12,%r12,2), %esi
addl %r13d, %esi
movslq %esi, %rsi
movq 0x3a0(%r14), %rdi
imulq $0x18, %rsi, %rsi
leal (%rdx,%rdx,2), %r8d
addl %ecx, %r8d
movslq %r8d, %r8
movq (%rdi,%rsi), %rsi
incl (%rsi,%r8,4)
xorl %ecx, %r13d
xorl %edx, %r12d
orl %r13d, %r12d
jne 0xc6ad
incl 0x8c(%rbx)
incl 0x94(%rbx)
jmp 0xc775
movl %edx, 0xc(%rsp)
movl %ecx, 0x10(%rsp)
movl 0x8c(%rbx), %ecx
movl %ecx, 0x14(%rsp)
testb %al, %al
jne 0xc6d4
leaq 0xa0(%rbx), %rdi
leaq 0xc(%rsp), %rsi
callq 0xe988
incl 0x90(%rbx)
andl $0x0, 0x8c(%rbx)
movq %rbx, %rsi
callq 0xd832
movl %eax, 0x28(%rbx)
cmpl $0x3, %ebp
jne 0xc775
cmpb $0x1, 0x15a(%r15)
jne 0xc775
leaq 0x31172(%rip), %rdi     # 0x3d878
leaq 0x3115b(%rip), %rax     # 0x3d868
movq 0x31164(%rip), %rcx     # 0x3d878
movq -0x18(%rcx), %rcx
movl 0x28(%rcx,%rax), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x28(%rcx,%rax)
leaq 0x1c9fb(%rip), %rsi     # 0x29128
callq 0x52c0
movq 0x20(%rbx), %rsi
movq %rax, %rdi
callq 0x5200
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0x1e4c9(%rip), %rsi     # 0x2ac23
movq %rax, %rdi
callq 0x52c0
movl 0x28(%rbx), %esi
movq %rax, %rdi
callq 0x5560
movq %rax, %rdi
callq 0x5190
movq 0x40(%rbx), %rax
cmpq %rax, 0x48(%rbx)
je 0xc783
movq %rax, 0x48(%rbx)
movq 0x58(%rbx), %rax
movq %rax, 0x68(%rbx)
andl $0x0, 0x70(%rbx)
xorl %eax, %eax
movl %eax, 0x84(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq