// File: /workspace/github_cpp_makefile_star2_O2/xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::BatchNormalization_UpdateGammaBeta()
void ConstructLayer::BatchNormalization_UpdateGammaBeta()
{
    // for batch normalization, update beta and gamma during back propagation

    // only apply for cnn, fc and output layers
    if(__type != LayerType::cnn && __type != LayerType::fullyConnected && __type != LayerType::output)
        return;

    size_t nK = 1;
    if(GetLayerDimension() == LayerDimension::_2D)
        nK = __n_kernels_cnn;

    assert(__gamma_BN.size() == nK);
    assert(__gamma_BN.size() == __v_partial_C_over_partial_gamma.size());
    assert(__beta_BN.size() == __v_partial_C_over_partial_beta.size());

    size_t batch_size = __p_data_interface->GetBatchSize();

    for(size_t i=0;i<nK;i++)
    {
        Matrix & gradient_gamma = __v_partial_C_over_partial_gamma[i];
        Matrix & gradient_beta = __v_partial_C_over_partial_beta[i];

        Matrix d_gamma =  gradient_gamma *  (__learningRate/(double)batch_size);
        __gamma_BN[i] = __gamma_BN[i] - d_gamma;
        Matrix d_beta =  gradient_beta * (__learningRate/(double)batch_size);
        __beta_BN[i] = __beta_BN[i] - d_beta;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl 0xc(%rdi), %eax
cmpl $0x4, %eax
ja 0xe68f
pushq $0x13
popq %rcx
btl %eax, %ecx
jae 0xe68f
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x258(%rax)
cmpl $0x1, %eax
jne 0xe51b
movq 0x18(%rbx), %rdi
jmp 0xe51e
pushq $0x1
popq %rdi
movq 0x310(%rbx), %rcx
subq 0x308(%rbx), %rcx
pushq $0x18
popq %rsi
movq %rcx, %rax
cqto
idivq %rsi
cmpq %rdi, %rax
jne 0xe69e
movq 0x370(%rbx), %rax
subq 0x368(%rbx), %rax
cmpq %rax, %rcx
jne 0xe6bd
movq 0x328(%rbx), %rax
subq 0x320(%rbx), %rax
movq 0x388(%rbx), %rcx
subq 0x380(%rbx), %rcx
cmpq %rcx, %rax
jne 0xe6dc
movq 0x400(%rbx), %rax
movslq (%rax), %rax
movq %rax, %xmm0
punpckldq 0x12a8d(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x12a95(%rip), %xmm0    # 0x21030
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x20(%rsp), %rbp
leaq 0x50(%rsp), %r15
subq $0x1, %rdi
jb 0xe68f
movq %rdi, 0x8(%rsp)
movq 0x368(%rbx), %rsi
addq %r14, %rsi
movq 0x380(%rbx), %r13
addq %r14, %r13
movsd 0xc0(%rbx), %xmm0
divsd 0x10(%rsp), %xmm0
leaq 0x38(%rsp), %r12
movq %r12, %rdi
callq 0x182dc
movq 0x308(%rbx), %rsi
addq %r14, %rsi
movq %rbp, %rdi
movq %r12, %rdx
callq 0x17eb0
movq 0x308(%rbx), %rdi
addq %r14, %rdi
movq %rbp, %rsi
callq 0x125b4
movq %rbp, %rdi
callq 0x17a9a
movsd 0xc0(%rbx), %xmm0
divsd 0x10(%rsp), %xmm0
movq %rbp, %rdi
movq %r13, %rsi
callq 0x182dc
movq 0x320(%rbx), %rsi
addq %r14, %rsi
movq %r15, %rdi
movq %rbp, %rdx
callq 0x17eb0
movq 0x320(%rbx), %rdi
addq %r14, %rdi
movq %r15, %rsi
callq 0x125b4
movq %r15, %rdi
callq 0x17a9a
movq %rbp, %rdi
callq 0x17a9a
leaq 0x38(%rsp), %rdi
callq 0x17a9a
addq $0x18, %r14
movq 0x8(%rsp), %rdi
jmp 0xe5ba
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14765(%rip), %rdi     # 0x22e0a
leaq 0x1302e(%rip), %rsi     # 0x216da
leaq 0x1476f(%rip), %rcx     # 0x22e22
movl $0xe7d, %edx            # imm = 0xE7D
callq 0x4180
leaq 0x14798(%rip), %rdi     # 0x22e5c
leaq 0x1300f(%rip), %rsi     # 0x216da
leaq 0x14750(%rip), %rcx     # 0x22e22
movl $0xe7e, %edx            # imm = 0xE7E
callq 0x4180
leaq 0x147b6(%rip), %rdi     # 0x22e99
leaq 0x12ff0(%rip), %rsi     # 0x216da
leaq 0x14731(%rip), %rcx     # 0x22e22
movl $0xe7f, %edx            # imm = 0xE7F
callq 0x4180
jmp 0xe6ff
jmp 0xe71d
movq %rax, %rbx
jmp 0xe711
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x17a9a
leaq 0x20(%rsp), %rdi
callq 0x17a9a
jmp 0xe720
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x17a9a
movq %rbx, %rdi
callq 0x43b0