// File: /workspace/github_c_makefile_star2_O2/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 0x4ae8
movq %rsi, %rbx
testq %rsi, %rsi
je 0x4b01
movq %rdi, %r14
pushq $0x18
popq %rdi
callq 0x10e0
testq %rax, %rax
je 0x4b1a
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 0x3812
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
pushq $0x1
popq %r9
pushq %rax
pushq %r10
callq 0x1ec9
popq %rcx
popq %rdx
movq 0x2a8(%r15), %rax
testq %rax, %rax
je 0x4b33
movq (%r12), %rdi
callq *%rax
movq 0x2b0(%r15), %rax
testq %rax, %rax
je 0x4b4c
movq 0x20(%rbx), %rdi
callq *%rax
movq 0x18(%rbx), %rdi
leaq 0x30(%rbx), %rsi
callq 0x208b
movq 0x20(%rbx), %rdi
leaq 0x38(%rbx), %rsi
callq 0x208b
movq 0x294(%r15), %rax
movq %rax, 0xf0(%rbx)
xorl %eax, %eax
jmp 0x4b6e
leaq 0x2556(%rip), %rdi      # 0x7045
leaq 0x2cac(%rip), %rsi      # 0x77a2
leaq 0x2cb2(%rip), %rdx      # 0x77af
pushq $0x33
jmp 0x4b63
leaq 0x253d(%rip), %rdi      # 0x7045
leaq 0x2c93(%rip), %rsi      # 0x77a2
leaq 0x2c99(%rip), %rdx      # 0x77af
pushq $0x34
jmp 0x4b63
leaq 0x2524(%rip), %rdi      # 0x7045
leaq 0x2c7a(%rip), %rsi      # 0x77a2
leaq 0x2c80(%rip), %rdx      # 0x77af
pushq $0x37
jmp 0x4b63
leaq 0x250b(%rip), %rdi      # 0x7045
leaq 0x2c61(%rip), %rsi      # 0x77a2
leaq 0x2c67(%rip), %rdx      # 0x77af
pushq $0x4c
jmp 0x4b63
leaq 0x24f2(%rip), %rdi      # 0x7045
leaq 0x2c48(%rip), %rsi      # 0x77a2
leaq 0x2c4e(%rip), %rdx      # 0x77af
pushq $0x4f
popq %rcx
xorl %eax, %eax
callq 0x1030
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq