mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 12:12:06 -06:00
core: enable FP16 conversions on MSVC ARM64 (#31185)
Three changes: intrin_neon.hpp — MSVC versions of v_load_expand / v_pack_store over the raw intrinsics system.cpp — report FP16 on Windows ARM64, matching the aarch64 branch at line 585. Baseline features are verified at startup, so without this the library builds and then refuses to run cpu_fp16.cpp — MSVC ARM64 branch for the check, written with _ARM64_DISTINCT_NEON_TYPES set so the check and the library agree. The old one did not, which is why it passed while the build failed
This commit is contained in:
@@ -11,8 +11,7 @@ int test()
|
||||
_mm_storel_epi64((__m128i*)dst, v_dst);
|
||||
return (int)dst[0];
|
||||
}
|
||||
#elif (defined __GNUC__ && (defined __arm__ || defined __aarch64__)) /*|| (defined _MSC_VER && defined _M_ARM64)*/
|
||||
// Windows + ARM64 case disabled: https://github.com/opencv/opencv/issues/25052
|
||||
#elif (defined __GNUC__ && (defined __arm__ || defined __aarch64__))
|
||||
#include "arm_neon.h"
|
||||
int test()
|
||||
{
|
||||
@@ -23,6 +22,17 @@ int test()
|
||||
*(float16x4_t*)dst = v_dst;
|
||||
return (int)dst[0];
|
||||
}
|
||||
#elif defined _MSC_VER && (defined _M_ARM64 || defined _M_ARM64EC)
|
||||
// OpenCV is built with _ARM64_DISTINCT_NEON_TYPES, which hides the vcvt_*_f16 wrappers.
|
||||
#define _ARM64_DISTINCT_NEON_TYPES
|
||||
#include "arm_neon.h"
|
||||
int test()
|
||||
{
|
||||
short dst[8] = { 0 };
|
||||
__n128 v_src = neon_fcvtl_32(neon_ld1m_16((const __int16*)dst));
|
||||
neon_st1m_16((__int16*)dst, neon_fcvtn_32(v_src));
|
||||
return (int)dst[0];
|
||||
}
|
||||
#else
|
||||
#error "FP16 is not supported"
|
||||
#endif
|
||||
|
||||
@@ -2651,6 +2651,23 @@ inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_flo
|
||||
|
||||
////// FP16 support ///////
|
||||
#if CV_FP16
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
// _ARM64_DISTINCT_NEON_TYPES, which this build requires for distinct NEON vector types, hides
|
||||
// float16x4_t and the vcvt_*_f16 wrappers; the same instructions stay reachable as raw neon_*.
|
||||
inline v_float32x4 v_load_expand(const hfloat* ptr)
|
||||
{
|
||||
__n128 f32 = neon_fcvtl_32(neon_ld1m_16((const __int16*)ptr));
|
||||
// memcpy is the only conversion MSVC accepts between __n128 and a distinct NEON type.
|
||||
float32x4_t v; std::memcpy(&v, &f32, sizeof(v));
|
||||
return v_float32x4(v);
|
||||
}
|
||||
|
||||
inline void v_pack_store(hfloat* ptr, const v_float32x4& v)
|
||||
{
|
||||
__n128 f32; std::memcpy(&f32, &v.val, sizeof(f32));
|
||||
neon_st1m_16((__int16*)ptr, neon_fcvtn_32(f32));
|
||||
}
|
||||
#else
|
||||
inline v_float32x4 v_load_expand(const hfloat* ptr)
|
||||
{
|
||||
float16x4_t v =
|
||||
@@ -2672,6 +2689,7 @@ inline void v_pack_store(hfloat* ptr, const v_float32x4& v)
|
||||
vst1_f16((__fp16*)ptr, hv);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
inline v_float32x4 v_load_expand(const hfloat* ptr)
|
||||
{
|
||||
|
||||
@@ -688,6 +688,7 @@ struct HWFeatures
|
||||
#endif
|
||||
#if defined _M_ARM64 || defined _M_ARM64EC
|
||||
have[CV_CPU_NEON] = true;
|
||||
have[CV_CPU_FP16] = true;
|
||||
#endif
|
||||
#ifdef __riscv_vector
|
||||
have[CV_CPU_RISCVV] = true;
|
||||
|
||||
Reference in New Issue
Block a user