// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movq %rdx, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
leaq 0x1be78(%rip), %rsi     # 0x29cb5
leaq 0x78(%rsp), %rbx
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x5310
xorl %ebp, %ebp
leaq 0x1be71(%rip), %r15     # 0x29cc7
leaq 0x1b1d5(%rip), %r12     # 0x29032
leaq 0x1e096(%rip), %r13     # 0x2befa
cmpq $0x5, %rbp
je 0xdec4
xorl %r14d, %r14d
cmpq $0x3, %r14
je 0xdebf
movq %rbx, %rdi
movq %r15, %rsi
callq 0x52c0
leaq 0x2f57b(%rip), %rcx     # 0x3d400
movq (%rcx,%rbp,8), %rsi
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
movq %r12, %rsi
callq 0x52c0
leaq 0x2f58d(%rip), %rcx     # 0x3d430
movq (%rcx,%r14,8), %rsi
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x52c0
incq %r14
jmp 0xde6d
incq %rbp
jmp 0xde64
leaq 0x78(%rsp), %rdi
callq 0x5190
xorl %r12d, %r12d
leaq 0x78(%rsp), %rbp
leaq 0x1bded(%rip), %r15     # 0x29cca
leaq 0x1cd3f(%rip), %r13     # 0x2ac23
movl %r12d, %r12d
movq 0x8(%rsp), %rcx
movq 0x3a8(%rcx), %rax
subq 0x3a0(%rcx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpq %r12, %rax
jbe 0xdfbb
movq %rbp, %rdi
leaq 0x1bdb3(%rip), %rsi     # 0x29cc8
callq 0x52c0
movq %rax, %rdi
movl %r12d, %eax
xorl %edx, %edx
pushq $0x3
popq %rcx
divl %ecx
movl %edx, %ebx
leaq 0x2f4d0(%rip), %rcx     # 0x3d400
movq (%rcx,%rax,8), %rsi
callq 0x52c0
movq %rax, %rdi
leaq 0x1b0ef(%rip), %rsi     # 0x29032
callq 0x52c0
movl %ebx, %ecx
leaq 0x2f4df(%rip), %rdx     # 0x3d430
movq (%rdx,%rcx,8), %rsi
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
movq %r15, %rsi
callq 0x52c0
xorl %ebx, %ebx
imulq $0x18, %r12, %r14
movl %ebx, %ebx
movq 0x8(%rsp), %rax
movq 0x3a0(%rax), %rcx
movq (%rcx,%r14), %rax
movq 0x8(%rcx,%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0xdfab
movl (%rax,%rbx,4), %esi
movq %rbp, %rdi
callq 0x5560
movq %rax, %rdi
movq %r13, %rsi
callq 0x52c0
incl %ebx
jmp 0xdf6e
movq %rbp, %rdi
callq 0x5190
incl %r12d
jmp 0xdee4
leaq 0x78(%rsp), %rdi
callq 0x5420
leaq 0x2ff84(%rip), %rax     # 0x3df50
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
cmpb $0x1, 0xa9(%rax)
jne 0xe0b7
leaq 0x1bce5(%rip), %rsi     # 0x29ccd
leaq 0x278(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x5310
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
xorl %r14d, %r14d
leaq 0x278(%rsp), %rbx
leaq 0x1cc11(%rip), %r15     # 0x2ac23
movl %r14d, %r14d
movq 0x8(%rsp), %rax
movq 0x3b8(%rax), %rcx
movq 0x3c0(%rax), %rax
subq %rcx, %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
cmpq %r14, %rax
jbe 0xe09d
imulq $0x18, %r14, %r13
movq (%rcx,%r13), %rax
movq (%rax), %r12
movq %rbx, %rdi
movl %r12d, %esi
callq 0x5560
movq %rax, %rdi
movq %r15, %rsi
callq 0x52c0
movq 0x8(%rsp), %rcx
movq 0x3b8(%rcx), %rcx
movq (%rcx,%r13), %rcx
movl 0x4(%rcx), %esi
movq %rax, %rdi
callq 0x5560
movq %rax, %rdi
callq 0x5190
movq %r12, %xmm0
cvtdq2pd %xmm0, %xmm0
movapd 0x20(%rsp), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
incl %r14d
jmp 0xe012
leaq 0x278(%rsp), %rdi
callq 0x5420
leaq 0x278(%rsp), %rdi
callq 0x5620
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5290
leaq 0x1bc18(%rip), %rsi     # 0x29ce5
movq %rax, %rdi
callq 0x52c0
movq 0x8(%rsp), %rcx
movl 0x374(%rcx), %esi
movq %rax, %rdi
callq 0x5200
movq %rax, %rdi
callq 0x5190
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5290
leaq 0x1bc00(%rip), %rsi     # 0x29d06
movq %rax, %rdi
callq 0x52c0
movq 0x8(%rsp), %rcx
movl 0x370(%rcx), %esi
movq %rax, %rdi
callq 0x5200
movq %rax, %rdi
callq 0x5190
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5290
leaq 0x1bbef(%rip), %rsi     # 0x29d2e
movq %rax, %rdi
callq 0x52c0
movq 0x8(%rsp), %rcx
movq 0x380(%rcx), %rsi
movq %rax, %rdi
callq 0x5200
movq %rax, %rdi
callq 0x5190
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5290
leaq 0x1bbd6(%rip), %rsi     # 0x29d4f
movq %rax, %rdi
callq 0x52c0
movq 0x8(%rsp), %rcx
movq 0x378(%rcx), %rsi
movq %rax, %rdi
callq 0x5200
movq %rax, %rdi
callq 0x5190
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5290
leaq 0x1bbbb(%rip), %rsi     # 0x29d6e
movq %rax, %rdi
callq 0x52c0
movq 0x8(%rsp), %rcx
movq 0x368(%rcx), %rsi
movq %rax, %rdi
callq 0x5200
movq %rax, %rdi
callq 0x5190
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5290
leaq 0x1bb9f(%rip), %rsi     # 0x29d8c
movq %rax, %rdi
callq 0x52c0
movq 0x8(%rsp), %rcx
movq 0x360(%rcx), %rsi
movq %rax, %rdi
callq 0x5200
movq %rax, %rdi
callq 0x5190
movapd 0x20(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movapd %xmm0, %xmm2
movapd %xmm1, 0x40(%rsp)
addsd %xmm1, %xmm2
xorpd %xmm0, %xmm0
movapd %xmm2, 0x30(%rsp)
ucomisd %xmm0, %xmm2
jbe 0xe351
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5290
leaq 0x1bb52(%rip), %rsi     # 0x29da9
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
movapd 0x30(%rsp), %xmm0
callq 0x54f0
movq %rax, %rdi
callq 0x5190
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5290
leaq 0x1bb3b(%rip), %rsi     # 0x29dc6
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
movapd 0x20(%rsp), %xmm0
callq 0x54f0
leaq 0x1c97b(%rip), %rsi     # 0x2ac23
movq %rax, %rdi
callq 0x52c0
movapd 0x20(%rsp), %xmm0
mulsd 0x1b6b2(%rip), %xmm0    # 0x29970
divsd 0x30(%rsp), %xmm0
movq %rax, %rdi
callq 0x54f0
leaq 0x1bb15(%rip), %rsi     # 0x29de8
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5290
leaq 0x1baf1(%rip), %rsi     # 0x29dea
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
movapd 0x40(%rsp), %xmm0
callq 0x54f0
leaq 0x1c90d(%rip), %rsi     # 0x2ac23
movq %rax, %rdi
callq 0x52c0
movapd 0x40(%rsp), %xmm0
mulsd 0x1b644(%rip), %xmm0    # 0x29970
divsd 0x30(%rsp), %xmm0
movq %rax, %rdi
callq 0x54f0
leaq 0x1baa7(%rip), %rsi     # 0x29de8
movq %rax, %rdi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
leaq 0x58(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5410
leaq 0x58(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x20390
leaq 0x58(%rsp), %rdi
callq 0x5618
leaq 0x78(%rsp), %rdi
callq 0x5620
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe3b3
jmp 0xe3c9
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x5618
jmp 0xe3cc
jmp 0xe3c9
jmp 0xe3c9
jmp 0xe3c9
movq %rax, %rbx
leaq 0x278(%rsp), %rdi
callq 0x5620
jmp 0xe3cc
jmp 0xe3c9
jmp 0xe3c9
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x5620
movq %rbx, %rdi
callq 0x5570