Title
§[simd] math functions should not needlessly access `errno`
Status
new
Section
[simd.math] [simd.complex.math]
Submitter
Jan Schultke

Created on 2026-11-10.00:00:00 last changed 1 week ago

Messages

Date: 2026-11-15.13:06:53

Proposed resolution:

This wording is relative to N5054.

  1. Modify [simd.math] as indicated:

    template<math-floating-point V>
      constexpr rebind_t<int, deduced-vec-t<V>> ilogb(const V& x);
    […]
    template<math-floating-point V>
      constexpr typename deduced-vec-t<V>::mask_type
        isunordered(const V& x, const deduced-vec-t<V>& y);
    

    -1- Let `Ret` denote the return type of the specialization of a function template […]

    -2- Returns: A value `ret` of type `Ret`, that is element-wise equal to the result of calling math-func-vec with the parameters of the above functions. If in an invocation of a scalar overload of math-func for index `i` in math-func-vec a domain, pole, or range error would occur, the value of `ret[i]` is unspecified.

    -3 Remarks: It is unspecified whether `errno` ([errno]) is accessed if a domain, pole, or range error would occur.

    template<math-floating-point V>
      constexpr deduced-vec-t<V> ldexp(const V& x, const rebind_t<int, deduced-vec-t<V>>& exp);
    […]
    template<math-floating-point V>
      constexpr deduced-vec-t<V>
        scalbln(const V& x, const rebind_t<long int, deduced-vec-t<V>>& n);
    

    -4- Let `Ret` be deduced-vec-t<V>. Let math-func denote the name of the function template. Let math-func-vec denote: […]

    -5- Returns: A value `ret` of type `Ret`, that is element-wise equal to the result of calling math-func-vec with the parameters of the above functions. If in an invocation of a scalar overload of math-func for index `i` in math-func-vec a domain, pole, or range error would occur, the value of `ret[i]` is unspecified.

    -6- Remarks: It is unspecified whether `errno` ([errno]) is accessed if a domain, pole, or range error would occur.

    […]
    template<math-floating-point V> constexpr deduced-vec-t<V> acos(const V& x);
    […]
    template<math-floating-point V> deduced-vec-t<V> riemann_zeta(const V& x);
    

    -9- Let `Ret` denote the return type of the specialization of a function template with the name math-func. Let math-func-vec denote: […]

    -10- Returns: A value `ret` of type `Ret`, that is element-wise approximately equal to the result of calling math-func-vec with the parameters of the above functions. If in an invocation of a scalar overload of math-func for index `i` in math-func-vec a domain, pole, or range error would occur, the value of `ret[i]` is unspecified.

    -11- Remarks: It is unspecified whether `errno` ([errno]) is accessed if a domain, pole, or range error would occur.

    […]
    template<math-floating-point V>
      constexpr deduced-vec-t<V> remquo(const V& x, const V& y,
        rebind_t<int, deduced-vec-t<V>>* quo);
    […]
    template<math-floating-point V>
      constexpr deduced-vec-t<V>
        remquo(const V& x, const deduced-vec-t<V>& y, rebind_t<int, deduced-vec-t<V>>* quo);
    

    -19- Let `V0` be deduced-vec-t<V>. Let remquo-vec denote: […] If in an invocation of a scalar overload of `remquo` for index `i` in remquo-vec a domain, pole, or range error would occur, the value of `ret[i]` is unspecified.

    -20- Effects: Sets `*quo` to `ret.second`.

    -21- Returns: `ret.first`.

    -22- Remarks: It is unspecified whether `errno` ([errno]) is accessed if a domain, pole, or range error would occur.

  2. Modify [simd.complex.math] as indicated:

    template<simd-complex V>
      constexpr rebind_t<simd-complex-value-type<V> , V> real(const V&) noexcept;
    […]
    template<simd-complex V> constexpr V atanh(const V& v);
    

    -1- Returns: A `basic_vec` object `ret` where […]. If in an invocation of cmplx-func for index i a domain, pole, or range error would occur, the value of ret[i] is unspecified.

    -2- Remarks: It is unspecified whether `errno` ([errno]) is accessed if a domain, pole, or range error would occur.

    template<simd-floating-point V>
      rebind_t<complex<typename V::value_type>, V> polar(const V& x, const V& y = {});
    
    template<simd-complex V> constexpr V pow(const V& x, const V& y);
    

    -3- Returns: A `basic_vec` object `ret` where […]. If in an invocation of cmplx-func for index i a domain, pole, or range error would occur, the value of ret[i] is unspecified.

    -4- Remarks: It is unspecified whether `errno` ([errno]) is accessed if a domain, pole, or range error would occur.

Date: 2026-11-10.00:00:00

Throughout subclause [simd], it is stated that access to `errno` is unspecified. This allows otherwise non-compliant optimizations like `-fno-math-errno`.

Unfortunately, the wording inadvertently permits accessing `errno` for no good reason, even when the underlying math function would have never done so. For example, `std::sqrt(0)` does not access `errno`, but it is unspecified whether std::simd::sqrt(std::simd::vec<double>(0)) accesses `errno`.

History
Date User Action Args
2026-11-15 13:06:53adminsetmessages: + msg16656
2026-11-10 00:00:00admincreate