// File: 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:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rax
movl 0x84(%rax), %eax
leaq 0x78596(%rip), %rcx     # 0x93ff0
cmpl 0xa0(%rcx), %eax
jge 0x1ba7b
movq 0x28(%rsp), %rax
movl 0x84(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x84(%rax)
jmp 0x1bd42
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rax
movl 0x98(%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x28(%rsp), %rax
movl 0x9c(%rax), %eax
movl %eax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movl 0x28(%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x28(%rsp), %rsi
callq 0x1dd70
leaq 0x77c4d(%rip), %rdi     # 0x93708
leaq 0x560f1(%rip), %rsi     # 0x71bb3
callq 0x5380
movq %rax, %rdi
movq 0x28(%rsp), %rax
movl 0x18(%rax), %esi
callq 0x5680
movq %rax, %rdi
leaq 0x560e5(%rip), %rsi     # 0x71bc6
callq 0x5380
movq %rax, %rdi
movq 0x28(%rsp), %rax
movl 0x98(%rax), %eax
movl %eax, %ecx
leaq 0x779a3(%rip), %rax     # 0x934a0
movq (%rax,%rcx,8), %rsi
callq 0x5380
movq %rax, %rdi
leaq 0x55532(%rip), %rsi     # 0x71042
callq 0x5380
movq %rax, %rdi
movq 0x28(%rsp), %rax
movl 0x9c(%rax), %eax
movl %eax, %ecx
leaq 0x779a4(%rip), %rax     # 0x934d0
movq (%rax,%rcx,8), %rsi
callq 0x5380
movq %rax, %rdi
leaq 0x583b5(%rip), %rsi     # 0x73ef4
callq 0x5380
movq %rax, %rdi
movq 0x7746a(%rip), %rsi     # 0x92fb8
callq 0x53d0
movq 0x8(%rsp), %rax
testb $0x1, 0x81(%rax)
jne 0x1bbab
movq 0x8(%rsp), %rdi
addq $0x3a0, %rdi            # imm = 0x3A0
movl 0x20(%rsp), %eax
imull $0x3, 0x24(%rsp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0xef70
movq %rax, %rdi
movq 0x28(%rsp), %rax
movl 0x9c(%rax), %eax
movq 0x28(%rsp), %rcx
imull $0x3, 0x98(%rcx), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0xef90
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl 0x20(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl 0x9c(%rcx), %eax
jne 0x1bbd1
movl 0x24(%rsp), %eax
movq 0x28(%rsp), %rcx
cmpl 0x98(%rcx), %eax
je 0x1bcef
movq 0x8(%rsp), %rax
movq 0x28(%rsp), %rcx
movl 0x98(%rcx), %ecx
movl %ecx, 0x10(%rsp)
movq 0x28(%rsp), %rcx
movl 0x9c(%rcx), %ecx
movl %ecx, 0x14(%rsp)
movq 0x28(%rsp), %rcx
movl 0x8c(%rcx), %ecx
movl %ecx, 0x18(%rsp)
testb $0x1, 0x81(%rax)
jne 0x1bc22
movq 0x28(%rsp), %rdi
addq $0xa0, %rdi
leaq 0x10(%rsp), %rsi
callq 0x20d50
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rax
movl 0x90(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x90(%rax)
movq 0x28(%rsp), %rax
movl $0x0, 0x8c(%rax)
movq 0x28(%rsp), %rsi
callq 0x1e340
movl %eax, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x28(%rax)
cmpl $0x3, 0x1c(%rsp)
jne 0x1bced
leaq 0x78380(%rip), %rax     # 0x93ff0
testb $0x1, 0x15a(%rax)
je 0x1bced
leaq 0x77c88(%rip), %rdi     # 0x93908
addq $0x10, %rdi
leaq -0xc48b(%rip), %rsi     # 0xf800
callq 0x5160
movq %rax, %rdi
leaq 0x5549e(%rip), %rsi     # 0x71138
callq 0x5380
movq %rax, %rdi
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rsi
callq 0x50f0
movq %rax, %rdi
leaq -0xc49a(%rip), %rsi     # 0xf820
callq 0x5160
movq %rax, %rdi
leaq 0x56f9a(%rip), %rsi     # 0x72c63
callq 0x5380
movq %rax, %rdi
movq 0x28(%rsp), %rax
movl 0x28(%rax), %esi
callq 0x5680
movq %rax, %rdi
movq 0x772d0(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1bd17
movq 0x28(%rsp), %rax
movl 0x8c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8c(%rax)
movq 0x28(%rsp), %rax
movl 0x94(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x94(%rax)
movq 0x28(%rsp), %rdi
addq $0x40, %rdi
callq 0x20c50
movq 0x28(%rsp), %rdi
addq $0x58, %rdi
callq 0x20c70
movq 0x28(%rsp), %rax
movl $0x0, 0x84(%rax)
addq $0x38, %rsp
retq
nopw (%rax,%rax)