// File: /workspace/github_cpp_makefile_star2_O3/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
movq 0x48(%rdi), %rcx
cmpq %rax, %rcx
je 0x7a87
xorl %r12d, %r12d
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
leaq (%r12,%r12,2), %r15
movq (%rax,%r15,8), %rdx
movq 0x8(%rax,%r15,8), %rdi
subq %rdx, %rdi
je 0x7a6d
movq (%rdx), %rax
movq 0x8(%rdx), %rcx
movq %rcx, 0x18(%rsp)
movq %rcx, %r13
movq %rax, 0x20(%rsp)
subq %rax, %r13
sarq $0x3, %r13
sarq $0x3, %rdi
imulq %rsi, %rdi
cmpq $0x1, %rdi
adcq $0x0, %rdi
movq $0x0, 0x10(%rsp)
movq %r15, 0x38(%rsp)
movq %rdi, 0x28(%rsp)
movq %r13, 0x30(%rsp)
movq 0x18(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x7a40
movq 0x10(%rsp), %rax
leaq (%rax,%rax,2), %rbp
xorl %ebx, %ebx
movq %rbp, 0x40(%rsp)
movq 0x40(%r14), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2089a
testb %al, %al
je 0x7a34
movq 0x40(%r14), %rax
leaq (,%r12,8), %rcx
leaq (%rcx,%rcx,2), %r13
movq (%rax,%r13), %rax
movq 0x10(%rsp), %rcx
leaq (,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %rbp
movq (%rax,%rbp), %rax
movq (%rax,%rbx,8), %rdi
movq %r12, %r15
movl 0xc(%rsp), %r12d
movl %r12d, %esi
callq 0x2028e
movq 0x40(%r14), %rax
movq (%rax,%r13), %rax
movq 0x30(%rsp), %r13
movq (%rax,%rbp), %rax
movq 0x40(%rsp), %rbp
movq (%rax,%rbx,8), %rdi
movl %r12d, %esi
movq %r15, %r12
movq 0x38(%rsp), %r15
callq 0x203ee
incq %rbx
cmpq %rbx, %r13
jne 0x79b4
movq 0x10(%rsp), %rcx
incq %rcx
movq 0x28(%rsp), %rdi
movq %rcx, 0x10(%rsp)
cmpq %rdi, %rcx
jne 0x7994
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
incq %r12
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %rsi, %rdx
cmpq %rdx, %r12
jb 0x793b
movq %r14, %rdi
movl 0xc(%rsp), %ebx
movl %ebx, %esi
callq 0x7aae
movq %r14, %rdi
movl %ebx, %esi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7efc
nop