Skip to content
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
4 changes: 2 additions & 2 deletions libc/benchmarks/LibcMemoryBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ MismatchOffsetDistribution::MismatchOffsetDistribution(size_t BufferSize,
: MismatchAt(MismatchAt) {
if (MismatchAt <= 1)
return;
for (size_t I = MaxSizeValue + 1; I < BufferSize; I += MaxSizeValue)
MismatchIndices.push_back(I);
for (size_t i = MaxSizeValue + 1; i < BufferSize; i += MaxSizeValue)
MismatchIndices.push_back(i);
if (MismatchIndices.empty())
report_fatal_error("Unable to generate mismatch");
MismatchIndexSelector =
Expand Down
6 changes: 3 additions & 3 deletions libc/benchmarks/LibcMemoryBenchmarkMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ struct MemfunctionBenchmarkBase : public BenchmarkSetup {
if (Percent == LastPercent)
return;
LastPercent = Percent;
size_t I = 0;
size_t i = 0;
errs() << '[';
for (; I <= Percent; ++I)
for (; i <= Percent; ++i)
errs() << '#';
for (; I <= 100; ++I)
for (; i <= 100; ++i)
errs() << '_';
errs() << "] " << Percent << '%' << '\r';
}
Expand Down
6 changes: 3 additions & 3 deletions libc/benchmarks/LibcMemoryBenchmarkTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ TEST(OffsetDistribution, AlignToBegin) {
const size_t BufferSize = 8192;
OffsetDistribution OD(BufferSize, 1024, std::nullopt);
std::default_random_engine Gen;
for (size_t I = 0; I <= 10; ++I)
for (size_t i = 0; i <= 10; ++i)
EXPECT_EQ(OD(Gen), 0U);
}

TEST(OffsetDistribution, NoAlignment) {
const size_t BufferSize = 8192;
OffsetDistribution OD(BufferSize, 1, Align(1));
std::default_random_engine Gen;
for (size_t I = 0; I <= 10; ++I)
for (size_t i = 0; i <= 10; ++i)
EXPECT_THAT(OD(Gen), AllOf(Ge(0U), Lt(8192U)));
}

Expand All @@ -59,7 +59,7 @@ TEST(OffsetDistribution, Aligned) {
const size_t BufferSize = 8192;
OffsetDistribution OD(BufferSize, 1, Align(16));
std::default_random_engine Gen;
for (size_t I = 0; I <= 10; ++I)
for (size_t i = 0; i <= 10; ++i)
EXPECT_THAT(OD(Gen), AllOf(Ge(0U), Lt(8192U), IsDivisibleBy(16U)));
}

Expand Down
48 changes: 24 additions & 24 deletions libc/src/__support/CPP/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,55 +48,55 @@ template <typename... Ts> LIBC_INLINE constexpr auto tie(Ts &...args) {
return tuple<Ts &...>(args...);
}

template <size_t I, typename Head, typename... Tail>
template <size_t Idx, typename Head, typename... Tail>
LIBC_INLINE constexpr auto &get(tuple<Head, Tail...> &t) {
if constexpr (I == 0)
if constexpr (Idx == 0)
return t.get_head();
else
return get<I - 1>(t.get_tail());
return get<Idx - 1>(t.get_tail());
}
template <size_t I, typename Head, typename... Tail>
template <size_t Idx, typename Head, typename... Tail>
LIBC_INLINE constexpr const auto &get(const tuple<Head, Tail...> &t) {
if constexpr (I == 0)
if constexpr (Idx == 0)
return t.get_head();
else
return get<I - 1>(t.get_tail());
return get<Idx - 1>(t.get_tail());
}
template <size_t I, typename Head, typename... Tail>
template <size_t Idx, typename Head, typename... Tail>
LIBC_INLINE constexpr auto &&get(tuple<Head, Tail...> &&t) {
if constexpr (I == 0)
if constexpr (Idx == 0)
return static_cast<Head &&>(t.get_head());
else
return get<I - 1>(static_cast<tuple<Tail...> &&>(t.get_tail()));
return get<Idx - 1>(static_cast<tuple<Tail...> &&>(t.get_tail()));
}
template <size_t I, typename Head, typename... Tail>
template <size_t Idx, typename Head, typename... Tail>
LIBC_INLINE constexpr const auto &&get(const tuple<Head, Tail...> &&t) {
if constexpr (I == 0)
if constexpr (Idx == 0)
return static_cast<const Head &&>(t.get_head());
else
return get<I - 1>(static_cast<const tuple<Tail...> &&>(t.get_tail()));
return get<Idx - 1>(static_cast<const tuple<Tail...> &&>(t.get_tail()));
}

template <typename T> struct tuple_size;
template <typename... Ts> struct tuple_size<tuple<Ts...>> {
static constexpr size_t value = sizeof...(Ts);
};

template <size_t I, typename T> struct tuple_element;
template <size_t I, typename Head, typename... Tail>
struct tuple_element<I, tuple<Head, Tail...>>
: tuple_element<I - 1, tuple<Tail...>> {};
template <size_t Idx, typename T> struct tuple_element;
template <size_t Idx, typename Head, typename... Tail>
struct tuple_element<Idx, tuple<Head, Tail...>>
: tuple_element<Idx - 1, tuple<Tail...>> {};
template <typename Head, typename... Tail>
struct tuple_element<0, tuple<Head, Tail...>> {
using type = cpp::remove_cv_t<cpp::remove_reference_t<Head>>;
};

namespace internal {
template <typename... As, typename... Bs, size_t... I, size_t... J>
template <typename... As, typename... Bs, size_t... Idx, size_t... J>
LIBC_INLINE constexpr auto
tuple_cat(const tuple<As...> &a, const tuple<Bs...> &b,
cpp::index_sequence<I...>, cpp::index_sequence<J...>) {
return tuple<As..., Bs...>(get<I>(a)..., get<J>(b)...);
cpp::index_sequence<Idx...>, cpp::index_sequence<J...>) {
return tuple<As..., Bs...>(get<Idx>(a)..., get<J>(b)...);
}

template <typename First, typename Second, typename... Rest>
Expand Down Expand Up @@ -128,16 +128,16 @@ LIBC_INLINE constexpr auto tuple_cat(const Tuples &...tuples) {
namespace std {

template <class T> struct tuple_size;
template <size_t I, class T> struct tuple_element;
template <size_t Idx, class T> struct tuple_element;

template <typename... Ts>
struct tuple_size<LIBC_NAMESPACE::cpp::tuple<Ts...>>
: LIBC_NAMESPACE::cpp::tuple_size<LIBC_NAMESPACE::cpp::tuple<Ts...>> {};

template <size_t I, typename... Ts>
struct tuple_element<I, LIBC_NAMESPACE::cpp::tuple<Ts...>>
: LIBC_NAMESPACE::cpp::tuple_element<I, LIBC_NAMESPACE::cpp::tuple<Ts...>> {
};
template <size_t Idx, typename... Ts>
struct tuple_element<Idx, LIBC_NAMESPACE::cpp::tuple<Ts...>>
: LIBC_NAMESPACE::cpp::tuple_element<Idx,
LIBC_NAMESPACE::cpp::tuple<Ts...>> {};

} // namespace std

Expand Down
4 changes: 2 additions & 2 deletions libc/test/UnitTest/MemoryMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ bool MemoryMatcher::match(MemoryView actualValue) {
}

static void display(char C) {
const auto print = [](unsigned char I) {
const auto print = [](unsigned char i) {
tlog << static_cast<char>(LIBC_NAMESPACE::internal::toupper(
LIBC_NAMESPACE::internal::int_to_b36_char(I)));
LIBC_NAMESPACE::internal::int_to_b36_char(i)));
};
print(static_cast<unsigned char>(C) / 16);
print(static_cast<unsigned char>(C) & 15);
Expand Down
8 changes: 4 additions & 4 deletions libc/test/integration/src/pthread/pthread_create_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ static void *successThread(void *Arg) {
volatile uint8_t *bytes_on_stack =
(volatile uint8_t *)__builtin_alloca(test_stacksize);

for (size_t I = 0; I < test_stacksize; ++I) {
for (size_t i = 0; i < test_stacksize; ++i) {
// Write permissions
bytes_on_stack[I] = static_cast<uint8_t>(I);
bytes_on_stack[i] = static_cast<uint8_t>(i);
}

for (size_t I = 0; I < test_stacksize; ++I) {
for (size_t i = 0; i < test_stacksize; ++i) {
// Read/write permissions
bytes_on_stack[I] += static_cast<uint8_t>(I);
bytes_on_stack[i] += static_cast<uint8_t>(i);
}
}

Expand Down
68 changes: 35 additions & 33 deletions libc/test/src/math/smoke/RoundToIntegerTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@
static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
FE_TONEAREST};

template <typename F, typename I, bool TestModes = false>
template <typename FloatType, typename IntType, bool TestModes = false>
class RoundToIntegerTestTemplate
: public LIBC_NAMESPACE::testing::FEnvSafeTest {
public:
typedef I (*RoundToIntegerFunc)(F);
typedef IntType (*RoundToIntegerFunc)(FloatType);

private:
DECLARE_SPECIAL_CONSTANTS(F)
DECLARE_SPECIAL_CONSTANTS(FloatType)

static constexpr StorageType MAX_SUBNORMAL =
FPBits::max_subnormal().uintval();
static constexpr StorageType MIN_SUBNORMAL =
FPBits::min_subnormal().uintval();

static constexpr I INTEGER_MIN = I(1) << (sizeof(I) * 8 - 1);
static constexpr I INTEGER_MAX = -(INTEGER_MIN + 1);
static constexpr IntType INTEGER_MIN = IntType(1)
<< (sizeof(IntType) * 8 - 1);
static constexpr IntType INTEGER_MAX = -(INTEGER_MIN + 1);

void test_one_input(RoundToIntegerFunc func, F input, I expected,
bool expectError) {
void test_one_input(RoundToIntegerFunc func, FloatType input,
IntType expected, bool expectError) {
libc_errno = 0;
LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);

Expand Down Expand Up @@ -92,14 +93,14 @@ class RoundToIntegerTestTemplate
}

void do_round_numbers_test(RoundToIntegerFunc func) {
test_one_input(func, zero, I(0), false);
test_one_input(func, neg_zero, I(0), false);
test_one_input(func, F(1.0), I(1), false);
test_one_input(func, F(-1.0), I(-1), false);
test_one_input(func, F(10.0), I(10), false);
test_one_input(func, F(-10.0), I(-10), false);
test_one_input(func, F(1232.0), I(1232), false);
test_one_input(func, F(-1232.0), I(-1232), false);
test_one_input(func, zero, IntType(0), false);
test_one_input(func, neg_zero, IntType(0), false);
test_one_input(func, FloatType(1.0), IntType(1), false);
test_one_input(func, FloatType(-1.0), IntType(-1), false);
test_one_input(func, FloatType(10.0), IntType(10), false);
test_one_input(func, FloatType(-10.0), IntType(-10), false);
test_one_input(func, FloatType(1232.0), IntType(1232), false);
test_one_input(func, FloatType(-1232.0), IntType(-1232), false);
}

void testRoundNumbers(RoundToIntegerFunc func) {
Expand All @@ -120,29 +121,29 @@ class RoundToIntegerTestTemplate
static_cast<StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
StorageType(1));
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
F x = FPBits(i).get_val();
if (x == F(0.0))
FloatType x = FPBits(i).get_val();
if (x == FloatType(0.0))
continue;
// All subnormal numbers should round to zero.
if (TestModes) {
if (x > zero) {
LIBC_NAMESPACE::fputil::set_round(FE_UPWARD);
test_one_input(func, x, I(1), false);
test_one_input(func, x, IntType(1), false);
LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD);
test_one_input(func, x, I(0), false);
test_one_input(func, x, IntType(0), false);
LIBC_NAMESPACE::fputil::set_round(FE_TOWARDZERO);
test_one_input(func, x, I(0), false);
test_one_input(func, x, IntType(0), false);
LIBC_NAMESPACE::fputil::set_round(FE_TONEAREST);
test_one_input(func, x, I(0), false);
test_one_input(func, x, IntType(0), false);
} else {
LIBC_NAMESPACE::fputil::set_round(FE_UPWARD);
test_one_input(func, x, I(0), false);
test_one_input(func, x, IntType(0), false);
LIBC_NAMESPACE::fputil::set_round(FE_DOWNWARD);
test_one_input(func, x, I(-1), false);
test_one_input(func, x, IntType(-1), false);
LIBC_NAMESPACE::fputil::set_round(FE_TOWARDZERO);
test_one_input(func, x, I(0), false);
test_one_input(func, x, IntType(0), false);
LIBC_NAMESPACE::fputil::set_round(FE_TONEAREST);
test_one_input(func, x, I(0), false);
test_one_input(func, x, IntType(0), false);
}
} else {
test_one_input(func, x, 0L, false);
Expand All @@ -151,9 +152,10 @@ class RoundToIntegerTestTemplate
}
};

#define LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, TestModes) \
#define LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, \
TestModes) \
using LlvmLibcRoundToIntegerTest = \
RoundToIntegerTestTemplate<F, I, TestModes>; \
RoundToIntegerTestTemplate<FloatType, IntType, TestModes>; \
TEST_F(LlvmLibcRoundToIntegerTest, InfinityAndNaN) { \
testInfinityAndNaN(&func); \
} \
Expand All @@ -164,16 +166,16 @@ class RoundToIntegerTestTemplate
testSubnormalRange(&func); \
}

#define LIST_ROUND_TO_INTEGER_TESTS(F, I, func) \
LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, false)
#define LIST_ROUND_TO_INTEGER_TESTS(FloatType, IntType, func) \
LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, false)

// The GPU target does not support different rounding modes.
#ifdef LIBC_TARGET_ARCH_IS_GPU
#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, I, func) \
LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, false)
#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(FloatType, IntType, func) \
LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, false)
#else
#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(F, I, func) \
LIST_ROUND_TO_INTEGER_TESTS_HELPER(F, I, func, true)
#define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES(FloatType, IntType, func) \
LIST_ROUND_TO_INTEGER_TESTS_HELPER(FloatType, IntType, func, true)
#endif

#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ROUNDTOINTEGERTEST_H
10 changes: 5 additions & 5 deletions libc/test/src/string/memory_utils/utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ TEST(LlvmLibcUtilsTest, DistanceToAlignDown) {
TEST(LlvmLibcUtilsTest, Adjust2) {
char a, b;
const size_t base_size = 10;
for (uintptr_t I = 0; I < 4; ++I) {
for (uintptr_t i = 0; i < 4; ++i) {
auto *p1 = &a;
auto *p2 = &b;
size_t size = base_size;
adjust(static_cast<ptrdiff_t>(I), p1, p2, size);
EXPECT_EQ(intptr_t(p1), intptr_t(&a + I));
EXPECT_EQ(intptr_t(p2), intptr_t(&b + I));
EXPECT_EQ(size, base_size - I);
adjust(static_cast<ptrdiff_t>(i), p1, p2, size);
EXPECT_EQ(intptr_t(p1), intptr_t(&a + i));
EXPECT_EQ(intptr_t(p2), intptr_t(&b + i));
EXPECT_EQ(size, base_size - i);
}
}

Expand Down
Loading