// File: /workspace/github_cpp_makefile_star2_O3/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 %r8, %r15
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, 0x18(%rsp)
movq %rdi, %rbp
movq %rcx, 0x68(%rsp)
movq %r8, 0x60(%rsp)
movq %r8, %rax
imulq %rcx, %rax
cmpq $0x1, %rax
jbe 0x2fabb
movq 0x8(%r12), %rax
movq %rax, 0x58(%rsp)
imulq (%r12), %r13
movq %r13, (%rsp)
imulq %rax, %r15
movq %r15, 0x10(%rsp)
imulq %r13, %r15
movq (%rbp), %r14
movq 0x8(%rbp), %rsi
movq %r15, %rax
xorl %edx, %edx
divq %r14
cmpq $0x1, %rdx
sbbq $-0x1, %rax
cmpq %r15, %rsi
movq %r15, %rcx
cmovbq %rsi, %rcx
cmpq %rsi, %rax
cmovaeq %rax, %rcx
cmpq %rcx, %rsi
jb 0x2f952
movq %r15, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r14
cmpq $0x1, %rdx
sbbq $-0x1, %r14
movq %r13, %rax
xorl %edx, %edx
divq %r14
movq %rax, %r13
cmpq $0x1, %rdx
sbbq $-0x1, %r13
leaq 0x40(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r14, %rsi
callq 0xa43e
movq 0x10(%r12), %rax
movq %rax, 0x38(%rsp)
movq %r15, %rax
shrq $0x3e, %rax
shlq $0x2, %r15
xorl %edi, %edi
negq %rax
sbbq %rdi, %rdi
orq %r15, %rdi
callq 0x9030
leaq 0x8(%rsp), %rcx
movq %rax, (%rcx)
xorl %ebx, %ebx
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x91d0
leaq 0x70(%rsp), %r12
leaq 0x28(%rsp), %rbp
movq %r14, %r15
leaq 0x38(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x8(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x10(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x68(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x98(%rsp)
movq %rbx, %rax
imulq %r13, %rax
movq %rax, 0x28(%rsp)
leaq 0x1(%rbx), %r14
movq %r14, %rax
imulq %r13, %rax
movq %rax, 0x20(%rsp)
leaq 0x20(%rsp), %rcx
cmpq (%rsp), %rax
jb 0x2fa32
movq %rsp, %rcx
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x2fb2e
movq 0x40(%rsp), %rax
cmpq $0x0, (%rax,%rbx,8)
jne 0x2fafc
movq 0x30(%rsp), %rcx
movq %rcx, (%rax,%rbx,8)
movq %r14, %rbx
cmpq %r14, %r15
movq %r15, %r14
jne 0x2f9bd
movq 0x40(%rsp), %r14
movq 0x48(%rsp), %rbx
cmpq %rbx, %r14
je 0x2fa87
movq %r14, %rdi
callq 0x95a0
addq $0x8, %r14
jmp 0x2fa74
movq 0x8(%rsp), %rsi
movq (%rsp), %rdx
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdi
callq 0x18808
leaq 0x40(%rsp), %rdi
callq 0xa536
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe15e(%rip), %rsi      # 0x3dc20
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movl $0x101, %edx            # imm = 0x101
movl $0x3, %ecx
callq 0x387b6
leaq 0xe17a(%rip), %rsi      # 0x3dc5a
movl $0x23, %edx
movq %r14, %rdi
callq 0x93b0
leaq 0x70(%rsp), %rdi
callq 0x389de
jmp 0x2f8f1
callq 0x90c0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x389de
jmp 0x2fb26
movq %rax, %rbx
jmp 0x2fb26
jmp 0x2fb19
jmp 0x2fb19
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xa536
movq %rbx, %rdi
callq 0x95d0