@@ -2491,6 +2491,7 @@ class LiOp(RISCVInstruction, ABC):
2491
2491
2492
2492
rd = result_def (IntRegisterType )
2493
2493
immediate = attr_def (base (Imm32Attr ) | base (LabelAttr ))
2494
+ fastmath = opt_attr_def (FastMathFlagsAttr )
2494
2495
2495
2496
traits = frozenset ((Pure (), ConstantLike (), LiOpHasCanonicalizationPatternTrait ()))
2496
2497
@@ -2499,6 +2500,7 @@ def __init__(
2499
2500
immediate : int | Imm32Attr | str | LabelAttr ,
2500
2501
* ,
2501
2502
rd : IntRegisterType | str | None = None ,
2503
+ fastmath : FastMathFlagsAttr | None = None ,
2502
2504
comment : str | StringAttr | None = None ,
2503
2505
):
2504
2506
if isinstance (immediate , int ):
@@ -2517,6 +2519,7 @@ def __init__(
2517
2519
attributes = {
2518
2520
"immediate" : immediate ,
2519
2521
"comment" : comment ,
2522
+ "fastmath" : fastmath ,
2520
2523
},
2521
2524
)
2522
2525
@@ -2527,12 +2530,22 @@ def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
2527
2530
def custom_parse_attributes (cls , parser : Parser ) -> dict [str , Attribute ]:
2528
2531
attributes = dict [str , Attribute ]()
2529
2532
attributes ["immediate" ] = parse_immediate_value (parser , i32 )
2533
+ fast = FastMathFlagsAttr ("none" )
2534
+ if parser .parse_optional_keyword ("fastmath" ) is not None :
2535
+ fast = FastMathFlagsAttr (FastMathFlagsAttr .parse_parameter (parser ))
2536
+ attributes ["fastmath" ] = fast
2530
2537
return attributes
2531
2538
2532
2539
def custom_print_attributes (self , printer : Printer ) -> Set [str ]:
2533
2540
printer .print (" " )
2534
2541
print_immediate_value (printer , self .immediate )
2535
- return {"immediate" }
2542
+
2543
+ if "fastmath" in self .attributes and self .attributes [
2544
+ "fastmath"
2545
+ ] != FastMathFlagsAttr ("none" ):
2546
+ printer .print (" fastmath" )
2547
+ self .fastmath .print_parameter (printer )
2548
+ return {"immediate" , "fastmath" }
2536
2549
2537
2550
@classmethod
2538
2551
def parse_op_type (
@@ -3016,6 +3029,65 @@ def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
3016
3029
return self .rd , self .rs1 , self .rs2
3017
3030
3018
3031
3032
+ class RdRsRsFloatFloatIntegerOperationWithFastMath (RISCVInstruction , ABC ):
3033
+ """
3034
+ A base class for RISC-V operations that have two source floating-point
3035
+ registers with an integer destination register, and can be annotated with fastmath flags.
3036
+
3037
+ This is called R-Type in the RISC-V specification.
3038
+ """
3039
+
3040
+ rd = result_def (IntRegisterType )
3041
+ rs1 = operand_def (FloatRegisterType )
3042
+ rs2 = operand_def (FloatRegisterType )
3043
+ fastmath = opt_attr_def (FastMathFlagsAttr )
3044
+
3045
+ def __init__ (
3046
+ self ,
3047
+ rs1 : Operation | SSAValue ,
3048
+ rs2 : Operation | SSAValue ,
3049
+ * ,
3050
+ rd : IntRegisterType | str | None = None ,
3051
+ fastmath : FastMathFlagsAttr | None = None ,
3052
+ comment : str | StringAttr | None = None ,
3053
+ ):
3054
+ if rd is None :
3055
+ rd = IntRegisterType .unallocated ()
3056
+ elif isinstance (rd , str ):
3057
+ rd = IntRegisterType (rd )
3058
+ if isinstance (comment , str ):
3059
+ comment = StringAttr (comment )
3060
+
3061
+ super ().__init__ (
3062
+ operands = [rs1 , rs2 ],
3063
+ attributes = {
3064
+ "fastmath" : fastmath ,
3065
+ "comment" : comment ,
3066
+ },
3067
+ result_types = [rd ],
3068
+ )
3069
+
3070
+ def assembly_line_args (self ) -> tuple [AssemblyInstructionArg , ...]:
3071
+ return self .rd , self .rs1 , self .rs2
3072
+
3073
+ @classmethod
3074
+ def custom_parse_attributes (cls , parser : Parser ) -> dict [str , Attribute ]:
3075
+ attributes = dict [str , Attribute ]()
3076
+ flags = FastMathFlagsAttr ("none" )
3077
+ if parser .parse_optional_keyword ("fastmath" ) is not None :
3078
+ flags = FastMathFlagsAttr (FastMathFlagsAttr .parse_parameter (parser ))
3079
+ if flags != FastMathFlagsAttr ("none" ):
3080
+ attributes ["fastmath" ] = flags
3081
+ cls .fastmath = flags
3082
+ return attributes
3083
+
3084
+ def custom_print_attributes (self , printer : Printer ) -> Set [str ]:
3085
+ if self .fastmath is not None and self .fastmath != FastMathFlagsAttr ("none" ):
3086
+ printer .print (" fastmath" )
3087
+ self .fastmath .print_parameter (printer )
3088
+ return {"fastmath" }
3089
+
3090
+
3019
3091
class RsRsImmFloatOperation (RISCVInstruction , ABC ):
3020
3092
"""
3021
3093
A base class for RV32F operations that have two source registers
@@ -3352,7 +3424,7 @@ class FMvXWOp(RdRsOperation[IntRegisterType, FloatRegisterType]):
3352
3424
3353
3425
3354
3426
@irdl_op_definition
3355
- class FeqSOP (RdRsRsFloatFloatIntegerOperation ):
3427
+ class FeqSOP (RdRsRsFloatFloatIntegerOperationWithFastMath ):
3356
3428
"""
3357
3429
Performs a quiet equal comparison between floating-point registers rs1 and rs2 and record the Boolean result in integer register rd.
3358
3430
Only signaling NaN inputs cause an Invalid Operation exception.
@@ -3367,7 +3439,7 @@ class FeqSOP(RdRsRsFloatFloatIntegerOperation):
3367
3439
3368
3440
3369
3441
@irdl_op_definition
3370
- class FltSOP (RdRsRsFloatFloatIntegerOperation ):
3442
+ class FltSOP (RdRsRsFloatFloatIntegerOperationWithFastMath ):
3371
3443
"""
3372
3444
Performs a quiet less comparison between floating-point registers rs1 and rs2 and record the Boolean result in integer register rd.
3373
3445
Only signaling NaN inputs cause an Invalid Operation exception.
@@ -3382,7 +3454,7 @@ class FltSOP(RdRsRsFloatFloatIntegerOperation):
3382
3454
3383
3455
3384
3456
@irdl_op_definition
3385
- class FleSOP (RdRsRsFloatFloatIntegerOperation ):
3457
+ class FleSOP (RdRsRsFloatFloatIntegerOperationWithFastMath ):
3386
3458
"""
3387
3459
Performs a quiet less or equal comparison between floating-point registers rs1 and rs2 and record the Boolean result in integer register rd.
3388
3460
Only signaling NaN inputs cause an Invalid Operation exception.
0 commit comments