// File: /workspace/github_c_makefile_star2_O1/xtanitfy[P]Murphy/src/layers/conv_layer.c
// Function: ConvLayerInit
int ConvLayerInit(NET_PARA_s *pNetPara,LAYER_s *pLayer)
{
	CHECK_EXPR_RET(pNetPara == NULL,-1);
	CHECK_EXPR_RET(pLayer == NULL,-1);
	
	CONV_LAYER_s *pConvLayer = (CONV_LAYER_s *)malloc(sizeof(CONV_LAYER_s));// = (CONV_LAYER_s *)pLayer->currLayer;
	CHECK_EXPR_RET(pConvLayer == NULL,-1);
	pLayer->currLayer = pConvLayer;

	CONV_LAYER_PARA_s *pPara = &pLayer->para->select.convLayer;

	int width =  (pLayer->pPrev[0]->pData->widthSize- pPara->kernelX)/pPara->strideX + 1;
	int height =  (pLayer->pPrev[0]->pData->heightSize- pPara->kernelY)/pPara->strideY + 1;
	pConvLayer->imgWidth = width;
	pConvLayer->imgheight = height;
	pConvLayer->imgSize = pConvLayer->imgWidth*pConvLayer->imgheight;

	CHECK_EXPR_RET(pLayer->pPrev[0]->pData == NULL,-1);
	NET_autoCreateBlob(pNetPara,pLayer->pPrev[0]->pData,&pLayer->pData,pPara->num,height,width,
						 pPara->kernelY,pPara->kernelX,&pLayer->k,&pLayer->b);
	#if 0
		BLOB_shapeLike(pLayer->pData,&pLayer->pDelta);
	#else
		BLOB_createAddPad(&pLayer->pDelta,pLayer->pData->numSize,
						pLayer->pData->channelSize,pLayer->pData->heightSize,
						pLayer->pData->widthSize,TRUE,pPara->kernelY-1,pPara->kernelX-1);
	#endif
	CHECK_EXPR_RET(pPara->weightInit == NULL,-1);
	pPara->weightInit(pLayer->k);

	CHECK_EXPR_RET(pPara->biasInit == NULL,-1);
	pPara->biasInit(pLayer->b);

	BLOB_shapeLike(pLayer->k,&pLayer->pDK);
	BLOB_shapeLike(pLayer->b,&pLayer->pDB);
	
	pLayer->strideX = pPara->strideX;
	pLayer->strideY = pPara->strideY;	

#if defined(CONV_FAST)
	/*��ʱû�п���stride*/
	BLOB_s *pK = pLayer->k;
	int kOutNum = pK->batches;
	int kInNum = pK->num;

	BLOB_s *pData = pLayer->pData;
	pConvLayer->matKWidth = kInNum * pK->width * pK->height * pK->channels;
	pConvLayer->matKHeight = kOutNum;
	
	/*չ��a_in*/
	pConvLayer->matPrevAHeight = pConvLayer->matKWidth;
	pConvLayer->matPrevAWidth = pData->batches * pData->width * pData->height;

	pConvLayer->pMatPrevAData = (double *)malloc(sizeof(double) * \
					pConvLayer->matPrevAHeight * pConvLayer->matPrevAWidth);
	CHECK_EXPR_RET(pConvLayer->pMatPrevAData == NULL,-1);

	pConvLayer->pMatKRot180 = (double *)malloc(sizeof(double) * pLayer->k->size);
	CHECK_EXPR_RET(pConvLayer->pMatKRot180 == NULL,-1);
	
#endif

	
	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x508a
movq %rsi, %rbx
testq %rsi, %rsi
je 0x50a9
movq %rdi, %r14
movl $0x18, %edi
callq 0x10d0
testq %rax, %rax
je 0x50c5
movq %rax, %rcx
movq %rax, (%rbx)
movq 0x8(%rbx), %r15
movq 0xa8(%rbx), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rsi), %rdi
movq 0x28(%rsi), %rax
movslq 0x28c(%r15), %r10
subq %r10, %rax
movslq 0x294(%r15), %r8
xorl %edx, %edx
divq %r8
movq %rax, %r9
incl %r9d
movslq 0x290(%r15), %r11
subq %r11, %rdi
movslq 0x298(%r15), %r8
movq %rdi, %rax
xorl %edx, %edx
divq %r8
incl %eax
movl %r9d, 0x4(%rcx)
movl %eax, 0x8(%rcx)
movl %eax, %edx
imull %r9d, %edx
movl %edx, (%rcx)
testq %rsi, %rsi
je 0x50e1
leaq 0x10(%rbx), %rdx
movl 0x288(%r15), %ecx
leaq 0x18(%rbx), %r12
leaq 0x20(%rbx), %r13
movq %r14, %rdi
movl %eax, %r8d
pushq %r13
pushq %r12
pushq %r10
pushq %r11
callq 0x3b2a
addq $0x20, %rsp
leaq 0x28(%rbx), %rdi
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
movq 0x20(%rax), %rcx
movq 0x28(%rax), %r8
movl 0x28c(%r15), %eax
movl 0x290(%r15), %r10d
decl %r10d
decl %eax
movl $0x1, %r9d
pushq %rax
pushq %r10
callq 0x1f6c
addq $0x10, %rsp
movq 0x2a8(%r15), %rax
testq %rax, %rax
je 0x50fd
movq (%r12), %rdi
callq *%rax
movq 0x2b0(%r15), %rax
testq %rax, %rax
je 0x5119
movq 0x20(%rbx), %rdi
callq *%rax
movq 0x18(%rbx), %rdi
leaq 0x30(%rbx), %rsi
callq 0x219a
movq 0x20(%rbx), %rdi
leaq 0x38(%rbx), %rsi
callq 0x219a
movl 0x294(%r15), %eax
movl %eax, 0xf0(%rbx)
movl 0x298(%r15), %eax
movl %eax, 0xf4(%rbx)
xorl %eax, %eax
jmp 0x513f
leaq 0x2fb4(%rip), %rdi      # 0x8045
leaq 0x371d(%rip), %rsi      # 0x87b5
leaq 0x3723(%rip), %rdx      # 0x87c2
movl $0x33, %ecx
jmp 0x5133
leaq 0x2f95(%rip), %rdi      # 0x8045
leaq 0x36fe(%rip), %rsi      # 0x87b5
leaq 0x3704(%rip), %rdx      # 0x87c2
movl $0x34, %ecx
jmp 0x5133
leaq 0x2f79(%rip), %rdi      # 0x8045
leaq 0x36e2(%rip), %rsi      # 0x87b5
leaq 0x36e8(%rip), %rdx      # 0x87c2
movl $0x37, %ecx
jmp 0x5133
leaq 0x2f5d(%rip), %rdi      # 0x8045
leaq 0x36c6(%rip), %rsi      # 0x87b5
leaq 0x36cc(%rip), %rdx      # 0x87c2
movl $0x42, %ecx
jmp 0x5133
leaq 0x2f41(%rip), %rdi      # 0x8045
leaq 0x36aa(%rip), %rsi      # 0x87b5
leaq 0x36b0(%rip), %rdx      # 0x87c2
movl $0x4c, %ecx
jmp 0x5133
leaq 0x2f25(%rip), %rdi      # 0x8045
leaq 0x368e(%rip), %rsi      # 0x87b5
leaq 0x3694(%rip), %rdx      # 0x87c2
movl $0x4f, %ecx
xorl %eax, %eax
callq 0x1030
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq