Skip to content

Commit

Permalink
chore: fix errors in cpplint
Browse files Browse the repository at this point in the history
  • Loading branch information
Inseon Yu(Merlyn) committed Oct 6, 2023
1 parent d5628bb commit 8fc7607
Show file tree
Hide file tree
Showing 103 changed files with 462 additions and 282 deletions.
3 changes: 3 additions & 0 deletions benchmark/ec/ec_config.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "benchmark/ec/ec_config.h"

#include <algorithm>
#include <string>

#include "tachyon/base/console/iostream.h"
#include "tachyon/base/flag/flag_parser.h"

Expand Down
1 change: 1 addition & 0 deletions benchmark/ec/ec_double_benchmark_gpu.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if TACHYON_CUDA || TACHYON_USE_ROCM

#include <iostream>

// clang-format off
Expand Down
3 changes: 3 additions & 0 deletions benchmark/ec/simple_ec_benchmark_reporter.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "benchmark/ec/simple_ec_benchmark_reporter.h"

#include <string>
#include <vector>

#include "absl/strings/substitute.h"

#include "tachyon/base/strings/string_number_conversions.h"
Expand Down
2 changes: 2 additions & 0 deletions benchmark/ec/simple_ec_benchmark_reporter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef BENCHMARK_EC_SIMPLE_EC_BENCHMARK_REPORTER_H_
#define BENCHMARK_EC_SIMPLE_EC_BENCHMARK_REPORTER_H_

#include <vector>

#include "benchmark/simple_benchmark_reporter.h"

namespace tachyon {
Expand Down
2 changes: 2 additions & 0 deletions benchmark/msm/msm_config.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "benchmark/msm/msm_config.h"

#include <algorithm>

#include "tachyon/base/console/iostream.h"
#include "tachyon/base/flag/flag_parser.h"

Expand Down
2 changes: 1 addition & 1 deletion benchmark/msm/msm_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MSMConfig {
MSMConfig& operator=(const MSMConfig& other) = delete;

const std::vector<uint64_t>& degrees() const { return degrees_; }
const std::vector<Vendor>& vendors() const { return vendors_; };
const std::vector<Vendor>& vendors() const { return vendors_; }
int algorithm() const { return algorithm_; }
bool check_results() const { return check_results_; }

Expand Down
2 changes: 1 addition & 1 deletion benchmark/msm/msm_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <stddef.h>

#include <memory>
#include <vector>

// clang-format off
#include "benchmark/msm/simple_msm_benchmark_reporter.h"
// clang-format on
Expand Down
3 changes: 3 additions & 0 deletions benchmark/msm/simple_msm_benchmark_reporter.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "benchmark/msm/simple_msm_benchmark_reporter.h"

#include <string>
#include <vector>

#include "absl/strings/substitute.h"

#include "tachyon/base/strings/string_number_conversions.h"
Expand Down
2 changes: 2 additions & 0 deletions benchmark/msm/simple_msm_benchmark_reporter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef BENCHMARK_MSM_SIMPLE_MSM_BENCHMARK_REPORTER_H_
#define BENCHMARK_MSM_SIMPLE_MSM_BENCHMARK_REPORTER_H_

#include <vector>

#include "benchmark/simple_benchmark_reporter.h"

namespace tachyon {
Expand Down
3 changes: 3 additions & 0 deletions tachyon/build/cc_writer.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "tachyon/build/cc_writer.h"

#include <string>
#include <vector>

#include "absl/strings/str_join.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/substitute.h"
Expand Down
2 changes: 2 additions & 0 deletions tachyon/build/cc_writer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef TACHYON_BUILD_CC_WRITER_H_
#define TACHYON_BUILD_CC_WRITER_H_

#include <string>

#include "tachyon/build/writer.h"

namespace tachyon::build {
Expand Down
2 changes: 2 additions & 0 deletions tachyon/build/writer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef TACHYON_BUILD_WRITER_H_
#define TACHYON_BUILD_WRITER_H_

#include <string>

#include "tachyon/base/files/file_path.h"

namespace tachyon::build {
Expand Down
5 changes: 5 additions & 0 deletions tachyon/c/math/elliptic_curves/msm/msm_gpu.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#ifndef TACHYON_C_MATH_ELLIPTIC_CURVES_MSM_MSM_GPU_H_
#define TACHYON_C_MATH_ELLIPTIC_CURVES_MSM_MSM_GPU_H_

#include <limits>
#include <memory>
#include <string>
#include <vector>

#include "tachyon/base/console/console_stream.h"
#include "tachyon/base/environment.h"
#include "tachyon/base/files/file_util.h"
Expand Down
2 changes: 2 additions & 0 deletions tachyon/c/math/elliptic_curves/msm/msm_input_provider.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef TACHYON_C_MATH_ELLIPTIC_CURVES_MSM_MSM_INPUT_PROVIDER_H_
#define TACHYON_C_MATH_ELLIPTIC_CURVES_MSM_MSM_INPUT_PROVIDER_H_

#include <vector>

#include "absl/numeric/bits.h"
#include "absl/types/span.h"

Expand Down
2 changes: 2 additions & 0 deletions tachyon/crypto/commitments/pedersen/pedersen.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define TACHYON_CRYPTO_COMMITMENTS_PEDERSEN_PEDERSEN_H_

#include <sstream>
#include <string>
#include <utility>
#include <vector>

#include "tachyon/base/containers/container_util.h"
Expand Down
2 changes: 1 addition & 1 deletion tachyon/crypto/hashes/prime_field_serializable.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ constexpr bool SerializeBatchToFieldElements(

} // namespace tachyon::crypto

#endif // TACHYON_CRYPTO_HASHES_BYTES_SERIALIZABLE_H_
#endif // TACHYON_CRYPTO_HASHES_PRIME_FIELD_SERIALIZABLE_H_
3 changes: 3 additions & 0 deletions tachyon/crypto/hashes/sponge/poseidon/poseidon.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#ifndef TACHYON_CRYPTO_HASHES_SPONGE_POSEIDON_POSEIDON_H_
#define TACHYON_CRYPTO_HASHES_SPONGE_POSEIDON_POSEIDON_H_

#include <utility>
#include <vector>

#include "tachyon/base/containers/container_util.h"
#include "tachyon/base/logging.h"
#include "tachyon/crypto/hashes/prime_field_serializable.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ TYPED_TEST(PoseidonUtilTest, PoseidonConfig_CreateDefault) {
{2, true, "25126470399169474618535500283750950727260324358529540538588217772729895991183", "46350838805835525240431215868760423854112287760212339623795708191499274188615"},
{3, true, "16345358380711600255519479157621098002794924491287389755192263320486827897573", "37432344439659887296708509941462699942272362339508052702346957525719991245918"},
{4, true, "2997721997773001075802235431463112417440167809433966871891875582435098138600", "43959024692079347032841256941012668338943730711936867712802582656046301966186"},
{5, true, "28142027771717376151411984909531650866105717069245696861966432993496676054077","13157425078305676755394500322568002504776463228389342308130514165393397413991"},
{6, true, "7417004907071346600696060525974582183666365156576759507353305331252133694222","51393878771453405560681338747290999206747890655420330824736778052231938173954"},
{7, true, "47093173418416013663709314805327945458844779999893881721688570889452680883650","51455917624412053400160569105425532358410121118308957353565646758865245830775"},
{8, true, "16478680729975035007348178961232525927424769683353433314299437589237598655079","39160448583049384229582837387246752222769278402304070376350288593586064961857"},
{5, true, "28142027771717376151411984909531650866105717069245696861966432993496676054077", "13157425078305676755394500322568002504776463228389342308130514165393397413991"},
{6, true, "7417004907071346600696060525974582183666365156576759507353305331252133694222", "51393878771453405560681338747290999206747890655420330824736778052231938173954"},
{7, true, "47093173418416013663709314805327945458844779999893881721688570889452680883650", "51455917624412053400160569105425532358410121118308957353565646758865245830775"},
{8, true, "16478680729975035007348178961232525927424769683353433314299437589237598655079", "39160448583049384229582837387246752222769278402304070376350288593586064961857"},
};
// clang-format on

Expand Down
2 changes: 2 additions & 0 deletions tachyon/crypto/hashes/sponge/poseidon/poseidon_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "tachyon/crypto/hashes/sponge/poseidon/poseidon.h"

#include <vector>

#include "gtest/gtest.h"

#include "tachyon/math/elliptic_curves/bls/bls12_381/fr.h"
Expand Down
6 changes: 4 additions & 2 deletions tachyon/crypto/hashes/sponge/sponge.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace tachyon::crypto {
// Specifying the output field element size.
class TACHYON_EXPORT FieldElementSize {
public:
static FieldElementSize Full() { return {false}; }
static FieldElementSize Full() { return FieldElementSize(false); }
static FieldElementSize Truncated(size_t num_bits) {
return {true, num_bits};
}
Expand Down Expand Up @@ -47,7 +47,9 @@ class TACHYON_EXPORT FieldElementSize {
bool IsTruncated() const { return is_truncated_; }

private:
FieldElementSize(bool is_truncated, size_t num_bits = 0)
explicit FieldElementSize(bool is_truncated)
: FieldElementSize(is_truncated, 0) {}
FieldElementSize(bool is_truncated, size_t num_bits)
: is_truncated_(is_truncated), num_bits_(num_bits) {}

// If |is_truncated_| is false, sample field elements from the entire field.
Expand Down
18 changes: 9 additions & 9 deletions tachyon/examples/cuda_example.cu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ int RealMain(int argc, char **argv) {
printf("[Vector addition of %d elements]\n", numElements);

// Allocate the host input vector A
float *h_A = (float *)malloc(size);
float *h_A = (float *)malloc(size); // NOLINT(readability/casting)

// Allocate the host input vector B
float *h_B = (float *)malloc(size);
float *h_B = (float *)malloc(size); // NOLINT(readability/casting)

// Allocate the host output vector C
float *h_C = (float *)malloc(size);
float *h_C = (float *)malloc(size); // NOLINT(readability/casting)

// Verify that allocations succeeded
if (h_A == NULL || h_B == NULL || h_C == NULL) {
Expand All @@ -86,13 +86,13 @@ int RealMain(int argc, char **argv) {

// Initialize the host input vectors
for (int i = 0; i < numElements; ++i) {
h_A[i] = rand() / (float)RAND_MAX;
h_B[i] = rand() / (float)RAND_MAX;
h_A[i] = rand() / (float)RAND_MAX; // NOLINT
h_B[i] = rand() / (float)RAND_MAX; // NOLINT
}

// Allocate the device input vector A
float *d_A = NULL;
err = cudaMalloc((void **)&d_A, size);
err = cudaMalloc((void **)&d_A, size); // NOLINT(readability/casting)

if (err != cudaSuccess) {
fprintf(stderr, "Failed to allocate device vector A (error code %s)!\n",
Expand All @@ -102,7 +102,7 @@ int RealMain(int argc, char **argv) {

// Allocate the device input vector B
float *d_B = NULL;
err = cudaMalloc((void **)&d_B, size);
err = cudaMalloc((void **)&d_B, size); // NOLINT(readability/casting)

if (err != cudaSuccess) {
fprintf(stderr, "Failed to allocate device vector B (error code %s)!\n",
Expand All @@ -111,8 +111,8 @@ int RealMain(int argc, char **argv) {
}

// Allocate the device output vector C
float *d_C = NULL;
err = cudaMalloc((void **)&d_C, size);
float *d_C = NULL; // NOLINT(readability/casting)
err = cudaMalloc((void **)&d_C, size); // NOLINT(readability/casting)

if (err != cudaSuccess) {
fprintf(stderr, "Failed to allocate device vector C (error code %s)!\n",
Expand Down
2 changes: 1 addition & 1 deletion tachyon/export.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
#define TACHYON_EXPORT
#endif // defined(TACHYON_COMPONENT_BUILD)

#endif // TACHYON_EXPORT_H_
#endif // TACHYON_EXPORT_H_
34 changes: 24 additions & 10 deletions tachyon/math/base/arithmetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#include "tachyon/math/base/arithmetics_results.h"

#if defined(__clang__) && HAS_BUILTIN(__builtin_addc)
// See https://clang.llvm.org/docs/LanguageExtensions.html#multiprecision-arithmetic-builtins
// See
// https://clang.llvm.org/docs/LanguageExtensions.html#multiprecision-arithmetic-builtins
#elif ARCH_CPU_X86_64
// See https://www.intel.com/content/www/us/en/docs/cpp-compiler/developer-guide-reference/2021-8/intrinsics-for-multi-precision-arithmetic.html
// See
// https://www.intel.com/content/www/us/en/docs/cpp-compiler/developer-guide-reference/2021-8/intrinsics-for-multi-precision-arithmetic.html
#include <x86gprintrin.h>
#endif

Expand Down Expand Up @@ -77,12 +79,18 @@ ALWAYS_INLINE AddResult<uint64_t> AddWithCarry(uint64_t a, uint64_t b,
uint64_t carry = 0) {
AddResult<uint64_t> result;
#if defined(__clang__) && HAS_BUILTIN(__builtin_addcl)
static_assert(sizeof(uint64_t) == sizeof(unsigned long));
result.result = __builtin_addcl(a, b, carry, reinterpret_cast<unsigned long*>(&result.carry));
static_assert(sizeof(uint64_t) ==
sizeof(unsigned long)); // NOLINT(runtime/int)
result.result = __builtin_addcl(
a, b, carry,
reinterpret_cast<unsigned long*>(&result.carry)); // NOLINT(runtime/int)
#elif ARCH_CPU_X86_64
static_assert(sizeof(uint64_t) == sizeof(unsigned long long));
static_assert(sizeof(uint64_t) ==
sizeof(unsigned long long)); // NOLINT(runtime/int)
result.carry = _addcarry_u64(
carry, a, b, reinterpret_cast<unsigned long long*>(&result.result));
carry, a, b,
reinterpret_cast<unsigned long long*>( // NOLINT(runtime/int)
&result.result));
#else
absl::uint128 tmp =
absl::uint128(a) + absl::uint128(b) + absl::uint128(carry);
Expand All @@ -97,12 +105,18 @@ ALWAYS_INLINE SubResult<uint64_t> SubWithBorrow(uint64_t& a, uint64_t b,
uint64_t borrow = 0) {
SubResult<uint64_t> result;
#if defined(__clang__) && HAS_BUILTIN(__builtin_subcl)
static_assert(sizeof(uint64_t) == sizeof(unsigned long));
result.result = __builtin_subcl(a, b, borrow, reinterpret_cast<unsigned long*>(&result.borrow));
static_assert(sizeof(uint64_t) ==
sizeof(unsigned long)); // NOLINT(runtime/int)
result.result = __builtin_subcl(
a, b, borrow,
reinterpret_cast<unsigned long*>(&result.borrow)); // NOLINT(runtime/int)
#elif ARCH_CPU_X86_64
static_assert(sizeof(uint64_t) == sizeof(unsigned long long));
static_assert(sizeof(uint64_t) ==
sizeof(unsigned long long)); // NOLINT(runtime/int)
result.borrow = _subborrow_u64(
borrow, a, b, reinterpret_cast<unsigned long long*>(&result.result));
borrow, a, b,
reinterpret_cast<unsigned long long*>( // NOLINT(runtime/int)
&result.result));
#else
absl::uint128 tmp = (absl::uint128(1) << 64) + absl::uint128(a) -
absl::uint128(b) - absl::uint128(borrow);
Expand Down
1 change: 1 addition & 0 deletions tachyon/math/base/arithmetics_results.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define TACHYON_MATH_BASE_ARITHMETICS_RESULTS_H_

#include <ostream>
#include <string>

#include "absl/strings/substitute.h"

Expand Down
2 changes: 2 additions & 0 deletions tachyon/math/base/arithmetics_unittest.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "tachyon/math/base/arithmetics.h"

#include <limits>

#include "absl/strings/substitute.h"
#include "gtest/gtest.h"

Expand Down
2 changes: 2 additions & 0 deletions tachyon/math/base/big_int.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "tachyon/math/base/big_int.h"

#include <string>

#include "tachyon/base/strings/string_util.h"
#include "tachyon/math/base/gmp/gmp_util.h"

Expand Down
7 changes: 6 additions & 1 deletion tachyon/math/base/big_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <stdint.h>

#include <bitset>
#include <limits>
#include <string>
#include <utility>
#include <vector>

#include "tachyon/base/compiler_specific.h"
#include "tachyon/base/endian_utils.h"
Expand Down Expand Up @@ -134,6 +138,7 @@ struct ALIGNAS(internal::LimbsAlignment(N)) BigInt {
set |= (i == BitNums - 1);
#endif
if (set) {
// NOLINTNEXTLINE(runtime/int)
static_assert(sizeof(unsigned long long) == sizeof(uint64_t));
uint64_t limb = limb_bits.to_ullong();
ret.limbs[limb_idx++] = limb;
Expand Down Expand Up @@ -161,6 +166,7 @@ struct ALIGNAS(internal::LimbsAlignment(N)) BigInt {
set |= (i == 0);
#endif
if (set) {
// NOLINTNEXTLINE(runtime/int)
static_assert(sizeof(unsigned long long) == sizeof(uint64_t));
uint64_t limb = limb_bits.to_ullong();
ret.limbs[limb_idx++] = limb;
Expand Down Expand Up @@ -924,7 +930,6 @@ class BitTraits<BigInt<N>> {
uint64_t bit_index_value = static_cast<uint64_t>(1) << bit_index;
return (bigint[limb_index] & bit_index_value) == bit_index_value;
}

constexpr static void SetBit(BigInt<N>& bigint, size_t index,
bool bit_value) {
size_t limb_index = index >> 6;
Expand Down
2 changes: 2 additions & 0 deletions tachyon/math/base/big_int_unittest.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "tachyon/math/base/big_int.h"

#include <vector>

#include "gtest/gtest.h"

namespace tachyon::math {
Expand Down
2 changes: 2 additions & 0 deletions tachyon/math/base/field.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef TACHYON_MATH_BASE_FIELD_H_
#define TACHYON_MATH_BASE_FIELD_H_

#include <utility>

#include "tachyon/math/base/rings.h"

namespace tachyon::math {
Expand Down
Loading

0 comments on commit 8fc7607

Please sign in to comment.