// File: xbai0624[P]dnn/src/Matrix.cpp
// Function: Matrix::_scalar_ComputeSection(HadamardOps, double, Matrix&, unsigned long, unsigned long, unsigned long, unsigned long)
void Matrix::_scalar_ComputeSection(HadamardOps op, const double v, Matrix &C, size_t r1, size_t r2, size_t c1, size_t c2)
{
    // compute a region inside C for scalar operation
    for(size_t i=r1; i<r2; i++)
    {
        for(size_t j=c1; j<c2; j++){
            if(op == HadamardOps::plus)
                C[i][j] = (*this)[i][j] + v;
            else if (op == HadamardOps::subtract)
                C[i][j] = (*this)[i][j] - v;
            else if (op == HadamardOps::multiply)
                C[i][j] = (*this)[i][j] * v;
            else if (op == HadamardOps::divide)
                if( v != 0)
                    C[i][j] = (*this)[i][j] / v;
                else {
                    std::cout<<"Error: dividing a Matrix by 0"<<std::endl;
                }
            else
                std::cout<<"Error: not supported hadamard operation."<<std::endl;
        }
    }
}

// Assembly:
subq $0x78, %rsp
movq 0x80(%rsp), %rax
movq %rdi, 0x70(%rsp)
movl %esi, 0x6c(%rsp)
movsd %xmm0, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq %r9, 0x40(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x48(%rsp), %rax
jae 0x3ce52
movq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq 0x80(%rsp), %rax
jae 0x3ce3d
cmpl $0x0, 0x6c(%rsp)
jne 0x3ccae
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movsd (%rax), %xmm0
addsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x3ce28
cmpl $0x1, 0x6c(%rsp)
jne 0x3cd0c
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movsd (%rax), %xmm0
subsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x3ce26
cmpl $0x2, 0x6c(%rsp)
jne 0x3cd6a
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movsd (%rax), %xmm0
mulsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x3ce24
cmpl $0x3, 0x6c(%rsp)
jne 0x3ce00
movsd 0x60(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x3cd88
jp 0x3cd88
jmp 0x3cddc
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movsd (%rax), %xmm0
divsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x58(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3be50
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1fd60
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x3cdfe
movq 0x2e1f5(%rip), %rdi     # 0x6afd8
leaq 0x1820c(%rip), %rsi     # 0x54ff6
callq 0x4230
movq %rax, %rdi
movq 0x2e1b7(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x3ce22
movq 0x2e1d1(%rip), %rdi     # 0x6afd8
leaq 0x181bf(%rip), %rsi     # 0x54fcd
callq 0x4230
movq %rax, %rdi
movq 0x2e193(%rip), %rsi     # 0x6afb0
callq 0x4260
jmp 0x3ce24
jmp 0x3ce26
jmp 0x3ce28
jmp 0x3ce2a
movq 0x30(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x3cc3d
jmp 0x3ce3f
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x3cc23
addq $0x78, %rsp
retq
nopw (%rax,%rax)