Skip to content

Commit 64367c8

Browse files
replace static_cast with braced / paren init where possible
1 parent 89629eb commit 64367c8

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/fields/clmul_common_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ template<typename I, int BITS, I MOD> NO_SANITIZE_MEMORY I MulWithClMulReduce(I
3333
static constexpr I MASK = Mask<BITS, I>();
3434

3535
const __m128i MOD128 = _mm_cvtsi64_si128(MOD);
36-
__m128i product = _mm_clmulepi64_si128(_mm_cvtsi64_si128((uint64_t)a), _mm_cvtsi64_si128((uint64_t)b), 0x00);
36+
__m128i product = _mm_clmulepi64_si128(_mm_cvtsi64_si128(uint64_t(a)), _mm_cvtsi64_si128(uint64_t(b)), 0x00);
3737
if (BITS <= 32) {
3838
__m128i high1 = _mm_srli_epi64(product, BITS);
3939
__m128i red1 = _mm_clmulepi64_si128(high1, MOD128, 0x00);
@@ -69,7 +69,7 @@ template<typename I, int BITS, int POS> NO_SANITIZE_MEMORY I MulTrinomial(I a, I
6969
{
7070
static constexpr I MASK = Mask<BITS, I>();
7171

72-
__m128i product = _mm_clmulepi64_si128(_mm_cvtsi64_si128((uint64_t)a), _mm_cvtsi64_si128((uint64_t)b), 0x00);
72+
__m128i product = _mm_clmulepi64_si128(_mm_cvtsi64_si128(uint64_t(a)), _mm_cvtsi64_si128(uint64_t(b)), 0x00);
7373
if (BITS <= 32) {
7474
__m128i high1 = _mm_srli_epi64(product, BITS);
7575
__m128i red1 = _mm_xor_si128(high1, _mm_slli_epi64(high1, POS));
@@ -92,7 +92,7 @@ template<typename I, int BITS, int POS> NO_SANITIZE_MEMORY I MulTrinomial(I a, I
9292
return _mm_cvtsi128_si64(_mm_xor_si128(_mm_xor_si128(product, red1), red2)) & MASK;
9393
}
9494
} else {
95-
const __m128i MOD128 = _mm_cvtsi64_si128(1 + (((uint64_t)1) << POS));
95+
const __m128i MOD128 = _mm_cvtsi64_si128(1 + ((uint64_t{1}) << POS));
9696
__m128i red1 = _mm_clmulepi64_si128(high1, MOD128, 0x00);
9797
__m128i high2 = _mm_or_si128(_mm_srli_epi64(red1, BITS), _mm_srli_si128(_mm_slli_epi64(red1, 64 - BITS), 8));
9898
__m128i red2 = _mm_xor_si128(high2, _mm_slli_epi64(high2, POS));
@@ -143,7 +143,7 @@ template<typename I, int B, I MOD, I (*MUL)(I, I), typename F, const F* SQR, con
143143
Elem FromSeed(uint64_t seed) const {
144144
uint64_t k0 = 0x434c4d554c466c64ull; // "CLMULFld"
145145
uint64_t k1 = seed;
146-
uint64_t count = ((uint64_t)B) << 32;
146+
uint64_t count = (uint64_t(B)) << 32;
147147
I ret;
148148
do {
149149
ret = O::Mask(I(SipHash(k0, k1, count++)));

src/fields/generic_common_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ template<typename I, int B, uint32_t MOD, typename F, typename T, const F* SQR,
4949
Elem FromSeed(uint64_t seed) const {
5050
uint64_t k0 = 0x496e744669656c64ull; // "IntField"
5151
uint64_t k1 = seed;
52-
uint64_t count = ((uint64_t)B) << 32;
52+
uint64_t count = (uint64_t(B)) << 32;
5353
Elem ret;
5454
do {
5555
ret = O::Mask(I(SipHash(k0, k1, count++)));

src/sketch_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ class SketchImpl final : public Sketch
397397
auto poly = BerlekampMassey(all_syndromes, max_count, m_field);
398398
if (poly.size() == 0) return -1;
399399
if (poly.size() == 1) return 0;
400-
if ((int)poly.size() > 1 + max_count) return -1;
400+
if (int(poly.size()) > 1 + max_count) return -1;
401401
std::reverse(poly.begin(), poly.end());
402402
auto roots = FindRoots(poly, m_basis, m_field);
403403
if (roots.size() == 0) return -1;
@@ -422,7 +422,7 @@ class SketchImpl final : public Sketch
422422

423423
void SetSeed(uint64_t seed) override
424424
{
425-
if (seed == (uint64_t)-1) {
425+
if (seed == std::numeric_limits<uint64_t>::max()) {
426426
m_basis = 1;
427427
} else {
428428
m_basis = m_field.FromSeed(seed);

src/test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ std::vector<Minisketch> CreateSketches(uint32_t bits, size_t capacity) {
3434
if (Minisketch::ImplementationSupported(bits, impl)) {
3535
CHECK(Minisketch::BitsSupported(bits));
3636
ret.push_back(Minisketch(bits, impl, capacity));
37-
CHECK((bool)ret.back());
37+
CHECK(bool{ret.back()});
3838
} else {
3939
// implementation 0 must always work unless field size is disabled
4040
CHECK(impl != 0 || !Minisketch::BitsSupported(bits));
@@ -274,7 +274,7 @@ int main(int argc, char** argv) {
274274
try {
275275
test_complexity = 0;
276276
long long complexity = std::stoll(arg, &len);
277-
if (complexity >= 1 && len == arg.size() && ((uint64_t)complexity <= std::numeric_limits<uint64_t>::max() >> 10)) {
277+
if (complexity >= 1 && len == arg.size() && (static_cast<uint64_t>(complexity) <= std::numeric_limits<uint64_t>::max() >> 10)) {
278278
test_complexity = complexity;
279279
}
280280
} catch (const std::logic_error&) {}
@@ -289,7 +289,7 @@ int main(int argc, char** argv) {
289289
#else
290290
const char* mode = "";
291291
#endif
292-
printf("Running libminisketch tests%s with complexity=%llu\n", mode, (unsigned long long)test_complexity);
292+
printf("Running libminisketch tests%s with complexity=%llu\n", mode, static_cast<unsigned long long>(test_complexity));
293293

294294
TestComputeFunctions();
295295

0 commit comments

Comments
 (0)