// File: /workspace/github_c_makefile_star2_O2/xtanitfy[P]Murphy/src/layers/samp_layer.c
// Function: SampLayerForward
int SampLayerForward(NET_PARA_s *pNetPara,LAYER_s *pLayer)
{
	SAMP_LAYER_PARA_s *pPara = &pLayer->para->select.sampLayer;

	BLOB_s *pPrevBlob = pLayer->pPrev[0]->pData;
	int nx =  pPrevBlob->widthSize/ pPara->stride;
	int ny =  pPrevBlob->heightSize/ pPara->stride;

	BLOB_s *pData = pLayer->pData;
	BLOB_DATA_PTR(pData,ptrCurr);
	BLOB_DATA_PTR(pPrevBlob,ptrPrev);
	double scale = (double)1 / (pPara->stride * pPara->stride);
	int xStart = 0,yStart = 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 y =0;y < ny;y++) {
				for (int x = 0;x < nx;x++) {
					yStart = y * pPara->stride;
					xStart = x * pPara->stride;
					ptrCurr[i_batch][i_out][y][x] = 0;
					for (int by = yStart; by < yStart + pPara->stride;by++) {
						for (int bx = xStart; bx < xStart + pPara->stride;bx++) {
							ptrCurr[i_batch][i_out][y][x] += \
									ptrPrev[i_batch][i_out][by][bx] * scale;
						}
					}
				}
			}
		}
	}
	
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0xa8(%rsi), %rax
movq 0x10(%rax), %r9
movq 0x28(%r9), %rcx
movq 0x8(%rsi), %rax
movq 0x10(%rsi), %rsi
movslq 0x28c(%rax), %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movq %rax, %rdi
movq 0x8(%r9), %rax
movq %rax, -0x70(%rsp)
movq 0x20(%r9), %r10
movq %r10, %rax
xorl %edx, %edx
divq %r8
movq 0x18(%rsi), %r11
movq 0x28(%rsi), %rbx
movq 0x8(%rsi), %rdx
movq %rdx, -0x58(%rsp)
movl %r8d, %edx
imull %r8d, %edx
cvtsi2sd %edx, %xmm1
movq 0x10(%rsi), %rdx
movq %rdx, -0x50(%rsp)
movsd 0x109f(%rip), %xmm0     # 0x7320
divsd %xmm1, %xmm0
movq 0x20(%rsi), %rdx
movq %rbx, -0x18(%rsp)
imulq %rbx, %rdx
movq %rdx, -0x40(%rsp)
movq %r11, -0x28(%rsp)
imulq %r11, %rdx
movq %rdx, -0x60(%rsp)
movslq %edi, %rdi
cltq
movq %rax, -0x8(%rsp)
xorl %eax, %eax
imulq %rcx, %r10
movq 0x18(%r9), %rdx
imulq %r10, %rdx
shlq $0x3, %rdx
movq %rdx, -0x68(%rsp)
shlq $0x3, %r10
movq %r10, -0x38(%rsp)
shlq $0x3, %rcx
cmpq -0x50(%rsp), %rax
je 0x640f
movq %rax, %rdx
movq -0x60(%rsp), %rax
movq %rdx, -0x48(%rsp)
imulq %rdx, %rax
movq -0x58(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
movq %rax, -0x30(%rsp)
movq -0x70(%rsp), %rax
movq %rax, -0x80(%rsp)
xorl %edx, %edx
cmpq -0x28(%rsp), %rdx
je 0x63f8
movq -0x40(%rsp), %rax
movq %rdx, -0x20(%rsp)
imulq %rdx, %rax
movq -0x30(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
movq %rax, -0x10(%rsp)
xorl %r13d, %r13d
xorl %eax, %eax
cmpq -0x8(%rsp), %r13
jge 0x63dc
movl %eax, -0x74(%rsp)
movslq %eax, %rbx
movq %rcx, %r12
imulq %rbx, %r12
addq -0x80(%rsp), %r12
movq -0x18(%rsp), %rax
imulq %r13, %rax
movq -0x10(%rsp), %rdx
leaq (%rdx,%rax,8), %rdx
incq %r13
movq %r13, (%rsp)
imulq %r8, %r13
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpq %rdi, %r14
jge 0x63cc
andq $0x0, (%rdx,%r14,8)
movslq %ebp, %r15
leaq 0x1(%r14), %r10
movq %r10, %r11
imulq %r8, %r11
xorpd %xmm1, %xmm1
movq %r12, %rsi
movq %rbx, %r9
movq %r15, %rax
cmpq %r13, %r9
jl 0x63b7
jmp 0x63c4
movsd (%rsi,%rax,8), %xmm2
mulsd %xmm0, %xmm2
addsd %xmm2, %xmm1
movsd %xmm1, (%rdx,%r14,8)
incq %rax
cmpq %r11, %rax
jl 0x63a1
incq %r9
addq %rcx, %rsi
jmp 0x6397
addl %r8d, %ebp
movq %r10, %r14
jmp 0x6375
movl -0x74(%rsp), %eax
addl %r8d, %eax
movq (%rsp), %r13
jmp 0x6335
movq -0x20(%rsp), %rdx
incq %rdx
movq -0x80(%rsp), %rax
addq -0x38(%rsp), %rax
movq %rax, -0x80(%rsp)
jmp 0x6309
movq -0x48(%rsp), %rax
incq %rax
movq -0x68(%rsp), %rdx
addq %rdx, -0x70(%rsp)
jmp 0x62d3
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq