Skip to content
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

Adam/fix allow explicit field init #460

Merged
merged 3 commits into from
May 19, 2023
Merged
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
10 changes: 7 additions & 3 deletions cpp/src/barretenberg/ecc/fields/field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
namespace barretenberg {
template <class Params> struct alignas(32) field {
public:
// We don't initialize data by default since we'd lose a lot of time on pointless initializations.
// We don't initialize data in the default constructor since we'd lose a lot of time on huge array initializations.
// Other alternatives have been noted, such as casting to get around constructors where they matter,
// however it is felt that sanitizer tools (e.g. MSAN) can detect garbage well, whereas doing
// hacky casts where needed would require rework to critical algos like MSM, FFT, Sumcheck.
// Instead, the recommended solution is use an explicit = 0 where initialization is important.
field() noexcept {}
// Instead, the recommended solution is use an explicit {} where initialization is important:
// field f; // not initialized
// field f{}; // zero-initialized
// std::array<field, N> arr; // not initialized, good for huge N
// std::array<field, N> arr {}; // zero-initialized, preferable for moderate N
field() = default;

constexpr field(const uint256_t& input) noexcept
: data{ input.data[0], input.data[1], input.data[2], input.data[3] }
Expand Down