opencv/hal/riscv-rvv/src/core/magnitude.cpp
Yuantao Feng 547cef4e88
Merge pull request #27301 from fengyuentau:4x/hal/riscv_rvv/refactor_build
hal/riscv-rvv: refactor the building process #27301

Current hal/riscv-rvv is built with all headers without building an object. This slows down the compilation progress, especially when re-compiling for minor changes in those headers (~170 files need to be re-compiled). This patch solves the problem.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2025-05-14 14:04:58 +03:00

46 lines
1.3 KiB
C++

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
// Copyright (C) 2025, Institute of Software, Chinese Academy of Sciences.
#include "rvv_hal.hpp"
#include "common.hpp"
namespace cv { namespace rvv_hal { namespace core {
#if CV_HAL_RVV_1P0_ENABLED
namespace {
template <typename SQRT_T, typename T = typename SQRT_T::T::ElemType>
inline int magnitude(const T* x, const T* y, T* dst, int len)
{
size_t vl;
for (; len > 0; len -= (int)vl, x += vl, y += vl, dst += vl)
{
vl = SQRT_T::T::setvl(len);
auto vx = SQRT_T::T::vload(x, vl);
auto vy = SQRT_T::T::vload(y, vl);
auto vmag = common::sqrt<SQRT_T::iter_times>(__riscv_vfmadd(vx, vx, __riscv_vfmul(vy, vy, vl), vl), vl);
SQRT_T::T::vstore(dst, vmag, vl);
}
return CV_HAL_ERROR_OK;
}
} // anonymous
int magnitude32f(const float *x, const float *y, float *dst, int len) {
return magnitude<common::Sqrt32f<RVV_F32M8>>(x, y, dst, len);
}
int magnitude64f(const double *x, const double *y, double *dst, int len) {
return magnitude<common::Sqrt64f<RVV_F64M8>>(x, y, dst, len);
}
#endif // CV_HAL_RVV_1P0_ENABLED
}}} // cv::rvv_hal::core