@@ -421,13 +421,19 @@ MLI_FORCE_INLINE vNx4char_t eltwise_perform_operation<vNx4char_t, vNx4char_t, EL
421421 int shift = post_op_shift - mul_hi_shift;
422422 int shift_left = mli_math_max_fx (1 - shift, 0 );
423423 int shift_right = mli_math_max_fx (shift, 1 );
424+ // As shift is limited by 23 the shift_right is limited by 7 so we can pre_shift left the out_offset
425+ int16_t offset = out_offset << shift_right;
426+ #ifdef ROUND_UP
427+ offset += ((1 << shift_right) >> 1 );
428+ #else
429+ #error Rounding mode not supported
430+ #endif
424431 vNx4short_t max = to_vNx4short_t (mli_math_max_fx (op1, op2));
425432 max = mli_math_sub_fx (max, (vNx4short_t)in_offset1);
426433 max = mli_math_asl_fx (max, shift_left);
427434 vNx4short_t max_scaled = mli_math_mul_fx_high (max, scale_factor1);
428- max_scaled = mli_math_asr_rnd_fx (max_scaled, shift_right);
429- max_scaled = mli_math_add_fx (max_scaled, (vNx4short_t) out_offset);
430- res = mli_math_cast_fx<vNx4short_t, vNx4char_t>(max_scaled);
435+ max_scaled = mli_math_add_fx (max_scaled, (vNx4short_t) offset);
436+ res = mli_math_cast_fx<vNx4short_t, vNx4char_t, false >(max_scaled, shift_right);
431437 return res;
432438}
433439
@@ -496,13 +502,19 @@ MLI_FORCE_INLINE vNx4char_t eltwise_perform_operation<vNx4char_t, vNx4char_t, EL
496502 int shift = post_op_shift - mul_hi_shift;
497503 int shift_left = mli_math_max_fx (1 - shift, 0 );
498504 int shift_right = mli_math_max_fx (shift, 1 );
505+ // As shift is limited by 23 the shift_right is limited by 7 so we can pre_shift left the out_offset
506+ int16_t offset = out_offset << shift_right;
507+ #ifdef ROUND_UP
508+ offset += ((1 << shift_right) >> 1 );
509+ #else
510+ #error Rounding mode not supported
511+ #endif
499512 vNx4short_t max = to_vNx4short_t (mli_math_min_fx (op1, op2));
500513 max = mli_math_sub_fx (max, (vNx4short_t)in_offset1);
501514 max = mli_math_asl_fx (max, shift_left);
502515 vNx4short_t max_scaled = mli_math_mul_fx_high (max, scale_factor1);
503- max_scaled = mli_math_asr_rnd_fx (max_scaled, shift_right);
504- max_scaled = mli_math_add_fx (max_scaled, (vNx4short_t) out_offset);
505- res = mli_math_cast_fx<vNx4short_t, vNx4char_t>(max_scaled);
516+ max_scaled = mli_math_add_fx (max_scaled, (vNx4short_t) offset);
517+ res = mli_math_cast_fx<vNx4short_t, vNx4char_t, false >(max_scaled, shift_right);
506518 return res;
507519
508520}
0 commit comments