// File: /workspace/github_cpp_makefile_star2_O2/btbujiangjun[P]abcdl/src/algebra/MatrixHelper.cpp
// Function: abcdl::algebra::MatrixHelper<int>::dot(abcdl::algebra::Matrix<int>&, abcdl::algebra::Matrix<int> const&, abcdl::algebra::Matrix<int> const&)
void MatrixHelper<T>::dot(Matrix<T>& mat,
						  const Matrix<T>& mat_a,
						  const Matrix<T>& mat_b){
    size_t row_a = mat_a.rows();
    size_t col_a = mat_a.cols();
    size_t row_b = mat_b.rows();
    size_t col_b = mat_b.cols();

    CHECK(col_a == row_b);

    T* data   = new T[row_a * col_b];
    T* data_a = mat_a.data();
    T* data_b = mat_b.data();

    size_t size = row_a * col_b * col_a;
    size_t num_thread = _po.get_num_thread(size, _po.get_block_size(size));
    size_t block_size = row_a / num_thread;
    if(row_a % num_thread != 0){
        block_size += 1;
    }

    std::vector<std::thread> threads(num_thread);
    for(size_t i = 0; i != num_thread; i++){
        threads[i] = std::thread(
            [&data, &data_a, &data_b, &col_a, &col_b](size_t start_idx, size_t end_idx){
				for(size_t ti = start_idx; ti < end_idx; ti++){
					size_t a_init_idx = ti * col_a;
					for(size_t tj = 0; tj != col_b; tj++){
						T value = 0;
						size_t a_idx = a_init_idx;
						for(size_t tk = 0; tk != col_a; tk++){
							value += data_a[a_idx++] * data_b[tk * col_b + tj];
						}
						data[ti * col_b + tj] = value;
					}
				}
            }, i * block_size , std::min(row_a, (i + 1) * block_size)
        );
    }

    for(auto& thread : threads){
        thread.join();
    }

    mat.set_shallow_data(data, row_a, col_b);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rcx, %r13
movq %rdx, %rbp
movq %rsi, 0x20(%rsp)
movq %rdi, %r12
movq (%rdx), %r15
movq %r15, 0x8(%rsp)
movq 0x8(%rdx), %r14
movq %r14, 0x60(%rsp)
movq 0x8(%rcx), %rbx
cmpq (%rcx), %r14
movq %rbx, 0x18(%rsp)
jne 0x266f8
imulq %r15, %rbx
movq %rbx, %rax
shrq $0x3e, %rax
leaq (,%rbx,4), %rcx
xorl %edi, %edi
negq %rax
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x9030
movq %rax, 0x10(%rsp)
movq 0x10(%rbp), %rax
movq %rax, 0x58(%rsp)
movq 0x10(%r13), %rax
movq %rax, 0x50(%rsp)
imulq %rbx, %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0xa05a
cmpq %rax, 0x8(%r12)
jae 0x265b8
movq (%r12), %r14
jmp 0x265ce
movq %rax, %rcx
movq %r14, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r14
cmpq $0x1, %rdx
sbbq $-0x1, %r14
movq %r15, %rax
xorl %edx, %edx
divq %r14
movq %rax, %r15
cmpq $0x1, %rdx
sbbq $-0x1, %r15
leaq 0x38(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r14, %rsi
callq 0xa09c
xorl %ebx, %ebx
leaq 0x68(%rsp), %r12
leaq 0x30(%rsp), %rbp
xorl %r13d, %r13d
subq $0x1, %r14
jb 0x266a6
leaq 0x10(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %r13, %rax
imulq %r15, %rax
movq %rax, 0x30(%rsp)
incq %r13
movq %r13, %rax
imulq %r15, %rax
cmpq 0x8(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x8(%rsp), %rcx
leaq 0x28(%rsp), %rax
cmovbq %rax, %rcx
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
movq %rbp, %rdx
callq 0x2675c
movq 0x38(%rsp), %rdi
addq %rbx, %rdi
movq %r12, %rsi
callq 0xa174
movq %r12, %rdi
callq 0xa18e
addq $0x8, %rbx
jmp 0x26602
movq 0x38(%rsp), %r14
movq 0x40(%rsp), %rbx
cmpq %rbx, %r14
je 0x266c3
movq %r14, %rdi
callq 0x95b0
addq $0x8, %r14
jmp 0x266b0
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdi
callq 0x17012
leaq 0x38(%rsp), %rdi
callq 0xa19c
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd4f1(%rip), %rsi      # 0x33bf0
leaq 0x70(%rsp), %rdi
pushq $0x21
popq %rdx
pushq $0x3
popq %rcx
callq 0x2ee18
leaq 0xd4f7(%rip), %rsi      # 0x33c0d
leaq 0x70(%rsp), %rdi
callq 0x9370
leaq 0x70(%rsp), %rdi
callq 0x2f054
jmp 0x26562
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x2f054
jmp 0x26754
jmp 0x26747
movq %rax, %rbx
jmp 0x26754
jmp 0x26747
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xa19c
movq %rbx, %rdi
callq 0x95e0