12#include <llvm/ADT/APSInt.h>
13#include <llvm/ADT/DenseMap.h>
14#include <llvm/Support/SMTAPI.h>
34 llvm::APSInt
prime()
const {
return primeMod; }
37 llvm::APSInt
half()
const {
return halfPrime; }
40 inline llvm::APSInt
felt(
int i)
const {
return reduce(i); }
43 inline llvm::APSInt
zero()
const {
return felt(0); }
46 inline llvm::APSInt
one()
const {
return felt(1); }
54 llvm::APSInt
reduce(llvm::APSInt i)
const;
55 llvm::APSInt
reduce(
int i)
const;
57 inline unsigned bitWidth()
const {
return primeMod.getBitWidth(); }
61 return solver->mkSymbol(
name, solver->getBitvectorSort(
bitWidth()));
65 return lhs.primeMod == rhs.primeMod;
69 Field(std::string_view primeStr);
71 llvm::APSInt primeMod, halfPrime;
73 static void initKnownFields(llvm::DenseMap<llvm::StringRef, Field> &knownFields);
llvm::APSInt one() const
Returns 1 at the bitwidth of the field.
llvm::SMTExprRef createSymbol(llvm::SMTSolverRef solver, const char *name) const
Create a SMT solver symbol with the current field's bitwidth.
llvm::APSInt zero() const
Returns 0 at the bitwidth of the field.
friend bool operator==(const Field &lhs, const Field &rhs)
llvm::APSInt felt(int i) const
Returns i as a signed field element.
Field(const Field &)=default
llvm::APSInt half() const
Returns p / 2.
unsigned bitWidth() const
Field & operator=(const Field &)=default
llvm::APSInt maxVal() const
Returns p - 1, which is the max value possible in a prime field described by p.
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.