// File: /workspace/github_cpp_makefile_star2_O1/btbujiangjun[P]abcdl/src/algebra/MatrixBase.cpp
// Function: abcdl::algebra::RandomMatrix<float>::reset()
void RandomMatrix<T>::reset(){
    T scale = _max - _min;
    T min   = _min;
    T max   = _max;

    size_t size = this->_rows * this->_cols;
    T* data = this->_data;
    size_t block_size = this->_po.get_block_size(size);
    size_t num_thread = this->_po.get_num_thread(size, block_size);
    std::vector<std::thread> threads(num_thread);
    std::default_random_engine engine(std::chrono::system_clock::now().time_since_epoch().count());
    std::normal_distribution<T> distribution(_mean_value, _stddev);

    for(size_t i = 0; i != num_thread; i++){
        threads[i] = std::thread(
            [&data, max, min, scale, &distribution, &engine](size_t start_idx, size_t end_idx){
                for(size_t ti = start_idx; ti != end_idx; ti++){
                    T value = static_cast<T>(distribution(engine));
                    if(max == min || value == max || value == min){
                        data[ti] = value;
                    }else if(value > max){
                        real step = (value - min)/scale;
                        value = min + (step - (int)step) * scale;
                    }else{
                        real step = (max - value)/scale;
                        value = min + (step - (int)step) * scale;
                    }
                }
            }, i * block_size, std::min(size, (i + 1) * block_size)
        );
    }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r14
movss 0x30(%rdi), %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x34(%rdi), %xmm0
movss %xmm0, 0xc(%rsp)
movq 0x8(%rdi), %rcx
imulq (%rdi), %rcx
movq %rcx, 0x18(%rsp)
movq 0x10(%rdi), %rax
movq %rax, 0x68(%rsp)
movq 0x18(%rdi), %rbx
movq 0x20(%rdi), %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rbx
cmpq $0x1, %rdx
sbbq $-0x1, %rax
cmpq %rcx, %rsi
movq %rcx, %r13
cmovbq %rsi, %r13
cmpq %rsi, %rax
cmovaeq %rax, %r13
cmpq %r13, %rsi
jb 0x1dc65
movq %rcx, %rax
xorl %edx, %edx
divq %r13
movq %rax, %rbx
cmpq $0x1, %rdx
sbbq $-0x1, %rbx
leaq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %rbx, %rsi
callq 0xa482
callq 0x9070
movq %rax, %rcx
movabsq $0x200000005, %rdx      # imm = 0x200000005
mulq %rdx
movq %rcx, %rax
subq %rdx, %rax
shrq %rax
addq %rdx, %rax
shrq $0x1e, %rax
movq %rax, %rdx
shlq $0x1f, %rdx
subq %rdx, %rax
leaq (%rcx,%rax), %rdx
cmpq $0x1, %rdx
adcq %rcx, %rax
movq %rax, 0x48(%rsp)
movsd 0x28(%r14), %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x0, 0x40(%rsp)
movb $0x0, 0x44(%rsp)
testq %rbx, %rbx
je 0x1dd93
movss 0xc(%rsp), %xmm0
subss 0x10(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
xorl %ebp, %ebp
leaq 0x70(%rsp), %r15
leaq 0x28(%rsp), %r12
xorl %r14d, %r14d
leaq 0x68(%rsp), %rax
movq %rax, 0x70(%rsp)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x78(%rsp)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x7c(%rsp)
movss 0x14(%rsp), %xmm0
movss %xmm0, 0x80(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x48(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %rbp, 0x28(%rsp)
addq %r13, %rbp
movq %rbp, 0x20(%rsp)
leaq 0x20(%rsp), %rcx
cmpq 0x18(%rsp), %rbp
jb 0x1dd62
leaq 0x18(%rsp), %rcx
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1dde8
movq 0x50(%rsp), %rax
cmpq $0x0, (%rax,%r14,8)
jne 0x1ddcc
movq 0x30(%rsp), %rcx
movq %rcx, (%rax,%r14,8)
incq %r14
cmpq %r14, %rbx
jne 0x1dcf9
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r14
cmpq %r14, %rbx
je 0x1ddb0
movq %rbx, %rdi
callq 0x95a0
addq $0x8, %rbx
jmp 0x1dd9d
leaq 0x50(%rsp), %rdi
callq 0xa594
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x90c0
jmp 0x1ddd3
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xa594
movq %rbx, %rdi
callq 0x95d0