// File: /workspace/github_cpp_makefile_star2_O1/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, 0x40(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x18(%rsp)
movq 0x170(%rsp), %r12
movq (%rsi), %r13
movq %rsi, 0x20(%rsp)
movq 0x8(%rsi), %rbx
xorl %r15d, %r15d
leaq 0x48(%rsp), %r14
movl %r15d, (%r14)
movq %rdi, 0x10(%rsp)
movq (%rdi), %rcx
movq %r9, 0x28(%rsp)
movq %r9, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x27d04
movl %r15d, (%r14)
leaq 0x48(%rsp), %rsi
movq %r12, %rdi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x27d04
leaq 0x48(%rsp), %rdi
callq 0x26b6c
movq %r13, 0x38(%rsp)
testq %r13, %r13
je 0x22fcc
movq 0x10(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0xe8(%rsp), %r15
leaq 0x70(%rsp), %r13
leaq 0x110(%rsp), %r14
testq %r12, %r12
je 0x22efa
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rbx
movl $0x1, %ecx
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
callq 0x27178
movq %rbp, %rdi
callq 0x27e2c
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
callq 0x3d76a
leaq -0x1(%r12), %rdx
movl $0x1, %ecx
movq %r14, %rbp
movq %r14, %rdi
movq 0x28(%rsp), %rsi
callq 0x27178
movq %rbp, %rdi
callq 0x27e2c
leaq 0x98(%rsp), %rbp
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %rax, %rcx
callq 0x3d76a
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2e952
movq (%rbx), %rax
movq %rbx, %rdi
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq *0x10(%rax)
movq %r13, %rdi
callq 0x26dc2
leaq 0x98(%rsp), %rdi
callq 0x26dc2
movq %r14, %rdi
callq 0x26dc2
movq %r15, %rdi
callq 0x26dc2
leaq 0xc0(%rsp), %rdi
jmp 0x22f56
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rbx
movl $0x1, %ecx
movq %r15, %rbp
movq %r15, %rdi
movq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x27178
movq %rbp, %rdi
callq 0x27e2c
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
callq 0x3d76a
movq (%rbx), %rax
movq %rbx, %rdi
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq *0x10(%rax)
movq %r13, %rdi
callq 0x26dc2
movq %r15, %rdi
callq 0x26dc2
movq %r13, %rdi
movq %rbx, %rsi
callq 0x27e5c
movq 0x28(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x272c8
movq %r13, %rdi
callq 0x26dc2
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %rbx, %rcx
callq 0x3d76a
movq %r13, %rdi
callq 0x37c46
movq %rax, %rdi
callq 0x27e2c
movq 0x170(%rsp), %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x272c8
movq %r13, %rdi
callq 0x26dc2
incq %r12
cmpq %r12, 0x38(%rsp)
jne 0x22e1e
leaq 0x48(%rsp), %rdi
callq 0x26dc2
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x23032
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x26dc2
jmp 0x23024
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x26dc2
jmp 0x23012
movq %rax, %rbx
jmp 0x2304c
jmp 0x23032
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x26dc2
jmp 0x2303f
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x2306b
jmp 0x23032
jmp 0x23063
movq %rax, %rbx
jmp 0x23070
movq %rax, %rbx
jmp 0x23059
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x26dc2
leaq 0xe8(%rsp), %rdi
callq 0x26dc2
leaq 0xc0(%rsp), %rdi
jmp 0x2306b
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x26dc2
leaq 0x48(%rsp), %rdi
callq 0x26dc2
movq %rbx, %rdi
callq 0xa780