12#include <llvm/ADT/DenseMap.h>
13#include <llvm/ADT/DynamicAPInt.h>
14#include <llvm/Support/SMTAPI.h>
37 llvm::DynamicAPInt
prime()
const {
return primeMod; }
40 llvm::DynamicAPInt
half()
const {
return halfPrime; }
43 inline llvm::DynamicAPInt
felt(
int i)
const {
return reduce(i); }
46 inline llvm::DynamicAPInt
zero()
const {
return felt(0); }
49 inline llvm::DynamicAPInt
one()
const {
return felt(1); }
57 llvm::DynamicAPInt
reduce(
const llvm::DynamicAPInt &i)
const;
58 inline llvm::DynamicAPInt
reduce(
int i)
const {
return reduce(llvm::DynamicAPInt(i)); }
59 llvm::DynamicAPInt
reduce(
const llvm::APInt &i)
const;
61 inline unsigned bitWidth()
const {
return bitwidth; }
65 return solver->mkSymbol(
name, solver->getBitvectorSort(
bitWidth()));
69 return lhs.primeMod == rhs.primeMod;
73 Field(std::string_view primeStr);
75 llvm::DynamicAPInt primeMod, halfPrime;
78 static void initKnownFields(llvm::DenseMap<llvm::StringRef, Field> &knownFields);
llvm::DynamicAPInt half() const
Returns p / 2.
llvm::SMTExprRef createSymbol(llvm::SMTSolverRef solver, const char *name) const
Create a SMT solver symbol with the current field's bitwidth.
friend bool operator==(const Field &lhs, const Field &rhs)
Field(const Field &)=default
llvm::DynamicAPInt zero() const
Returns 0 at the bitwidth of the field.
llvm::DynamicAPInt prime() const
For the prime field p, returns p.
llvm::DynamicAPInt reduce(const llvm::DynamicAPInt &i) const
Returns i mod p and reduces the result into the appropriate bitwidth.
llvm::DynamicAPInt one() const
Returns 1 at the bitwidth of the field.
llvm::DynamicAPInt reduce(int i) const
llvm::DynamicAPInt felt(int i) const
Returns i as a signed field element.
llvm::DynamicAPInt reduce(const llvm::APInt &i) const
unsigned bitWidth() const
static const Field & getField(const char *fieldName)
Get a Field from a given field name string.
Field(Field &&) noexcept=default
llvm::DynamicAPInt maxVal() const
Returns p - 1, which is the max value possible in a prime field described by p.