From 83026bfe871bb9b575f62df03743704a01c13fcd Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov <2536374+asmorkalov@users.noreply.github.com> Date: Mon, 10 Nov 2025 12:11:24 +0300 Subject: [PATCH] Merge pull request #27990 from asmorkalov:as/power9_build_fix Fix missing vec_cvfo on IBM POWER9 due to unavailable VSX float64 conversion #27990 Replaces https://github.com/opencv/opencv/pull/27633 Closes https://github.com/opencv/opencv/issues/27635 ### 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 - [ ] 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 --- .../core/include/opencv2/core/vsx_utils.hpp | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/core/include/opencv2/core/vsx_utils.hpp b/modules/core/include/opencv2/core/vsx_utils.hpp index 4d5a694bae..aafc6c07b1 100644 --- a/modules/core/include/opencv2/core/vsx_utils.hpp +++ b/modules/core/include/opencv2/core/vsx_utils.hpp @@ -257,8 +257,27 @@ VSX_IMPL_1VRG(vec_udword2, vec_udword2, vpopcntd, vec_popcntu) VSX_IMPL_1VRG(vec_udword2, vec_dword2, vpopcntd, vec_popcntu) // converts between single and double-precision -VSX_REDIRECT_1RG(vec_float4, vec_double2, vec_cvfo, vec_floate) -VSX_REDIRECT_1RG(vec_double2, vec_float4, vec_cvfo, vec_doubleo) +// vec_floate and vec_doubleo are available since Power10 and z14 +#if defined(__POWER10__) || (defined(__powerpc64__) && defined(__ARCH_PWR10__) +// Use VSX double<->float conversion instructions (if supported by the architecture) + VSX_REDIRECT_1RG(vec_float4, vec_double2, vec_cvfo, vec_floate) + VSX_REDIRECT_1RG(vec_double2, vec_float4, vec_cvfo, vec_doubleo) +#else +// Fallback: implement vec_cvfo using scalar operations (to ensure successful linking) + static inline vec_float4 vec_cvfo(const vec_double2& a) + { + float r0 = static_cast(reinterpret_cast(&a)[0]); + float r1 = static_cast(reinterpret_cast(&a)[1]); + return (vec_float4){r0, 0.f, r1, 0.f}; + } + + static inline vec_double2 vec_cvfo(const vec_float4& a) + { + double r0 = static_cast(reinterpret_cast(&a)[0]); + double r1 = static_cast(reinterpret_cast(&a)[2]); + return (vec_double2){r0, r1}; + } +#endif // converts word and doubleword to double-precision #undef vec_ctd