// File: /workspace/github_cpp_makefile_star2_O2/gvaumour[P]cache-simulator/src/FeatureTable.cc
// Function: FeatureTable::finishSimu()
void 
FeatureTable::finishSimu()
{

	if(!simu_parameters.perceptron_drawFeatureMaps || stats_heatmap_allocation.size() == 0)
		return;
		
	int height = m_size;
	int width = stats_heatmap_allocation[0].size();


	if(width > IMG_WIDTH)
	{
		stats_heatmap_allocation = resize_image(stats_heatmap_allocation);
		stats_heatmap_weight = resize_image(stats_heatmap_weight);
		width = stats_heatmap_allocation[0].size();
	}	
	vector< vector<int> > red = vector< vector<int> >(width, vector<int>(height, 0));
	vector< vector<int> > blue  = red;
	vector< vector<int> > green = red;
	
	for(unsigned i = 0 ; i < stats_heatmap_allocation.size(); i++)
	{
		for(unsigned j = 0 ; j < stats_heatmap_allocation[i].size(); j++)
		{
			int value = stats_heatmap_allocation[i][j];
			
			if(value >= 0)
			{
				red[j][i] = 255;
				blue[j][i] = 255 - 255 * value / 32;			
				green[j][i] =  255 - 255 * value / 32; 
			}
			else
			{
				blue[j][i] = 255;
				red[j][i] = 255 - 255 * -value / 32;
				green[j][i] = 255 - 255 * -value / 32; 
			}
		}
	}

	writeBMPimage(string("allocation_" + m_name + ".bmp") , width , height , red, blue, green );
	
	for(unsigned i = 0 ; i < stats_heatmap_weight.size(); i++)
	{
		for(unsigned j = 0 ; j < stats_heatmap_weight[i].size(); j++)
		{
			int value = stats_heatmap_weight[i][j] - simu_parameters.perceptron_counter_size/2;
			
			if(value >= 0)
			{
				red[j][i] = 255;
				blue[j][i] = 255 - 255 * value / 32;			
				green[j][i] =  255 - 255 * value / 32; 
			}
			else
			{
				blue[j][i] = 255;
				red[j][i] = 255 - 255 * -value / 32;
				green[j][i] = 255 - 255 * -value / 32; 
			}
		}
	}

	writeBMPimage(string("weight_" + m_name + ".bmp") , width , height , red, blue, green );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
leaq 0x2cbf4(%rip), %r13     # 0x3df50
cmpb $0x1, 0x1cc(%r13)
jne 0x117ab
movq %rdi, %rbx
movq 0x60(%rdi), %rax
cmpq %rax, 0x68(%rdi)
je 0x117ab
movslq (%rbx), %rcx
movq %rcx, 0x10(%rsp)
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x2, %rcx
movq %rcx, 0x8(%rsp)
cmpl $0x7d1, %ecx            # imm = 0x7D1
jl 0x113fd
leaq 0x60(%rbx), %r14
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x2561b
movq %r14, %rdi
movq %r12, %rsi
callq 0xa710
movq %r12, %rdi
callq 0x9d36
leaq 0x48(%rbx), %r14
leaq 0x28(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x2561b
movq %r14, %rdi
movq %r12, %rsi
callq 0xa710
movq %r12, %rdi
callq 0x9d36
movq 0x60(%rbx), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x2, %rcx
movq %rcx, 0x8(%rsp)
leaq 0x78(%rsp), %rdx
andl $0x0, (%rdx)
leaq 0x28(%rsp), %rdi
leaq 0x60(%rsp), %rcx
movq 0x10(%rsp), %rsi
callq 0x9c8a
movslq 0x8(%rsp), %rsi
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
leaq 0x7(%rsp), %rcx
callq 0x9ce0
leaq 0x28(%rsp), %rdi
callq 0xa49a
leaq 0x78(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x119a0
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x119a0
movq 0x60(%rbx), %rcx
movq 0x68(%rbx), %rax
movq %rcx, 0x18(%rsp)
subq %rcx, %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
movq %rax, 0x20(%rsp)
xorl %edx, %edx
movl $0xff, %esi
movl %edx, %edx
cmpq %rdx, 0x20(%rsp)
jbe 0x11519
movq %rbx, %rax
imulq $0x18, %rdx, %r8
movq 0x18(%rsp), %rcx
movq (%rcx,%r8), %rdi
movq 0x8(%rcx,%r8), %r8
subq %rdi, %r8
sarq $0x2, %r8
movq 0x78(%rsp), %r14
movq 0x48(%rsp), %rcx
xorl %ebx, %ebx
movq 0x60(%rsp), %r11
movl %ebx, %ebx
cmpq %rbx, %r8
jbe 0x1150f
movl (%rdi,%rbx,4), %r12d
imulq $0x18, %rbx, %rbp
testl %r12d, %r12d
movq %r14, %r9
cmovnsq %rcx, %r9
movl $0xffffff01, %r15d      # imm = 0xFFFFFF01
cmovnsl %esi, %r15d
movq %rcx, %r10
cmovnsq %r14, %r10
movq (%r9,%rbp), %r9
movl %esi, (%r9,%rdx,4)
imull %r12d, %r15d
shrl $0x5, %r15d
movl $0xff, %r9d
subl %r15d, %r9d
movq (%r10,%rbp), %r10
movl %r9d, (%r10,%rdx,4)
movq (%r11,%rbp), %r10
movl %r9d, (%r10,%rdx,4)
incl %ebx
jmp 0x114b8
incl %edx
movq %rax, %rbx
jmp 0x1147e
leaq 0x8(%rbx), %rdx
leaq 0x18cb4(%rip), %rsi     # 0x2a1d8
leaq 0x28(%rsp), %rdi
movq %rdx, 0x90(%rsp)
callq 0x119fa
leaq 0x18ca7(%rip), %rdx     # 0x2a1e4
leaq 0x148(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xa0bd
leaq 0x110(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x119a0
leaq 0xf8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x119a0
leaq 0xe0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x119a0
leaq 0x148(%rsp), %rdi
leaq 0x110(%rsp), %rcx
leaq 0xf8(%rsp), %r8
leaq 0xe0(%rsp), %r9
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x2577d
leaq 0xe0(%rsp), %rdi
callq 0x9d36
leaq 0xf8(%rsp), %rdi
callq 0x9d36
leaq 0x110(%rsp), %rdi
callq 0x9d36
leaq 0x148(%rsp), %rdi
callq 0x5618
leaq 0x28(%rsp), %rdi
callq 0x5618
movq 0x48(%rbx), %rcx
movq 0x50(%rbx), %rax
movq %rcx, 0x18(%rsp)
subq %rcx, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, 0x20(%rsp)
xorl %edi, %edi
pushq $-0x2
popq %r8
movl $0xff, %r9d
movl %edi, %edi
cmpq %rdi, 0x20(%rsp)
jbe 0x116b8
imulq $0x18, %rdi, %rax
movq 0x18(%rsp), %rcx
movq (%rcx,%rax), %r10
movq 0x8(%rcx,%rax), %r11
subq %r10, %r11
sarq $0x2, %r11
movq 0x78(%rsp), %r15
movq 0x48(%rsp), %rsi
xorl %eax, %eax
movq 0x60(%rsp), %rbx
movl %eax, %r12d
cmpq %r12, %r11
jbe 0x116b1
movl 0x1b0(%r13), %eax
cltd
idivl %r8d
addl (%r10,%r12,4), %eax
imulq $0x18, %r12, %rdx
testl %eax, %eax
movq %r15, %r14
cmovnsq %rsi, %r14
movl $0xffffff01, %ecx       # imm = 0xFFFFFF01
cmovnsl %r9d, %ecx
movq %rsi, %rbp
cmovnsq %r15, %rbp
movq (%r14,%rdx), %r14
movl %r9d, (%r14,%rdi,4)
imull %eax, %ecx
shrl $0x5, %ecx
movl $0xff, %eax
subl %ecx, %eax
movq (%rbp,%rdx), %rcx
movl %eax, (%rcx,%rdi,4)
movq (%rbx,%rdx), %rcx
movl %eax, (%rcx,%rdi,4)
leal 0x1(%r12), %eax
jmp 0x11652
incl %edi
jmp 0x1161b
leaq 0x18b2a(%rip), %rsi     # 0x2a1e9
leaq 0x28(%rsp), %rdi
movq 0x90(%rsp), %rdx
callq 0x119fa
leaq 0x18b0c(%rip), %rdx     # 0x2a1e4
leaq 0x128(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xa0bd
leaq 0xc8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x119a0
leaq 0xb0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x119a0
leaq 0x98(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x119a0
leaq 0x128(%rsp), %rdi
leaq 0xc8(%rsp), %rcx
leaq 0xb0(%rsp), %r8
leaq 0x98(%rsp), %r9
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x2577d
leaq 0x98(%rsp), %rdi
callq 0x9d36
leaq 0xb0(%rsp), %rdi
callq 0x9d36
leaq 0xc8(%rsp), %rdi
callq 0x9d36
leaq 0x128(%rsp), %rdi
callq 0x5618
leaq 0x28(%rsp), %rdi
callq 0x5618
leaq 0x60(%rsp), %rdi
callq 0x9d36
leaq 0x78(%rsp), %rdi
callq 0x9d36
leaq 0x48(%rsp), %rdi
callq 0x9d36
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x9d36
jmp 0x117d2
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x9d36
jmp 0x117e4
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x9d36
jmp 0x117f6
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
jmp 0x11845
jmp 0x1184c
jmp 0x1187f
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x9d36
jmp 0x11819
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x9d36
jmp 0x1182b
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x9d36
jmp 0x1183d
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x5618
jmp 0x1184f
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x5618
leaq 0x60(%rsp), %rdi
callq 0x9d36
leaq 0x78(%rsp), %rdi
callq 0x9d36
leaq 0x48(%rsp), %rdi
callq 0x9d36
movq %rbx, %rdi
callq 0x5570
movq %rax, %rbx
jmp 0x11859
movq %rax, %rbx
jmp 0x11863
movq %rax, %rbx
jmp 0x1186d
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xa49a
jmp 0x11877
movq %rax, %rbx
jmp 0x11877