// File: /workspace/github_cpp_makefile_star2_O2/xbai0624[P]dnn/src/Matrix.cpp
// Function: Matrix::Correlation(Matrix&, unsigned long, bool, double)
Matrix Matrix::Correlation(Matrix &T, size_t stride, bool pad_front, double padding_value)
{
    // matrix correlation
    auto l_dim = Dimension();
    auto r_dim = T.Dimension();

    if(l_dim.first < r_dim.first || l_dim.second < r_dim.second) {
        std::cout<<"Error: matrix correlation dimension not match."<<std::endl;
        exit(0);
    }

    Matrix M = (*this); // left operand
    size_t row, col;
    row = (l_dim.first - r_dim.first + 1) / stride;
    col = (l_dim.second - r_dim.second + 1) / stride;

    if(stride > 1) { // check if padding needed
        row += 1; col+=1;
        size_t extra_row = row*stride - l_dim.first;
        size_t extra_col = col*stride - l_dim.second;

        if( extra_row > 0  || extra_col > 0) {
            M = (*this).Padding(l_dim.first + extra_row, l_dim.second+extra_col, pad_front, padding_value);
        }
    }

    l_dim = M.Dimension();

    Matrix res(row, col);
    for(size_t i=0;i<row;i++){
        for(size_t j=0;j<col;j++){
            Matrix l = M.GetSection(i*stride, i*stride + r_dim.first, j*stride, j*stride + r_dim.second);
            Matrix _t = l^T;
            auto __D = _t.Dimension();
            res[i][j] = _t.SumInSection(0, __D.first, 0, __D.second);
        }
    }
    return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movsd %xmm0, 0x10(%rsp)
movl %r8d, %ebp
movq %rcx, 0x18(%rsp)
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
movq %rsi, %rdi
callq 0x17a6a
movq %rax, %r15
movq %rdx, %r14
movq %r12, 0x40(%rsp)
movq %r12, %rdi
callq 0x17a6a
movq %r15, %r13
movq %rax, 0x30(%rsp)
subq %rax, %r13
jb 0x1a193
movq %r14, %r12
subq %rdx, %r12
jb 0x1a193
movq %rdx, 0x48(%rsp)
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x1796e
incq %r13
movq %r13, %rax
xorl %edx, %edx
movq 0x18(%rsp), %r13
divq %r13
movq %rax, %rsi
incq %r12
movq %r12, %rax
xorl %edx, %edx
divq %r13
cmpq $0x2, %r13
jb 0x1a06f
movl %ebp, %edi
incq %rsi
incq %rax
movq %rsi, %rdx
imulq %r13, %rdx
movq %rax, %rbp
movq %rax, %rcx
imulq %r13, %rcx
cmpq %r15, %rdx
movq %rsi, %r12
jne 0x1a03a
cmpq %r14, %rcx
je 0x1a06a
movzbl %dil, %r8d
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movsd 0x10(%rsp), %xmm0
callq 0x19178
leaq 0x68(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x125b4
leaq 0x50(%rsp), %rdi
callq 0x17a9a
movq %rbp, %rax
jmp 0x1a072
movq %rsi, %r12
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %rax, 0x20(%rsp)
movq %rax, %rdx
callq 0x176e6
xorl %edx, %edx
leaq 0x50(%rsp), %rbp
leaq 0x80(%rsp), %r15
movq 0x20(%rsp), %rcx
movq %r12, 0x28(%rsp)
cmpq %r12, %rdx
je 0x1a172
movq %rdx, %rbx
imulq %r13, %rbx
movq 0x30(%rsp), %rax
addq %rbx, %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x38(%rsp)
imulq $0x18, %rdx, %r12
xorl %r13d, %r13d
xorl %r14d, %r14d
cmpq %r14, %rcx
je 0x1a15b
movq 0x48(%rsp), %rax
leaq (%rax,%r13), %r9
andl $0x0, (%rsp)
xorps %xmm0, %xmm0
movq %rbp, %rdi
leaq 0x68(%rsp), %rsi
movq %rbx, %rdx
movq 0x10(%rsp), %rcx
movq %r13, %r8
callq 0x19010
movq %r15, %rdi
movq %rbp, %rsi
movq 0x40(%rsp), %rdx
callq 0x17f64
movq %r15, %rdi
callq 0x17a6a
movq %rdx, %r8
movq %r15, %rdi
xorl %esi, %esi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x19b90
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r12), %rax
movsd %xmm0, (%rax,%r14,8)
movq %r15, %rdi
callq 0x17a9a
movq %rbp, %rdi
callq 0x17a9a
incq %r14
addq 0x18(%rsp), %r13
movq 0x20(%rsp), %rcx
jmp 0x1a0cc
movq 0x38(%rsp), %rdx
incq %rdx
movq 0x18(%rsp), %r13
movq 0x28(%rsp), %r12
jmp 0x1a0a0
leaq 0x68(%rsp), %rdi
callq 0x17a9a
movq 0x8(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18e3e(%rip), %rdi     # 0x32fd8
leaq 0xa572(%rip), %rsi      # 0x24713
callq 0x4240
movq %rax, %rdi
callq 0x4130
xorl %edi, %edi
callq 0x4260
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0x1a1ef
jmp 0x1a1c1
movq %rax, %rbx
jmp 0x1a1f4
movq %rax, %rbx
jmp 0x1a1ea
movq %rax, %rbx
jmp 0x1a1e0
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x17a9a
leaq 0x50(%rsp), %rdi
callq 0x17a9a
movq 0x8(%rsp), %rdi
callq 0x17a9a
leaq 0x68(%rsp), %rdi
callq 0x17a9a
movq %rbx, %rdi
callq 0x43b0