|
| 1 | +#ifndef LIB_DIALECT_PISA_IR_PISAOPS_TD_ |
| 2 | +#define LIB_DIALECT_PISA_IR_PISAOPS_TD_ |
| 3 | + |
| 4 | +include "lib/Dialect/PISA/IR/PISADialect.td" |
| 5 | +include "mlir/IR/BuiltinAttributes.td" |
| 6 | +include "mlir/IR/CommonTypeConstraints.td" |
| 7 | +include "mlir/IR/OpBase.td" |
| 8 | +include "mlir/Interfaces/InferTypeOpInterface.td" |
| 9 | +include "mlir/Interfaces/SideEffectInterfaces.td" |
| 10 | + |
| 11 | +def Tensor8192I32 : TypeConstraint<CPred<[{ |
| 12 | + mlir::isa<mlir::RankedTensorType>($_self) && |
| 13 | + mlir::cast<mlir::RankedTensorType>($_self).getRank() == 1 && |
| 14 | + mlir::cast<mlir::RankedTensorType>($_self).getDimSize(0) == 8192 && |
| 15 | + mlir::cast<mlir::RankedTensorType>($_self).getElementType().isInteger(32) |
| 16 | +}]>, "tensor<8192xi32>">; |
| 17 | + |
| 18 | +class PISA_Op<string mnemonic, list<Trait> traits = [Pure]> : |
| 19 | + Op<PISA_Dialect, mnemonic, traits> { |
| 20 | + let cppNamespace = "::mlir::heir::pisa"; |
| 21 | +} |
| 22 | + |
| 23 | +class PISA_BinaryOp<string mnemonic, list<Trait> traits = []> : |
| 24 | + PISA_Op<mnemonic, traits # [SameOperandsAndResultType]>, |
| 25 | + Arguments<(ins Tensor8192I32:$lhs, Tensor8192I32:$rhs, I32Attr:$q, I32Attr:$i)>, |
| 26 | + Results<(outs Tensor8192I32:$output)> { |
| 27 | + let assemblyFormat = "$lhs `,` $rhs attr-dict `:` qualified(type($output))"; |
| 28 | + } |
| 29 | + |
| 30 | +def PISA_AddOp : PISA_BinaryOp<"add", [Commutative]> { |
| 31 | + let summary = "addition operation"; |
| 32 | + let description = [{ |
| 33 | + Computes addition of two polynomials (irrespective of ntt/coefficient representation). |
| 34 | + }]; |
| 35 | +} |
| 36 | + |
| 37 | +def PISA_SubOp : PISA_BinaryOp<"sub", []> { |
| 38 | + let summary = "subtraction operation"; |
| 39 | + let description = [{ |
| 40 | + Computes subtraction of two polynomials (irrespective of ntt/coefficient representation). |
| 41 | + }]; |
| 42 | +} |
| 43 | + |
| 44 | +def PISA_MulOp : PISA_BinaryOp<"mul", [Commutative]> { |
| 45 | + let summary = "multiplication operation"; |
| 46 | + let description = [{ |
| 47 | + Computes addition of two polynomials (in ntt representation). |
| 48 | + }]; |
| 49 | +} |
| 50 | + |
| 51 | +def PISA_MuliOp : PISA_Op<"muli", [SameOperandsAndResultType]> { |
| 52 | + let summary = "multiplication-with-immediate operation"; |
| 53 | + let description = [{ |
| 54 | + Computes multiplication of a polynomial (in ntt representation) with a constant. |
| 55 | + }]; |
| 56 | + let arguments = (ins Tensor8192I32:$lhs, I32Attr:$q, I32Attr:$i, I32Attr:$imm); |
| 57 | + let results = (outs Tensor8192I32:$output); |
| 58 | + let assemblyFormat = "$lhs attr-dict `:` qualified(type($output))"; |
| 59 | +} |
| 60 | + |
| 61 | +def PISA_MacOp : PISA_Op<"mac", [SameOperandsAndResultType]> { |
| 62 | + let summary = "multiply-and-accumulate operation"; |
| 63 | + let description = [{ |
| 64 | + Computes multiplication of two polynomials (in ntt representation) and adds the result to a third polynomial. |
| 65 | + }]; |
| 66 | + let arguments = (ins Tensor8192I32:$lhs, Tensor8192I32:$rhs, Tensor8192I32:$acc, I32Attr:$q, I32Attr:$i); |
| 67 | + let results = (outs Tensor8192I32:$output); |
| 68 | + let assemblyFormat = "$lhs `,` $rhs `,` $acc attr-dict `:` qualified(type($output))"; |
| 69 | +} |
| 70 | + |
| 71 | +def PISA_MaciOp : PISA_Op<"maci", [SameOperandsAndResultType]> { |
| 72 | + let summary = "multiply-and-accumulate-with-immediate operation"; |
| 73 | + let description = [{ |
| 74 | + Computes multiplication of a polynomial (in ntt representation) with a constant and adds the result to a third polynomial. |
| 75 | + }]; |
| 76 | + let arguments = (ins Tensor8192I32:$lhs, Tensor8192I32:$acc, I32Attr:$q, I32Attr:$i, I32Attr:$imm); |
| 77 | + let results = (outs Tensor8192I32:$output); |
| 78 | + let assemblyFormat = "$lhs `,` $acc attr-dict `:` qualified(type($output))"; |
| 79 | +} |
| 80 | + |
| 81 | +def PISA_NTTOp : PISA_Op<"ntt", [SameOperandsAndResultType]> { |
| 82 | + let summary = "number-theoretic-transform operation"; |
| 83 | + let description = [{ |
| 84 | + Computes number-theoretic-transform of a polynomial. |
| 85 | + }]; |
| 86 | + let arguments = (ins Tensor8192I32:$poly, Tensor8192I32:$w, I32Attr:$q, I32Attr:$i); |
| 87 | + let results = (outs Tensor8192I32:$output); |
| 88 | + let assemblyFormat = "$poly `,` $w attr-dict `:` qualified(type($output))"; |
| 89 | +} |
| 90 | + |
| 91 | +def PISA_INTTOp : PISA_Op<"intt", [SameOperandsAndResultType]> { |
| 92 | + let summary = "inverse number-theoretic-transform operation"; |
| 93 | + let description = [{ |
| 94 | + Computes inverse number-theoretic-transform of a polynomial. |
| 95 | + }]; |
| 96 | + let arguments = (ins Tensor8192I32:$poly, Tensor8192I32:$w, I32Attr:$q, I32Attr:$i); |
| 97 | + let results = (outs Tensor8192I32:$output); |
| 98 | + let assemblyFormat = "$poly `,` $w attr-dict `:` qualified(type($output))"; |
| 99 | +} |
| 100 | + |
| 101 | + |
| 102 | +#endif // LIB_DIALECT_PISA_IR_PISAOPS_TD_ |
0 commit comments