// File: /workspace/github_cpp_makefile_star2_O1/xbai0624[P]dnn/src/ConstructLayer.cpp
// Function: ConstructLayer::ForwardPropagate_SigmaPrimeAndA_ForSample(int)
void ConstructLayer::ForwardPropagate_SigmaPrimeAndA_ForSample(int sample_index)
{
    // forward propagation: 
    //     ---) compute Z, A, A'(Z) for this layer
    //          these works are done neuron by neuron (neuron level)

    // layers needs to finish all z's first 
    // this special treatment is for softmax actuation functions in output layer
    // b/c in softmax, one need all Z's already calculated before updating A and sigma^\prime
    // step 1) finish z -- done in ForwardPropagate_Z_ForSample(sample_index)

    // step 2) then  finish a and sigma^\prime
    for(size_t k=0;k<__neurons.size();k++)
    {
        auto dim = __neurons[k].Dimension();
        for(size_t i=0;i<dim.first;i++)
        {
            for(size_t j=0;j<dim.second;j++)
            {
                //cout<<"coord (i, j, k): ("<<i<<", "<<j<<", "<<k<<")"<<endl;
                if(!__neurons[k][i][j]->IsActive()) continue;
                __neurons[k][i][j] -> UpdateA(sample_index);
                __neurons[k][i][j] -> UpdateSigmaPrime(sample_index); // sigma^\prime is not needed in layer, but needed in neuron
            }
        }
    }
    UpdateImagesA(sample_index);

    // after finished A and Z matrix, get Sigma^\prime matrix
    UpdateImagesSigmaPrime(sample_index);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, 0xc(%rsp)
movq %rdi, %r14
movq 0x40(%rdi), %rax
cmpq %rax, 0x48(%rdi)
je 0x7b2d
xorl %edx, %edx
leaq (%rdx,%rdx,2), %r12
movq (%rax,%r12,8), %rcx
movq 0x8(%rax,%r12,8), %rsi
subq %rcx, %rsi
movq %rdx, 0x18(%rsp)
je 0x7a19
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rsi
movq 0x8(%rcx), %rbp
subq (%rcx), %rbp
sarq $0x3, %rbp
jmp 0x7a1d
xorl %esi, %esi
xorl %ebp, %ebp
testq %rsi, %rsi
je 0x7aff
movq 0x18(%rsp), %rax
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x10(%rsp)
movq %rsi, 0x20(%rsp)
movq %r12, 0x28(%rsp)
testq %rbp, %rbp
je 0x7ae4
movq 0x10(%rsp), %rax
leaq (%rax,%rax,2), %rbx
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x38(%rsp)
xorl %r13d, %r13d
movq %rbx, 0x40(%rsp)
movq 0x40(%r14), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%rbx,8), %rax
movq (%rax,%r13,8), %rdi
callq 0x2097e
testb %al, %al
je 0x7adc
movq 0x40(%r14), %rax
movq 0x30(%rsp), %rbx
movq (%rax,%rbx), %rax
movq 0x38(%rsp), %r15
movq (%rax,%r15), %rax
movq (%rax,%r13,8), %rdi
movl 0xc(%rsp), %r12d
movl %r12d, %esi
callq 0x2035e
movq 0x40(%r14), %rax
movq (%rax,%rbx), %rax
movq 0x40(%rsp), %rbx
movq (%rax,%r15), %rax
movq (%rax,%r13,8), %rdi
movl %r12d, %esi
movq 0x28(%rsp), %r12
callq 0x204cc
incq %r13
cmpq %r13, %rbp
jne 0x7a7a
movq 0x10(%rsp), %rcx
incq %rcx
movq 0x20(%rsp), %rsi
movq %rcx, 0x10(%rsp)
cmpq %rsi, %rcx
jne 0x7a4f
movq 0x18(%rsp), %rdx
incq %rdx
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rcx
cmpq %rcx, %rdx
jb 0x79e3
movq %r14, %rdi
movl 0xc(%rsp), %ebx
movl %ebx, %esi
callq 0x7b54
movq %r14, %rdi
movl %ebx, %esi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7f90
nop