LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
Ops.td
Go to the documentation of this file.
1//===-- Ops.td ---------------------------------------------*- tablegen -*-===//
2//
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
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLZK_FELT_OPS
11#define LLZK_FELT_OPS
12
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"
18
19include "mlir/IR/OpAsmInterface.td"
20include "mlir/IR/OpBase.td"
21include "mlir/IR/SymbolInterfaces.td"
22include "mlir/Interfaces/SideEffectInterfaces.td"
23
24//===------------------------------------------------------------------===//
25// Op Classes
26//===------------------------------------------------------------------===//
27
28class FeltDialectOp<string mnemonic, list<Trait> traits = []>
29 : Op<FeltDialect, mnemonic, traits>;
30
31class FeltDialectBinaryOp<string mnemonic, Type resultType,
32 list<Trait> traits = []>
33 : BinaryOpBase<FeltDialect, mnemonic, resultType, traits>;
34
35class FeltDialectUnaryOp<string mnemonic, Type resultType,
36 list<Trait> traits = []>
37 : UnaryOpBase<FeltDialect, mnemonic, resultType, traits>;
38
39//===------------------------------------------------------------------===//
40// Constants
41//===------------------------------------------------------------------===//
42
43def LLZK_FeltConstantOp
44 : FeltDialectOp<"const", [ConstantLike, Pure,
45 DeclareOpInterfaceMethods<
46 OpAsmOpInterface, ["getAsmResultNames"]>]> {
47 let summary = "field element constant";
48 let description = [{
49 This operation produces a felt-typed SSA value holding an integer constant.
50
51 Example:
52
53 ```llzk
54 %0 = llzk.const 42
55 ```
56 }];
57
58 let arguments = (ins LLZK_FeltConstAttr:$value);
59 let results = (outs LLZK_FeltType:$result);
60 let assemblyFormat = [{ $value attr-dict }];
61 let hasFolder = 1;
62}
63
64def LLZK_FeltNonDetOp
65 : FeltDialectOp<"nondet", [ConstantLike, Pure,
66 DeclareOpInterfaceMethods<
67 OpAsmOpInterface, ["getAsmResultNames"]>]> {
68 let summary = "uninitialized field element";
69 let description = [{
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.
73
74 Example:
75
76 ```llzk
77 %0 = llzk.nondet
78 ```
79 }];
80
81 let results = (outs LLZK_FeltType:$result);
82 let assemblyFormat = [{ attr-dict }];
83}
84
85//===------------------------------------------------------------------===//
86// Operators
87//===------------------------------------------------------------------===//
88
89def LLZK_AddFeltOp : FeltDialectBinaryOp<"add", LLZK_FeltType, [Commutative]> {
90 let summary = "addition operator for field elements";
91 let description = [{}];
92}
93
94def LLZK_SubFeltOp : FeltDialectBinaryOp<"sub", LLZK_FeltType> {
95 let summary = "subtraction operator for field elements";
96 let description = [{}];
97}
98
99def LLZK_MulFeltOp : FeltDialectBinaryOp<"mul", LLZK_FeltType, [Commutative]> {
100 let summary = "multiplication operator for field elements";
101 let description = [{}];
102}
103
104def LLZK_DivFeltOp : FeltDialectBinaryOp<"div", LLZK_FeltType> {
105 let summary = "division operator for field elements";
106 let description = [{}];
107}
108
109def LLZK_ModFeltOp : FeltDialectBinaryOp<"mod", LLZK_FeltType> {
110 let summary = "modulus/remainder operator for field elements";
111 let description = [{}];
112}
113
114def LLZK_NegFeltOp : FeltDialectUnaryOp<"neg", LLZK_FeltType> {
115 let summary = "negation operator for field elements";
116 let description = [{}];
117}
118
119def LLZK_InvFeltOp : FeltDialectUnaryOp<"inv", LLZK_FeltType, [WitnessGen]> {
120 let summary = "inverse operator for field elements";
121 let description = [{}];
122}
123
124def LLZK_AndFeltOp
125 : FeltDialectBinaryOp<"bit_and", LLZK_FeltType, [WitnessGen, Commutative]> {
126 let summary = "bitwise AND operator for field elements";
127 let description = [{}];
128}
129
130def LLZK_OrFeltOp
131 : FeltDialectBinaryOp<"bit_or", LLZK_FeltType, [WitnessGen, Commutative]> {
132 let summary = "bitwise OR operator for field elements";
133 let description = [{}];
134}
135
136def LLZK_XorFeltOp
137 : FeltDialectBinaryOp<"bit_xor", LLZK_FeltType, [WitnessGen, Commutative]> {
138 let summary = "bitwise XOR operator for field elements";
139 let description = [{}];
140}
141
142def LLZK_NotFeltOp
143 : FeltDialectUnaryOp<"bit_not", LLZK_FeltType, [WitnessGen]> {
144 let summary = "bit flip operator for field elements";
145 let description = [{}];
146}
147
148def LLZK_ShlFeltOp : FeltDialectBinaryOp<"shl", LLZK_FeltType, [WitnessGen]> {
149 let summary = "left shift operator for field elements";
150 let description = [{}];
151}
152
153def LLZK_ShrFeltOp : FeltDialectBinaryOp<"shr", LLZK_FeltType, [WitnessGen]> {
154 let summary = "right shift operator for field elements";
155 let description = [{}];
156}
157
158#endif // LLZK_FELT_OPS