// File: /workspace/github_cpp_makefile_star2_O1/xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::GetMu_BFor2DLayer(std::vector<Images, std::allocator<Images>>&, Images&)
void ConstructLayer::GetMu_BFor2DLayer(std::vector<Images> &source, Images &res)
{
    // 1) get \mu_B (average)
    // --- 2d case

    double batch_size = source.size();
    if(batch_size <= 0) return;
    size_t nKernel = source[0].OutputImageFromKernel.size();
    for(size_t i = 0; i< nKernel;i++)
    {
        auto dim = source[0].OutputImageFromKernel[i].Dimension();
        Matrix tmp(1, 1, 0);
        for(size_t n=0;n<source.size();n++)
        {
            Matrix& m = source[n].OutputImageFromKernel[i];
            double _sum = m.SumInSection(0, dim.first, 0, dim.second);
            tmp = tmp + _sum;
        }
        tmp = tmp / batch_size / (double)dim.first / (double) dim.second; // = sum /n /(p x q)
        res.OutputImageFromKernel.push_back(tmp);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, 0x28(%rsp)
movq (%rsi), %rcx
movq %rsi, 0x8(%rsp)
movq 0x8(%rsi), %rax
subq %rcx, %rax
je 0xb71f
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
je 0xb71f
movq %rdx, %rcx
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rax
movq %rax, %xmm0
punpckldq 0x1bae6(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1baee(%rip), %xmm0    # 0x27050
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
sarq $0x3, %rcx
imulq %rdx, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
movq %rcx, 0x20(%rsp)
addsd %xmm0, %xmm1
movapd %xmm1, 0x50(%rsp)
xorl %ecx, %ecx
leaq 0x90(%rsp), %r15
movq 0x8(%rsp), %rbx
movq (%rbx), %rax
movq %rcx, 0x30(%rsp)
leaq (%rcx,%rcx,2), %r13
shlq $0x3, %r13
movq (%rax), %rdi
addq %r13, %rdi
callq 0x1ac7c
movq %rax, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movl $0x1, %esi
movl $0x1, %edx
xorpd %xmm0, %xmm0
movq %r15, %r14
movq %r15, %rdi
callq 0x1a952
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0xb651
xorl %r15d, %r15d
xorl %ebp, %ebp
movq (%rax,%r15), %rdi
addq %r13, %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
movq 0x10(%rsp), %r8
callq 0x1d87e
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r14, %rbx
movq %r14, %rsi
callq 0x1b4b6
movq %rbx, %rdi
movq %r12, %rsi
callq 0x14f80
movq %r12, %rdi
callq 0x1acb6
incq %rbp
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
addq $0x18, %r15
cmpq %rcx, %rbp
jb 0xb5e4
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %r15
movq %r14, %rsi
movapd 0x50(%rsp), %xmm0
callq 0x1b88c
movsd 0x18(%rsp), %xmm1
movsd 0x1b9c8(%rip), %xmm0    # 0x27040
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x1b9cd(%rip), %xmm0    # 0x27050
subpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
leaq 0x78(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1b88c
movsd 0x10(%rsp), %xmm1
unpcklps 0x1b990(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1b998(%rip), %xmm1    # 0x27050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x1b88c
movq %r15, %rdi
movq %r12, %rsi
callq 0x14f80
movq %r12, %rdi
callq 0x1acb6
movq %r14, %rdi
callq 0x1acb6
movq %rbx, %rdi
callq 0x1acb6
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x13a14
movq %r15, %rdi
callq 0x1acb6
movq 0x30(%rsp), %rcx
incq %rcx
cmpq 0x20(%rsp), %rcx
jne 0xb593
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb76e
movq %rax, %rbx
jmp 0xb754
movq %rax, %rbx
jmp 0xb74a
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x1acb6
leaq 0x78(%rsp), %rdi
callq 0x1acb6
leaq 0x60(%rsp), %rdi
jmp 0xb765
jmp 0xb76e
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x1acb6
jmp 0xb771
jmp 0xb76e
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x1acb6
movq %rbx, %rdi
callq 0x43e0