// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x58, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x7175
leaq 0x3ec6(%rip), %rdi      # 0xb015
leaq 0x462c(%rip), %rsi      # 0xb782
leaq 0x4632(%rip), %rdx      # 0xb78f
movl $0x33, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x7478
cmpq $0x0, -0x20(%rbp)
jne 0x71a9
leaq 0x3e92(%rip), %rdi      # 0xb015
leaq 0x45f8(%rip), %rsi      # 0xb782
leaq 0x45fe(%rip), %rdx      # 0xb78f
movl $0x34, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x7478
movl $0x18, %edi
callq 0x10e0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x71eb
leaq 0x3e50(%rip), %rdi      # 0xb015
leaq 0x45b6(%rip), %rsi      # 0xb782
leaq 0x45bc(%rip), %rdx      # 0xb78f
movl $0x37, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x7478
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x288, %rax            # imm = 0x288
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x10(%rax), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rcx
movslq 0x4(%rcx), %rcx
subq %rcx, %rax
movq -0x30(%rbp), %rcx
movslq 0xc(%rcx), %rcx
xorl %edx, %edx
divq %rcx
addq $0x1, %rax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
movq -0x30(%rbp), %rcx
movslq 0x8(%rcx), %rcx
subq %rcx, %rax
movq -0x30(%rbp), %rcx
movslq 0x10(%rcx), %rcx
xorl %edx, %edx
divq %rcx
addq $0x1, %rax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x28(%rbp), %rax
imull 0x8(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movq 0xa8(%rax), %rax
cmpq $0x0, 0x10(%rax)
jne 0x72d4
leaq 0x3d67(%rip), %rdi      # 0xb015
leaq 0x44cd(%rip), %rsi      # 0xb782
leaq 0x44d3(%rip), %rdx      # 0xb78f
movl $0x42, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x7478
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0x10(%rax), %rsi
movq -0x20(%rbp), %rdx
addq $0x10, %rdx
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movl -0x38(%rbp), %r8d
movl -0x34(%rbp), %r9d
movq -0x30(%rbp), %rax
movl 0x8(%rax), %ebx
movq -0x30(%rbp), %rax
movl 0x4(%rax), %r11d
movq -0x20(%rbp), %r10
addq $0x18, %r10
movq -0x20(%rbp), %rax
addq $0x20, %rax
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x5190
movq -0x20(%rbp), %rdi
addq $0x28, %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rcx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x28(%rax), %r8
movq -0x30(%rbp), %rax
movl 0x8(%rax), %r10d
subl $0x1, %r10d
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
movl $0x1, %r9d
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x2550
movq -0x30(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x73cc
leaq 0x3c6f(%rip), %rdi      # 0xb015
leaq 0x43d5(%rip), %rsi      # 0xb782
leaq 0x43db(%rip), %rdx      # 0xb78f
movl $0x4c, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x7478
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rdi
callq *%rax
movq -0x30(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x7413
leaq 0x3c25(%rip), %rdi      # 0xb015
leaq 0x438b(%rip), %rsi      # 0xb782
leaq 0x4391(%rip), %rdx      # 0xb78f
movl $0x4f, %ecx
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x7478
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x20(%rcx), %rdi
callq *%rax
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x30, %rsi
callq 0x28e0
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x38, %rsi
callq 0x28e0
movq -0x30(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xf0(%rax)
movq -0x30(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xf4(%rax)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x58, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)