Skip to content

P3008R6 Atomic floating-point min/max #8019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/numerics.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9649,6 +9649,11 @@
constexpr float fminf(float x, float y);
constexpr long double fminl(long double x, long double y);

constexpr @\placeholdernc{floating-point-type}@ fmaximum(@\placeholdernc{floating-point-type}@ x, @\placeholdernc{floating-point-type}@ y);
constexpr @\placeholdernc{floating-point-type}@ fmaximum_num(@\placeholdernc{floating-point-type}@ x, @\placeholdernc{floating-point-type}@ y);
constexpr @\placeholdernc{floating-point-type}@ fminimum(@\placeholdernc{floating-point-type}@ x, @\placeholdernc{floating-point-type}@ y);
constexpr @\placeholdernc{floating-point-type}@ fminimum_num(@\placeholdernc{floating-point-type}@ x, @\placeholdernc{floating-point-type}@ y);

constexpr @\placeholdernc{floating-point-type}@ fma(@\placeholdernc{floating-point-type}@ x, @\placeholdernc{floating-point-type}@ y,
@\placeholdernc{floating-point-type}@ z);
constexpr float fmaf(float x, float y, float z);
Expand Down
2 changes: 1 addition & 1 deletion source/support.tex
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@
#define @\defnlibxname{cpp_lib_atomic_float}@ 201711L // freestanding, also in \libheader{atomic}
#define @\defnlibxname{cpp_lib_atomic_is_always_lock_free}@ 201603L // freestanding, also in \libheader{atomic}
#define @\defnlibxname{cpp_lib_atomic_lock_free_type_aliases}@ 201907L // also in \libheader{atomic}
#define @\defnlibxname{cpp_lib_atomic_min_max}@ 202403L // freestanding, also in \libheader{atomic}
#define @\defnlibxname{cpp_lib_atomic_min_max}@ 202506L // freestanding, also in \libheader{atomic}
#define @\defnlibxname{cpp_lib_atomic_ref}@ 202411L // freestanding, also in \libheader{atomic}
#define @\defnlibxname{cpp_lib_atomic_shared_ptr}@ 201711L // also in \libheader{memory}
#define @\defnlibxname{cpp_lib_atomic_value_initialization}@ 201911L // freestanding, also in \libheader{atomic}, \libheader{memory}
Expand Down
143 changes: 141 additions & 2 deletions source/threads.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3773,6 +3773,19 @@
constexpr value_type fetch_sub(value_type,
memory_order = memory_order::seq_cst) const noexcept;

constexpr value_type fetch_max(value_type,
memory_order = memory_order::seq_cst) const noexcept;
constexpr value_type fetch_min(value_type,
memory_order = memory_order::seq_cst) const noexcept;
constexpr value_type fetch_fmaximum(value_type,
memory_order = memory_order::seq_cst) const noexcept;
constexpr valu_type fetch_fminimum(value_type,
memory_order = memory_order::seq_cst) const noexcept;
constexpr value_type fetch_fmaximum_num(value_type,
memory_order = memory_order::seq_cst) const noexcept;
constexpr value_type fetch_fminimum_num(value_type,
memory_order = memory_order::seq_cst) const noexcept;

constexpr value_type operator+=(value_type) const noexcept;
constexpr value_type operator-=(value_type) const noexcept;

Expand All @@ -3792,10 +3805,24 @@
\pnum
The following operations perform arithmetic computations.
The correspondence among key, operator, and computation is specified
in \tref{atomic.types.int.comp}.
in \tref{atomic.types.int.comp},
except for the keys
\tcode{max},
\tcode{min},
\tcode{fmaximum},
\tcode{fminimum},
\tcode{fmaximum_num}, and
\tcode{fminimum_num},
which are specified below.

\indexlibrarymember{fetch_add}{atomic_ref<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_sub}{atomic_ref<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_fmaximum}{atomic_ref<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_fminimum}{atomic_ref<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_fmaximum_num}{atomic_ref<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_fminimum_num}{atomic_ref<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_max}{atomic_ref<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_min}{atomic_ref<\placeholder{floating-point-type}>}%
\begin{itemdecl}
constexpr value_type fetch_@\placeholdernc{key}@(value_type operand,
memory_order order = memory_order::seq_cst) const noexcept;
Expand Down Expand Up @@ -3830,6 +3857,41 @@
The floating-point environment\iref{cfenv}
for atomic arithmetic operations on \tcode{\placeholder{floating-\newline point-type}}
may be different than the calling thread's floating-point environment.

\pnum
\begin{itemize}
\item
For \tcode{fetch_fmaximum} and \tcode{fetch_fminimum},
the maximum and minimum computation is performed
as if by \tcode{fmaximum} and \tcode{fminimum}, respectively,
with \tcode{*ptr} and the first parameter as the arguments.
\item
For \tcode{fetch_fmaximum_num} and \tcode{fetch_fminimum_num},
the maximum and minimum computation is performed
as if by \tcode{fmaximum_num} and \tcode{fminimum_num}, respectively,
with \tcode{*ptr} and the first parameter as the arguments.
\item
For \tcode{fetch_max} and \tcode{fetch_min},
the maximum and minimum computation is performed
as if by \tcode{fmaximum_num} and \tcode{fminimum_num}, respectively,
with \tcode{*ptr} and the first parameter as the arguments, except that:
\begin{itemize}
\item
If both arguments are NaN, an unspecified NaN value is stored at \tcode{*ptr}.
\item
If exactly one argument is a NaN,
either the other argument or an unspecified NaN value is stored at \tcode{*ptr};
it is unspecified which.
\item
If the arguments are differently signed zeros,
which of these values is stored at \tcode{*ptr} is unspecified.
\end{itemize}
\end{itemize}

\pnum
\recommended
The implementation of \tcode{fetch_max} and \tcode{fetch_min}
should treat negative zero as smaller than positive zero.
\end{itemdescr}

\indexlibrarymember{operator+=}{atomic_ref<\placeholder{floating-point-type}>}%
Expand Down Expand Up @@ -4965,6 +5027,30 @@
memory_order = memory_order::seq_cst) volatile noexcept;
constexpr @\placeholdernc{floating-point-type}@ fetch_sub(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) noexcept;
@\placeholdernc{floating-point-type}@ fetch_max(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) volatile noexcept;
constexpr @\placeholdernc{floating-point-type}@ fetch_max(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) noexcept;
@\placeholdernc{floating-point-type}@ fetch_min(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) volatile noexcept;
constexpr @\placeholdernc{floating-poin-type}@t fetch_min(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) noexcept;
@\placeholdernc{floating-point-type}@ fetch_fmaximum(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) volatile noexcept;
constexpr @\placeholdernc{floating-point-type}@ fetch_fmaximum(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) noexcept;
@\placeholdernc{floating-point-type}@ fetch_fminimum(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) volatile noexcept;
constexpr @\placeholdernc{floating-point-type}@ fetch_fminimum(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) noexcept;
@\placeholdernc{floating-point-type}@ fetch_fmaximum_num(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) volatile noexcept;
constexpr @\placeholdernc{floating-point-type}@ fetch_fmaximum_num(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) noexcept;
@\placeholdernc{floating-point-type}@ fetch_fminimum_num(@\placeholdernc{floating-point-type}@,
memory_order = memory_order::seq_cst) volatile noexcept;
constexpr @\placeholdernc{floating-point-type}@ fetch_fminimum_num(f@\placeholdernc{loating-point-type}@,
memory_order = memory_order::seq_cst) noexcept;

@\placeholdernc{floating-point-type}@ operator+=(@\placeholder{floating-point-type}@) volatile noexcept;
constexpr @\placeholdernc{floating-point-type}@ operator+=(@\placeholder{floating-point-type}@) noexcept;
Expand Down Expand Up @@ -4994,14 +5080,28 @@
\pnum
The following operations perform arithmetic addition and subtraction computations.
The correspondence among key, operator, and computation is specified
in \tref{atomic.types.int.comp}.
in \tref{atomic.types.int.comp},
except for the keys
\tcode{max},
\tcode{min},
\tcode{fmaximum},
\tcode{fminimum},
\tcode{fmaximum_num}, and
\tcode{fminimum_num},
which are specified below.

\indexlibraryglobal{atomic_fetch_add}%
\indexlibraryglobal{atomic_fetch_sub}%
\indexlibraryglobal{atomic_fetch_add_explicit}%
\indexlibraryglobal{atomic_fetch_sub_explicit}%
\indexlibrarymember{fetch_add}{atomic<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_sub}{atomic<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_fmaximum}{atomic<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_fminimum}{atomic<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_fmaximum_num}{atomic<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_fminimum_num}{atomic<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_max}{atomic<\placeholder{floating-point-type}>}%
\indexlibrarymember{fetch_min}{atomic<\placeholder{floating-point-type}>}%
\begin{itemdecl}
T fetch_@\placeholdernc{key}@(T operand, memory_order order = memory_order::seq_cst) volatile noexcept;
constexpr T fetch_@\placeholdernc{key}@(T operand, memory_order order = memory_order::seq_cst) noexcept;
Expand Down Expand Up @@ -5035,6 +5135,45 @@
The floating-point environment\iref{cfenv} for atomic arithmetic operations
on \tcode{\placeholder{floating-point-type}} may be different than the
calling thread's floating-point environment.

\pnum
\begin{itemize}
\item
For \tcode{fetch_fmaximum} and \tcode{fetch_fminimum},
the maximum and minimum computation is performed
as if by \tcode{fmaximum} and \tcode{fminimum}, respectively,
with the value pointed to by \tcode{this} and the first parameter
as the arguments.
\item
For \tcode{fetch_fmaximum_num} and \tcode{fetch_fminimum_num},
the maximum and minimum computation is performed
as if by \tcode{fmaximum_num} and \tcode{fminimum_num}, respectively,
with the value pointed to by \tcode{this} and the first parameter
as the arguments.
\item
For \tcode{fetch_max} and \tcode{fetch_min},
the maximum and minimum computation is performed
as if by \tcode{fmaximum_num} and \tcode{fminimum_num}, respectively,
with the value pointed to by \tcode{this} and the first parameter
as the arguments, except that:
\begin{itemize}
\item
If both arguments are NaN,
an unspecified NaN value replaces the value pointed to by \tcode{this}.
\item
If exactly one argument is a NaN,
either the other argument or an unspecified NaN value
replaces the value pointed to by \tcode{this}; it is unspecified which.
\item
If the arguments are differently signed zeros,
which of these values replaces the value pointed to by this is unspecified.
\end{itemize}
\end{itemize}

\pnum
\recommended
The implementation of \tcode{fetch_max} and \tcode{fetch_min}
should treat negative zero as smaller than positive zero.
\end{itemdescr}

\indexlibrarymember{operator+=}{atomic<T*>}%
Expand Down