// File: /workspace/github_c_makefile_star2_O1/xtanitfy[P]Murphy/src/layers/conv_layer.c
// Function: ConvLayerForward
int ConvLayerForward(NET_PARA_s *pNetPara,LAYER_s *pLayer)
{
	CONV_LAYER_s *pConvLayer = (CONV_LAYER_s *)pLayer->currLayer;
	BLOB_s *pData = pLayer->pData;
	
	CONV_LAYER_PARA_s *pPara = &pLayer->para->select.convLayer;

	BLOB_s *pPrevData = pLayer->pPrev[0]->pData;
	
	BLOB_DATA_PTR(pLayer->pData,ptrCurr);
	BLOB_DATA_PTR(pLayer->k,ptrK);
	BLOB_DATA_PTR(pPrevData,ptrPrevData);
	BLOB_DATA_PTR(pLayer->b,ptrB);

	//CalTimeStart();
	int blockMinX = 0,blockMinY = 0;
	int ytmp = pPara->kernelY-1;
	int xtmp = pPara->kernelX-1;
	double tmp = 0;
	
	for (int i_batch = 0;i_batch < pData->numSize;i_batch++) {
		for (int i_out = 0;i_out < pData->channelSize;i_out++) {
			for (int h = 0;h < pConvLayer->imgheight;h++) {
				for (int w = 0;w < pConvLayer->imgWidth;w++) {
					tmp = 0;
					blockMinY = h*pPara->strideY;
					blockMinX = w*pPara->strideX;
					for (int i_in = 0;i_in < pPrevData->channelSize;i_in++) {
						for (int offsetY = blockMinY;offsetY < (blockMinY + pPara->kernelY);offsetY++) {
							for (int offsetX = blockMinX;offsetX < (blockMinX + pPara->kernelX);offsetX++) {	
								tmp += ptrK[i_out][i_in][ytmp-offsetY+blockMinY][xtmp-offsetX+blockMinX] * \
										ptrPrevData[i_batch][i_in][offsetY][offsetX];
								
							}
						}
					}	
					ptrCurr[i_batch][i_out][h][w]  = pPara->function(tmp + \
								ptrB[0][i_out][0][0],FUNC_VALUE);

				}
		
			}
			
		}
	}
	
	//CalTimeEnd("conv");

#if 0
	static int cnt = 0;
	cnt++;
	if (cnt == 1) {
		LOG_writeBlobToTxtFile("murphy_conv1.txt",pData);
		LOG_writeBlobToBinFile("murphy_conv1.bin",pData);
		LOG_compBinFile("murphy_conv1.bin","a1.bin",sizeof(BLOB_DATA_TYPE)*pData->size);
	}
#endif
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq 0x10(%rsi), %rdx
cmpq $0x0, 0x10(%rdx)
je 0x5514
movq 0x8(%rsi), %rdi
movq 0xa8(%rsi), %rax
movq 0x10(%rax), %r8
movq 0x28(%rdx), %r9
movq 0x18(%rsi), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x60(%rsp)
movq 0x28(%rax), %r10
movq 0x28(%r8), %r13
movq 0x20(%rsi), %rcx
movq 0x8(%rcx), %r11
movq %r11, 0x90(%rsp)
movq 0x28(%rcx), %r11
movq (%rsi), %rsi
movq 0x20(%rax), %rbx
movq %r10, 0xf0(%rsp)
imulq %r10, %rbx
movq 0x18(%rax), %rax
movq %rbx, 0xb8(%rsp)
imulq %rbx, %rax
movq %rax, 0x50(%rsp)
movq 0x20(%rdx), %rax
movq %r9, 0x78(%rsp)
imulq %r9, %rax
movq 0x18(%rdx), %r9
movq %rax, 0x48(%rsp)
imulq %rax, %r9
movq %r9, 0x38(%rsp)
imulq 0x20(%rcx), %r11
movq %r11, 0x58(%rsp)
movq 0x20(%r8), %rax
imulq %r13, %rax
movq 0x18(%r8), %rcx
imulq %rax, %rcx
shlq $0x3, %rcx
movq %rcx, 0x40(%rsp)
shlq $0x3, %r13
shlq $0x3, %rax
movq %rax, 0xd8(%rsp)
movl 0x28c(%rdi), %eax
decl %eax
movl %eax, 0x2c(%rsp)
movq 0x8(%rdx), %rax
movq %rax, 0x30(%rsp)
movq %r8, 0x98(%rsp)
movq 0x8(%r8), %rax
movq %rax, 0x18(%rsp)
movq %rdi, 0x20(%rsp)
movl 0x290(%rdi), %eax
movl %eax, 0x28(%rsp)
movq $0x0, 0x8(%rsp)
movq %rdx, 0x70(%rsp)
movq %rsi, 0x88(%rsp)
cmpq $0x0, 0x18(%rdx)
je 0x54ee
movq 0x38(%rsp), %rax
imulq 0x8(%rsp), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x68(%rsp)
movq $0x0, 0x10(%rsp)
cmpl $0x0, 0x8(%rsi)
jle 0x54d2
movq 0x50(%rsp), %rax
movq 0x10(%rsp), %rdx
imulq %rdx, %rax
movq 0x58(%rsp), %rcx
imulq %rdx, %rcx
movq %rcx, 0xa0(%rsp)
movq 0x48(%rsp), %rcx
imulq %rdx, %rcx
movq 0x60(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
movq %rax, 0xc0(%rsp)
movq 0x68(%rsp), %rax
leaq (%rax,%rcx,8), %rax
movq %rax, 0x80(%rsp)
movq $0x0, (%rsp)
cmpl $0x0, 0x4(%rsi)
jle 0x54ba
movq 0x78(%rsp), %rax
imulq (%rsp), %rax
movq 0x80(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0xa8(%rsp)
xorl %r8d, %r8d
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0xe8(%rsp)
testq %rax, %rax
movq %r8, 0xb0(%rsp)
je 0x5466
movq 0x20(%rsp), %rcx
movl 0x294(%rcx), %eax
movl %eax, %r10d
imull %r8d, %r10d
movl 0x290(%rcx), %edx
movl 0x298(%rcx), %ecx
movl %ecx, %esi
movq (%rsp), %rdi
imull %edi, %esi
movq %rdx, 0xe0(%rsp)
addl %esi, %edx
imull %r8d, %eax
movslq %eax, %r12
movslq %esi, %rax
movq %rax, 0xc8(%rsp)
addl 0x28(%rsp), %esi
movslq %edx, %r9
imull %edi, %ecx
movslq %ecx, %rax
imulq %r13, %rax
movq %r10, 0xd0(%rsp)
movslq %r10d, %rcx
leaq (%rax,%rcx,8), %rbp
addq 0x18(%rsp), %rbp
xorpd %xmm0, %xmm0
xorl %r11d, %r11d
cmpl $0x0, 0xe0(%rsp)
jle 0x544b
movq 0x20(%rsp), %rax
movl 0x28c(%rax), %r14d
movq 0xd0(%rsp), %rax
addl %r14d, %eax
movq 0xb8(%rsp), %rcx
imulq %r11, %rcx
movq 0xc0(%rsp), %rdx
leaq (%rdx,%rcx,8), %r15
movslq %eax, %rbx
movq %rbp, %r8
movq 0xc8(%rsp), %rcx
testl %r14d, %r14d
jle 0x5440
movl %ecx, %eax
notl %eax
addl %esi, %eax
cltq
imulq 0xf0(%rsp), %rax
leaq (%r15,%rax,8), %rax
movl 0x2c(%rsp), %edx
movq %r8, %r10
movq %r12, %rdi
movslq %edx, %rdx
movsd (%rax,%rdx,8), %xmm1
mulsd (%r10), %xmm1
addsd %xmm1, %xmm0
incq %rdi
addq $0x8, %r10
decl %edx
cmpq %rbx, %rdi
jl 0x5421
incq %rcx
addq %r13, %r8
cmpq %r9, %rcx
jl 0x53fd
incq %r11
addq 0xd8(%rsp), %rbp
cmpq 0xe8(%rsp), %r11
jne 0x53b2
jmp 0x546a
xorpd %xmm0, %xmm0
movq 0x90(%rsp), %rax
movq 0xa0(%rsp), %rcx
addsd (%rax,%rcx,8), %xmm0
xorl %edi, %edi
movq 0x20(%rsp), %rax
callq *0x2a0(%rax)
movq 0xa8(%rsp), %rax
movq 0xb0(%rsp), %r8
movsd %xmm0, (%rax,%r8,8)
incq %r8
movq 0x88(%rsp), %rsi
movslq 0x4(%rsi), %rax
cmpq %rax, %r8
jl 0x531e
movq (%rsp), %rdx
incq %rdx
movslq 0x8(%rsi), %rax
movq %rdx, (%rsp)
cmpq %rax, %rdx
jl 0x52f3
movq 0x10(%rsp), %rcx
incq %rcx
movq 0x70(%rsp), %rdx
movq %rcx, 0x10(%rsp)
cmpq %rcx, 0x18(%rdx)
ja 0x5297
movq 0x8(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %rcx, 0x8(%rsp)
cmpq %rcx, 0x10(%rdx)
ja 0x526a
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq