-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ModArithType for
mod_arith
dialect
- Loading branch information
1 parent
840f0f7
commit 07b4ac1
Showing
6 changed files
with
157 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef LIB_DIALECT_MODARITH_IR_MODARITHTYPES_H_ | ||
#define LIB_DIALECT_MODARITH_IR_MODARITHTYPES_H_ | ||
|
||
#include "lib/Dialect/ModArith/IR/ModArithDialect.h" | ||
|
||
#define GET_TYPEDEF_CLASSES | ||
#include "lib/Dialect/ModArith/IR/ModArithTypes.h.inc" | ||
|
||
#endif // LIB_DIALECT_MODARITH_IR_MODARITHTYPES_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef LIB_TYPES_MODARITH_IR_MODARITHTYPES_TD_ | ||
#define LIB_TYPES_MODARITH_IR_MODARITHTYPES_TD_ | ||
|
||
include "lib/Dialect/ModArith/IR/ModArithDialect.td" | ||
|
||
include "mlir/IR/DialectBase.td" | ||
include "mlir/IR/BuiltinTypeInterfaces.td" | ||
include "mlir/IR/AttrTypeBase.td" | ||
|
||
class ModArith_Type<string name, string typeMnemonic> | ||
: TypeDef<ModArith_Dialect, name> { | ||
let mnemonic = typeMnemonic; | ||
} | ||
|
||
def ModArith_ModArith : ModArith_Type<"ModArith", "mod_arith"> { | ||
let summary = "Integer type with modular arithmetic"; | ||
let description = [{ | ||
`modulus` is the modulus the arithmetic working with. | ||
|
||
`modulus` should be specified as, for example, `65537 : i32`. | ||
It is required that the underlying integer type should be larger than | ||
the modulus for a few bits. This requirement eases the handling of | ||
modulus of similar bitwidth as the underlying type. | ||
|
||
For example, when `modulus == 2 ** 32 - 1`, the underlying type | ||
for the modulus should be `i64`. | ||
|
||
The integer type should typically be `i32`, `i64` or higher. | ||
|
||
Note that when the integer type is not specified, `i64` is implicitly | ||
specified. | ||
|
||
Examples: | ||
``` | ||
!Zp1 = !mod_arith.mod_arith<modulus = 7> // implicitly being i64 | ||
!Zp2 = !mod_arith.mod_arith<modulus = 65537 : i32> | ||
!Zp3 = !mod_arith.mod_arith<modulus = 536903681 : i64> | ||
``` | ||
}]; | ||
let parameters = (ins | ||
"::mlir::IntegerAttr":$modulus | ||
); | ||
let assemblyFormat = "`<` struct(params) `>`"; | ||
} | ||
|
||
def ModArithLike: TypeOrContainer<ModArith_ModArith, "mod_arith-like">; | ||
|
||
#endif // LIB_TYPES_MODARITH_IR_MODARITHTYPES_TD_ |