Skip to content

Commit

Permalink
Merge pull request #15 from AntelopeIO/c++20_update
Browse files Browse the repository at this point in the history
Changes for building with the C++20 flag
  • Loading branch information
greg7mdp authored Apr 25, 2023
2 parents f61ef19 + 6a5565a commit 63c6c99
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/bn256/span.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#ifdef __cpp_lib_span
#if __cplusplus > 201703L
# include <span>
#else
# include <limits>
Expand Down
15 changes: 9 additions & 6 deletions src/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
#include <cstddef>
#include <cstring>
#if __cplusplus > 201703L
# include <array>
namespace bn256 {
template <typename T, std::size_t S>
using array = std::array<T, S>;
}
#include <span>
#include <cstdint>
#include <tuple>
#include <array>
namespace bn256 {
template <typename T, std::size_t S>
using array = std::array<T, S>;
}
#else
#include <bn256/span.h>

Expand Down Expand Up @@ -84,4 +87,4 @@ constexpr bool bit_test(std::span<const uint64_t, N> value, int i) {
int index_in_limb = i % (sizeof(uint64_t)*8);
return value[limb_index] & (1ULL << index_in_limb);
}
}
}
10 changes: 9 additions & 1 deletion src/bitint_arithmetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ constexpr bool addcarry_u512(bool carry, const uint64_t* a, const uint64_t* b, u
uint64_t* c) noexcept {
#ifdef BN256_HAS_EXTINT
if (!BN256_IS_CONSTANT_EVALUATED) {
#if __clang__ && __clang_major__ >= 14
using extint_t = _BitInt(512);
#else
using extint_t = _ExtInt(512);
#endif
extint_t x = 0, y = 0;
memcpy(&x, a, sizeof(uint64_t) * 4);
memcpy(&y, b, sizeof(uint64_t) * 4);
Expand Down Expand Up @@ -185,7 +189,11 @@ constexpr bool addcarry_u512(bool carry, const uint64_t* a, const uint64_t* b, u
constexpr void half_mul_u256(const uint64_t* a, const uint64_t* b, uint64_t* c) noexcept {
#ifdef BN256_HAS_EXTINT
if (!BN256_IS_CONSTANT_EVALUATED) {
#if __clang__ && __clang_major__ >= 14
using extint_t = _BitInt(256);
#else
using extint_t = _ExtInt(256);
#endif
extint_t x = 0, y = 0;
memcpy(&x, a, sizeof(uint64_t) * 4);
memcpy(&y, b, sizeof(uint64_t) * 4);
Expand Down Expand Up @@ -226,4 +234,4 @@ constexpr void half_mul_u256(const uint64_t* a, const uint64_t* b, uint64_t* c)
carry = addcarry_u64(carry, rdi, rbx, &c[3]);
}

} // namespace bn256
} // namespace bn256
4 changes: 2 additions & 2 deletions src/bn256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ int32_t pairing_check(std::span<const uint8_t> marshaled_g1g2_pair, std::functio
acc.set_one();
while (data < data_end) {
g1 a;
if (auto err = a.unmarshal({ data, 64 }); err)
if (auto err = a.unmarshal(std::span<const uint8_t, 64>{ data, 64 }); err)
return -1;
data += 64;
g2 b;
if (auto err = b.unmarshal({ data, 128 }); err)
if (auto err = b.unmarshal(std::span<const uint8_t, 128>{ data, 128 }); err)
return -1;
data += 128;
if (a.p().is_infinity() || b.p().is_infinity()) {
Expand Down

0 comments on commit 63c6c99

Please sign in to comment.