13#include <llvm/ADT/Twine.h>
23 halfPrime = (primeMod + felt(1)) / felt(2);
27 static llvm::DenseMap<llvm::StringRef, Field> knownFields;
28 static std::once_flag fieldsInit;
29 std::call_once(fieldsInit, initKnownFields, knownFields);
31 if (
auto it = knownFields.find(fieldName); it != knownFields.end()) {
34 llvm::report_fatal_error(
"field \"" + llvm::Twine(fieldName) +
"\" is unsupported");
37void Field::initKnownFields(llvm::DenseMap<llvm::StringRef, Field> &knownFields) {
39 knownFields.try_emplace(
41 Field(
"21888242871839275222246405745257275088696311157297823662689037894645226208583")
43 knownFields.try_emplace(
"bn254", knownFields.at(
"bn128"));
45 knownFields.try_emplace(
"babybear",
Field(
"2013265921"));
47 knownFields.try_emplace(
"goldilocks",
Field(
"18446744069414584321"));
49 knownFields.try_emplace(
"mersenne31",
Field(
"2147483647"));
55 unsigned maxBits = std::max(i.getBitWidth(),
bitWidth());
56 llvm::APSInt m = (i.extend(maxBits) %
prime().extend(maxBits)).trunc(
bitWidth());
64 auto ap = llvm::APSInt(llvm::APInt(
bitWidth(), i),
false);
This file defines helpers for manipulating APInts/APSInts for large numbers and operations over those...
Information about the prime finite field used for the interval analysis.
unsigned bitWidth() const
static const Field & getField(const char *fieldName)
Get a Field from a given field name string.
llvm::APSInt prime() const
For the prime field p, returns p.
llvm::APSInt reduce(llvm::APSInt i) const
Returns i mod p and reduces the result into the appropriate bitwidth.
llvm::APSInt safeToSigned(llvm::APSInt i)
Safely converts the given int to a signed int if it is an unsigned int by adding an extra bit for the...