**File:** modules/gapi/src/backends/fluid/gfluidcore.cpp
**Change Type:** modified
**Context:** PR #18466: GAPI: SIMD optimization for AddWeighted kernel. - SIMD optimization for AddWeighted kernel via universal intrinsics. <cut/> ``` force_build...

**Code Changes:**
```diff
@@ -97,6 +97,130 @@ static inline DST divr(SRC1 x, SRC2 y, float scale=1)
 // Fluid kernels: addWeighted
 //
 //---------------------------
+#if CV_SSE2
+CV_ALWAYS_INLINE v_float32 v_load_f32(const ushort* in)
+{
+    return v_cvt_f32(v_reinterpret_as_s32(vx_load_expand(in)));
+}
+
```

Review comment:
I don't tried to improve performance with commit "Refactoring.Step2". I've just tried remove excess intermediate function which has the same name `addw_simd()` but look like this: ```` template<typename SRC, typename DST> CV_ALWAYS_INLINE int addw_simd(const SRC in1[], const SRC in2[], DST out[], float _alpha, float _beta, float _gamma, int length) { //Cases when dst type is float are successfully vectorized with compiler. if (std::is_same<DST, float>::value) return 0; v_float32 alpha = vx_setall_f32(_alpha); v_float32 beta = vx_setall_f32(_beta); v_float32 gamma = vx_setall_f32(_gamma); if (std::is_same<SRC, ushort>::value && std::is_same<DST, ushort>::value) { return addw_short2short(reinterpret_cast<const ushort*>(in1), reinterpret_cast<const ushort*>(in2), reinterpret_cast<ushort*>(out), alpha, beta, gamma, length); } else if (std::is_same<SRC, short>::value && std::is_same<DST, short>::value) { return addw_short2short(reinterpret_cast<const short*>(in1), reinterpret_cast<const short*>(in2), reinterpret_cast<short*>(out), alpha, beta, gamma, length); } else if (std::is_same<SRC, short>::value && std::is_same<DST, uchar>::value) { return addw_short2uchar(reinterpret_cast<const short*>(in1), reinterpret_cast<const short*>(in2), reinterpret_cast<uchar*>(out), alpha, beta, gamma, length); } else if (std::is_same<SRC, ushort>::value && std::is_same<DST, uchar>::value) { return addw_short2uchar(reinterpret_cast<const ushort*>(in1), reinterpret_cast<const ushort*>(in2), reinterpret_cast<uchar*>(out), alpha, beta, gamma, length); } else if (std::is_same<SRC, uchar>::value && std::is_same<DST, uchar>::value) { constexpr int nlanes = v_uint8::nlanes; if (length < nlanes) return 0; int x = 0; for (;;) { for (; x <= length - nlanes; x += nlanes) { v_float32 a1 = v_load_f32(reinterpret_cast<const uchar*>(&in1[x])); v_float32 a2 = v_load_f32(reinterpret_cast<const uchar*>(&in1[x + nlanes / 4])); v_float32 a3 = v_load_f32(reinterpret_cast<const uchar*>(&in1[x + nlanes / 2])); v_float32 a4 = v_load_f32(reinterpret_cast<const uchar*>(&in1[x + 3 * nlanes / 4])); v_float32 b1 = v_load_f32(reinterpret_cast<const uchar*>(&in2[x])); v_float32 b2 = v_load_f32(reinterpret_cast<const uchar*>(&in2[x + nlanes / 4])); v_float32 b3 = v_load_f32(reinterpret_cast<const uchar*>(&in2[x + nlanes / 2])); v_float32 b4 = v_load_f32(reinterpret_cast<const uchar*>(&in2[x + 3 * nlanes / 4])); v_int32 sum1 = v_round(v_fma(a1, alpha, v_fma(b1, beta, gamma))), sum2 = v_round(v_fma(a2, alpha, v_fma(b2, beta, gamma))), sum3 = v_round(v_fma(a3, alpha, v_fma(b3, beta, gamma))), sum4 = v_round(v_fma(a4, alpha, v_fma(b4, beta, gamma))); vx_store(reinterpret_cast<uchar*>(&out[x]), v_pack_u(v_pack(sum1, sum2), v_pack(sum3, sum4))); } if (x < length) { x = length - nlanes; continue; // process one more time (unaligned tail) } break; } return x; } return 0; }` ```