// File: /workspace/github_cpp_makefile_star2_O1/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 0x37170(%rip), %rcx     # 0x45f50
cmpl 0xa0(%rcx), %eax
jge 0xedef
incl %eax
jmp 0xf0e1
movq %rdi, %r14
movl 0x28(%rbx), %eax
movl %eax, 0x8(%rsp)
movl 0x98(%rbx), %ebp
movl 0x9c(%rbx), %r13d
movq %rbx, %rsi
callq 0x1051c
leaq 0x36853(%rip), %r15     # 0x45668
leaq 0x25dc7(%rip), %rsi     # 0x34be3
movl $0x12, %edx
movq %r15, %rdi
callq 0x5350
movl 0x18(%rbx), %esi
movq %r15, %rdi
callq 0x5580
movq %rax, %r15
leaq 0x25db8(%rip), %rsi     # 0x34bf6
movl $0xd, %edx
movq %rax, %rdi
callq 0x5350
movl 0x98(%rbx), %eax
leaq 0x365a8(%rip), %rcx     # 0x45400
movq (%rcx,%rax,8), %r12
testq %r12, %r12
je 0xee79
movq %r12, %rdi
callq 0x5160
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x5350
jmp 0xee91
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x5560
leaq 0x251aa(%rip), %rsi     # 0x34042
movl $0x1, %edx
movq %r15, %rdi
callq 0x5350
movl 0x9c(%rbx), %eax
leaq 0x3657e(%rip), %rcx     # 0x45430
movq (%rcx,%rax,8), %r12
testq %r12, %r12
je 0xeed3
movq %r12, %rdi
callq 0x5160
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x5350
jmp 0xeeed
movq (%r15), %rax
movq -0x18(%rax), %rax
movq %r15, %rdi
addq %rax, %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x5560
leaq 0x2805e(%rip), %rsi     # 0x36f52
movl $0x1, %edx
movq %r15, %rdi
callq 0x5350
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movb 0x81(%r14), %al
testb %al, %al
jne 0xef64
leal (%rbp,%rbp,2), %ecx
addl %r13d, %ecx
movslq %ecx, %rcx
movq 0x3a0(%r14), %rdx
leaq (%rcx,%rcx,2), %rcx
movslq 0x9c(%rbx), %rsi
movslq 0x98(%rbx), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rsi, %rdi
movq (%rdx,%rcx,8), %rcx
incl (%rcx,%rdi,4)
movl 0x9c(%rbx), %ecx
cmpl %ecx, %r13d
jne 0xef88
cmpl 0x98(%rbx), %ebp
jne 0xef88
incl 0x8c(%rbx)
incl 0x94(%rbx)
jmp 0xf0c2
movl 0x98(%rbx), %edx
movl %edx, 0xc(%rsp)
movl %ecx, 0x10(%rsp)
movl 0x8c(%rbx), %ecx
movl %ecx, 0x14(%rsp)
testb %al, %al
jne 0xefde
movq 0xa8(%rbx), %rsi
cmpq 0xb0(%rbx), %rsi
je 0xefcd
movl 0x14(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0xc(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0xa8(%rbx)
jmp 0xefde
leaq 0xa0(%rbx), %rdi
leaq 0xc(%rsp), %rdx
callq 0x12d6a
incl 0x90(%rbx)
movl $0x0, 0x8c(%rbx)
movq %rbx, %rsi
callq 0x106c0
movl %eax, 0x28(%rbx)
cmpl $0x3, 0x8(%rsp)
jne 0xf0c2
leaq 0x36f45(%rip), %rax     # 0x45f50
cmpb $0x1, 0x15a(%rax)
jne 0xf0c2
leaq 0x36859(%rip), %r14     # 0x45878
leaq 0x36842(%rip), %rax     # 0x45868
movq 0x3684b(%rip), %rcx     # 0x45878
movq -0x18(%rcx), %rcx
movl 0x28(%rcx,%rax), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x28(%rcx,%rax)
leaq 0x250f2(%rip), %rsi     # 0x34138
movl $0x2, %edx
movq %r14, %rdi
callq 0x5350
movq 0x20(%rbx), %rsi
movq %r14, %rdi
callq 0x51e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rax
movl 0x18(%r14,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, 0x18(%r14,%rax)
leaq 0x26bfb(%rip), %rsi     # 0x35c7b
movl $0x1, %edx
movq %r14, %rdi
callq 0x5350
movl 0x28(%rbx), %esi
movq %r14, %rdi
callq 0x5580
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq 0x40(%rbx), %rax
cmpq %rax, 0x48(%rbx)
je 0xf0d0
movq %rax, 0x48(%rbx)
movq 0x58(%rbx), %rax
movq %rax, 0x68(%rbx)
movl $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