Skip to content

Commit f254d59

Browse files
jensmaurertkoeppe
authored andcommitted
P3008R6 Atomic floating-point min/max
1 parent 7e0e1c7 commit f254d59

File tree

3 files changed

+147
-3
lines changed

3 files changed

+147
-3
lines changed

source/numerics.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9664,6 +9664,11 @@
96649664
constexpr float fminf(float x, float y);
96659665
constexpr long double fminl(long double x, long double y);
96669666

9667+
constexpr @\placeholdernc{floating-point-type}@ fmaximum(@\placeholdernc{floating-point-type}@ x, @\placeholdernc{floating-point-type}@ y);
9668+
constexpr @\placeholdernc{floating-point-type}@ fmaximum_num(@\placeholdernc{floating-point-type}@ x, @\placeholdernc{floating-point-type}@ y);
9669+
constexpr @\placeholdernc{floating-point-type}@ fminimum(@\placeholdernc{floating-point-type}@ x, @\placeholdernc{floating-point-type}@ y);
9670+
constexpr @\placeholdernc{floating-point-type}@ fminimum_num(@\placeholdernc{floating-point-type}@ x, @\placeholdernc{floating-point-type}@ y);
9671+
96679672
constexpr @\placeholdernc{floating-point-type}@ fma(@\placeholdernc{floating-point-type}@ x, @\placeholdernc{floating-point-type}@ y,
96689673
@\placeholdernc{floating-point-type}@ z);
96699674
constexpr float fmaf(float x, float y, float z);

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@
590590
#define @\defnlibxname{cpp_lib_atomic_float}@ 201711L // freestanding, also in \libheader{atomic}
591591
#define @\defnlibxname{cpp_lib_atomic_is_always_lock_free}@ 201603L // freestanding, also in \libheader{atomic}
592592
#define @\defnlibxname{cpp_lib_atomic_lock_free_type_aliases}@ 201907L // also in \libheader{atomic}
593-
#define @\defnlibxname{cpp_lib_atomic_min_max}@ 202403L // freestanding, also in \libheader{atomic}
593+
#define @\defnlibxname{cpp_lib_atomic_min_max}@ 202506L // freestanding, also in \libheader{atomic}
594594
#define @\defnlibxname{cpp_lib_atomic_ref}@ 202411L // freestanding, also in \libheader{atomic}
595595
#define @\defnlibxname{cpp_lib_atomic_shared_ptr}@ 201711L // also in \libheader{memory}
596596
#define @\defnlibxname{cpp_lib_atomic_value_initialization}@ 201911L // freestanding, also in \libheader{atomic}, \libheader{memory}

source/threads.tex

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3773,6 +3773,19 @@
37733773
constexpr value_type fetch_sub(value_type,
37743774
memory_order = memory_order::seq_cst) const noexcept;
37753775

3776+
constexpr @\placeholdernc{floating-point-type}@ fetch_max(@\placeholdernc{floating-point-type}@,
3777+
memory_order = memory_order::seq_cst) const noexcept;
3778+
constexpr @\placeholdernc{floating-point-type}@ fetch_min(@\placeholdernc{floating-point-type}@,
3779+
memory_order = memory_order::seq_cst) const noexcept;
3780+
constexpr @\placeholdernc{floating-point-type}@ fetch_fmaximum(@\placeholdernc{floating-point-type}@,
3781+
memory_order = memory_order::seq_cst) const noexcept;
3782+
constexpr @\placeholdernc{floating-point-type}@ fetch_fminimum(@\placeholdernc{floating-point-type}@,
3783+
memory_order = memory_order::seq_cst) const noexcept;
3784+
constexpr @\placeholdernc{floating-point-type}@ fetch_fmaximum_num(@\placeholdernc{floating-point}@,
3785+
memory_order = memory_order::seq_cst) const noexcept;
3786+
constexpr @\placeholdernc{floating-point-type}@ fetch_fminimum_num(@\placeholdernc{floating-point-type}@,
3787+
memory_order = memory_order::seq_cst) const noexcept;
3788+
37763789
constexpr value_type operator+=(value_type) const noexcept;
37773790
constexpr value_type operator-=(value_type) const noexcept;
37783791

@@ -3792,10 +3805,24 @@
37923805
\pnum
37933806
The following operations perform arithmetic computations.
37943807
The correspondence among key, operator, and computation is specified
3795-
in \tref{atomic.types.int.comp}.
3808+
in \tref{atomic.types.int.comp},
3809+
except for the keys
3810+
\tcode{max},
3811+
\tcode{min},
3812+
\tcode{fmaximum},
3813+
\tcode{fminimum},
3814+
\tcode{fmaximum_num}, and
3815+
\tcode{fminimum_num},
3816+
which are specified below.
37963817

37973818
\indexlibrarymember{fetch_add}{atomic_ref<\placeholder{floating-point-type}>}%
37983819
\indexlibrarymember{fetch_sub}{atomic_ref<\placeholder{floating-point-type}>}%
3820+
\indexlibrarymember{fetch_fmaximum}{atomic_ref<\placeholder{floating-point-type}>}%
3821+
\indexlibrarymember{fetch_fminimum}{atomic_ref<\placeholder{floating-point-type}>}%
3822+
\indexlibrarymember{fetch_fmaximum_num}{atomic_ref<\placeholder{floating-point-type}>}%
3823+
\indexlibrarymember{fetch_fminimum_num}{atomic_ref<\placeholder{floating-point-type}>}%
3824+
\indexlibrarymember{fetch_max}{atomic_ref<\placeholder{floating-point-type}>}%
3825+
\indexlibrarymember{fetch_min}{atomic_ref<\placeholder{floating-point-type}>}%
37993826
\begin{itemdecl}
38003827
constexpr value_type fetch_@\placeholdernc{key}@(value_type operand,
38013828
memory_order order = memory_order::seq_cst) const noexcept;
@@ -3830,6 +3857,41 @@
38303857
The floating-point environment\iref{cfenv}
38313858
for atomic arithmetic operations on \tcode{\placeholder{floating-\newline point-type}}
38323859
may be different than the calling thread's floating-point environment.
3860+
3861+
\pnum
3862+
\begin{itemize}
3863+
\item
3864+
For \tcode{fetch_fmaximum} and \tcode{fetch_fminimum},
3865+
the maximum and minimum computation is performed
3866+
as if by \tcode{fmaximum} and \tcode{fminimum}, respectively,
3867+
with \tcode{*ptr} and the first parameter as the arguments.
3868+
\item
3869+
For \tcode{fetch_fmaximum_num} and \tcode{fetch_fminimum_num},
3870+
the maximum and minimum computation is performed
3871+
as if by \tcode{fmaximum_num} and \tcode{fminimum_num}, respectively,
3872+
with \tcode{*ptr} and the first parameter as the arguments.
3873+
\item
3874+
For \tcode{fetch_max} and \tcode{fetch_min},
3875+
the maximum and minimum computation is performed
3876+
as if by \tcode{fmaximum_num} and \tcode{fminimum_num}, respectively,
3877+
with \tcode{*ptr} and the first parameter as the arguments, except that:
3878+
\begin{itemize}
3879+
\item
3880+
If both arguments are NaN, an unspecified NaN value is stored at \tcode{*ptr}.
3881+
\item
3882+
If exactly one argument is a NaN,
3883+
either the other argument or an unspecified NaN value is stored at \tcode{*ptr};
3884+
it is unspecified which.
3885+
\item
3886+
If the arguments are differently signed zeros,
3887+
which of these values is stored at \tcode{*ptr} is unspecified.
3888+
\end{itemize}
3889+
\end{itemize}
3890+
3891+
\pnum
3892+
\recommended
3893+
The implementation of \tcode{fetch_max} and \tcode{fetch_min}
3894+
should treat negative zero as smaller than positive zero.
38333895
\end{itemdescr}
38343896

38353897
\indexlibrarymember{operator+=}{atomic_ref<\placeholder{floating-point-type}>}%
@@ -4965,6 +5027,30 @@
49655027
memory_order = memory_order::seq_cst) volatile noexcept;
49665028
constexpr @\placeholdernc{floating-point-type}@ fetch_sub(@\placeholdernc{floating-point-type}@,
49675029
memory_order = memory_order::seq_cst) noexcept;
5030+
@\placeholdernc{floating-point-type}@ fetch_max(@\placeholdernc{floating-point-type}@,
5031+
memory_order = memory_order::seq_cst) volatile noexcept;
5032+
constexpr @\placeholdernc{floating-point-type}@ fetch_max(@\placeholdernc{floating-point-type}@,
5033+
memory_order = memory_order::seq_cst) noexcept;
5034+
@\placeholdernc{floating-point-type}@ fetch_min(@\placeholdernc{floating-point-type}@,
5035+
memory_order = memory_order::seq_cst) volatile noexcept;
5036+
constexpr @\placeholdernc{floating-poin-type}@t fetch_min(@\placeholdernc{floating-point-type}@,
5037+
memory_order = memory_order::seq_cst) noexcept;
5038+
@\placeholdernc{floating-point-type}@ fetch_fmaximum(@\placeholdernc{floating-point-type}@,
5039+
memory_order = memory_order::seq_cst) volatile noexcept;
5040+
constexpr @\placeholdernc{floating-point-type}@ fetch_fmaximum(@\placeholdernc{floating-point-type}@,
5041+
memory_order = memory_order::seq_cst) noexcept;
5042+
@\placeholdernc{floating-point-type}@ fetch_fminimum(@\placeholdernc{floating-point-type}@,
5043+
memory_order = memory_order::seq_cst) volatile noexcept;
5044+
constexpr @\placeholdernc{floating-point-type}@ fetch_fminimum(@\placeholdernc{floating-point-type}@,
5045+
memory_order = memory_order::seq_cst) noexcept;
5046+
@\placeholdernc{floating-point-type}@ fetch_fmaximum_num(@\placeholdernc{floating-point-type}@,
5047+
memory_order = memory_order::seq_cst) volatile noexcept;
5048+
constexpr @\placeholdernc{floating-point-type}@ fetch_fmaximum_num(@\placeholdernc{floating-point-type}@,
5049+
memory_order = memory_order::seq_cst) noexcept;
5050+
@\placeholdernc{floating-point-type}@ fetch_fminimum_num(@\placeholdernc{floating-point-type}@,
5051+
memory_order = memory_order::seq_cst) volatile noexcept;
5052+
constexpr @\placeholdernc{floating-point-type}@ fetch_fminimum_num(f@\placeholdernc{loating-point-type}@,
5053+
memory_order = memory_order::seq_cst) noexcept;
49685054

49695055
@\placeholdernc{floating-point-type}@ operator+=(@\placeholder{floating-point-type}@) volatile noexcept;
49705056
constexpr @\placeholdernc{floating-point-type}@ operator+=(@\placeholder{floating-point-type}@) noexcept;
@@ -4994,14 +5080,28 @@
49945080
\pnum
49955081
The following operations perform arithmetic addition and subtraction computations.
49965082
The correspondence among key, operator, and computation is specified
4997-
in \tref{atomic.types.int.comp}.
5083+
in \tref{atomic.types.int.comp},
5084+
except for the keys
5085+
\tcode{max},
5086+
\tcode{min},
5087+
\tcode{fmaximum},
5088+
\tcode{fminimum},
5089+
\tcode{fmaximum_num}, and
5090+
\tcode{fminimum_num},
5091+
which are specified below.
49985092

49995093
\indexlibraryglobal{atomic_fetch_add}%
50005094
\indexlibraryglobal{atomic_fetch_sub}%
50015095
\indexlibraryglobal{atomic_fetch_add_explicit}%
50025096
\indexlibraryglobal{atomic_fetch_sub_explicit}%
50035097
\indexlibrarymember{fetch_add}{atomic<\placeholder{floating-point-type}>}%
50045098
\indexlibrarymember{fetch_sub}{atomic<\placeholder{floating-point-type}>}%
5099+
\indexlibrarymember{fetch_fmaximum}{atomic<\placeholder{floating-point-type}>}%
5100+
\indexlibrarymember{fetch_fminimum}{atomic<\placeholder{floating-point-type}>}%
5101+
\indexlibrarymember{fetch_fmaximum_num}{atomic<\placeholder{floating-point-type}>}%
5102+
\indexlibrarymember{fetch_fminimum_num}{atomic<\placeholder{floating-point-type}>}%
5103+
\indexlibrarymember{fetch_max}{atomic<\placeholder{floating-point-type}>}%
5104+
\indexlibrarymember{fetch_min}{atomic<\placeholder{floating-point-type}>}%
50055105
\begin{itemdecl}
50065106
T fetch_@\placeholdernc{key}@(T operand, memory_order order = memory_order::seq_cst) volatile noexcept;
50075107
constexpr T fetch_@\placeholdernc{key}@(T operand, memory_order order = memory_order::seq_cst) noexcept;
@@ -5035,6 +5135,45 @@
50355135
The floating-point environment\iref{cfenv} for atomic arithmetic operations
50365136
on \tcode{\placeholder{floating-point-type}} may be different than the
50375137
calling thread's floating-point environment.
5138+
5139+
\pnum
5140+
\begin{itemize}
5141+
\item
5142+
For \tcode{fetch_fmaximum} and \tcode{fetch_fminimum},
5143+
the maximum and minimum computation is performed
5144+
as if by \tcode{fmaximum} and \tcode{fminimum}, respectively,
5145+
with the value pointed to by \tcode{this} and the first parameter
5146+
as the arguments.
5147+
\item
5148+
For \tcode{fetch_fmaximum_num} and \tcode{fetch_fminimum_num},
5149+
the maximum and minimum computation is performed
5150+
as if by \tcode{fmaximum_num} and \tcode{fminimum_num}, respectively,
5151+
with the value pointed to by \tcode{this} and the first parameter
5152+
as the arguments.
5153+
\item
5154+
For \tcode{fetch_max} and \tcode{fetch_min},
5155+
the maximum and minimum computation is performed
5156+
as if by \tcode{fmaximum_num} and \tcode{fminimum_num}, respectively,
5157+
with the value pointed to by \tcode{this} and the first parameter
5158+
as the arguments, except that:
5159+
\begin{itemize}
5160+
\item
5161+
If both arguments are NaN,
5162+
an unspecified NaN value replaces the value pointed to by \tcode{this}.
5163+
\item
5164+
If exactly one argument is a NaN,
5165+
either the other argument or an unspecified NaN value
5166+
replaces the value pointed to by \tcode{this}; it is unspecified which.
5167+
\item
5168+
If the arguments are differently signed zeros,
5169+
which of these values replaces the value pointed to by this is unspecified.
5170+
\end{itemize}
5171+
\end{itemize}
5172+
5173+
\pnum
5174+
\recommended
5175+
The implementation of \tcode{fetch_max} and \tcode{fetch_min}
5176+
should treat negative zero as smaller than positive zero.
50385177
\end{itemdescr}
50395178

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

0 commit comments

Comments
 (0)