Skip to content

Commit 2c939cc

Browse files
committed
Cleanup
1 parent 48c4463 commit 2c939cc

File tree

6 files changed

+11
-118
lines changed

6 files changed

+11
-118
lines changed

libcxx/include/__numeric/saturation_arithmetic.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2525
#if _LIBCPP_STD_VER >= 26
2626

2727
template <typename _Tp>
28-
// concept __libcpp_standard_integer = __libcpp_unsigned_integer<_Tp> || __libcpp_signed_integer<_Tp>;
29-
// concept __libcpp_standard_integer =
30-
// __libcpp_unsigned_integer<remove_cv<_Tp>> || __libcpp_signed_integer<remove_cv<_Tp>>;
3128
concept __libcpp_standard_integer = __libcpp_unsigned_integer<decay_t<_Tp>> || __libcpp_signed_integer<decay_t<_Tp>>;
3229

3330
template <__libcpp_standard_integer _Tp>
3431
// requires __libcpp_standard_integer<_Tp>
3532
_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
36-
// builtins: clang/docs/LanguageExtensions.rst
37-
// builtins:
38-
// https://github.com/llvm/llvm-project/blob/7b45c549670a8e8b6fe90f4382b0699dd20707d3/clang/docs/LanguageExtensions.rst#L3500
3933
if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
4034
return __sum;
4135
// Handle overflow
@@ -80,12 +74,6 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
8074
return std::numeric_limits<_Tp>::max();
8175
} else {
8276
// Signed multiplication overflow
83-
// if (__x > 0 && __y > 0)
84-
// // Overflows if (x > 0 && y > 0)
85-
// return std::numeric_limits<_Tp>::max();
86-
// else if (__y > 0)
87-
// // Overflows if (x > 0 && y < 0)
88-
// return std::numeric_limits<_Tp>::max();
8977
if (__x > 0) {
9078
if (__y > 0)
9179
// Overflows if (x > 0 && y > 0)
@@ -116,9 +104,6 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
116104

117105
template <__libcpp_standard_integer _Rp, __libcpp_standard_integer _Tp>
118106
_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {
119-
// if (std::in_range<_Rp>(__x)) {
120-
// return _Rp{__x};
121-
// }
122107
// Handle overflow
123108
if (std::cmp_less_equal(__x, std::numeric_limits<_Rp>::min()))
124109
return std::numeric_limits<_Rp>::min();

libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/add_sat.pass.cpp

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ constexpr bool test_unsigned() {
7474
}
7575

7676
constexpr bool test() {
77-
// signed
77+
// Signed
7878
test_signed<signed char>();
7979
test_signed<short int>();
8080
test_signed<int>();
8181
test_signed<long int>();
8282
test_signed<long long int>();
83-
// unsigned
83+
// Unsigned
8484
test_unsigned<unsigned char>();
8585
test_unsigned<unsigned short int>();
8686
test_unsigned<unsigned int>();
@@ -90,40 +90,9 @@ constexpr bool test() {
9090
return true;
9191
}
9292

93-
// ADDITIONAL_COMPILE_FLAGS: -Wno-constant-conversion
94-
95-
constexpr void cppreference_test() {
96-
{
97-
constexpr int a = std::add_sat(3, 4); // no saturation occurs, T = int
98-
static_assert(a == 7);
99-
100-
constexpr unsigned char b = std::add_sat<unsigned char>(UCHAR_MAX, 4); // saturated
101-
static_assert(b == UCHAR_MAX);
102-
103-
constexpr unsigned char c = std::add_sat(UCHAR_MAX, 4); // not saturated, T = int
104-
// add_sat(int, int) returns int tmp == 259,
105-
// then assignment truncates 259 % 256 == 3
106-
static_assert(c == 3);
107-
108-
// unsigned char d = std::add_sat(252, c); // Error: inconsistent deductions for T
109-
110-
constexpr unsigned char e = std::add_sat<unsigned char>(251, a); // saturated
111-
static_assert(e == UCHAR_MAX);
112-
// 251 is of type T = unsigned char, `a` is converted to unsigned char value;
113-
// might yield an int -> unsigned char conversion warning for `a`
114-
115-
constexpr signed char f = std::add_sat<signed char>(-123, -3); // not saturated
116-
static_assert(f == -126);
117-
118-
constexpr signed char g = std::add_sat<signed char>(-123, -13); // saturated
119-
static_assert(g == std::numeric_limits<signed char>::min()); // g == -128
120-
}
121-
}
122-
12393
int main(int, char**) {
12494
test();
12595
static_assert(test());
126-
cppreference_test();
12796

12897
return 0;
12998
}

libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/div_sat.pass.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ constexpr bool test_unsigned() {
7474
}
7575

7676
constexpr bool test() {
77-
// signed
77+
// Signed
7878
test_signed<signed char>();
7979
test_signed<short int>();
8080
test_signed<int>();
8181
test_signed<long int>();
8282
test_signed<long long int>();
83-
// unsigned
83+
// Unsigned
8484
test_unsigned<unsigned char>();
8585
test_unsigned<unsigned short int>();
8686
test_unsigned<unsigned int>();
@@ -90,19 +90,9 @@ constexpr bool test() {
9090
return true;
9191
}
9292

93-
constexpr void cppreference_test() {
94-
{
95-
static_assert("" && (std::div_sat<int>(6, 3) == 2) // not saturated
96-
&& (std::div_sat<int>(INT_MIN, -1) == INT_MAX) // saturated
97-
&& (std::div_sat<unsigned>(6, 3) == 2) // not saturated
98-
);
99-
}
100-
}
101-
10293
int main(int, char**) {
10394
test();
10495
static_assert(test());
105-
cppreference_test();
10696

10797
return 0;
10898
}

libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/mul_sat.pass.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ constexpr bool test_unsigned() {
8181
}
8282

8383
constexpr bool test() {
84-
// signed
84+
// Signed
8585
test_signed<signed char>();
8686
test_signed<short int>();
8787
test_signed<int>();
8888
test_signed<long int>();
8989
test_signed<long long int>();
90-
// unsigned
90+
// Unsigned
9191
test_unsigned<unsigned char>();
9292
test_unsigned<unsigned short int>();
9393
test_unsigned<unsigned int>();
@@ -97,23 +97,9 @@ constexpr bool test() {
9797
return true;
9898
}
9999

100-
constexpr void cppreference_test() {
101-
{
102-
static_assert(
103-
"" && (std::mul_sat<int>(2, 3) == 6) // not saturated
104-
&& (std::mul_sat<int>(INT_MAX / 2, 3) == INT_MAX) // saturated
105-
&& (std::mul_sat<int>(-2, 3) == -6) // not saturated
106-
&& (std::mul_sat<int>(INT_MIN / -2, -3) == INT_MIN) // saturated
107-
&& (std::mul_sat<unsigned>(2, 3) == 6) // not saturated
108-
&& (std::mul_sat<unsigned>(UINT_MAX / 2, 3) == UINT_MAX) // saturated
109-
);
110-
}
111-
}
112-
113100
int main(int, char**) {
114101
test();
115102
static_assert(test());
116-
cppreference_test();
117103

118104
return 0;
119105
}

libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/saturate_cast.pass.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include <limits>
1919
#include <numeric>
2020

21-
#include <print>
22-
2321
template <typename IntegerResultT, typename IntegerT>
2422
constexpr bool test_signed_notsaturated() {
2523
constexpr auto minVal = std::numeric_limits<IntegerT>::min();
@@ -77,7 +75,7 @@ constexpr bool test_unsigned_saturated() {
7775
}
7876

7977
constexpr bool test() {
80-
// signed
78+
// Signed
8179
test_signed_notsaturated<long long int, signed char>();
8280
test_signed_notsaturated<long long int, short int>();
8381
test_signed_notsaturated<long long int, int>();
@@ -88,7 +86,7 @@ constexpr bool test() {
8886
test_signed_saturated<int, long long int>();
8987
test_signed_saturated<long int, long long int>();
9088
test_signed_saturated<long long int, long long int>();
91-
// unsigned
89+
// Unsigned
9290
test_unsigned_notsaturated<unsigned long long int, unsigned char>();
9391
test_unsigned_notsaturated<unsigned long long int, unsigned short int>();
9492
test_unsigned_notsaturated<unsigned long long int, unsigned int>();
@@ -103,30 +101,9 @@ constexpr bool test() {
103101
return true;
104102
}
105103

106-
constexpr void cppreference_test() {
107-
{
108-
constexpr std::int16_t x1{696};
109-
110-
constexpr std::int8_t x2 = std::saturate_cast<std::int8_t>(x1);
111-
static_assert(x2 == std::numeric_limits<std::int8_t>::max());
112-
113-
constexpr std::uint8_t x3 = std::saturate_cast<std::uint8_t>(x1);
114-
static_assert(x3 == std::numeric_limits<std::uint8_t>::max());
115-
116-
constexpr std::int16_t y1{-696};
117-
118-
constexpr std::int8_t y2 = std::saturate_cast<std::int8_t>(y1);
119-
static_assert(y2 == std::numeric_limits<std::int8_t>::min());
120-
121-
constexpr std::uint8_t y3 = std::saturate_cast<std::uint8_t>(y1);
122-
static_assert(y3 == 0);
123-
}
124-
}
125-
126104
int main(int, char**) {
127105
test();
128-
// static_assert(test());
129-
cppreference_test();
106+
static_assert(test());
130107

131108
return 0;
132109
}

libcxx/test/std/numerics/numeric.ops/numeric.ops.sat/sub_sat.pass.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ constexpr bool test_unsigned() {
6969
}
7070

7171
constexpr bool test() {
72-
// signed
72+
// Signed
7373
test_signed<signed char>();
7474
test_signed<short int>();
7575
test_signed<int>();
7676
test_signed<long int>();
7777
test_signed<long long int>();
78-
// unsigned
78+
// Unsigned
7979
test_unsigned<unsigned char>();
8080
test_unsigned<unsigned short int>();
8181
test_unsigned<unsigned int>();
@@ -85,23 +85,9 @@ constexpr bool test() {
8585
return true;
8686
}
8787

88-
constexpr void cppreference_test() {
89-
{
90-
static_assert(
91-
"" && (std::sub_sat<int>(INT_MIN + 4, 3) == INT_MIN + 1) // not saturated
92-
&& (std::sub_sat<int>(INT_MIN + 4, 5) == INT_MIN) // saturated
93-
&& (std::sub_sat<int>(INT_MAX - 4, -3) == INT_MAX - 1) // not saturated
94-
&& (std::sub_sat<int>(INT_MAX - 4, -5) == INT_MAX) // saturated
95-
&& (std::sub_sat<unsigned>(4, 3) == 1) // not saturated
96-
&& (std::sub_sat<unsigned>(4, 5) == 0) // saturated
97-
);
98-
}
99-
}
100-
10188
int main(int, char**) {
10289
test();
10390
static_assert(test());
104-
cppreference_test();
10591

10692
return 0;
10793
}

0 commit comments

Comments
 (0)