@@ -1127,28 +1127,58 @@ inline HVX_Vector_x2 hvx_vsf_convert_vhf(HVX_Vector vxl, HVX_Vector one) {
11271127 return ret;
11281128}
11291129
1130+ /* *
1131+ * @brief Calculates exponential (e^x) for vector elements with infinity guard
1132+ *
1133+ * This function computes the exponential value for each element in the input vector.
1134+ * For input values greater than kMaxExp (88.02f), the function returns the provided
1135+ * infinity value instead of attempting to calculate an exponential that would overflow.
1136+ *
1137+ * @param sline The input vector containing values to compute exponential for
1138+ * @param inf The vector containing the infinity representation to use for guarded values
1139+ * @return HVX_Vector containing exponential values, with values > kMaxExp replaced by inf
1140+ *
1141+ * @note Input values greater than 88.02f will return the specified infinity value
1142+ */
11301143inline HVX_Vector qhmath_hvx_exp_vf_guard_inf (HVX_Vector sline, const HVX_Vector inf) {
11311144 constexpr float kMaxExp = 88 .02f ;
11321145 const HVX_Vector max_exp = Q6_V_vsplat_R (reinterpret_cast <const uint32_t &>(kMaxExp ));
11331146
1134- HVX_VectorPred pred0 = Q6_Q_vcmp_gt_VsfVsf (sline, max_exp);
1147+ HVX_VectorPred pred_gt_max_exp = Q6_Q_vcmp_gt_VsfVsf (sline, max_exp);
11351148
11361149 HVX_Vector out = qhmath_hvx_exp_vf (sline);
11371150
1138- out = Q6_V_vmux_QVV (pred0 , inf, out);
1151+ out = Q6_V_vmux_QVV (pred_gt_max_exp , inf, out);
11391152 return out;
11401153}
11411154
1155+ /* *
1156+ * @brief Vectorized division with guard for infinite denominators on HVX.
1157+ *
1158+ * Performs element-wise division num/denom using qhmath_hvx_div_vf and then
1159+ * masks out lanes where denom equals the provided inf value, forcing those
1160+ * lanes of the result to zero. This is a temporary guard until proper INF
1161+ * handling is implemented in the underlying division routine.
1162+ *
1163+ * @param num Numerator vector (per-lane).
1164+ * @param denom Denominator vector (per-lane); lanes equal to inf are zeroed in the output.
1165+ * @param coeffs Coefficients used by qhmath_hvx_div_vf for the reciprocal/division approximation.
1166+ * @param inf Lane value representing +INF to compare against denom.
1167+ * @return Vector of num/denom with lanes set to zero where denom == inf.
1168+ *
1169+ * @note NaNs, negative infinity, zero denominators, and subnormals are not explicitly handled.
1170+ * @see qhmath_hvx_div_vf
1171+ */
11421172inline HVX_Vector qhmath_hvx_div_vf_guard_inf (HVX_Vector num,
11431173 HVX_Vector denom,
11441174 HVX_VectorPair_x4 coeffs,
11451175 const HVX_Vector inf) {
1146- HVX_VectorPred pred0 = Q6_Q_vcmp_eq_VwVw (denom, inf);
1176+ HVX_VectorPred pred_inf = Q6_Q_vcmp_eq_VwVw (denom, inf);
11471177
11481178 // TODO: fix the inf in div
11491179 HVX_Vector out = qhmath_hvx_div_vf (num, denom, coeffs);
11501180
1151- out = Q6_V_vmux_QVV (pred0 , Q6_V_vzero (), out);
1181+ out = Q6_V_vmux_QVV (pred_inf , Q6_V_vzero (), out);
11521182 return out;
11531183}
11541184
0 commit comments