// File: /workspace/github_cpp_makefile_star2_O3/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 $0x178, %rsp            # imm = 0x178
leaq 0x3132a(%rip), %r13     # 0x45f50
cmpb $0x1, 0x1cc(%r13)
jne 0x151c9
movq %rdi, %r15
movq 0x60(%rdi), %rax
cmpq %rax, 0x68(%rdi)
je 0x151c9
movslq (%r15), %rbx
movq 0x8(%rax), %r14
subq (%rax), %r14
shrq $0x2, %r14
cmpl $0x7d1, %r14d           # imm = 0x7D1
jl 0x14d18
leaq 0x60(%r15), %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x2eda1
movq 0x70(%r15), %rax
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x70(%r15)
movups 0x60(%r15), %xmm1
movups %xmm0, 0x60(%r15)
leaq 0x10(%rsp), %r12
movaps %xmm1, (%r12)
movq %rax, 0x10(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
xorl %ebp, %ebp
movq %rbp, 0x10(%r14)
movq %r12, %rdi
callq 0xc5b4
movq %r14, %rdi
callq 0xc5b4
leaq 0x48(%r15), %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x2eda1
movq 0x58(%r15), %rax
movaps (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x58(%r15)
movups 0x48(%r15), %xmm1
movups %xmm0, 0x48(%r15)
movaps %xmm1, (%r12)
movq %rax, 0x10(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq %rbp, 0x10(%r14)
leaq 0x10(%rsp), %rdi
callq 0xc5b4
movq %r14, %rdi
callq 0xc5b4
movq 0x60(%r15), %rax
movq 0x8(%rax), %r14
subq (%rax), %r14
shrq $0x2, %r14
leaq 0x80(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rcx
movq %rbx, %rsi
callq 0x152ee
movslq %r14d, %rsi
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0xf(%rsp), %rcx
callq 0xc524
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x14d5e
callq 0x52b0
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x154f6
movq %r14, 0x58(%rsp)
movq %rbx, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x154f6
movq 0x60(%r15), %rax
movq %r15, 0xa0(%rsp)
movq 0x68(%r15), %rcx
subq %rax, %rcx
je 0x14e56
movq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
movq %rdx, 0x38(%rsp)
xorl %edx, %edx
movl $0xff, %esi
leaq (%rdx,%rdx,2), %r8
movq (%rax,%r8,8), %rdi
movq 0x8(%rax,%r8,8), %r8
subq %rdi, %r8
je 0x14e46
sarq $0x2, %r8
movq 0x80(%rsp), %r14
movq 0x40(%rsp), %rcx
movq 0x68(%rsp), %r11
xorl %r12d, %r12d
xorl %ebp, %ebp
movl (%rdi,%r12,4), %ebx
testl %ebx, %ebx
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 %ebx, %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)
incq %r12
movl %r12d, %r9d
addq $0x18, %rbp
cmpq %r9, %r8
ja 0x14df0
incq %rdx
movl %edx, %edi
cmpq %rdi, 0x38(%rsp)
ja 0x14dc3
movq 0xa0(%rsp), %r15
leaq 0x8(%r15), %r12
leaq 0x203c3(%rip), %rsi     # 0x3522c
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
callq 0x15588
leaq 0x203bb(%rip), %rsi     # 0x35238
leaq 0x10(%rsp), %rdi
callq 0x55f0
movq 0x60(%rsp), %rbx
movq 0x58(%rsp), %r14
leaq 0xd8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x14ec1
movq %rdx, 0xc8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xd8(%rsp)
jmp 0x14ec8
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0xd0(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x160(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x154f6
leaq 0x148(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x154f6
leaq 0x130(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x154f6
leaq 0xc8(%rsp), %rdi
leaq 0x160(%rsp), %rcx
leaq 0x148(%rsp), %r8
leaq 0x130(%rsp), %r9
movl %r14d, %esi
movl %ebx, %edx
callq 0x2ef63
leaq 0x130(%rsp), %rdi
callq 0xc5b4
leaq 0x148(%rsp), %rdi
callq 0xc5b4
leaq 0x160(%rsp), %rdi
callq 0xc5b4
movq 0xc8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x14f7f
callq 0x52b0
movq %r12, 0x98(%rsp)
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14f9a
callq 0x52b0
movq 0x48(%r15), %rax
movq 0x50(%r15), %rcx
subq %rax, %rcx
je 0x15077
movq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
movq %rdx, 0x38(%rsp)
xorl %edx, %edx
movl $0xff, %esi
leaq (%rdx,%rdx,2), %r8
movq (%rax,%r8,8), %rdi
movq 0x8(%rax,%r8,8), %r8
subq %rdi, %r8
je 0x15067
sarq $0x2, %r8
movq 0x80(%rsp), %r9
movq 0x40(%rsp), %rcx
movq 0x68(%rsp), %r11
xorl %r15d, %r15d
xorl %ebp, %ebp
movl (%rdi,%r15,4), %ebx
movl 0x1b0(%r13), %r12d
movl %r12d, %r14d
shrl $0x1f, %r14d
addl %r12d, %r14d
sarl %r14d
subl %r14d, %ebx
movq %r9, %r14
cmovnsq %rcx, %r14
movl $0xffffff01, %r12d      # imm = 0xFFFFFF01
cmovnsl %esi, %r12d
movq %rcx, %r10
cmovnsq %r9, %r10
movq (%r14,%rbp), %r14
movl %esi, (%r14,%rdx,4)
imull %ebx, %r12d
shrl $0x5, %r12d
movl $0xff, %ebx
subl %r12d, %ebx
movq (%r10,%rbp), %r10
movl %ebx, (%r10,%rdx,4)
movq (%r11,%rbp), %r10
movl %ebx, (%r10,%rdx,4)
incq %r15
movl %r15d, %r10d
addq $0x18, %rbp
cmpq %r10, %r8
ja 0x14ffd
incq %rdx
movl %edx, %edi
cmpq %rdi, 0x38(%rsp)
ja 0x14fcc
leaq 0x201bf(%rip), %rsi     # 0x3523d
leaq 0x10(%rsp), %rdi
movq 0x98(%rsp), %rdx
callq 0x15588
leaq 0x201a1(%rip), %rsi     # 0x35238
leaq 0x10(%rsp), %rdi
callq 0x55f0
leaq 0xb8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x150d1
movq %rdx, 0xa8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb8(%rsp)
jmp 0x150d8
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0xb0(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x118(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x154f6
leaq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x154f6
leaq 0xe8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x154f6
leaq 0xa8(%rsp), %rdi
leaq 0x118(%rsp), %rcx
leaq 0x100(%rsp), %r8
leaq 0xe8(%rsp), %r9
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
callq 0x2ef63
leaq 0xe8(%rsp), %rdi
callq 0xc5b4
leaq 0x100(%rsp), %rdi
callq 0xc5b4
leaq 0x118(%rsp), %rdi
callq 0xc5b4
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x15194
callq 0x52b0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x151a8
callq 0x52b0
leaq 0x68(%rsp), %rdi
callq 0xc5b4
leaq 0x80(%rsp), %rdi
callq 0xc5b4
leaq 0x40(%rsp), %rdi
callq 0xc5b4
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0xc5b4
jmp 0x151f0
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0xc5b4
jmp 0x15202
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0xc5b4
jmp 0x15214
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x1522b
callq 0x52b0
jmp 0x1522b
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
jmp 0x15292
jmp 0x1529e
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0xc5b4
jmp 0x1524e
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0xc5b4
jmp 0x15260
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0xc5b4
jmp 0x15272
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x15289
callq 0x52b0
jmp 0x15289
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x152a1
callq 0x52b0
jmp 0x152a1
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0xc5b4
leaq 0x80(%rsp), %rdi
callq 0xc5b4
leaq 0x40(%rsp), %rdi
callq 0xc5b4
movq %rbx, %rdi
callq 0x55a0
movq %rax, %rbx
jmp 0x152ab
movq %rax, %rbx
jmp 0x152b8
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x152c2
callq 0x52b0
jmp 0x152c2
movq %rax, %rbx
jmp 0x152c2
nop