// File: 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:
subq $0x288, %rsp            # imm = 0x288
movq 0x290(%rsp), %rax
movq %rdi, 0x280(%rsp)
movq %rsi, 0x278(%rsp)
movq %rdx, 0x270(%rsp)
movq %rcx, 0x268(%rsp)
movq %r8, 0x260(%rsp)
movq %r9, 0x258(%rsp)
movq 0x280(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x278(%rsp), %rdi
callq 0x531e0
movq %rax, 0x250(%rsp)
movq 0x278(%rsp), %rdi
callq 0x531f0
movq %rax, %rcx
movq 0x90(%rsp), %rax
movq %rcx, 0x248(%rsp)
movq 0x258(%rsp), %rdi
xorps %xmm0, %xmm0
movss %xmm0, 0x244(%rsp)
movq 0x250(%rsp), %rdx
movq (%rax), %rcx
leaq 0x244(%rsp), %rsi
callq 0x5d120
movq 0x290(%rsp), %rdi
xorps %xmm0, %xmm0
movss %xmm0, 0x240(%rsp)
movq 0x250(%rsp), %rdx
movq 0x248(%rsp), %rcx
leaq 0x240(%rsp), %rsi
callq 0x5d120
leaq 0x218(%rsp), %rdi
callq 0x5b7d0
movq $0x0, 0x210(%rsp)
movq 0x210(%rsp), %rax
cmpq 0x250(%rsp), %rax
je 0x537c7
cmpq $0x0, 0x210(%rsp)
jbe 0x53582
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x78(%rsp)
addq $0x20, %rax
movq %rax, 0x80(%rsp)
movq 0x270(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x278(%rsp), %rsi
movq 0x210(%rsp), %rdx
leaq 0x198(%rsp), %rdi
movl $0x1, %ecx
callq 0x5bf50
jmp 0x53380
leaq 0x198(%rsp), %rdi
callq 0x5d370
movq %rax, 0x70(%rsp)
jmp 0x53394
movq 0x70(%rsp), %rcx
movq 0x88(%rsp), %rdx
movq 0x80(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0x919b0
jmp 0x533b8
movq 0x90(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x60(%rsp)
movq 0x268(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x258(%rsp), %rsi
movq 0x210(%rsp), %rdx
decq %rdx
leaq 0x138(%rsp), %rdi
movl $0x1, %ecx
callq 0x5bf50
jmp 0x533fd
leaq 0x138(%rsp), %rdi
callq 0x5d370
movq %rax, 0x58(%rsp)
jmp 0x53411
movq 0x58(%rsp), %rcx
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x919b0
jmp 0x5342f
leaq 0x1e8(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
leaq 0x160(%rsp), %rdx
callq 0x6a360
jmp 0x5344e
movq 0x78(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq 0x218(%rsp), %rsi
leaq 0x1e8(%rsp), %rdx
callq *%rax
jmp 0x5346e
leaq 0x1e8(%rsp), %rdi
callq 0x5bc10
leaq 0x160(%rsp), %rdi
callq 0x5bc10
leaq 0x138(%rsp), %rdi
callq 0x5bc10
leaq 0x1c0(%rsp), %rdi
callq 0x5bc10
leaq 0x198(%rsp), %rdi
callq 0x5bc10
jmp 0x53684
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x537dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x53570
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x53563
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x53556
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x53549
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x5bc10
leaq 0x160(%rsp), %rdi
callq 0x5bc10
leaq 0x138(%rsp), %rdi
callq 0x5bc10
leaq 0x1c0(%rsp), %rdi
callq 0x5bc10
leaq 0x198(%rsp), %rdi
callq 0x5bc10
jmp 0x537dc
movq 0x90(%rsp), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x40(%rsp)
addq $0x20, %rax
movq %rax, 0x48(%rsp)
movq 0x270(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x278(%rsp), %rsi
movq 0x210(%rsp), %rdx
leaq 0xe8(%rsp), %rdi
movl $0x1, %ecx
callq 0x5bf50
jmp 0x535cd
leaq 0xe8(%rsp), %rdi
callq 0x5d370
movq %rax, 0x38(%rsp)
jmp 0x535e1
movq 0x38(%rsp), %rcx
movq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rsi
leaq 0x110(%rsp), %rdi
callq 0x919b0
jmp 0x535ff
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq 0x218(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq *%rax
jmp 0x5361f
leaq 0x110(%rsp), %rdi
callq 0x5bc10
leaq 0xe8(%rsp), %rdi
callq 0x5bc10
jmp 0x53684
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
jmp 0x53672
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x5bc10
leaq 0xe8(%rsp), %rdi
callq 0x5bc10
jmp 0x537dc
movq 0x258(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x218(%rsp), %rsi
callq 0x5d3b0
jmp 0x536b5
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x5c180
jmp 0x536ce
leaq 0xc0(%rsp), %rdi
callq 0x5bc10
movq 0x90(%rsp), %rsi
movq 0x290(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x20(%rsp)
addq $0x20, %rsi
movq 0x260(%rsp), %rdx
leaq 0x98(%rsp), %rdi
leaq 0x218(%rsp), %rcx
callq 0x919b0
jmp 0x53720
leaq 0x98(%rsp), %rdi
callq 0x848c0
movq %rax, 0x10(%rsp)
jmp 0x53734
movq 0x10(%rsp), %rdi
callq 0x5d370
movq %rax, 0x8(%rsp)
jmp 0x53745
movq 0x8(%rsp), %rdx
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdi
callq 0x5c180
jmp 0x5375b
leaq 0x98(%rsp), %rdi
callq 0x5bc10
movq 0x210(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x210(%rsp)
jmp 0x5330a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x5bc10
jmp 0x537dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x190(%rsp)
movl %eax, 0x18c(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x5bc10
jmp 0x537dc
leaq 0x218(%rsp), %rdi
callq 0x5bc10
addq $0x288, %rsp            # imm = 0x288
retq
leaq 0x218(%rsp), %rdi
callq 0x5bc10
movq 0x190(%rsp), %rdi
callq 0xb980
nopw %cs:(%rax,%rax)