// File: /workspace/github_cpp_makefile_star2_O1/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 0x1e013
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 0x1e013
movl %r8d, %ebp
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x1aafe
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 0x1de19
incq %rsi
incq %r12
movq %r12, %rcx
movq %rsi, 0x28(%rsp)
movq %rsi, %rdx
imulq %r15, %rdx
imulq %r15, %rcx
cmpq %r14, %rdx
jne 0x1ddb2
cmpq %r13, %rcx
je 0x1de14
movzbl %bpl, %r8d
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
movsd 0x48(%rsp), %xmm0
callq 0x1cac6
leaq 0x68(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x14f80
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %rbx, %r14
je 0x1de0a
movq %rbx, %r15
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1ddf7
callq 0x4230
addq $0x18, %r15
cmpq %r14, %r15
jne 0x1ddea
movq %rbx, 0x18(%rsp)
movq 0x40(%rsp), %r15
leaq 0x10(%rsp), %rdi
callq 0x146b8
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdi
movq %r12, %rdx
movq %rsi, %rbx
callq 0x1a82e
testq %rbx, %rbx
je 0x1dfc5
movq %rbx, %rax
movq $0x0, 0x38(%rsp)
leaq 0x10(%rsp), %rbx
movq %rax, 0x28(%rsp)
testq %r12, %r12
je 0x1dfaa
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 0x1c954
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq 0x88(%rsp), %rdx
callq 0x1b2b2
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 0x1d87e
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 0x1df58
movq %r12, %r15
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1df45
callq 0x4230
addq $0x18, %r15
cmpq %r14, %r15
jne 0x1df38
movq %r12, 0x58(%rsp)
leaq 0x50(%rsp), %r15
movq %r15, %rdi
callq 0x146b8
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r14
cmpq %r15, %r14
je 0x1df8e
movq %r15, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1df80
callq 0x4230
addq $0x18, %r12
cmpq %r14, %r12
jne 0x1df72
movq %r15, 0x18(%rsp)
movq %rbx, %rdi
callq 0x146b8
incq %r13
movq %rbp, %r12
cmpq %rbp, %r13
movq 0x40(%rsp), %r15
jne 0x1de84
movq 0x38(%rsp), %rdx
incq %rdx
movq 0x28(%rsp), %rax
movq %rdx, 0x38(%rsp)
cmpq %rax, %rdx
jne 0x1de48
movq 0x68(%rsp), %rbx
movq 0x70(%rsp), %r14
cmpq %rbx, %r14
je 0x1dff2
movq %rbx, %r15
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1dfe4
callq 0x4230
addq $0x18, %r15
cmpq %r14, %r15
jne 0x1dfd7
movq %rbx, 0x70(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x146b8
movq 0x30(%rsp), %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18fbe(%rip), %rdi     # 0x36fd8
leaq 0xc78e(%rip), %rsi      # 0x2a7af
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 0x1e066
movq %rbx, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1e058
callq 0x4230
addq $0x18, %r12
cmpq %r15, %r12
jne 0x1e04a
movq %rbx, 0x18(%rsp)
leaq 0x10(%rsp), %rdi
jmp 0x1e107
jmp 0x1e072
movq %rax, %r14
jmp 0x1e10c
movq %rax, %r14
jmp 0x1e0bf
movq %rax, %r14
jmp 0x1e0f7
movq %rax, %r14
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r15
cmpq %rbx, %r15
je 0x1e0b5
movq %rbx, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1e0a7
callq 0x4230
addq $0x18, %r12
cmpq %r15, %r12
jne 0x1e099
movq %rbx, 0x58(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x146b8
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r15
cmpq %rbx, %r15
je 0x1e0ed
movq %rbx, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1e0df
callq 0x4230
addq $0x18, %r12
cmpq %r15, %r12
jne 0x1e0d1
movq %rbx, 0x18(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x146b8
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x1e9ea
movq %rbx, %rdi
callq 0x146b8
movq 0x68(%rsp), %rbx
movq 0x70(%rsp), %r15
cmpq %rbx, %r15
je 0x1e13a
movq %rbx, %r12
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1e12c
callq 0x4230
addq $0x18, %r12
cmpq %r15, %r12
jne 0x1e11e
movq %rbx, 0x70(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x146b8
movq %r14, %rdi
callq 0x43e0