|
39 | 39 | ) |
40 | 40 |
|
41 | 41 |
|
| 42 | +@irdl_attr_definition |
| 43 | +class RoundingModeType(ParametrizedAttribute, SMTLibSort, TypeAttribute): |
| 44 | + """ |
| 45 | + Defines Rounding Mode of FP operations, it includes following constants and their abbreviated version |
| 46 | + :funs ((roundNearestTiesToEven RoundingMode) (RNE RoundingMode) |
| 47 | + (roundNearestTiesToAway RoundingMode) (RNA RoundingMode) |
| 48 | + (roundTowardPositive RoundingMode) (RTP RoundingMode) |
| 49 | + (roundTowardNegative RoundingMode) (RTN RoundingMode) |
| 50 | + (roundTowardZero RoundingMode) (RTZ RoundingMode) |
| 51 | + ) |
| 52 | + """ |
| 53 | + |
| 54 | + name = "smt.fp.rounding_mode" |
| 55 | + |
| 56 | + def __init__(self): |
| 57 | + super().__init__() |
| 58 | + |
| 59 | + def print_sort_to_smtlib(self, stream: IO[str]) -> None: |
| 60 | + print(f"RoundingMode") |
| 61 | + |
| 62 | + |
| 63 | +class RunningModeConstantOp(IRDLOperation, Pure, SMTLibOp): |
| 64 | + """ |
| 65 | + This class is an abstract class for all RoundingMode constants |
| 66 | + :funs ((roundNearestTiesToEven RoundingMode) (RNE RoundingMode) |
| 67 | + (roundNearestTiesToAway RoundingMode) (RNA RoundingMode) |
| 68 | + (roundTowardPositive RoundingMode) (RTP RoundingMode) |
| 69 | + (roundTowardNegative RoundingMode) (RTN RoundingMode) |
| 70 | + (roundTowardZero RoundingMode) (RTZ RoundingMode) |
| 71 | + ) |
| 72 | + """ |
| 73 | + |
| 74 | + res: OpResult = result_def(RoundingModeType) |
| 75 | + |
| 76 | + def __init__(self): |
| 77 | + super().__init__(result_types=[RoundingModeType()]) |
| 78 | + |
| 79 | + def print_expr_to_smtlib(self, stream: IO[str], ctx: SMTConversionCtx) -> None: |
| 80 | + print(f"{self.constant_name()}", file=stream, end="") |
| 81 | + |
| 82 | + @abstractmethod |
| 83 | + def constant_name(self) -> str: |
| 84 | + """RoundingMode name when printed in SMTLib.""" |
| 85 | + ... |
| 86 | + |
| 87 | + |
| 88 | +@irdl_op_definition |
| 89 | +class RoundNearestTiesToEvenOp(RunningModeConstantOp): |
| 90 | + name = "smt.fp.round_nearest_ties_to_even" |
| 91 | + |
| 92 | + def constant_name(self) -> str: |
| 93 | + return "roundNearestTiesToEven" |
| 94 | + |
| 95 | + |
| 96 | +@irdl_op_definition |
| 97 | +class RNEOp(RunningModeConstantOp): |
| 98 | + name = "smt.fp.rne" |
| 99 | + |
| 100 | + def constant_name(self) -> str: |
| 101 | + return "RNE" |
| 102 | + |
| 103 | + |
| 104 | +@irdl_op_definition |
| 105 | +class RoundNearestTiesToAwayOp(RunningModeConstantOp): |
| 106 | + name = "smt.fp.round_nearest_ties_to_away" |
| 107 | + |
| 108 | + def constant_name(self) -> str: |
| 109 | + return "roundNearestTiesToAway" |
| 110 | + |
| 111 | + |
| 112 | +@irdl_op_definition |
| 113 | +class RNAOp(RunningModeConstantOp): |
| 114 | + name = "smt.fp.rna" |
| 115 | + |
| 116 | + def constant_name(self) -> str: |
| 117 | + return "RNA" |
| 118 | + |
| 119 | + |
| 120 | +@irdl_op_definition |
| 121 | +class RoundTowardPositiveOp(RunningModeConstantOp): |
| 122 | + name = "smt.fp.round_toward_positive" |
| 123 | + |
| 124 | + def constant_name(self) -> str: |
| 125 | + return "roundTowardPositive" |
| 126 | + |
| 127 | + |
| 128 | +@irdl_op_definition |
| 129 | +class RTPOp(RunningModeConstantOp): |
| 130 | + name = "smt.fp.rtp" |
| 131 | + |
| 132 | + def constant_name(self) -> str: |
| 133 | + return "RTP" |
| 134 | + |
| 135 | + |
| 136 | +@irdl_op_definition |
| 137 | +class RoundTowardNegativeOp(RunningModeConstantOp): |
| 138 | + name = "smt.fp.round_toward_negative" |
| 139 | + |
| 140 | + def constant_name(self) -> str: |
| 141 | + return "roundTowardNegative" |
| 142 | + |
| 143 | + |
| 144 | +@irdl_op_definition |
| 145 | +class RTNOp(RunningModeConstantOp): |
| 146 | + name = "smt.fp.rtn" |
| 147 | + |
| 148 | + def constant_name(self) -> str: |
| 149 | + return "RTN" |
| 150 | + |
| 151 | + |
| 152 | +@irdl_op_definition |
| 153 | +class RoundTowardZeroOp(RunningModeConstantOp): |
| 154 | + name = "smt.fp.round_toward_zero" |
| 155 | + |
| 156 | + def constant_name(self) -> str: |
| 157 | + return "roundTowardZero" |
| 158 | + |
| 159 | + |
| 160 | +@irdl_op_definition |
| 161 | +class RTZOp(RunningModeConstantOp): |
| 162 | + name = "smt.fp.rtz" |
| 163 | + |
| 164 | + def constant_name(self) -> str: |
| 165 | + return "RTZ" |
| 166 | + |
| 167 | + |
42 | 168 | @irdl_attr_definition |
43 | 169 | class FloatingPointType(ParametrizedAttribute, SMTLibSort, TypeAttribute): |
44 | 170 | """ |
@@ -208,6 +334,17 @@ def constant_name(self) -> str: |
208 | 334 | PositiveInfinityOp, |
209 | 335 | NegativeInfinityOp, |
210 | 336 | NaNOp, |
| 337 | + # Rounding Mode constants |
| 338 | + RoundNearestTiesToEvenOp, |
| 339 | + RNEOp, |
| 340 | + RoundNearestTiesToAwayOp, |
| 341 | + RNAOp, |
| 342 | + RoundTowardPositiveOp, |
| 343 | + RTPOp, |
| 344 | + RoundTowardNegativeOp, |
| 345 | + RTNOp, |
| 346 | + RoundTowardZeroOp, |
| 347 | + RTZOp, |
211 | 348 | ], |
212 | | - [FloatingPointType], |
| 349 | + [FloatingPointType, RoundingModeType], |
213 | 350 | ) |
0 commit comments