core: arm64: v_round() works with round to nearest, ties to even.

pull/24215/head
Kumataro 1 year ago committed by Alexander Smorkalov
parent a308dfca98
commit 72bb8bb73c
  1. 4
      modules/core/include/opencv2/core/hal/intrin_neon.hpp
  2. 8
      modules/core/test/test_intrin_utils.hpp

@ -1997,12 +1997,12 @@ inline v_int32x4 v_trunc(const v_float32x4& a)
inline v_int32x4 v_round(const v_float64x2& a) inline v_int32x4 v_round(const v_float64x2& a)
{ {
static const int32x2_t zero = vdup_n_s32(0); static const int32x2_t zero = vdup_n_s32(0);
return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), zero)); return v_int32x4(vcombine_s32(vmovn_s64(vcvtnq_s64_f64(a.val)), zero));
} }
inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b) inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b)
{ {
return v_int32x4(vcombine_s32(vmovn_s64(vcvtaq_s64_f64(a.val)), vmovn_s64(vcvtaq_s64_f64(b.val)))); return v_int32x4(vcombine_s32(vmovn_s64(vcvtnq_s64_f64(a.val)), vmovn_s64(vcvtnq_s64_f64(b.val))));
} }
inline v_int32x4 v_floor(const v_float64x2& a) inline v_int32x4 v_floor(const v_float64x2& a)

@ -1475,12 +1475,15 @@ template<typename R> struct TheTest
TheTest & test_float_math() TheTest & test_float_math()
{ {
typedef typename V_RegTraits<R>::round_reg Ri; typedef typename V_RegTraits<R>::round_reg Ri;
Data<R> data1, data2, data3; Data<R> data1, data1_border, data2, data3;
// See https://github.com/opencv/opencv/issues/24213
data1_border *= 0.5;
data1 *= 1.1; data1 *= 1.1;
data2 += 10; data2 += 10;
R a1 = data1, a2 = data2, a3 = data3; R a1 = data1, a1_border = data1_border, a2 = data2, a3 = data3;
Data<Ri> resB = v_round(a1), Data<Ri> resB = v_round(a1),
resB_border = v_round(a1_border),
resC = v_trunc(a1), resC = v_trunc(a1),
resD = v_floor(a1), resD = v_floor(a1),
resE = v_ceil(a1); resE = v_ceil(a1);
@ -1493,6 +1496,7 @@ template<typename R> struct TheTest
{ {
SCOPED_TRACE(cv::format("i=%d", i)); SCOPED_TRACE(cv::format("i=%d", i));
EXPECT_EQ(cvRound(data1[i]), resB[i]); EXPECT_EQ(cvRound(data1[i]), resB[i]);
EXPECT_EQ(cvRound(data1_border[i]), resB_border[i]);
EXPECT_EQ((typename VTraits<Ri>::lane_type)data1[i], resC[i]); EXPECT_EQ((typename VTraits<Ri>::lane_type)data1[i], resC[i]);
EXPECT_EQ(cvFloor(data1[i]), resD[i]); EXPECT_EQ(cvFloor(data1[i]), resD[i]);
EXPECT_EQ(cvCeil(data1[i]), resE[i]); EXPECT_EQ(cvCeil(data1[i]), resE[i]);

Loading…
Cancel
Save