// File: gvaumour[P]cache-simulator/src/DBAMBPredictor.cc
// Function: DBAMBPredictor::printStats(std::ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void 
DBAMBPredictor::printStats(std::ostream& out, string entete)
{	

	
	ofstream output_file(RAP_OUTPUT_FILE);
	
	for(int i = 0 ; i < NUM_RW_TYPE ;i++)
	{
		for(int j = 0 ; j < NUM_RD_TYPE ; j++)
			output_file << "\t[" << str_RW_status[i] << ","<< str_RD_status[j] << "]";
	}
	output_file << endl;
	
	for(unsigned i = 0 ; i < stats_ClassErrors.size() ; i++)
	{
		output_file << "[" << str_RW_status[i/NUM_RD_TYPE] << ","<< str_RD_status[i%NUM_RD_TYPE] << "]\t";
		for(unsigned j = 0 ; j < stats_ClassErrors[i].size() ; j++)
		{
			output_file << stats_ClassErrors[i][j] << "\t";
		}
		output_file << endl;
	}
	output_file.close();


	double migrationNVM=0, migrationSRAM = 0;

	if(simu_parameters.enableMigration)
	{

		ofstream file_migration_stats(RAP_MIGRATION_STATS);
		
		for(unsigned i = 0 ; i < stats_nbMigrationsFromNVM.size() ; i++)
		{
			migrationNVM += stats_nbMigrationsFromNVM[i][FROMNVM];
			migrationSRAM += stats_nbMigrationsFromNVM[i][FROMSRAM];			
			
			file_migration_stats << stats_nbMigrationsFromNVM[i][FROMNVM] << "\t" << stats_nbMigrationsFromNVM[i][FROMSRAM] << endl;	
		}
		file_migration_stats.close();
	}
	/*
	out << "\tRAP Table:" << endl;
	out << "\t\t NB Hits\t" << stats_RAP_hits << endl;
	out << "\t\t NB Miss\t" << stats_RAP_miss << endl;
	out << "\t\t Miss Ratio\t" << stats_RAP_miss*100.0/(double)(stats_RAP_hits+stats_RAP_miss)<< "%" << endl;
	*/
	
	/*out << "\tSource of Error, NVM error" << endl;
	out << "\t\tWrong Policy\t" << stats_error_wrongpolicy << endl;
	out << "\t\tWrong Allocation\t" << stats_error_wrongallocation << endl;
	out << "\t\tLearning\t" << stats_error_learning << endl;		
	*/
	/*
	if(simu_parameters.enableMigration)
		out << "\t\tMigration Error\t" << migrationSRAM << endl;		
	*/
	out << entete << ":DBAMBPredictor:NVM_medium_pred\t" << stats_NVM_medium_pred << endl;
	out << entete << ":DBAMBPredictor:NVM_medium_pred_errors\t" << stats_NVM_medium_pred_errors << endl;
	out << entete << ":DBAMBPredictor:BusynessMigrate\t" << stats_busyness_migrate_change << endl;
	out << entete << ":DBAMBPredictor:BusynessAlloc\t" << stats_busyness_alloc_change << endl;
	out << entete << ":DBAMBPredictor:AllocateSRAM\t" << stats_allocate_SRAM << endl;
	out << entete << ":DBAMBPredictor:AllocateNVM\t" << stats_allocate_NVM << endl;
	
//	out << "\tSource of Error, SRAM error" << endl;
//	out << "\t\tWrong Policy\t" << stats_error_SRAMwrongpolicy << endl;
//	out << "\t\tWrong Allocation\t" << stats_error_SRAMwrongallocation << endl;
//	out << "\t\tLearning\t" << stats_error_SRAMlearning << endl;		
	
	
	/*
	if(stats_nbSwitchDst.size() > 0)
	{
		double sum=0;
		for(auto d : stats_nbSwitchDst)
			sum+= d;
		out << "\t Average Switch\t" << sum / (double) stats_nbSwitchDst.size() << endl;	
	}*/
	


	double total = migrationNVM+migrationSRAM;

	if(total > 0){
		out << entete << ":DBAMBPredictor:NBMigration\t" << total << endl;
		out << entete << ":DBAMBPredictor:MigrationFromNVM\t" << migrationNVM << "\t" << migrationNVM*100/total << "%" << endl;
		out << entete << ":DBAMBPredictor:MigrationFromSRAM\t" << migrationSRAM << "\t" << migrationSRAM*100/total << "%" << endl;
	}
	
	Predictor::printStats(out, entete);
}

// Assembly:
subq $0x628, %rsp            # imm = 0x628
movq %rdx, 0x1a0(%rsp)
movq %rdi, 0x620(%rsp)
movq %rsi, 0x618(%rsp)
movq %rdx, 0x610(%rsp)
movq 0x620(%rsp), %rax
movq %rax, 0x1a8(%rsp)
leaq 0x410(%rsp), %rdi
leaq 0x52caf(%rip), %rsi     # 0x71cc5
movl $0x10, %edx
callq 0x53f0
movl $0x0, 0x40c(%rsp)
cmpl $0x5, 0x40c(%rsp)
jge 0x1f141
movl $0x0, 0x408(%rsp)
cmpl $0x3, 0x408(%rsp)
jge 0x1f129
leaq 0x52c7e(%rip), %rsi     # 0x71cd7
leaq 0x410(%rsp), %rdi
callq 0x5380
movq %rax, 0x198(%rsp)
jmp 0x1f070
movq 0x198(%rsp), %rdi
movslq 0x40c(%rsp), %rcx
leaq 0x74419(%rip), %rax     # 0x934a0
movq (%rax,%rcx,8), %rsi
callq 0x5380
movq %rax, 0x190(%rsp)
jmp 0x1f09a
movq 0x190(%rsp), %rdi
leaq 0x51f99(%rip), %rsi     # 0x71042
callq 0x5380
movq %rax, 0x188(%rsp)
jmp 0x1f0b8
movq 0x188(%rsp), %rdi
movslq 0x408(%rsp), %rcx
leaq 0x74401(%rip), %rax     # 0x934d0
movq (%rax,%rcx,8), %rsi
callq 0x5380
movq %rax, 0x180(%rsp)
jmp 0x1f0e2
movq 0x180(%rsp), %rdi
leaq 0x54e03(%rip), %rsi     # 0x73ef4
callq 0x5380
jmp 0x1f0f8
jmp 0x1f0fa
movl 0x408(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x408(%rsp)
jmp 0x1f044
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x400(%rsp)
movl %eax, 0x3fc(%rsp)
jmp 0x1fb0b
jmp 0x1f12b
movl 0x40c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40c(%rsp)
jmp 0x1f02b
movq 0x73e70(%rip), %rsi     # 0x92fb8
leaq 0x410(%rsp), %rdi
callq 0x53d0
jmp 0x1f157
movl $0x0, 0x3f8(%rsp)
movq 0x1a8(%rsp), %rdi
movl 0x3f8(%rsp), %eax
movq %rax, 0x178(%rsp)
addq $0x3a0, %rdi            # imm = 0x3A0
callq 0xfb20
movq %rax, %rcx
movq 0x178(%rsp), %rax
cmpq %rcx, %rax
jae 0x1f35a
leaq 0x52b38(%rip), %rsi     # 0x71cd8
leaq 0x410(%rsp), %rdi
callq 0x5380
movq %rax, 0x170(%rsp)
jmp 0x1f1b7
movq 0x170(%rsp), %rdi
movl 0x3f8(%rsp), %eax
movl %eax, %ecx
movl $0xaaaaaaab, %eax       # imm = 0xAAAAAAAB
imulq %rax, %rcx
shrq $0x21, %rcx
leaq 0x742c4(%rip), %rax     # 0x934a0
movq (%rax,%rcx,8), %rsi
callq 0x5380
movq %rax, 0x168(%rsp)
jmp 0x1f1ef
movq 0x168(%rsp), %rdi
leaq 0x51e44(%rip), %rsi     # 0x71042
callq 0x5380
movq %rax, 0x160(%rsp)
jmp 0x1f20d
movq 0x160(%rsp), %rdi
movl 0x3f8(%rsp), %eax
movl %eax, %ecx
movl %ecx, %eax
movl $0xaaaaaaab, %edx       # imm = 0xAAAAAAAB
imulq %rdx, %rcx
shrq $0x21, %rcx
movl %ecx, %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
movl %eax, %ecx
leaq 0x74291(%rip), %rax     # 0x934d0
movq (%rax,%rcx,8), %rsi
callq 0x5380
movq %rax, 0x158(%rsp)
jmp 0x1f252
movq 0x158(%rsp), %rdi
leaq 0x52a79(%rip), %rsi     # 0x71cda
callq 0x5380
jmp 0x1f268
movl $0x0, 0x3f4(%rsp)
movq 0x1a8(%rsp), %rdi
movl 0x3f4(%rsp), %eax
movq %rax, 0x150(%rsp)
addq $0x3a0, %rdi            # imm = 0x3A0
movl 0x3f8(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
callq 0x11020
movq %rax, %rcx
movq 0x150(%rsp), %rax
cmpq %rcx, %rax
jae 0x1f32c
movq 0x1a8(%rsp), %rdi
addq $0x3a0, %rdi            # imm = 0x3A0
movl 0x3f8(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
movl 0x3f4(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl (%rax), %esi
leaq 0x410(%rsp), %rdi
callq 0x5680
movq %rax, 0x148(%rsp)
jmp 0x1f2fe
movq 0x148(%rsp), %rdi
leaq 0x53956(%rip), %rsi     # 0x72c63
callq 0x5380
jmp 0x1f314
jmp 0x1f316
movl 0x3f4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3f4(%rsp)
jmp 0x1f273
movq 0x73c85(%rip), %rsi     # 0x92fb8
leaq 0x410(%rsp), %rdi
callq 0x53d0
jmp 0x1f342
jmp 0x1f344
movl 0x3f8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3f8(%rsp)
jmp 0x1f162
leaq 0x410(%rsp), %rdi
callq 0x5550
jmp 0x1f369
xorps %xmm0, %xmm0
movsd %xmm0, 0x3e8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x3e0(%rsp)
leaq 0x74c68(%rip), %rax     # 0x93ff0
testb $0x1, 0xa9(%rax)
je 0x1f592
leaq 0x52941(%rip), %rsi     # 0x71cdd
leaq 0x1e0(%rsp), %rdi
movl $0x10, %edx
callq 0x53f0
jmp 0x1f3b0
movl $0x0, 0x1dc(%rsp)
movq 0x1a8(%rsp), %rdi
movl 0x1dc(%rsp), %eax
movq %rax, 0x140(%rsp)
addq $0x3b8, %rdi            # imm = 0x3B8
callq 0xfb20
movq %rax, %rcx
movq 0x140(%rsp), %rax
cmpq %rcx, %rax
jae 0x1f576
movq 0x1a8(%rsp), %rdi
addq $0x3b8, %rdi            # imm = 0x3B8
movq %rdi, 0x128(%rsp)
movl 0x1dc(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
movq %rsi, 0x130(%rsp)
callq 0xef90
movq 0x128(%rsp), %rdi
cvtsi2sdl (%rax), %xmm1
movsd 0x3e8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x3e8(%rsp)
movl 0x1dc(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
movl $0x1, %esi
callq 0xef90
movq 0x128(%rsp), %rdi
cvtsi2sdl (%rax), %xmm1
movsd 0x3e0(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x3e0(%rsp)
movl 0x1dc(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq 0x130(%rsp), %rsi
movq %rax, %rdi
callq 0xef90
movl (%rax), %esi
leaq 0x1e0(%rsp), %rdi
callq 0x5680
movq %rax, 0x138(%rsp)
jmp 0x1f4c1
movq 0x138(%rsp), %rdi
leaq 0x53793(%rip), %rsi     # 0x72c63
callq 0x5380
movq %rax, 0x120(%rsp)
jmp 0x1f4df
movq 0x1a8(%rsp), %rdi
addq $0x3b8, %rdi            # imm = 0x3B8
movl 0x1dc(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
movl $0x1, %esi
callq 0xef90
movq 0x120(%rsp), %rdi
movl (%rax), %esi
callq 0x5680
movq %rax, 0x118(%rsp)
jmp 0x1f522
movq 0x118(%rsp), %rdi
movq 0x73a87(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1f538
jmp 0x1f53a
movl 0x1dc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1dc(%rsp)
jmp 0x1f3bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x400(%rsp)
movl %eax, 0x3fc(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x5770
jmp 0x1fb0b
leaq 0x1e0(%rsp), %rdi
callq 0x5550
jmp 0x1f585
leaq 0x1e0(%rsp), %rdi
callq 0x5770
movq 0x1a0(%rsp), %rsi
movq 0x618(%rsp), %rdi
callq 0x5330
movq %rax, 0x110(%rsp)
jmp 0x1f5b1
movq 0x110(%rsp), %rdi
leaq 0x52735(%rip), %rsi     # 0x71cf5
callq 0x5380
movq %rax, 0x108(%rsp)
jmp 0x1f5cf
movq 0x108(%rsp), %rdi
movq 0x1a8(%rsp), %rax
movl 0x374(%rax), %esi
callq 0x5510
movq %rax, 0x100(%rsp)
jmp 0x1f5f4
movq 0x100(%rsp), %rdi
movq 0x739b5(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1f60a
movq 0x1a0(%rsp), %rsi
movq 0x618(%rsp), %rdi
callq 0x5330
movq %rax, 0xf8(%rsp)
jmp 0x1f629
movq 0xf8(%rsp), %rdi
leaq 0x526de(%rip), %rsi     # 0x71d16
callq 0x5380
movq %rax, 0xf0(%rsp)
jmp 0x1f647
movq 0xf0(%rsp), %rdi
movq 0x1a8(%rsp), %rax
movl 0x370(%rax), %esi
callq 0x5510
movq %rax, 0xe8(%rsp)
jmp 0x1f66c
movq 0xe8(%rsp), %rdi
movq 0x7393d(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1f682
movq 0x1a0(%rsp), %rsi
movq 0x618(%rsp), %rdi
callq 0x5330
movq %rax, 0xe0(%rsp)
jmp 0x1f6a1
movq 0xe0(%rsp), %rdi
leaq 0x5268e(%rip), %rsi     # 0x71d3e
callq 0x5380
movq %rax, 0xd8(%rsp)
jmp 0x1f6bf
movq 0xd8(%rsp), %rdi
movq 0x1a8(%rsp), %rax
movq 0x380(%rax), %rsi
callq 0x50f0
movq %rax, 0xd0(%rsp)
jmp 0x1f6e5
movq 0xd0(%rsp), %rdi
movq 0x738c4(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1f6fb
movq 0x1a0(%rsp), %rsi
movq 0x618(%rsp), %rdi
callq 0x5330
movq %rax, 0xc8(%rsp)
jmp 0x1f71a
movq 0xc8(%rsp), %rdi
leaq 0x52636(%rip), %rsi     # 0x71d5f
callq 0x5380
movq %rax, 0xc0(%rsp)
jmp 0x1f738
movq 0xc0(%rsp), %rdi
movq 0x1a8(%rsp), %rax
movq 0x378(%rax), %rsi
callq 0x50f0
movq %rax, 0xb8(%rsp)
jmp 0x1f75e
movq 0xb8(%rsp), %rdi
movq 0x7384b(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1f774
movq 0x1a0(%rsp), %rsi
movq 0x618(%rsp), %rdi
callq 0x5330
movq %rax, 0xb0(%rsp)
jmp 0x1f793
movq 0xb0(%rsp), %rdi
leaq 0x525dc(%rip), %rsi     # 0x71d7e
callq 0x5380
movq %rax, 0xa8(%rsp)
jmp 0x1f7b1
movq 0xa8(%rsp), %rdi
movq 0x1a8(%rsp), %rax
movq 0x368(%rax), %rsi
callq 0x50f0
movq %rax, 0xa0(%rsp)
jmp 0x1f7d7
movq 0xa0(%rsp), %rdi
movq 0x737d2(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1f7ed
movq 0x1a0(%rsp), %rsi
movq 0x618(%rsp), %rdi
callq 0x5330
movq %rax, 0x98(%rsp)
jmp 0x1f80c
movq 0x98(%rsp), %rdi
leaq 0x52581(%rip), %rsi     # 0x71d9c
callq 0x5380
movq %rax, 0x90(%rsp)
jmp 0x1f82a
movq 0x90(%rsp), %rdi
movq 0x1a8(%rsp), %rax
movq 0x360(%rax), %rsi
callq 0x50f0
movq %rax, 0x88(%rsp)
jmp 0x1f850
movq 0x88(%rsp), %rdi
movq 0x73759(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1f866
movsd 0x3e8(%rsp), %xmm0
addsd 0x3e0(%rsp), %xmm0
movsd %xmm0, 0x1d0(%rsp)
movsd 0x1d0(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1fa88
movq 0x1a0(%rsp), %rsi
movq 0x618(%rsp), %rdi
callq 0x5330
movq %rax, 0x80(%rsp)
jmp 0x1f8b6
movq 0x80(%rsp), %rdi
leaq 0x524f4(%rip), %rsi     # 0x71db9
callq 0x5380
movq %rax, 0x78(%rsp)
jmp 0x1f8d1
movq 0x78(%rsp), %rdi
movsd 0x1d0(%rsp), %xmm0
callq 0x56f0
movq %rax, 0x70(%rsp)
jmp 0x1f8eb
movq 0x70(%rsp), %rdi
movq 0x736c1(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1f8fe
movq 0x1a0(%rsp), %rsi
movq 0x618(%rsp), %rdi
callq 0x5330
movq %rax, 0x68(%rsp)
jmp 0x1f91a
movq 0x68(%rsp), %rdi
leaq 0x524b0(%rip), %rsi     # 0x71dd6
callq 0x5380
movq %rax, 0x60(%rsp)
jmp 0x1f932
movq 0x60(%rsp), %rdi
movsd 0x3e8(%rsp), %xmm0
callq 0x56f0
movq %rax, 0x58(%rsp)
jmp 0x1f94c
movq 0x58(%rsp), %rdi
leaq 0x5330b(%rip), %rsi     # 0x72c63
callq 0x5380
movq %rax, 0x50(%rsp)
jmp 0x1f964
movq 0x50(%rsp), %rdi
movsd 0x3e8(%rsp), %xmm0
movsd 0x52006(%rip), %xmm1    # 0x71980
mulsd %xmm1, %xmm0
movsd 0x1d0(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x56f0
movq %rax, 0x48(%rsp)
jmp 0x1f997
movq 0x48(%rsp), %rdi
leaq 0x52455(%rip), %rsi     # 0x71df8
callq 0x5380
movq %rax, 0x40(%rsp)
jmp 0x1f9af
movq 0x40(%rsp), %rdi
movq 0x735fd(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1f9c2
movq 0x1a0(%rsp), %rsi
movq 0x618(%rsp), %rdi
callq 0x5330
movq %rax, 0x38(%rsp)
jmp 0x1f9de
movq 0x38(%rsp), %rdi
leaq 0x52410(%rip), %rsi     # 0x71dfa
callq 0x5380
movq %rax, 0x30(%rsp)
jmp 0x1f9f6
movq 0x30(%rsp), %rdi
movsd 0x3e0(%rsp), %xmm0
callq 0x56f0
movq %rax, 0x28(%rsp)
jmp 0x1fa10
movq 0x28(%rsp), %rdi
leaq 0x53247(%rip), %rsi     # 0x72c63
callq 0x5380
movq %rax, 0x20(%rsp)
jmp 0x1fa28
movq 0x20(%rsp), %rdi
movsd 0x3e0(%rsp), %xmm0
movsd 0x51f42(%rip), %xmm1    # 0x71980
mulsd %xmm1, %xmm0
movsd 0x1d0(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x56f0
movq %rax, 0x18(%rsp)
jmp 0x1fa5b
movq 0x18(%rsp), %rdi
leaq 0x52391(%rip), %rsi     # 0x71df8
callq 0x5380
movq %rax, 0x10(%rsp)
jmp 0x1fa73
movq 0x10(%rsp), %rdi
movq 0x73539(%rip), %rsi     # 0x92fb8
callq 0x53d0
jmp 0x1fa86
jmp 0x1fa88
movq 0x1a0(%rsp), %rsi
movq 0x618(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x51b0
jmp 0x1faac
movq 0x8(%rsp), %rsi
movq 0x1a8(%rsp), %rdi
leaq 0x1b0(%rsp), %rdx
callq 0x57bf0
jmp 0x1fac8
leaq 0x1b0(%rsp), %rdi
callq 0x5768
leaq 0x410(%rsp), %rdi
callq 0x5770
addq $0x628, %rsp            # imm = 0x628
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x400(%rsp)
movl %eax, 0x3fc(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x5768
leaq 0x410(%rsp), %rdi
callq 0x5770
movq 0x400(%rsp), %rdi
callq 0x5690
nopw %cs:(%rax,%rax)