// File: /workspace/github_c_makefile_star2_O3/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 %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x4efe
movq %rsi, %rbx
testq %rsi, %rsi
je 0x4f1a
movq %rdi, %r14
movl $0x18, %edi
callq 0x10e0
testq %rax, %rax
je 0x4f36
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
leal 0x1(%rax), %r9d
movslq 0x290(%r15), %r11
subq %r11, %rdi
movslq 0x298(%r15), %r8
movq %rdi, %rax
xorl %edx, %edx
divq %r8
leal 0x1(%rax), %r8d
movl %r9d, 0x4(%rcx)
movl %r8d, 0x8(%rcx)
movl %r8d, %eax
imull %r9d, %eax
movl %eax, (%rcx)
leaq 0x10(%rbx), %rdx
movl 0x288(%r15), %ecx
leaq 0x18(%rbx), %r12
leaq 0x20(%rbx), %rax
movq %r14, %rdi
pushq %rax
pushq %r12
pushq %r10
pushq %r11
callq 0x39ff
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 0x1f16
addq $0x10, %rsp
movq 0x2a8(%r15), %rax
testq %rax, %rax
je 0x4f52
movq (%r12), %rdi
callq *%rax
movq 0x2b0(%r15), %rax
testq %rax, %rax
je 0x4f6e
movq 0x20(%rbx), %rdi
callq *%rax
movq 0x18(%rbx), %rdi
leaq 0x30(%rbx), %rsi
callq 0x2144
movq 0x20(%rbx), %rdi
leaq 0x38(%rbx), %rsi
callq 0x2144
movq 0x294(%r15), %rax
movq %rax, 0xf0(%rbx)
xorl %eax, %eax
jmp 0x4f94
leaq 0x2140(%rip), %rdi      # 0x7045
leaq 0x2896(%rip), %rsi      # 0x77a2
leaq 0x289c(%rip), %rdx      # 0x77af
movl $0x33, %ecx
jmp 0x4f88
leaq 0x2124(%rip), %rdi      # 0x7045
leaq 0x287a(%rip), %rsi      # 0x77a2
leaq 0x2880(%rip), %rdx      # 0x77af
movl $0x34, %ecx
jmp 0x4f88
leaq 0x2108(%rip), %rdi      # 0x7045
leaq 0x285e(%rip), %rsi      # 0x77a2
leaq 0x2864(%rip), %rdx      # 0x77af
movl $0x37, %ecx
jmp 0x4f88
leaq 0x20ec(%rip), %rdi      # 0x7045
leaq 0x2842(%rip), %rsi      # 0x77a2
leaq 0x2848(%rip), %rdx      # 0x77af
movl $0x4c, %ecx
jmp 0x4f88
leaq 0x20d0(%rip), %rdi      # 0x7045
leaq 0x2826(%rip), %rsi      # 0x77a2
leaq 0x282c(%rip), %rdx      # 0x77af
movl $0x4f, %ecx
xorl %eax, %eax
callq 0x1030
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq