// File: /workspace/github_cpp_makefile_star2_O2/huiwenliuge[P]EmoAnaer/src/RNNet.cpp
// Function: RNNet::_Forward_CROSSENTROPY(sentence*)
double RNNet::_Forward_CROSSENTROPY(Sentence sen){

    int t,i,j;
    
    for(i=0;i<hidlayerNUM;++i){
        sen->hidLay[0][i]=0.0;
        for(j=0;j<featureNUM;++j)
            sen->hidLay[0][i]+=in2hid[i][j]*sen->inVec[0][j];
        sen->kLayer[0][i]=sigm(sen->hidLay[0][i]);
    }
    
    for(i=0;i<EMOTIONNUM;++i){
        sen->outLay[0][i]=0.0;
        for(j=0;j<hidlayerNUM;++j)
            sen->outLay[0][i]+=k2out[i][j]*sen->kLayer[0][j];
        sen->eng[i]=0.0;
    }
    softmax_add(sen,sen->outLay[0],0);
    // sen->loss=0.0;
    // for(i=0;i<EMOTIONNUM;++i)
    //     sen->loss+=-sen->stdAns[i]*log(sen->energy[i]);

    for(t=1;t<sen->tlen;++t){

        for(i=0;i<hidlayerNUM;++i){
            sen->hidLay[t][i]=0.0;
            for(j=0;j<featureNUM;++j)
                sen->hidLay[t][i]+=in2hid[i][j]*sen->inVec[t][j];
            for(j=0;j<hidlayerNUM;++j)
                sen->hidLay[t][i]+=rh2h[i][j]*sen->kLayer[t-1][j];
            for(j=0;j<EMOTIONNUM;++j)
                sen->hidLay[t][i]+=ro2h[i][j]*sen->outLay[t-1][j];
            sen->kLayer[t][i]=sigm(sen->hidLay[t][i]);
        }

        for(i=0;i<EMOTIONNUM;++i){
            sen->outLay[t][i]=0.0;
            for(j=0;j<hidlayerNUM;++j)
                sen->outLay[t][i]+=k2out[i][j]*sen->kLayer[t][j];  
        }
        softmax_add(sen,sen->outLay[t],t);

    }

    for(i=0;i<sen->tlen;++i)
        for(j=0;j<EMOTIONNUM;++j)
            sen->eng[j]+=sen->energy[i][j];
    for(i=0;i<EMOTIONNUM;++i)
        sen->eng[i]/=sen->tlen;
    
    sen->loss=0.0;
    for(i=0;i<EMOTIONNUM;++i)
        sen->loss+=-sen->stdAns[i]*log(sen->eng[i]);
    
    return sen->loss;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
xorl %r12d, %r12d
movslq 0x34(%r14), %rax
cmpq %rax, %r12
jge 0x3278
movq 0x20(%rbx), %rax
movq (%rax), %rax
andq $0x0, (%rax,%r12,8)
movl 0x30(%r14), %ecx
movq 0x10(%r14), %rdx
testl %ecx, %ecx
cmovlel %r15d, %ecx
xorpd %xmm0, %xmm0
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x325e
movq (%rdx,%r12,8), %rdi
movsd (%rdi,%rsi,8), %xmm1
movq 0x18(%rbx), %rdi
movq (%rdi), %rdi
mulsd (%rdi,%rsi,8), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%r12,8)
incq %rsi
jmp 0x3235
movq %r14, %rdi
callq 0x476c
movq 0x28(%rbx), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%r12,8)
incq %r12
jmp 0x320c
movq 0x30(%rbx), %rdx
movq 0x40(%rbx), %rcx
movq (%rdx), %rdx
xorl %esi, %esi
testl %eax, %eax
cmovlel %esi, %eax
cmpq $0x7, %rsi
je 0x32d4
andq $0x0, (%rdx,%rsi,8)
movq 0x18(%r14), %rdi
xorpd %xmm0, %xmm0
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x32ca
movq (%rdi,%rsi,8), %r9
movsd (%r9,%r8,8), %xmm1
movq 0x28(%rbx), %r9
movq (%r9), %r9
mulsd (%r9,%r8,8), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %r8
jmp 0x32a0
andq $0x0, (%rcx,%rsi,8)
incq %rsi
jmp 0x328a
xorl %r12d, %r12d
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x43aa
pushq $0x1
popq %r15
movslq 0x10(%rbx), %rax
cmpq %rax, %r15
jge 0x343a
xorl %r13d, %r13d
movslq 0x34(%r14), %rcx
movl %ecx, %eax
cmpq %rcx, %r13
jge 0x33d2
movq 0x20(%rbx), %rcx
movq (%rcx,%r15,8), %rcx
andq $0x0, (%rcx,%r13,8)
movl 0x30(%r14), %edx
movq 0x10(%r14), %rsi
testl %edx, %edx
cmovlel %r12d, %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
cmpq %rdi, %rdx
je 0x3351
movq (%rsi,%r13,8), %r8
movsd (%r8,%rdi,8), %xmm1
movq 0x18(%rbx), %r8
movq (%r8,%r15,8), %r8
mulsd (%r8,%rdi,8), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%r13,8)
incq %rdi
jmp 0x3325
movq 0x20(%r14), %rdx
xorl %esi, %esi
cmpq %rsi, %rax
je 0x3382
movq (%rdx,%r13,8), %rdi
movsd (%rdi,%rsi,8), %xmm1
movq 0x28(%rbx), %rdi
movq -0x8(%rdi,%r15,8), %rdi
mulsd (%rdi,%rsi,8), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%r13,8)
incq %rsi
jmp 0x3357
movq 0x28(%r14), %rax
movq (%rax,%r13,8), %rax
movq 0x30(%rbx), %rdx
movq -0x8(%rdx,%r15,8), %rdx
xorl %esi, %esi
cmpq $0x7, %rsi
je 0x33b4
movsd (%rax,%rsi,8), %xmm1
mulsd (%rdx,%rsi,8), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%r13,8)
incq %rsi
jmp 0x3395
movq %r14, %rdi
callq 0x476c
movq 0x28(%rbx), %rax
movq (%rax,%r15,8), %rax
movsd %xmm0, (%rax,%r13,8)
incq %r13
jmp 0x32f5
movq 0x30(%rbx), %rcx
movq (%rcx,%r15,8), %rdx
testl %eax, %eax
cmovlel %r12d, %eax
xorl %ecx, %ecx
cmpq $0x7, %rcx
je 0x3427
andq $0x0, (%rdx,%rcx,8)
movq 0x18(%r14), %rsi
xorpd %xmm0, %xmm0
xorl %edi, %edi
cmpq %rdi, %rax
je 0x3422
movq (%rsi,%rcx,8), %r8
movsd (%r8,%rdi,8), %xmm1
movq 0x28(%rbx), %r8
movq (%r8,%r15,8), %r8
mulsd (%r8,%rdi,8), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%rdx,%rcx,8)
incq %rdi
jmp 0x33f7
incq %rcx
jmp 0x33e2
movq %rbx, %rsi
movl %r15d, %ecx
callq 0x43aa
incq %r15
jmp 0x32e5
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
cmpq %rdx, %rcx
je 0x347c
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %rsi
movq (%rdi,%rcx,8), %rdi
xorl %r8d, %r8d
cmpq $0x7, %r8
je 0x3477
movsd (%rdi,%r8,8), %xmm0
addsd (%rsi,%r8,8), %xmm0
movsd %xmm0, (%rsi,%r8,8)
incq %r8
jmp 0x345a
incq %rcx
jmp 0x3446
cvtsi2sd %eax, %xmm0
movq 0x40(%rbx), %rax
xorl %ecx, %ecx
cmpq $0x7, %rcx
je 0x349f
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rcx,8)
incq %rcx
jmp 0x3486
andq $0x0, 0x50(%rbx)
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
cmpq $0x7, %r14
je 0x34eb
movq 0x40(%rbx), %rax
movq 0x48(%rbx), %rcx
movsd (%rcx,%r14,8), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd (%rax,%r14,8), %xmm0
callq 0x20f0
movapd %xmm0, %xmm1
movsd 0x50(%rbx), %xmm0
mulsd -0x30(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rbx)
incq %r14
jmp 0x34ab
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq