1//===-- Ops.td ---------------------------------------------*- tablegen -*-===//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
8//===----------------------------------------------------------------------===//
13include "llzk/Dialect/Felt/IR/Dialect.td"
14include "llzk/Dialect/Felt/IR/Types.td"
15include "llzk/Dialect/Felt/IR/Attrs.td"
16include "llzk/Dialect/Function/IR/OpTraits.td"
17include "llzk/Dialect/Shared/OpsBase.td"
19include "mlir/IR/OpAsmInterface.td"
20include "mlir/IR/OpBase.td"
21include "mlir/IR/SymbolInterfaces.td"
22include "mlir/Interfaces/SideEffectInterfaces.td"
24//===------------------------------------------------------------------===//
26//===------------------------------------------------------------------===//
28class FeltDialectOp<string mnemonic, list<Trait> traits = []>
29 : Op<FeltDialect, mnemonic, traits>;
31class FeltDialectBinaryOp<string mnemonic, Type resultType,
32 list<Trait> traits = []>
33 : BinaryOpBase<FeltDialect, mnemonic, resultType, traits>;
35class FeltDialectUnaryOp<string mnemonic, Type resultType,
36 list<Trait> traits = []>
37 : UnaryOpBase<FeltDialect, mnemonic, resultType, traits>;
39//===------------------------------------------------------------------===//
41//===------------------------------------------------------------------===//
43def LLZK_FeltConstantOp
44 : FeltDialectOp<"const", [ConstantLike, Pure,
45 DeclareOpInterfaceMethods<
46 OpAsmOpInterface, ["getAsmResultNames"]>]> {
47 let summary = "field element constant";
49 This operation produces a felt-typed SSA value holding an integer constant.
58 let arguments = (ins LLZK_FeltConstAttr:$value);
59 let results = (outs LLZK_FeltType:$result);
60 let assemblyFormat = [{ $value attr-dict }];
65 : FeltDialectOp<"nondet", [ConstantLike, Pure,
66 DeclareOpInterfaceMethods<
67 OpAsmOpInterface, ["getAsmResultNames"]>]> {
68 let summary = "uninitialized field element";
70 This operation produces a felt-typed SSA value without a specified value.
71 This can be used in `constrain()` functions in place of expressions that
72 cannot be included in constraints.
81 let results = (outs LLZK_FeltType:$result);
82 let assemblyFormat = [{ attr-dict }];
85//===------------------------------------------------------------------===//
87//===------------------------------------------------------------------===//
89def LLZK_AddFeltOp : FeltDialectBinaryOp<"add", LLZK_FeltType, [Commutative]> {
90 let summary = "addition operator for field elements";
91 let description = [{}];
94def LLZK_SubFeltOp : FeltDialectBinaryOp<"sub", LLZK_FeltType> {
95 let summary = "subtraction operator for field elements";
96 let description = [{}];
99def LLZK_MulFeltOp : FeltDialectBinaryOp<"mul", LLZK_FeltType, [Commutative]> {
100 let summary = "multiplication operator for field elements";
101 let description = [{}];
104def LLZK_DivFeltOp : FeltDialectBinaryOp<"div", LLZK_FeltType> {
105 let summary = "division operator for field elements";
106 let description = [{}];
109def LLZK_ModFeltOp : FeltDialectBinaryOp<"mod", LLZK_FeltType> {
110 let summary = "modulus/remainder operator for field elements";
111 let description = [{}];
114def LLZK_NegFeltOp : FeltDialectUnaryOp<"neg", LLZK_FeltType> {
115 let summary = "negation operator for field elements";
116 let description = [{}];
119def LLZK_InvFeltOp : FeltDialectUnaryOp<"inv", LLZK_FeltType, [WitnessGen]> {
120 let summary = "inverse operator for field elements";
121 let description = [{}];
125 : FeltDialectBinaryOp<"bit_and", LLZK_FeltType, [WitnessGen, Commutative]> {
126 let summary = "bitwise AND operator for field elements";
127 let description = [{}];
131 : FeltDialectBinaryOp<"bit_or", LLZK_FeltType, [WitnessGen, Commutative]> {
132 let summary = "bitwise OR operator for field elements";
133 let description = [{}];
137 : FeltDialectBinaryOp<"bit_xor", LLZK_FeltType, [WitnessGen, Commutative]> {
138 let summary = "bitwise XOR operator for field elements";
139 let description = [{}];
143 : FeltDialectUnaryOp<"bit_not", LLZK_FeltType, [WitnessGen]> {
144 let summary = "bit flip operator for field elements";
145 let description = [{}];
148def LLZK_ShlFeltOp : FeltDialectBinaryOp<"shl", LLZK_FeltType, [WitnessGen]> {
149 let summary = "left shift operator for field elements";
150 let description = [{}];
153def LLZK_ShrFeltOp : FeltDialectBinaryOp<"shr", LLZK_FeltType, [WitnessGen]> {
154 let summary = "right shift operator for field elements";
155 let description = [{}];
158#endif // LLZK_FELT_OPS