// File: /workspace/github_cpp_makefile_star2_O2/btbujiangjun[P]abcdl/src/cnn/Layer.cpp
// Function: abcdl::cnn::OutputLayer::backward(abcdl::cnn::Layer*, abcdl::cnn::Layer*)
void OutputLayer::backward(Layer* pre_layer, Layer* back_layer){
    abcdl::algebra::Mat error;
    _cost->delta(error, this->get_activation(0), _y);

    _loss = (error * error).sum() / 2;

    //error * derivate_of_output
    abcdl::algebra::Mat derivative_output;
    _activate_func->derivative(derivative_output, this->get_activation(0));
    derivative_output *= error;

    //calc delta: weight.T * derivate_output
    this->set_delta(0, _helper.dot(this->get_weight(0, 0).Ts(), derivative_output));

    //if pre_layer is ConvolutionLayer, has sigmoid function
    if(pre_layer->get_layer_type() == abcdl::framework::CONVOLUTION){
        abcdl::algebra::Mat mat;
        _activate_func->derivative(mat, _pre_activation_array);
        this->get_delta(0) *= mat;
    }

    //derivate_weight = derivate_output * _pre_activation_array.T
    //derivate_bias = derivate_output
    auto delta_weight = _helper.dot(derivative_output, _pre_activation_array.Ts());
    this->set_delta_weight(0, 0, delta_weight);
    (*this->_delta_bias) = derivative_output;

    this->set_batch_weight(0, 0, this->get_delta_weight(0, 0)); 
    (*this->_batch_bias) += derivative_output;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0xa0, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x78(%rsp), %rdi
callq 0x165d0
movq 0x128(%rbx), %r15
movq %rbx, %rdi
xorl %esi, %esi
callq 0x13864
leaq 0xd8(%rbx), %rcx
movq (%r15), %r8
leaq 0x78(%rsp), %rsi
movq %r15, %rdi
movq %rax, %rdx
callq *0x10(%r8)
leaq 0x28(%rsp), %rdi
leaq 0x78(%rsp), %rdx
movq %rdx, %rsi
callq 0x1d012
leaq 0x28(%rsp), %rdi
callq 0x22a68
mulss 0x1d76a(%rip), %xmm0    # 0x30d60
movss %xmm0, 0xd0(%rbx)
leaq 0x28(%rsp), %rdi
callq 0x167fa
leaq 0x28(%rsp), %rdi
callq 0x165d0
movq 0x130(%rbx), %r15
movq %rbx, %rdi
xorl %esi, %esi
callq 0x13864
movq (%r15), %rcx
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
movq %rax, %rdx
callq *0x18(%rcx)
leaq 0x28(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x1d21c
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x13a7c
leaq 0x50(%rsp), %rdi
movq %rax, %rsi
callq 0x17512
leaq 0x30(%rbx), %r15
movq %rsp, %rdi
leaq 0x50(%rsp), %rdx
leaq 0x28(%rsp), %rcx
movq %r15, %rsi
callq 0x26554
movq %rsp, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x139f8
movq %rsp, %rdi
callq 0x167fa
leaq 0x50(%rsp), %rdi
callq 0x167fa
cmpl $0x3, 0x28(%r14)
jne 0x136d7
movq %rsp, %rdi
callq 0x165d0
movq 0x130(%rbx), %rdi
leaq 0x100(%rbx), %rdx
movq (%rdi), %rax
movq %rsp, %rsi
callq *0x18(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1396a
movq %rsp, %rsi
movq %rax, %rdi
callq 0x1d21c
movq %rsp, %rdi
callq 0x167fa
leaq 0x100(%rbx), %rsi
leaq 0x50(%rsp), %rdi
callq 0x17512
movq %rsp, %rdi
leaq 0x28(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %r15, %rsi
callq 0x26554
leaq 0x50(%rsp), %rdi
callq 0x167fa
movq %rsp, %rcx
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x13c22
movq 0x90(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq 0x1c67e
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x13df6
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rax, %rcx
callq 0x13cc4
movq 0xb0(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq 0x1c9c4
movq %rsp, %rdi
callq 0x167fa
leaq 0x28(%rsp), %rdi
callq 0x167fa
leaq 0x78(%rsp), %rdi
callq 0x167fa
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %r15
retq
jmp 0x137a8
jmp 0x1378f
jmp 0x137a8
movq %rax, %rbx
movq %rsp, %rdi
callq 0x167fa
jmp 0x13792
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0x137b3
jmp 0x137a3
jmp 0x137a8
jmp 0x137a3
jmp 0x137ad
jmp 0x137a8
movq %rax, %rbx
jmp 0x137c2
movq %rax, %rbx
jmp 0x137b8
movq %rax, %rbx
movq %rsp, %rdi
callq 0x167fa
leaq 0x28(%rsp), %rdi
callq 0x167fa
leaq 0x78(%rsp), %rdi
callq 0x167fa
movq %rbx, %rdi
callq 0x84f0