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