Skip to content

Commit 6f8d826

Browse files
[libc] fix readability-identifier-naming.ConstexprFunctionCase (#83345)
Codify that we use lower_case for readability-identifier-naming.ConstexprFunctionCase and then fix the 11 violations (rather than codify UPPER_CASE and have to fix the 170 violations).
1 parent fc8d481 commit 6f8d826

File tree

12 files changed

+87
-85
lines changed

12 files changed

+87
-85
lines changed

libc/.clang-tidy

+2
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ CheckOptions:
2626
value: UPPER_CASE
2727
- key: readability-identifier-naming.ConstexprVariableCase
2828
value: UPPER_CASE
29+
- key: readability-identifier-naming.ConstexprFunctionCase
30+
value: lower_case
2931
- key: readability-identifier-naming.GetConfigPerFile
3032
value: true

libc/src/__support/FPUtil/FPBits.h

+56-56
Original file line numberDiff line numberDiff line change
@@ -239,23 +239,23 @@ template <FPType fp_type> struct FPStorage : public FPLayout<fp_type> {
239239

240240
// An opaque type to store a floating point exponent.
241241
// We define special values but it is valid to create arbitrary values as long
242-
// as they are in the range [MIN, MAX].
242+
// as they are in the range [min, max].
243243
struct Exponent : public TypedInt<int32_t> {
244244
using UP = TypedInt<int32_t>;
245245
using UP::UP;
246-
LIBC_INLINE static constexpr auto SUBNORMAL() {
246+
LIBC_INLINE static constexpr auto subnormal() {
247247
return Exponent(-EXP_BIAS);
248248
}
249-
LIBC_INLINE static constexpr auto MIN() { return Exponent(1 - EXP_BIAS); }
250-
LIBC_INLINE static constexpr auto ZERO() { return Exponent(0); }
251-
LIBC_INLINE static constexpr auto MAX() { return Exponent(EXP_BIAS); }
252-
LIBC_INLINE static constexpr auto INF() { return Exponent(EXP_BIAS + 1); }
249+
LIBC_INLINE static constexpr auto min() { return Exponent(1 - EXP_BIAS); }
250+
LIBC_INLINE static constexpr auto zero() { return Exponent(0); }
251+
LIBC_INLINE static constexpr auto max() { return Exponent(EXP_BIAS); }
252+
LIBC_INLINE static constexpr auto inf() { return Exponent(EXP_BIAS + 1); }
253253
};
254254

255255
// An opaque type to store a floating point biased exponent.
256256
// We define special values but it is valid to create arbitrary values as long
257-
// as they are in the range [BITS_ALL_ZEROES, BITS_ALL_ONES].
258-
// Values greater than BITS_ALL_ONES are truncated.
257+
// as they are in the range [zero, bits_all_ones].
258+
// Values greater than bits_all_ones are truncated.
259259
struct BiasedExponent : public TypedInt<uint32_t> {
260260
using UP = TypedInt<uint32_t>;
261261
using UP::UP;
@@ -269,23 +269,23 @@ template <FPType fp_type> struct FPStorage : public FPLayout<fp_type> {
269269
}
270270

271271
LIBC_INLINE constexpr BiasedExponent &operator++() {
272-
LIBC_ASSERT(*this != BiasedExponent(Exponent::INF()));
272+
LIBC_ASSERT(*this != BiasedExponent(Exponent::inf()));
273273
++UP::value;
274274
return *this;
275275
}
276276

277277
LIBC_INLINE constexpr BiasedExponent &operator--() {
278-
LIBC_ASSERT(*this != BiasedExponent(Exponent::SUBNORMAL()));
278+
LIBC_ASSERT(*this != BiasedExponent(Exponent::subnormal()));
279279
--UP::value;
280280
return *this;
281281
}
282282
};
283283

284284
// An opaque type to store a floating point significand.
285285
// We define special values but it is valid to create arbitrary values as long
286-
// as they are in the range [ZERO, BITS_ALL_ONES].
286+
// as they are in the range [zero, bits_all_ones].
287287
// Note that the semantics of the Significand are implementation dependent.
288-
// Values greater than BITS_ALL_ONES are truncated.
288+
// Values greater than bits_all_ones are truncated.
289289
struct Significand : public TypedInt<StorageType> {
290290
using UP = TypedInt<StorageType>;
291291
using UP::UP;
@@ -305,16 +305,16 @@ template <FPType fp_type> struct FPStorage : public FPLayout<fp_type> {
305305
return Significand(StorageType(a.to_storage_type() >> shift));
306306
}
307307

308-
LIBC_INLINE static constexpr auto ZERO() {
308+
LIBC_INLINE static constexpr auto zero() {
309309
return Significand(StorageType(0));
310310
}
311-
LIBC_INLINE static constexpr auto LSB() {
311+
LIBC_INLINE static constexpr auto lsb() {
312312
return Significand(StorageType(1));
313313
}
314-
LIBC_INLINE static constexpr auto MSB() {
314+
LIBC_INLINE static constexpr auto msb() {
315315
return Significand(StorageType(1) << (SIG_LEN - 1));
316316
}
317-
LIBC_INLINE static constexpr auto BITS_ALL_ONES() {
317+
LIBC_INLINE static constexpr auto bits_all_ones() {
318318
return Significand(SIG_MASK);
319319
}
320320
};
@@ -393,58 +393,58 @@ struct FPRepSem : public FPStorage<fp_type> {
393393
public:
394394
// Builders
395395
LIBC_INLINE static constexpr RetT zero(Sign sign = Sign::POS) {
396-
return RetT(encode(sign, Exponent::SUBNORMAL(), Significand::ZERO()));
396+
return RetT(encode(sign, Exponent::subnormal(), Significand::zero()));
397397
}
398398
LIBC_INLINE static constexpr RetT one(Sign sign = Sign::POS) {
399-
return RetT(encode(sign, Exponent::ZERO(), Significand::ZERO()));
399+
return RetT(encode(sign, Exponent::zero(), Significand::zero()));
400400
}
401401
LIBC_INLINE static constexpr RetT min_subnormal(Sign sign = Sign::POS) {
402-
return RetT(encode(sign, Exponent::SUBNORMAL(), Significand::LSB()));
402+
return RetT(encode(sign, Exponent::subnormal(), Significand::lsb()));
403403
}
404404
LIBC_INLINE static constexpr RetT max_subnormal(Sign sign = Sign::POS) {
405405
return RetT(
406-
encode(sign, Exponent::SUBNORMAL(), Significand::BITS_ALL_ONES()));
406+
encode(sign, Exponent::subnormal(), Significand::bits_all_ones()));
407407
}
408408
LIBC_INLINE static constexpr RetT min_normal(Sign sign = Sign::POS) {
409-
return RetT(encode(sign, Exponent::MIN(), Significand::ZERO()));
409+
return RetT(encode(sign, Exponent::min(), Significand::zero()));
410410
}
411411
LIBC_INLINE static constexpr RetT max_normal(Sign sign = Sign::POS) {
412-
return RetT(encode(sign, Exponent::MAX(), Significand::BITS_ALL_ONES()));
412+
return RetT(encode(sign, Exponent::max(), Significand::bits_all_ones()));
413413
}
414414
LIBC_INLINE static constexpr RetT inf(Sign sign = Sign::POS) {
415-
return RetT(encode(sign, Exponent::INF(), Significand::ZERO()));
415+
return RetT(encode(sign, Exponent::inf(), Significand::zero()));
416416
}
417417
LIBC_INLINE static constexpr RetT signaling_nan(Sign sign = Sign::POS,
418418
StorageType v = 0) {
419-
return RetT(encode(sign, Exponent::INF(),
420-
(v ? Significand(v) : (Significand::MSB() >> 1))));
419+
return RetT(encode(sign, Exponent::inf(),
420+
(v ? Significand(v) : (Significand::msb() >> 1))));
421421
}
422422
LIBC_INLINE static constexpr RetT quiet_nan(Sign sign = Sign::POS,
423423
StorageType v = 0) {
424424
return RetT(
425-
encode(sign, Exponent::INF(), Significand::MSB() | Significand(v)));
425+
encode(sign, Exponent::inf(), Significand::msb() | Significand(v)));
426426
}
427427

428428
// Observers
429429
LIBC_INLINE constexpr bool is_zero() const { return exp_sig_bits() == 0; }
430430
LIBC_INLINE constexpr bool is_nan() const {
431-
return exp_sig_bits() > encode(Exponent::INF(), Significand::ZERO());
431+
return exp_sig_bits() > encode(Exponent::inf(), Significand::zero());
432432
}
433433
LIBC_INLINE constexpr bool is_quiet_nan() const {
434-
return exp_sig_bits() >= encode(Exponent::INF(), Significand::MSB());
434+
return exp_sig_bits() >= encode(Exponent::inf(), Significand::msb());
435435
}
436436
LIBC_INLINE constexpr bool is_signaling_nan() const {
437437
return is_nan() && !is_quiet_nan();
438438
}
439439
LIBC_INLINE constexpr bool is_inf() const {
440-
return exp_sig_bits() == encode(Exponent::INF(), Significand::ZERO());
440+
return exp_sig_bits() == encode(Exponent::inf(), Significand::zero());
441441
}
442442
LIBC_INLINE constexpr bool is_finite() const {
443-
return exp_bits() != encode(Exponent::INF());
443+
return exp_bits() != encode(Exponent::inf());
444444
}
445445
LIBC_INLINE
446446
constexpr bool is_subnormal() const {
447-
return exp_bits() == encode(Exponent::SUBNORMAL());
447+
return exp_bits() == encode(Exponent::subnormal());
448448
}
449449
LIBC_INLINE constexpr bool is_normal() const {
450450
return is_finite() && !is_subnormal();
@@ -493,37 +493,37 @@ struct FPRepSem<FPType::X86_Binary80, RetT>
493493
public:
494494
// Builders
495495
LIBC_INLINE static constexpr RetT zero(Sign sign = Sign::POS) {
496-
return RetT(encode(sign, Exponent::SUBNORMAL(), Significand::ZERO()));
496+
return RetT(encode(sign, Exponent::subnormal(), Significand::zero()));
497497
}
498498
LIBC_INLINE static constexpr RetT one(Sign sign = Sign::POS) {
499-
return RetT(encode(sign, Exponent::ZERO(), Significand::MSB()));
499+
return RetT(encode(sign, Exponent::zero(), Significand::msb()));
500500
}
501501
LIBC_INLINE static constexpr RetT min_subnormal(Sign sign = Sign::POS) {
502-
return RetT(encode(sign, Exponent::SUBNORMAL(), Significand::LSB()));
502+
return RetT(encode(sign, Exponent::subnormal(), Significand::lsb()));
503503
}
504504
LIBC_INLINE static constexpr RetT max_subnormal(Sign sign = Sign::POS) {
505-
return RetT(encode(sign, Exponent::SUBNORMAL(),
506-
Significand::BITS_ALL_ONES() ^ Significand::MSB()));
505+
return RetT(encode(sign, Exponent::subnormal(),
506+
Significand::bits_all_ones() ^ Significand::msb()));
507507
}
508508
LIBC_INLINE static constexpr RetT min_normal(Sign sign = Sign::POS) {
509-
return RetT(encode(sign, Exponent::MIN(), Significand::MSB()));
509+
return RetT(encode(sign, Exponent::min(), Significand::msb()));
510510
}
511511
LIBC_INLINE static constexpr RetT max_normal(Sign sign = Sign::POS) {
512-
return RetT(encode(sign, Exponent::MAX(), Significand::BITS_ALL_ONES()));
512+
return RetT(encode(sign, Exponent::max(), Significand::bits_all_ones()));
513513
}
514514
LIBC_INLINE static constexpr RetT inf(Sign sign = Sign::POS) {
515-
return RetT(encode(sign, Exponent::INF(), Significand::MSB()));
515+
return RetT(encode(sign, Exponent::inf(), Significand::msb()));
516516
}
517517
LIBC_INLINE static constexpr RetT signaling_nan(Sign sign = Sign::POS,
518518
StorageType v = 0) {
519-
return RetT(encode(sign, Exponent::INF(),
520-
Significand::MSB() |
521-
(v ? Significand(v) : (Significand::MSB() >> 2))));
519+
return RetT(encode(sign, Exponent::inf(),
520+
Significand::msb() |
521+
(v ? Significand(v) : (Significand::msb() >> 2))));
522522
}
523523
LIBC_INLINE static constexpr RetT quiet_nan(Sign sign = Sign::POS,
524524
StorageType v = 0) {
525-
return RetT(encode(sign, Exponent::INF(),
526-
Significand::MSB() | (Significand::MSB() >> 1) |
525+
return RetT(encode(sign, Exponent::inf(),
526+
Significand::msb() | (Significand::msb() >> 1) |
527527
Significand(v)));
528528
}
529529

@@ -541,33 +541,33 @@ struct FPRepSem<FPType::X86_Binary80, RetT>
541541
// - Quiet Not a Number
542542
// - Unnormal
543543
// This can be reduced to the following logic:
544-
if (exp_bits() == encode(Exponent::INF()))
544+
if (exp_bits() == encode(Exponent::inf()))
545545
return !is_inf();
546-
if (exp_bits() != encode(Exponent::SUBNORMAL()))
547-
return (sig_bits() & encode(Significand::MSB())) == 0;
546+
if (exp_bits() != encode(Exponent::subnormal()))
547+
return (sig_bits() & encode(Significand::msb())) == 0;
548548
return false;
549549
}
550550
LIBC_INLINE constexpr bool is_quiet_nan() const {
551551
return exp_sig_bits() >=
552-
encode(Exponent::INF(),
553-
Significand::MSB() | (Significand::MSB() >> 1));
552+
encode(Exponent::inf(),
553+
Significand::msb() | (Significand::msb() >> 1));
554554
}
555555
LIBC_INLINE constexpr bool is_signaling_nan() const {
556556
return is_nan() && !is_quiet_nan();
557557
}
558558
LIBC_INLINE constexpr bool is_inf() const {
559-
return exp_sig_bits() == encode(Exponent::INF(), Significand::MSB());
559+
return exp_sig_bits() == encode(Exponent::inf(), Significand::msb());
560560
}
561561
LIBC_INLINE constexpr bool is_finite() const {
562562
return !is_inf() && !is_nan();
563563
}
564564
LIBC_INLINE
565565
constexpr bool is_subnormal() const {
566-
return exp_bits() == encode(Exponent::SUBNORMAL());
566+
return exp_bits() == encode(Exponent::subnormal());
567567
}
568568
LIBC_INLINE constexpr bool is_normal() const {
569569
const auto exp = exp_bits();
570-
if (exp == encode(Exponent::SUBNORMAL()) || exp == encode(Exponent::INF()))
570+
if (exp == encode(Exponent::subnormal()) || exp == encode(Exponent::inf()))
571571
return false;
572572
return get_implicit_bit();
573573
}
@@ -578,7 +578,7 @@ struct FPRepSem<FPType::X86_Binary80, RetT>
578578
} else if (exp_sig_bits() == max_subnormal().uintval()) {
579579
return min_normal(sign());
580580
} else if (sig_bits() == SIG_MASK) {
581-
return RetT(encode(sign(), ++biased_exponent(), Significand::ZERO()));
581+
return RetT(encode(sign(), ++biased_exponent(), Significand::zero()));
582582
} else {
583583
return RetT(bits + StorageType(1));
584584
}
@@ -715,9 +715,9 @@ struct FPRepImpl : public FPRepSem<fp_type, RetT> {
715715
LIBC_INLINE constexpr int get_explicit_exponent() const {
716716
Exponent exponent(UP::biased_exponent());
717717
if (is_zero())
718-
exponent = Exponent::ZERO();
719-
if (exponent == Exponent::SUBNORMAL())
720-
exponent = Exponent::MIN();
718+
exponent = Exponent::zero();
719+
if (exponent == Exponent::subnormal())
720+
exponent = Exponent::min();
721721
return static_cast<int32_t>(exponent);
722722
}
723723

libc/src/string/memory_utils/aarch64/inline_bcmp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace LIBC_NAMESPACE {
2727
}
2828
switch (count) {
2929
case 0:
30-
return BcmpReturnType::ZERO();
30+
return BcmpReturnType::zero();
3131
case 1:
3232
return generic::Bcmp<uint8_t>::block(p1, p2);
3333
case 2:

libc/src/string/memory_utils/aarch64/inline_memcmp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ inline_memcmp_aarch64_neon_gt16(CPtr p1, CPtr p2, size_t count) {
5050
LIBC_INLINE MemcmpReturnType inline_memcmp_aarch64(CPtr p1, CPtr p2,
5151
size_t count) {
5252
if (count == 0)
53-
return MemcmpReturnType::ZERO();
53+
return MemcmpReturnType::zero();
5454
if (count == 1)
5555
return generic::Memcmp<uint8_t>::block(p1, p2);
5656
if (count == 2)

libc/src/string/memory_utils/generic/aligned_access.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ inline_bcmp_aligned_access_32bit(CPtr p1, CPtr p2, size_t count) {
135135
uint32_t a = load32_aligned<uint32_t>(p1, offset);
136136
uint32_t b = load32_aligned(p2, offset, p2_alignment);
137137
if (a != b)
138-
return BcmpReturnType::NONZERO();
138+
return BcmpReturnType::nonzero();
139139
}
140140
return inline_bcmp_byte_per_byte(p1, p2, count, offset);
141141
}
@@ -154,7 +154,7 @@ inline_bcmp_aligned_access_64bit(CPtr p1, CPtr p2, size_t count) {
154154
uint64_t a = load64_aligned<uint64_t>(p1, offset);
155155
uint64_t b = load64_aligned(p2, offset, p2_alignment);
156156
if (a != b)
157-
return BcmpReturnType::NONZERO();
157+
return BcmpReturnType::nonzero();
158158
}
159159
return inline_bcmp_byte_per_byte(p1, p2, count, offset);
160160
}

libc/src/string/memory_utils/generic/byte_per_byte.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ inline_bcmp_byte_per_byte(CPtr p1, CPtr p2, size_t count, size_t offset = 0) {
5656
LIBC_LOOP_NOUNROLL
5757
for (; offset < count; ++offset)
5858
if (p1[offset] != p2[offset])
59-
return BcmpReturnType::NONZERO();
60-
return BcmpReturnType::ZERO();
59+
return BcmpReturnType::zero();
60+
return BcmpReturnType::zero();
6161
}
6262

6363
[[maybe_unused]] LIBC_INLINE MemcmpReturnType
@@ -70,7 +70,7 @@ inline_memcmp_byte_per_byte(CPtr p1, CPtr p2, size_t count, size_t offset = 0) {
7070
if (diff)
7171
return diff;
7272
}
73-
return MemcmpReturnType::ZERO();
73+
return MemcmpReturnType::zero();
7474
}
7575

7676
} // namespace LIBC_NAMESPACE

libc/src/string/memory_utils/op_aarch64.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ template <size_t Size> struct Bcmp {
108108
} else {
109109
static_assert(cpp::always_false<decltype(Size)>, "SIZE not implemented");
110110
}
111-
return BcmpReturnType::ZERO();
111+
return BcmpReturnType::zero();
112112
}
113113

114114
LIBC_INLINE static BcmpReturnType tail(CPtr p1, CPtr p2, size_t count) {
@@ -154,7 +154,7 @@ template <size_t Size> struct Bcmp {
154154
} else {
155155
static_assert(cpp::always_false<decltype(Size)>, "SIZE not implemented");
156156
}
157-
return BcmpReturnType::ZERO();
157+
return BcmpReturnType::zero();
158158
}
159159

160160
LIBC_INLINE static BcmpReturnType loop_and_tail(CPtr p1, CPtr p2,
@@ -217,7 +217,7 @@ LIBC_INLINE MemcmpReturnType cmp<uint64_t>(CPtr p1, CPtr p2, size_t offset) {
217217
const auto b = load_be<uint64_t>(p2, offset);
218218
if (a != b)
219219
return a > b ? 1 : -1;
220-
return MemcmpReturnType::ZERO();
220+
return MemcmpReturnType::zero();
221221
}
222222

223223
///////////////////////////////////////////////////////////////////////////////
@@ -245,7 +245,7 @@ LIBC_INLINE MemcmpReturnType cmp<uint8x16_t>(CPtr p1, CPtr p2, size_t offset) {
245245
return cmp_neq_uint64_t(a, b);
246246
offset += sizeof(uint64_t);
247247
}
248-
return MemcmpReturnType::ZERO();
248+
return MemcmpReturnType::zero();
249249
}
250250

251251
///////////////////////////////////////////////////////////////////////////////
@@ -262,7 +262,7 @@ LIBC_INLINE MemcmpReturnType cmp<uint8x16x2_t>(CPtr p1, CPtr p2,
262262
return cmp_neq_uint64_t(a, b);
263263
offset += sizeof(uint64_t);
264264
}
265-
return MemcmpReturnType::ZERO();
265+
return MemcmpReturnType::zero();
266266
}
267267
} // namespace LIBC_NAMESPACE::generic
268268

0 commit comments

Comments
 (0)