// File: /workspace/github_cpp_makefile_star2_O1/btbujiangjun[P]abcdl/src/algebra/MatrixHelper.cpp
// Function: abcdl::algebra::MatrixHelper<int>::expand(abcdl::algebra::Matrix<int>&, abcdl::algebra::Matrix<int> const&, unsigned long, unsigned long)
void MatrixHelper<T>::expand(Matrix<T>& result,
                             const Matrix<T>& mat,
                             const size_t row_dim,
                             const size_t col_dim){

    CHECK(row_dim * col_dim > 1);
   
    size_t col_a = mat.cols();
    size_t row   = mat.rows() * row_dim;
    size_t col   = col_a * col_dim;
    size_t size  = row * col;

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

    std::vector<std::thread> threads(num_thread);
    T* data = mat.data();
    T* new_data = new T[size];
    memset(new_data, 0, sizeof(T) * size);

    for(size_t i = 0; i != num_thread; i++){
        threads[i] = std::thread(
            [&data, &new_data,&col, &col_a, &row_dim, &col_dim](size_t start_idx, size_t end_idx){
				for(size_t ti = start_idx; ti < end_idx; ti++){
					for(size_t tj = 0; tj != col; tj++){
                        new_data[ti * col + tj] = data[ti / row_dim * col_a + tj / col_dim];
					}
				}
            }, i * block_size , std::min(row, (i + 1) * block_size)
        );
    }

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

    result.set_shallow_data(new_data, row, col);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdx, %r15
movq %rsi, 0x28(%rsp)
movq %rdi, %r12
movq %rcx, 0x20(%rsp)
movq %r8, 0x18(%rsp)
imulq %rcx, %r8
cmpq $0x1, %r8
jbe 0x2fc91
movq 0x8(%r15), %r13
movq %r13, 0x68(%rsp)
movq 0x20(%rsp), %rcx
imulq (%r15), %rcx
movq %rcx, (%rsp)
imulq 0x18(%rsp), %r13
movq %r13, 0x10(%rsp)
imulq %rcx, %r13
movq (%r12), %r14
movq 0x8(%r12), %rdi
movq %r13, %rax
xorl %edx, %edx
divq %r14
cmpq $0x1, %rdx
sbbq $-0x1, %rax
cmpq %r13, %rdi
movq %r13, %rsi
cmovbq %rdi, %rsi
cmpq %rdi, %rax
cmovaeq %rax, %rsi
cmpq %rsi, %rdi
jb 0x2fb29
movq %r13, %rax
xorl %edx, %edx
divq %rsi
movq %rax, %r14
cmpq $0x1, %rdx
sbbq $-0x1, %r14
movq %rcx, %rax
xorl %edx, %edx
divq %r14
movq %rax, %r12
cmpq $0x1, %rdx
sbbq $-0x1, %r12
leaq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r14, %rsi
callq 0xa482
movq 0x10(%r15), %rax
movq %rax, 0x48(%rsp)
movq %r13, %rax
shrq $0x3e, %rax
shlq $0x2, %r13
xorl %edi, %edi
negq %rax
sbbq %rdi, %rdi
orq %r13, %rdi
callq 0x9030
leaq 0x8(%rsp), %rcx
movq %rax, (%rcx)
xorl %ebx, %ebx
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x91d0
leaq 0x70(%rsp), %r13
leaq 0x38(%rsp), %rbp
movq %r14, %r15
leaq 0x48(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x8(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x10(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x68(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, 0x98(%rsp)
movq %rbx, %rax
imulq %r12, %rax
movq %rax, 0x38(%rsp)
leaq 0x1(%rbx), %r14
movq %r14, %rax
imulq %r12, %rax
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rcx
cmpq (%rsp), %rax
jb 0x2fc08
movq %rsp, %rcx
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2fd04
movq 0x50(%rsp), %rax
cmpq $0x0, (%rax,%rbx,8)
jne 0x2fcd2
movq 0x40(%rsp), %rcx
movq %rcx, (%rax,%rbx,8)
movq %r14, %rbx
cmpq %r14, %r15
movq %r15, %r14
jne 0x2fb93
movq 0x50(%rsp), %r14
movq 0x58(%rsp), %rbx
cmpq %rbx, %r14
je 0x2fc5d
movq %r14, %rdi
callq 0x95a0
addq $0x8, %r14
jmp 0x2fc4a
movq 0x8(%rsp), %rsi
movq (%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x28(%rsp), %rdi
callq 0x18a60
leaq 0x50(%rsp), %rdi
callq 0xa594
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdfa8(%rip), %rsi      # 0x3dc40
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movl $0x101, %edx            # imm = 0x101
movl $0x3, %ecx
callq 0x3894e
leaq 0xdfc4(%rip), %rsi      # 0x3dc7a
movl $0x23, %edx
movq %r14, %rdi
callq 0x93b0
leaq 0x70(%rsp), %rdi
callq 0x38b76
jmp 0x2fac2
callq 0x90c0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x38b76
jmp 0x2fcfc
movq %rax, %rbx
jmp 0x2fcfc
jmp 0x2fcef
jmp 0x2fcef
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xa594
movq %rbx, %rdi
callq 0x95d0