// File: /workspace/github_cpp_makefile_star2_O2/btbujiangjun[P]abcdl/src/rnn/Layer.cpp
// Function: abcdl::rnn::Layer::farward(abcdl::algebra::Matrix<float> const&, abcdl::algebra::Matrix<float> const&, abcdl::algebra::Matrix<float> const&, abcdl::algebra::Matrix<float> const&, abcdl::algebra::Matrix<float>&, abcdl::algebra::Matrix<float>&)
void Layer::farward(const abcdl::algebra::Mat& train_seq_data,
					const abcdl::algebra::Mat& weight,
					const abcdl::algebra::Mat& pre_weight,
					const abcdl::algebra::Mat& act_weight,
					abcdl::algebra::Mat& state,
					abcdl::algebra::Mat& activation){
	
	size_t seq_rows = train_seq_data.rows();
	size_t seq_cols = train_seq_data.cols();
	state.reset(0, seq_rows, _hidden_dim);
	activation.reset(0, seq_rows, seq_cols);

	abcdl::algebra::Mat s_t;
	for(size_t t = 0; t != seq_rows; t++){
		//s[t] = tanh(U*x[t] + W*s[t-1])
		//o[t] = softmax(V* s[t])
		if(t > 0){
			_activate_func->activate(s_t, helper.dot(weight, train_seq_data.get_row(t).transpose()) + helper.dot(pre_weight, state.get_row(t - 1).transpose()));
		}else{
			_activate_func->activate(s_t, helper.dot(weight, train_seq_data.get_row(t).transpose()));
		}

		state.set_row(t, s_t.Ts());
		activation.set_row(t, helper.dot(act_weight, s_t).softmax().transpose());	
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %r8, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, 0x10(%rsp)
movq %rdi, %r15
movq 0x170(%rsp), %r12
movq (%rsi), %r13
movq %rsi, 0x18(%rsp)
movq 0x8(%rsi), %r14
leaq 0x48(%rsp), %rbx
andl $0x0, (%rbx)
movq (%rdi), %rcx
movq %r9, 0x20(%rsp)
movq %r9, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x24598
andl $0x0, (%rbx)
leaq 0x48(%rsp), %rsi
movq %r12, %rdi
movq %r13, 0x40(%rsp)
movq %r13, %rdx
movq %r14, %rcx
callq 0x24598
leaq 0x48(%rsp), %rdi
callq 0x23808
movq %r15, 0x38(%rsp)
leaq 0x20(%r15), %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
leaq 0xe8(%rsp), %r12
leaq 0x70(%rsp), %r15
leaq 0x110(%rsp), %rbx
cmpq %r13, 0x40(%rsp)
je 0x2041b
movq 0x38(%rsp), %rax
movq 0x18(%rax), %r14
testq %r13, %r13
je 0x2035a
movq %rbx, %rbp
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %r13, %rdx
pushq $0x1
popq %rcx
callq 0x23bc0
movq %rbp, %rdi
callq 0x24698
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rax, %rcx
callq 0x335c8
leaq -0x1(%r13), %rdx
leaq 0x98(%rsp), %rbp
movq %rbp, %rdi
movq 0x20(%rsp), %rsi
pushq $0x1
popq %rcx
callq 0x23bc0
movq %rbp, %rdi
callq 0x24698
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %rax, %rcx
callq 0x335c8
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x29810
movq (%r14), %rax
movq %r14, %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
movq %r15, %rdx
callq *0x10(%rax)
movq %r15, %rdi
callq 0x23a32
leaq 0xc0(%rsp), %rdi
callq 0x23a32
leaq 0x98(%rsp), %rdi
callq 0x23a32
movq %r12, %rdi
callq 0x23a32
movq %rbx, %rdi
jmp 0x203ab
movq %r12, %rbp
movq %r12, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
pushq $0x1
popq %rcx
callq 0x23bc0
movq %rbp, %rdi
callq 0x24698
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rax, %rcx
callq 0x335c8
movq (%r14), %rax
movq %r14, %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
movq %r15, %rdx
callq *0x10(%rax)
movq %r15, %rdi
callq 0x23a32
movq %r12, %rdi
callq 0x23a32
movq %r15, %rdi
movq %r14, %rsi
callq 0x246c8
movq 0x20(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x23cf6
movq %r15, %rdi
callq 0x23a32
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r14, %rcx
callq 0x335c8
movq %r15, %rdi
callq 0x2f55e
movq %rax, %rdi
callq 0x24698
movq 0x170(%rsp), %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x23cf6
movq %r15, %rdi
callq 0x23a32
incq %r13
jmp 0x20278
leaq 0x48(%rsp), %rdi
callq 0x23a32
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2047f
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x23a32
jmp 0x20473
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x23a32
jmp 0x2045c
jmp 0x2047f
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x23a32
jmp 0x2048e
movq %rax, %rbx
jmp 0x2049b
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x204ba
jmp 0x2047f
movq %rax, %rbx
jmp 0x204bf
jmp 0x204b2
movq %rax, %rbx
jmp 0x204a8
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x23a32
leaq 0xe8(%rsp), %rdi
callq 0x23a32
leaq 0x110(%rsp), %rdi
jmp 0x204ba
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x23a32
leaq 0x48(%rsp), %rdi
callq 0x23a32
movq %rbx, %rdi
callq 0xa7a0
nop