// File: /workspace/github_cpp_makefile_star2_O3/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 0xb6b5
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
je 0xb6b5
movq %rdx, %rcx
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rax
movq %rax, %xmm0
punpckldq 0x1bb50(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1bb58(%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 0x1abb8
movq %rax, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movl $0x1, %esi
movl $0x1, %edx
xorpd %xmm0, %xmm0
movq %r15, %r14
movq %r15, %rdi
callq 0x1a892
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0xb5e7
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 0x1d774
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r14, %rbx
movq %r14, %rsi
callq 0x1b3f2
movq %rbx, %rdi
movq %r12, %rsi
callq 0x14e2c
movq %r12, %rdi
callq 0x1abf2
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 0xb57a
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %r15
movq %r14, %rsi
movapd 0x50(%rsp), %xmm0
callq 0x1b7c8
movsd 0x18(%rsp), %xmm1
movsd 0x1ba32(%rip), %xmm0    # 0x27040
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0x1ba37(%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 0x1b7c8
movsd 0x10(%rsp), %xmm1
unpcklps 0x1b9fa(%rip), %xmm1    # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1ba02(%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 0x1b7c8
movq %r15, %rdi
movq %r12, %rsi
callq 0x14e2c
movq %r12, %rdi
callq 0x1abf2
movq %r14, %rdi
callq 0x1abf2
movq %rbx, %rdi
callq 0x1abf2
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x138a4
movq %r15, %rdi
callq 0x1abf2
movq 0x30(%rsp), %rcx
incq %rcx
cmpq 0x20(%rsp), %rcx
jne 0xb529
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xb704
movq %rax, %rbx
jmp 0xb6ea
movq %rax, %rbx
jmp 0xb6e0
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x1abf2
leaq 0x78(%rsp), %rdi
callq 0x1abf2
leaq 0x60(%rsp), %rdi
jmp 0xb6fb
jmp 0xb704
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x1abf2
jmp 0xb707
jmp 0xb704
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x1abf2
movq %rbx, %rdi
callq 0x43e0