// File: /workspace/github_cpp_makefile_star2_O3/xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::BackwardPropagateForBatch()
void ConstructLayer::BackwardPropagateForBatch()
{
    int sample_size = __p_data_interface->GetBatchSize();

#ifdef MULTI_THREAD
    auto process_range = [&](int start, int end)
    {
        for(int i = start;i<end;i++)
        {
            BackwardPropagateForSample(i);
        }
    };

    std::vector<std::thread> vth;
    int Range[NTHREAD+1];
    for(int i=0;i<NTHREAD;i++)
        Range[i] = sample_size/NTHREAD*i;
    Range[NTHREAD] = sample_size;

    for(int i=0;i<NTHREAD;i++)
    {
        vth.push_back(std::thread(process_range, Range[i], Range[i+1]));
    }

    for(auto &i: vth)
        i.join();
#else
    for(int i=0;i<sample_size;i++)
    {
        BackwardPropagateForSample(i);
    }
#endif

    // if use batch normalization, then do the transformation 
    // the gradients on \gamma \beta parameters will also be calculated 
    // in function BatchNormalization_RestoreDelta();
    if(__use_batch_normalization)
    {
        BatchNormalization_RestoreDelta();
    }

    // progress
    //std::cout<<"backward propagate for batch finished. Layer: "<<GetID()<<std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movq 0x400(%rdi), %rax
movl (%rax), %eax
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
movq $0x0, 0x20(%rsp)
movd %ecx, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
psrad $0x3, %xmm0
movdqa 0x1e1ab(%rip), %xmm1    # 0x27020
xorl %ecx, %ecx
pshufd $0xf5, %xmm0, %xmm2     # xmm2 = xmm0[1,1,3,3]
movdqa 0x1e1ac(%rip), %xmm3    # 0x27030
movdqa %xmm0, %xmm4
pmuludq %xmm1, %xmm4
pshufd $0xe8, %xmm4, %xmm4     # xmm4 = xmm4[0,2,2,3]
pshufd $0xf5, %xmm1, %xmm5     # xmm5 = xmm1[1,1,3,3]
pmuludq %xmm2, %xmm5
pshufd $0xe8, %xmm5, %xmm5     # xmm5 = xmm5[0,2,2,3]
punpckldq %xmm5, %xmm4    # xmm4 = xmm4[0],xmm5[0],xmm4[1],xmm5[1]
movdqa %xmm4, 0x30(%rsp,%rcx,4)
addq $0x4, %rcx
paddd %xmm3, %xmm1
cmpq $0x8, %rcx
jne 0x8e84
movl %eax, 0x50(%rsp)
movl $0x1, %r13d
movl 0x30(%rsp), %ebp
movq %rsp, %r14
leaq 0x10(%rsp), %r12
movl 0x30(%rsp,%r13,4), %r15d
movq $0x0, (%rsp)
movl $0x18, %edi
callq 0x4270
leaq 0x2da3d(%rip), %rcx     # 0x36928
movq %rcx, (%rax)
movl %r15d, 0x8(%rax)
movl %ebp, 0xc(%rax)
movq %rbx, 0x10(%rax)
movq %rax, 0x8(%rsp)
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x4210
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x8f1d
movq (%rdi), %rax
callq *0x8(%rax)
movq %r12, %rdi
movq %r14, %rsi
callq 0x1718e
cmpq $0x0, (%rsp)
jne 0x8fc1
incq %r13
movl %r15d, %ebp
cmpq $0x9, %r13
jne 0x8ecd
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
cmpq %r15, %r14
je 0x8f5c
movq %r14, %rdi
callq 0x43b0
addq $0x8, %r14
jmp 0x8f49
cmpb $0x0, 0x210(%rbx)
je 0x8f71
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x1c8(%rax)
leaq 0x10(%rsp), %rdi
callq 0x138d0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8fac
jmp 0x8fac
jmp 0x8fac
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x8faf
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x8faf
cmpq $0x0, (%rsp)
jne 0x8fc1
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x138d0
movq %rbx, %rdi
callq 0x43e0
callq 0x40a0