Skip to content

[libc] fix more readability-identifier-naming lints #83914

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

Merged
merged 2 commits into from
Mar 5, 2024
Merged
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
30 changes: 15 additions & 15 deletions libc/src/__support/blockstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BlockStore {
struct Pair {
Block *first, *second;
};
Pair getLastBlocks() {
Pair get_last_blocks() {
if (REVERSE_ORDER)
return {current, current->next};
Block *prev = nullptr;
Expand All @@ -56,20 +56,20 @@ class BlockStore {
return {curr, prev};
}

Block *getLastBlock() { return getLastBlocks().first; }
Block *get_last_block() { return get_last_blocks().first; }

public:
constexpr BlockStore() = default;
~BlockStore() = default;

class iterator {
class Iterator {
Block *block;
size_t index;

public:
constexpr iterator(Block *b, size_t i) : block(b), index(i) {}
constexpr Iterator(Block *b, size_t i) : block(b), index(i) {}

iterator &operator++() {
Iterator &operator++() {
if (REVERSE_ORDER) {
if (index == 0)
return *this;
Expand Down Expand Up @@ -98,11 +98,11 @@ class BlockStore {
return *reinterpret_cast<T *>(block->data + sizeof(T) * true_index);
}

bool operator==(const iterator &rhs) const {
bool operator==(const Iterator &rhs) const {
return block == rhs.block && index == rhs.index;
}

bool operator!=(const iterator &rhs) const {
bool operator!=(const Iterator &rhs) const {
return block != rhs.block || index != rhs.index;
}
};
Expand Down Expand Up @@ -138,15 +138,15 @@ class BlockStore {
}

T &back() {
return *reinterpret_cast<T *>(getLastBlock()->data +
return *reinterpret_cast<T *>(get_last_block()->data +
sizeof(T) * (fill_count - 1));
}

void pop_back() {
fill_count--;
if (fill_count || current == &first)
return;
auto [last, prev] = getLastBlocks();
auto [last, prev] = get_last_blocks();
if (REVERSE_ORDER) {
LIBC_ASSERT(last == current);
current = current->next;
Expand All @@ -162,18 +162,18 @@ class BlockStore {

bool empty() const { return current == &first && !fill_count; }

iterator begin() {
Iterator begin() {
if (REVERSE_ORDER)
return iterator(current, fill_count);
return Iterator(current, fill_count);
else
return iterator(&first, 0);
return Iterator(&first, 0);
}

iterator end() {
Iterator end() {
if (REVERSE_ORDER)
return iterator(&first, 0);
return Iterator(&first, 0);
else
return iterator(current, fill_count);
return Iterator(current, fill_count);
}
};

Expand Down
14 changes: 7 additions & 7 deletions libc/src/__support/integer_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ template <typename T, typename Fmt = radix::Dec> class IntegerToString {
static_assert(cpp::is_integral_v<T>);

LIBC_INLINE static constexpr size_t compute_buffer_size() {
constexpr auto max_digits = []() -> size_t {
constexpr auto MAX_DIGITS = []() -> size_t {
// We size the string buffer for base 10 using an approximation algorithm:
//
// size = ceil(sizeof(T) * 5 / 2)
Expand All @@ -188,19 +188,19 @@ template <typename T, typename Fmt = radix::Dec> class IntegerToString {
// For other bases, we approximate by rounding down to the nearest power
// of two base, since the space needed is easy to calculate and it won't
// overestimate by too much.
constexpr auto floor_log_2 = [](size_t num) -> size_t {
constexpr auto FLOOR_LOG_2 = [](size_t num) -> size_t {
size_t i = 0;
for (; num > 1; num /= 2)
++i;
return i;
};
constexpr size_t BITS_PER_DIGIT = floor_log_2(Fmt::BASE);
constexpr size_t BITS_PER_DIGIT = FLOOR_LOG_2(Fmt::BASE);
return ((sizeof(T) * 8 + (BITS_PER_DIGIT - 1)) / BITS_PER_DIGIT);
};
constexpr size_t digit_size = cpp::max(max_digits(), Fmt::MIN_DIGITS);
constexpr size_t sign_size = Fmt::BASE == 10 ? 1 : 0;
constexpr size_t prefix_size = Fmt::PREFIX ? 2 : 0;
return digit_size + sign_size + prefix_size;
constexpr size_t DIGIT_SIZE = cpp::max(MAX_DIGITS(), Fmt::MIN_DIGITS);
constexpr size_t SIGN_SIZE = Fmt::BASE == 10 ? 1 : 0;
constexpr size_t PREFIX_SIZE = Fmt::PREFIX ? 2 : 0;
return DIGIT_SIZE + SIGN_SIZE + PREFIX_SIZE;
}

static constexpr size_t BUFFER_SIZE = compute_buffer_size();
Expand Down
14 changes: 7 additions & 7 deletions libc/src/__support/math_extras.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ namespace LIBC_NAMESPACE {
template <typename T, size_t count>
LIBC_INLINE constexpr T mask_trailing_ones() {
static_assert(cpp::is_unsigned_v<T>);
constexpr unsigned t_bits = CHAR_BIT * sizeof(T);
static_assert(count <= t_bits && "Invalid bit index");
constexpr unsigned T_BITS = CHAR_BIT * sizeof(T);
static_assert(count <= T_BITS && "Invalid bit index");
// It's important not to initialize T with -1, since T may be BigInt which
// will take -1 as a uint64_t and only initialize the low 64 bits.
constexpr T all_zeroes(0);
constexpr T all_ones(~all_zeroes); // bitwise NOT performs integer promotion.
return count == 0 ? 0 : (all_ones >> (t_bits - count));
constexpr T ALL_ZEROES(0);
constexpr T ALL_ONES(~ALL_ZEROES); // bitwise NOT performs integer promotion.
return count == 0 ? 0 : (ALL_ONES >> (T_BITS - count));
}

// Create a bitmask with the count left-most bits set to 1, and all other bits
// set to 0. Only unsigned types are allowed.
template <typename T, size_t count>
LIBC_INLINE constexpr T mask_leading_ones() {
constexpr T mask(mask_trailing_ones<T, CHAR_BIT * sizeof(T) - count>());
return T(~mask); // bitwise NOT performs integer promotion.
constexpr T MASK(mask_trailing_ones<T, CHAR_BIT * sizeof(T) - count>());
return T(~MASK); // bitwise NOT performs integer promotion.
}

// Add with carry
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/hypotf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ LLVM_LIBC_FUNCTION(float, hypotf, (float x, float y)) {
// Correct rounding.
double r_sq = result.get_val() * result.get_val();
double diff = sum_sq - r_sq;
constexpr uint64_t mask = 0x0000'0000'3FFF'FFFFULL;
uint64_t lrs = result.uintval() & mask;
constexpr uint64_t MASK = 0x0000'0000'3FFF'FFFFULL;
uint64_t lrs = result.uintval() & MASK;

if (lrs == 0x0000'0000'1000'0000ULL && err < diff) {
result.set_uintval(result.uintval() | 1ULL);
Expand Down
22 changes: 11 additions & 11 deletions libc/src/string/memory_utils/op_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ template <typename T> T load(CPtr src) {
return ::LIBC_NAMESPACE::load<T>(src);
} else if constexpr (is_array_v<T>) {
using value_type = typename T::value_type;
T Value;
for (size_t I = 0; I < array_size_v<T>; ++I)
Value[I] = load<value_type>(src + (I * sizeof(value_type)));
return Value;
T value;
for (size_t i = 0; i < array_size_v<T>; ++i)
value[i] = load<value_type>(src + (i * sizeof(value_type)));
return value;
}
}

Expand All @@ -108,8 +108,8 @@ template <typename T> void store(Ptr dst, T value) {
::LIBC_NAMESPACE::store<T>(dst, value);
} else if constexpr (is_array_v<T>) {
using value_type = typename T::value_type;
for (size_t I = 0; I < array_size_v<T>; ++I)
store<value_type>(dst + (I * sizeof(value_type)), value[I]);
for (size_t i = 0; i < array_size_v<T>; ++i)
store<value_type>(dst + (i * sizeof(value_type)), value[i]);
}
}

Expand All @@ -118,11 +118,11 @@ template <typename T> T splat(uint8_t value) {
if constexpr (is_scalar_v<T>)
return T(~0) / T(0xFF) * T(value);
else if constexpr (is_vector_v<T>) {
T Out;
T out;
// This for loop is optimized out for vector types.
for (size_t i = 0; i < sizeof(T); ++i)
Out[i] = value;
return Out;
out[i] = value;
return out;
}
}

Expand All @@ -140,8 +140,8 @@ template <typename T> struct Memset {
} else if constexpr (is_array_v<T>) {
using value_type = typename T::value_type;
const auto Splat = splat<value_type>(value);
for (size_t I = 0; I < array_size_v<T>; ++I)
store<value_type>(dst + (I * sizeof(value_type)), Splat);
for (size_t i = 0; i < array_size_v<T>; ++i)
store<value_type>(dst + (i * sizeof(value_type)), Splat);
}
}

Expand Down
12 changes: 6 additions & 6 deletions libc/src/string/memory_utils/op_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
namespace LIBC_NAMESPACE::x86 {

// A set of constants to check compile time features.
LIBC_INLINE_VAR constexpr bool kSse2 = LLVM_LIBC_IS_DEFINED(__SSE2__);
LIBC_INLINE_VAR constexpr bool kSse41 = LLVM_LIBC_IS_DEFINED(__SSE4_1__);
LIBC_INLINE_VAR constexpr bool kAvx = LLVM_LIBC_IS_DEFINED(__AVX__);
LIBC_INLINE_VAR constexpr bool kAvx2 = LLVM_LIBC_IS_DEFINED(__AVX2__);
LIBC_INLINE_VAR constexpr bool kAvx512F = LLVM_LIBC_IS_DEFINED(__AVX512F__);
LIBC_INLINE_VAR constexpr bool kAvx512BW = LLVM_LIBC_IS_DEFINED(__AVX512BW__);
LIBC_INLINE_VAR constexpr bool K_SSE2 = LLVM_LIBC_IS_DEFINED(__SSE2__);
LIBC_INLINE_VAR constexpr bool K_SSE41 = LLVM_LIBC_IS_DEFINED(__SSE4_1__);
LIBC_INLINE_VAR constexpr bool K_AVX = LLVM_LIBC_IS_DEFINED(__AVX__);
LIBC_INLINE_VAR constexpr bool K_AVX2 = LLVM_LIBC_IS_DEFINED(__AVX2__);
LIBC_INLINE_VAR constexpr bool K_AVX512_F = LLVM_LIBC_IS_DEFINED(__AVX512F__);
LIBC_INLINE_VAR constexpr bool K_AVX512_BW = LLVM_LIBC_IS_DEFINED(__AVX512BW__);

///////////////////////////////////////////////////////////////////////////////
// Memcpy repmovsb implementation
Expand Down
18 changes: 9 additions & 9 deletions libc/src/string/memory_utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ LIBC_INLINE MemcmpReturnType cmp_neq_uint64_t(uint64_t a, uint64_t b) {
// Loads bytes from memory (possibly unaligned) and materializes them as
// type.
template <typename T> LIBC_INLINE T load(CPtr ptr) {
T Out;
memcpy_inline<sizeof(T)>(&Out, ptr);
return Out;
T out;
memcpy_inline<sizeof(T)>(&out, ptr);
return out;
}

// Stores a value of type T in memory (possibly unaligned).
Expand All @@ -228,12 +228,12 @@ LIBC_INLINE ValueType load_aligned(CPtr src) {
static_assert(sizeof(ValueType) >= (sizeof(T) + ... + sizeof(TS)));
const ValueType value = load<T>(assume_aligned<sizeof(T)>(src));
if constexpr (sizeof...(TS) > 0) {
constexpr size_t shift = sizeof(T) * 8;
constexpr size_t SHIFT = sizeof(T) * 8;
const ValueType next = load_aligned<ValueType, TS...>(src + sizeof(T));
if constexpr (Endian::IS_LITTLE)
return value | (next << shift);
return value | (next << SHIFT);
else if constexpr (Endian::IS_BIG)
return (value << shift) | next;
return (value << SHIFT) | next;
else
static_assert(cpp::always_false<T>, "Invalid endianness");
} else {
Expand Down Expand Up @@ -261,16 +261,16 @@ LIBC_INLINE auto load64_aligned(CPtr src, size_t offset) {
template <typename ValueType, typename T, typename... TS>
LIBC_INLINE void store_aligned(ValueType value, Ptr dst) {
static_assert(sizeof(ValueType) >= (sizeof(T) + ... + sizeof(TS)));
constexpr size_t shift = sizeof(T) * 8;
constexpr size_t SHIFT = sizeof(T) * 8;
if constexpr (Endian::IS_LITTLE) {
store<T>(assume_aligned<sizeof(T)>(dst), value & ~T(0));
if constexpr (sizeof...(TS) > 0)
store_aligned<ValueType, TS...>(value >> shift, dst + sizeof(T));
store_aligned<ValueType, TS...>(value >> SHIFT, dst + sizeof(T));
} else if constexpr (Endian::IS_BIG) {
constexpr size_t OFFSET = (0 + ... + sizeof(TS));
store<T>(assume_aligned<sizeof(T)>(dst + OFFSET), value & ~T(0));
if constexpr (sizeof...(TS) > 0)
store_aligned<ValueType, TS...>(value >> shift, dst);
store_aligned<ValueType, TS...>(value >> SHIFT, dst);
} else {
static_assert(cpp::always_false<T>, "Invalid endianness");
}
Expand Down
Loading