// File: /workspace/github_cpp_makefile_star2_O3/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 $0xa8, %rsp
movsd %xmm0, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %rsi, %rbx
movq %rdi, 0x30(%rsp)
movq (%rsi), %rax
movq 0x8(%rsi), %r14
subq %rax, %r14
sarq $0x3, %r14
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %r14
movq (%rdx), %rcx
movq %rdx, 0x88(%rsp)
movq 0x8(%rdx), %rdi
subq %rcx, %rdi
sarq $0x3, %rdi
imulq %rsi, %rdi
movq %r14, %r15
movq %rdi, 0x80(%rsp)
subq %rdi, %r15
jb 0x1def9
movq 0x8(%rax), %r13
subq (%rax), %r13
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
sarq $0x3, %r13
sarq $0x3, %rdx
movq %r13, %r12
movq %rdx, 0x90(%rsp)
subq %rdx, %r12
jb 0x1def9
movl %r8d, %ebp
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x1aa3e
incq %r15
movq %r15, %rax
xorl %edx, %edx
movq 0x40(%rsp), %r15
divq %r15
movq %rax, %rsi
incq %r12
movq %r12, %rax
xorl %edx, %edx
divq %r15
movq %rax, %r12
cmpq $0x2, %r15
jb 0x1dcff
incq %rsi
incq %r12
movq %r12, %rcx
movq %rsi, 0x28(%rsp)
movq %rsi, %rdx
imulq %r15, %rdx
imulq %r15, %rcx
cmpq %r14, %rdx
jne 0x1dc98
cmpq %r13, %rcx
je 0x1dcfa
movzbl %bpl, %r8d
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
movsd 0x48(%rsp), %xmm0
callq 0x1c9dc
leaq 0x68(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x14e2c
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %rbx, %r14
je 0x1dcf0
movq %rbx, %r15
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1dcdd
callq 0x4230
addq $0x18, %r15
cmpq %r14, %r15
jne 0x1dcd0
movq %rbx, 0x18(%rsp)
movq 0x40(%rsp), %r15
leaq 0x10(%rsp), %rdi
callq 0x14578
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdi
movq %r12, %rdx
movq %rsi, %rbx
callq 0x1a76e
testq %rbx, %rbx
je 0x1deab
movq %rbx, %rax
movq $0x0, 0x38(%rsp)
leaq 0x10(%rsp), %rbx
movq %rax, 0x28(%rsp)
testq %r12, %r12
je 0x1de90
movq 0x38(%rsp), %rcx
movq %rcx, %rdx
imulq %r15, %rdx
movq 0x80(%rsp), %rax
movq %rdx, 0x48(%rsp)
addq %rdx, %rax
movq %rax, 0xa0(%rsp)
leaq (%rcx,%rcx,2), %rax
movq %rax, 0x98(%rsp)
xorl %r13d, %r13d
movq %r13, %r8
imulq %r15, %r8
movq 0x90(%rsp), %rax
leaq (%r8,%rax), %r9
movl $0x0, (%rsp)
xorps %xmm0, %xmm0
movq %rbx, %rdi
leaq 0x68(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0xa0(%rsp), %rcx
callq 0x1c864
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq 0x88(%rsp), %rdx
callq 0x1b1ee
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
movq 0x8(%rax), %r8
subq (%rax), %r8
sarq $0x3, %r8
movq %r15, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x1d774
movq %r12, %rbp
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x98(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax,%r13,8)
movq 0x50(%rsp), %r12
movq 0x58(%rsp), %r14
cmpq %r12, %r14
je 0x1de3e
movq %r12, %r15
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1de2b
callq 0x4230
addq $0x18, %r15
cmpq %r14, %r15
jne 0x1de1e
movq %r12, 0x58(%rsp)
leaq 0x50(%rsp), %r15
movq %r15, %rdi
callq 0x14578
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r14
cmpq %r15, %r14
je 0x1de74
movq %r15, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1de66
callq 0x4230
addq $0x18, %r12
cmpq %r14, %r12
jne 0x1de58
movq %r15, 0x18(%rsp)
movq %rbx, %rdi
callq 0x14578
incq %r13
movq %rbp, %r12
cmpq %rbp, %r13
movq 0x40(%rsp), %r15
jne 0x1dd6a
movq 0x38(%rsp), %rdx
incq %rdx
movq 0x28(%rsp), %rax
movq %rdx, 0x38(%rsp)
cmpq %rax, %rdx
jne 0x1dd2e
movq 0x68(%rsp), %rbx
movq 0x70(%rsp), %r14
cmpq %rbx, %r14
je 0x1ded8
movq %rbx, %r15
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1deca
callq 0x4230
addq $0x18, %r15
cmpq %r14, %r15
jne 0x1debd
movq %rbx, 0x70(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x14578
movq 0x30(%rsp), %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x190d8(%rip), %rdi     # 0x36fd8
leaq 0xc868(%rip), %rsi      # 0x2a76f
callq 0x4260
movq %rax, %rdi
callq 0x4100
xorl %edi, %edi
callq 0x4290
movq %rax, %r14
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r15
cmpq %rbx, %r15
je 0x1df4c
movq %rbx, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1df3e
callq 0x4230
addq $0x18, %r12
cmpq %r15, %r12
jne 0x1df30
movq %rbx, 0x18(%rsp)
leaq 0x10(%rsp), %rdi
jmp 0x1dfed
jmp 0x1df58
movq %rax, %r14
jmp 0x1dff2
movq %rax, %r14
jmp 0x1dfa5
movq %rax, %r14
jmp 0x1dfdd
movq %rax, %r14
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r15
cmpq %rbx, %r15
je 0x1df9b
movq %rbx, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1df8d
callq 0x4230
addq $0x18, %r12
cmpq %r15, %r12
jne 0x1df7f
movq %rbx, 0x58(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x14578
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r15
cmpq %rbx, %r15
je 0x1dfd3
movq %rbx, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1dfc5
callq 0x4230
addq $0x18, %r12
cmpq %r15, %r12
jne 0x1dfb7
movq %rbx, 0x18(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x14578
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x1e8dc
movq %rbx, %rdi
callq 0x14578
movq 0x68(%rsp), %rbx
movq 0x70(%rsp), %r15
cmpq %rbx, %r15
je 0x1e020
movq %rbx, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1e012
callq 0x4230
addq $0x18, %r12
cmpq %r15, %r12
jne 0x1e004
movq %rbx, 0x70(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x14578
movq %r14, %rdi
callq 0x43e0