43
43
irdl_op_definition ,
44
44
operand_def ,
45
45
opt_attr_def ,
46
+ opt_prop_def ,
46
47
region_def ,
47
48
result_def ,
48
49
var_operand_def ,
@@ -2532,7 +2533,7 @@ def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
2532
2533
def custom_print_attributes (self , printer : Printer ) -> Set [str ]:
2533
2534
printer .print (" " )
2534
2535
print_immediate_value (printer , self .immediate )
2535
- return {"immediate" }
2536
+ return {"immediate" , "fastmath" }
2536
2537
2537
2538
@classmethod
2538
2539
def parse_op_type (
@@ -3016,6 +3017,67 @@ def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
3016
3017
return self .rd , self .rs1 , self .rs2
3017
3018
3018
3019
3020
+ class RdRsRsFloatFloatIntegerOperationWithFastMath (RISCVInstruction , ABC ):
3021
+ """
3022
+ A base class for RISC-V operations that have two source floating-point
3023
+ registers with an integer destination register, and can be annotated with fastmath flags.
3024
+
3025
+ This is called R-Type in the RISC-V specification.
3026
+ """
3027
+
3028
+ rd = result_def (IntRegisterType )
3029
+ rs1 = operand_def (FloatRegisterType )
3030
+ rs2 = operand_def (FloatRegisterType )
3031
+ fastmath = opt_prop_def (FastMathFlagsAttr )
3032
+
3033
+ def __init__ (
3034
+ self ,
3035
+ rs1 : Operation | SSAValue ,
3036
+ rs2 : Operation | SSAValue ,
3037
+ * ,
3038
+ rd : IntRegisterType | str | None = None ,
3039
+ fastmath : FastMathFlagsAttr = FastMathFlagsAttr ("none" ),
3040
+ comment : str | StringAttr | None = None ,
3041
+ ):
3042
+ if rd is None :
3043
+ rd = IntRegisterType .unallocated ()
3044
+ elif isinstance (rd , str ):
3045
+ rd = IntRegisterType (rd )
3046
+ if isinstance (comment , str ):
3047
+ comment = StringAttr (comment )
3048
+
3049
+ super ().__init__ (
3050
+ operands = [rs1 , rs2 ],
3051
+ properties = {
3052
+ "fastmath" : fastmath ,
3053
+ },
3054
+ attributes = {
3055
+ "comment" : comment ,
3056
+ },
3057
+ result_types = [rd ],
3058
+ )
3059
+
3060
+ def assembly_line_args (self ) -> tuple [AssemblyInstructionArg , ...]:
3061
+ return self .rd , self .rs1 , self .rs2
3062
+
3063
+ @classmethod
3064
+ def custom_parse_attributes (cls , parser : Parser ) -> dict [str , Attribute ]:
3065
+ attributes = dict [str , Attribute ]()
3066
+ fast = FastMathFlagsAttr ("none" )
3067
+ if parser .parse_optional_keyword ("fastmath" ) is not None :
3068
+ fast = FastMathFlagsAttr (FastMathFlagsAttr .parse_parameter (parser ))
3069
+ if fast != FastMathFlagsAttr ("none" ):
3070
+ attributes ["fastmath" ] = fast
3071
+ cls .fastmath = fast
3072
+ return attributes
3073
+
3074
+ def custom_print_attributes (self , printer : Printer ) -> Set [str ]:
3075
+ if self .fastmath is not None and self .fastmath != FastMathFlagsAttr ("none" ):
3076
+ printer .print (" fastmath" )
3077
+ self .fastmath .print_parameter (printer )
3078
+ return {"fastmath" }
3079
+
3080
+
3019
3081
class RsRsImmFloatOperation (RISCVInstruction , ABC ):
3020
3082
"""
3021
3083
A base class for RV32F operations that have two source registers
@@ -3352,7 +3414,7 @@ class FMvXWOp(RdRsOperation[IntRegisterType, FloatRegisterType]):
3352
3414
3353
3415
3354
3416
@irdl_op_definition
3355
- class FeqSOP (RdRsRsFloatFloatIntegerOperation ):
3417
+ class FeqSOP (RdRsRsFloatFloatIntegerOperationWithFastMath ):
3356
3418
"""
3357
3419
Performs a quiet equal comparison between floating-point registers rs1 and rs2 and record the Boolean result in integer register rd.
3358
3420
Only signaling NaN inputs cause an Invalid Operation exception.
@@ -3367,7 +3429,7 @@ class FeqSOP(RdRsRsFloatFloatIntegerOperation):
3367
3429
3368
3430
3369
3431
@irdl_op_definition
3370
- class FltSOP (RdRsRsFloatFloatIntegerOperation ):
3432
+ class FltSOP (RdRsRsFloatFloatIntegerOperationWithFastMath ):
3371
3433
"""
3372
3434
Performs a quiet less comparison between floating-point registers rs1 and rs2 and record the Boolean result in integer register rd.
3373
3435
Only signaling NaN inputs cause an Invalid Operation exception.
@@ -3382,7 +3444,7 @@ class FltSOP(RdRsRsFloatFloatIntegerOperation):
3382
3444
3383
3445
3384
3446
@irdl_op_definition
3385
- class FleSOP (RdRsRsFloatFloatIntegerOperation ):
3447
+ class FleSOP (RdRsRsFloatFloatIntegerOperationWithFastMath ):
3386
3448
"""
3387
3449
Performs a quiet less or equal comparison between floating-point registers rs1 and rs2 and record the Boolean result in integer register rd.
3388
3450
Only signaling NaN inputs cause an Invalid Operation exception.
0 commit comments