// File: /workspace/github_cpp_makefile_star2_O3/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, 0x10(%rsp)
movq 0x170(%rsp), %r12
movq (%rsi), %r13
movq %rsi, 0x18(%rsp)
movq 0x8(%rsi), %rbx
xorl %r15d, %r15d
leaq 0x48(%rsp), %r14
movl %r15d, (%r14)
movq %rdi, 0x20(%rsp)
movq (%rdi), %rcx
movq %r9, 0x28(%rsp)
movq %r9, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x2796e
movl %r15d, (%r14)
leaq 0x48(%rsp), %rsi
movq %r12, %rdi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x2796e
leaq 0x48(%rsp), %rdi
callq 0x267d8
movq %r13, 0x38(%rsp)
testq %r13, %r13
je 0x22c43
movq 0x20(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0xe8(%rsp), %r15
leaq 0x70(%rsp), %r13
leaq 0x110(%rsp), %r14
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rbx
testq %r12, %r12
je 0x22b7a
movl $0x1, %ecx
movq %r14, %rbp
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq %r12, %rdx
callq 0x26de4
movq %rbp, %rdi
callq 0x27a96
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rax, %rcx
callq 0x3d460
leaq -0x1(%r12), %rdx
movl $0x1, %ecx
leaq 0x98(%rsp), %rbp
movq %rbp, %rdi
movq 0x28(%rsp), %rsi
callq 0x26de4
movq %rbp, %rdi
callq 0x27a96
leaq 0xc0(%rsp), %rbp
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %rax, %rcx
callq 0x3d460
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2e560
movq (%rbx), %rax
movq %rbx, %rdi
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq *0x10(%rax)
movq %r13, %rdi
callq 0x26a2e
leaq 0xc0(%rsp), %rdi
callq 0x26a2e
leaq 0x98(%rsp), %rdi
callq 0x26a2e
movq %r15, %rdi
callq 0x26a2e
movq %r14, %rdi
jmp 0x22bcd
movl $0x1, %ecx
movq %r15, %rbp
movq %r15, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x26de4
movq %rbp, %rdi
callq 0x27a96
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rax, %rcx
callq 0x3d460
movq (%rbx), %rax
movq %rbx, %rdi
leaq 0x48(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq *0x10(%rax)
movq %r13, %rdi
callq 0x26a2e
movq %r15, %rdi
callq 0x26a2e
movq %r13, %rdi
movq %rbx, %rsi
callq 0x27ac6
movq 0x28(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x26f34
movq %r13, %rdi
callq 0x26a2e
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %rbx, %rcx
callq 0x3d460
movq %r13, %rdi
callq 0x379b0
movq %rax, %rdi
callq 0x27a96
movq 0x170(%rsp), %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x26f34
movq %r13, %rdi
callq 0x26a2e
incq %r12
cmpq %r12, 0x38(%rsp)
jne 0x22a9e
leaq 0x48(%rsp), %rdi
callq 0x26a2e
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x22ca9
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x26a2e
jmp 0x22c9b
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x26a2e
jmp 0x22c89
movq %rax, %rbx
jmp 0x22cc3
jmp 0x22ca9
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x26a2e
jmp 0x22cb6
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x22ce2
jmp 0x22ca9
jmp 0x22cda
movq %rax, %rbx
jmp 0x22ce7
movq %rax, %rbx
jmp 0x22cd0
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x26a2e
leaq 0xe8(%rsp), %rdi
callq 0x26a2e
leaq 0x110(%rsp), %rdi
jmp 0x22ce2
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x26a2e
leaq 0x48(%rsp), %rdi
callq 0x26a2e
movq %rbx, %rdi
callq 0xa780
nop