Skip to content

Riscv

riscv

RV32I_INDEX_BY_NAME = _RV32I_X_INDEX_BY_NAME | _RV32I_ABI_INDEX_BY_NAME module-attribute

RV32F_INDEX_BY_NAME = _RV32F_F_INDEX_BY_NAME | _RV32F_ABI_INDEX_BY_NAME module-attribute

RDInvT = TypeVar('RDInvT', bound=RISCVRegisterType) module-attribute

RSInvT = TypeVar('RSInvT', bound=RISCVRegisterType) module-attribute

RS1InvT = TypeVar('RS1InvT', bound=RISCVRegisterType) module-attribute

RS2InvT = TypeVar('RS2InvT', bound=RISCVRegisterType) module-attribute

ui5 = IntegerType(5, Signedness.UNSIGNED) module-attribute

si20 = IntegerType(20, Signedness.SIGNED) module-attribute

si12 = IntegerType(12, Signedness.SIGNED) module-attribute

i12 = IntegerType(12, Signedness.SIGNLESS) module-attribute

i20 = IntegerType(20, Signedness.SIGNLESS) module-attribute

UImm5Attr = IntegerAttr[Annotated[IntegerType, ui5]] module-attribute

SImm12Attr = IntegerAttr[Annotated[IntegerType, si12]] module-attribute

SImm20Attr = IntegerAttr[Annotated[IntegerType, si20]] module-attribute

Imm12Attr = IntegerAttr[Annotated[IntegerType, i12]] module-attribute

Imm20Attr = IntegerAttr[Annotated[IntegerType, i20]] module-attribute

Imm32Attr = IntegerAttr[Annotated[IntegerType, i32]] module-attribute

AssemblyInstructionArg: TypeAlias = IntegerAttr | LabelAttr | SSAValue | RegisterType | str module-attribute

RISCV = Dialect('riscv', [AddiOp, SltiOp, SltiuOp, AndiOp, OriOp, XoriOp, SlliOp, SrliOp, SraiOp, LuiOp, AuipcOp, MVOp, SeqzOp, SnezOp, ZextBOp, ZextWOp, SextWOp, AddOp, SltOp, SltuOp, AndOp, OrOp, XorOp, SllOp, SrlOp, SubOp, SraOp, NopOp, JalOp, JOp, JalrOp, ReturnOp, BeqOp, BneOp, BltOp, BgeOp, BltuOp, BgeuOp, LbOp, LbuOp, LhOp, LhuOp, LwOp, SbOp, ShOp, SwOp, CsrrwOp, CsrrsOp, CsrrcOp, CsrrwiOp, CsrrsiOp, CsrrciOp, MulOp, MulhOp, MulhsuOp, MulhuOp, DivOp, DivuOp, RemOp, RemuOp, LiOp, RolOp, RorOp, RemuwOp, SrliwOp, SraiwOp, AddwOp, SubwOp, SllwOp, SrlwOp, SrawOp, RemwOp, MulwOp, DivwOp, DivuwOp, CZeroEqzOp, CZeroNezOp, BclrOp, BextOp, BinvOp, BsetOp, RolwOp, RorwOp, AddUwOp, Sh1addOp, Sh2addOp, Sh3addOp, Sh1addUwOp, Sh2addUwOp, Sh3addUwOp, SextBOp, SextHOp, ZextHOp, AndnOp, OrnOp, XnorOp, MaxOp, MaxUOp, MinOp, MinUOp, BclrIOp, BextIOp, BsetIOp, BinvIOp, RoriOp, RoriwOp, SlliUwOp, EcallOp, LabelOp, DirectiveOp, AssemblySectionOp, EbreakOp, WfiOp, CustomAssemblyInstructionOp, CommentOp, GetRegisterOp, GetFloatRegisterOp, FMVOp, FMAddSOp, FMSubSOp, FNMSubSOp, FNMAddSOp, FAddSOp, FSubSOp, FMulSOp, FDivSOp, FSqrtSOp, FSgnJSOp, FSgnJNSOp, FSgnJXSOp, FMinSOp, FMaxSOp, FCvtWSOp, FCvtWuSOp, FMvXWOp, FeqSOp, FltSOp, FleSOp, FClassSOp, FCvtSWOp, FCvtSWuOp, FMvWXOp, FLwOp, FSwOp, FMAddDOp, FMSubDOp, FAddDOp, FSubDOp, FMulDOp, FDivDOp, FMinDOp, FMaxDOp, FCvtDWOp, FCvtDWuOp, FLdOp, FSdOp, FMvDOp, VFAddSOp, VFMulSOp, ParallelMovOp], [IntRegisterType, FloatRegisterType, LabelAttr, FastMathFlagsAttr]) module-attribute

FastMathFlagsAttr

Bases: FastMathAttrBase

riscv.fastmath is a mirror of LLVMs fastmath flags.

Source code in xdsl/dialects/riscv.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
@irdl_attr_definition
class FastMathFlagsAttr(FastMathAttrBase):
    """
    riscv.fastmath is a mirror of LLVMs fastmath flags.
    """

    name = "riscv.fastmath"

    def __init__(self, flags: None | Sequence[FastMathFlag] | Literal["none", "fast"]):
        # irdl_attr_definition defines an __init__ if none is defined, so we need to
        # explicitely define one here.
        super().__init__(flags)

name = 'riscv.fastmath' class-attribute instance-attribute

__init__(flags: None | Sequence[FastMathFlag] | Literal['none', 'fast'])

Source code in xdsl/dialects/riscv.py
 98
 99
100
101
def __init__(self, flags: None | Sequence[FastMathFlag] | Literal["none", "fast"]):
    # irdl_attr_definition defines an __init__ if none is defined, so we need to
    # explicitely define one here.
    super().__init__(flags)

RISCVRegisterType dataclass

Bases: RegisterType

A RISC-V register type.

Source code in xdsl/dialects/riscv.py
104
105
106
107
108
109
110
111
112
class RISCVRegisterType(RegisterType):
    """
    A RISC-V register type.
    """

    @classmethod
    @abstractmethod
    def a_register(cls, index: int) -> Self:
        raise NotImplementedError()

a_register(index: int) -> Self abstractmethod classmethod

Source code in xdsl/dialects/riscv.py
109
110
111
112
@classmethod
@abstractmethod
def a_register(cls, index: int) -> Self:
    raise NotImplementedError()

IntRegisterType dataclass

Bases: RISCVRegisterType

A RISC-V register type.

Source code in xdsl/dialects/riscv.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
@irdl_attr_definition
class IntRegisterType(RISCVRegisterType):
    """
    A RISC-V register type.
    """

    name = "riscv.reg"

    @classmethod
    def index_by_name(cls) -> dict[str, int]:
        return RV32I_INDEX_BY_NAME

    @classmethod
    def a_register(cls, index: int) -> IntRegisterType:
        return Registers.A[index]

    @classmethod
    def infinite_register_prefix(cls):
        return "j_"

    # This class variable is created and exclusively accessed in `abi_name_by_index`.
    # _ALLOCATABLE_REGISTERS: ClassVar[tuple[IntRegisterType, ...]]

    @classmethod
    def allocatable_registers(cls):
        if not hasattr(cls, "_ALLOCATABLE_REGISTERS"):
            cls._ALLOCATABLE_REGISTERS = (*Registers.T, *Registers.A)
        return cls._ALLOCATABLE_REGISTERS

name = 'riscv.reg' class-attribute instance-attribute

index_by_name() -> dict[str, int] classmethod

Source code in xdsl/dialects/riscv.py
162
163
164
@classmethod
def index_by_name(cls) -> dict[str, int]:
    return RV32I_INDEX_BY_NAME

a_register(index: int) -> IntRegisterType classmethod

Source code in xdsl/dialects/riscv.py
166
167
168
@classmethod
def a_register(cls, index: int) -> IntRegisterType:
    return Registers.A[index]

infinite_register_prefix() classmethod

Source code in xdsl/dialects/riscv.py
170
171
172
@classmethod
def infinite_register_prefix(cls):
    return "j_"

allocatable_registers() classmethod

Source code in xdsl/dialects/riscv.py
177
178
179
180
181
@classmethod
def allocatable_registers(cls):
    if not hasattr(cls, "_ALLOCATABLE_REGISTERS"):
        cls._ALLOCATABLE_REGISTERS = (*Registers.T, *Registers.A)
    return cls._ALLOCATABLE_REGISTERS

FloatRegisterType dataclass

Bases: RISCVRegisterType

A RISC-V register type.

Source code in xdsl/dialects/riscv.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
@irdl_attr_definition
class FloatRegisterType(RISCVRegisterType):
    """
    A RISC-V register type.
    """

    name = "riscv.freg"

    @classmethod
    def index_by_name(cls) -> dict[str, int]:
        return RV32F_INDEX_BY_NAME

    @classmethod
    def a_register(cls, index: int) -> FloatRegisterType:
        return Registers.FA[index]

    @classmethod
    def infinite_register_prefix(cls):
        return "fj_"

    # This class variable is created and exclusively accessed in `abi_name_by_index`.
    # _ALLOCATABLE_REGISTERS: ClassVar[tuple[FloatRegisterType, ...]]

    @classmethod
    def allocatable_registers(cls):
        if not hasattr(cls, "_ALLOCATABLE_REGISTERS"):
            cls._ALLOCATABLE_REGISTERS = (*Registers.FT, *Registers.FA)
        return cls._ALLOCATABLE_REGISTERS

name = 'riscv.freg' class-attribute instance-attribute

index_by_name() -> dict[str, int] classmethod

Source code in xdsl/dialects/riscv.py
230
231
232
@classmethod
def index_by_name(cls) -> dict[str, int]:
    return RV32F_INDEX_BY_NAME

a_register(index: int) -> FloatRegisterType classmethod

Source code in xdsl/dialects/riscv.py
234
235
236
@classmethod
def a_register(cls, index: int) -> FloatRegisterType:
    return Registers.FA[index]

infinite_register_prefix() classmethod

Source code in xdsl/dialects/riscv.py
238
239
240
@classmethod
def infinite_register_prefix(cls):
    return "fj_"

allocatable_registers() classmethod

Source code in xdsl/dialects/riscv.py
245
246
247
248
249
@classmethod
def allocatable_registers(cls):
    if not hasattr(cls, "_ALLOCATABLE_REGISTERS"):
        cls._ALLOCATABLE_REGISTERS = (*Registers.FT, *Registers.FA)
    return cls._ALLOCATABLE_REGISTERS

Registers

Bases: ABC

Namespace for named register constants.

Source code in xdsl/dialects/riscv.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
class Registers(ABC):
    """Namespace for named register constants."""

    UNALLOCATED_INT = IntRegisterType.unallocated()
    ZERO = IntRegisterType.from_name("zero")
    RA = IntRegisterType.from_name("ra")
    SP = IntRegisterType.from_name("sp")
    GP = IntRegisterType.from_name("gp")
    TP = IntRegisterType.from_name("tp")
    T0 = IntRegisterType.from_name("t0")
    T1 = IntRegisterType.from_name("t1")
    T2 = IntRegisterType.from_name("t2")
    FP = IntRegisterType.from_name("fp")
    S0 = IntRegisterType.from_name("s0")
    S1 = IntRegisterType.from_name("s1")
    A0 = IntRegisterType.from_name("a0")
    A1 = IntRegisterType.from_name("a1")
    A2 = IntRegisterType.from_name("a2")
    A3 = IntRegisterType.from_name("a3")
    A4 = IntRegisterType.from_name("a4")
    A5 = IntRegisterType.from_name("a5")
    A6 = IntRegisterType.from_name("a6")
    A7 = IntRegisterType.from_name("a7")
    S2 = IntRegisterType.from_name("s2")
    S3 = IntRegisterType.from_name("s3")
    S4 = IntRegisterType.from_name("s4")
    S5 = IntRegisterType.from_name("s5")
    S6 = IntRegisterType.from_name("s6")
    S7 = IntRegisterType.from_name("s7")
    S8 = IntRegisterType.from_name("s8")
    S9 = IntRegisterType.from_name("s9")
    S10 = IntRegisterType.from_name("s10")
    S11 = IntRegisterType.from_name("s11")
    T3 = IntRegisterType.from_name("t3")
    T4 = IntRegisterType.from_name("t4")
    T5 = IntRegisterType.from_name("t5")
    T6 = IntRegisterType.from_name("t6")

    UNALLOCATED_FLOAT = FloatRegisterType.unallocated()
    FT0 = FloatRegisterType.from_name("ft0")
    FT1 = FloatRegisterType.from_name("ft1")
    FT2 = FloatRegisterType.from_name("ft2")
    FT3 = FloatRegisterType.from_name("ft3")
    FT4 = FloatRegisterType.from_name("ft4")
    FT5 = FloatRegisterType.from_name("ft5")
    FT6 = FloatRegisterType.from_name("ft6")
    FT7 = FloatRegisterType.from_name("ft7")
    FS0 = FloatRegisterType.from_name("fs0")
    FS1 = FloatRegisterType.from_name("fs1")
    FA0 = FloatRegisterType.from_name("fa0")
    FA1 = FloatRegisterType.from_name("fa1")
    FA2 = FloatRegisterType.from_name("fa2")
    FA3 = FloatRegisterType.from_name("fa3")
    FA4 = FloatRegisterType.from_name("fa4")
    FA5 = FloatRegisterType.from_name("fa5")
    FA6 = FloatRegisterType.from_name("fa6")
    FA7 = FloatRegisterType.from_name("fa7")
    FS2 = FloatRegisterType.from_name("fs2")
    FS3 = FloatRegisterType.from_name("fs3")
    FS4 = FloatRegisterType.from_name("fs4")
    FS5 = FloatRegisterType.from_name("fs5")
    FS6 = FloatRegisterType.from_name("fs6")
    FS7 = FloatRegisterType.from_name("fs7")
    FS8 = FloatRegisterType.from_name("fs8")
    FS9 = FloatRegisterType.from_name("fs9")
    FS10 = FloatRegisterType.from_name("fs10")
    FS11 = FloatRegisterType.from_name("fs11")
    FT8 = FloatRegisterType.from_name("ft8")
    FT9 = FloatRegisterType.from_name("ft9")
    FT10 = FloatRegisterType.from_name("ft10")
    FT11 = FloatRegisterType.from_name("ft11")

    # register classes:

    A = (A0, A1, A2, A3, A4, A5, A6, A7)
    T = (T0, T1, T2, T3, T4, T5, T6)
    S = (S0, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11)

    FA = (FA0, FA1, FA2, FA3, FA4, FA5, FA6, FA7)
    FT = (FT0, FT1, FT2, FT3, FT4, FT5, FT6, FT7, FT8, FT9, FT10, FT11)
    FS = (FS0, FS1, FS2, FS3, FS4, FS5, FS6, FS7, FS8, FS9, FS10, FS11)

UNALLOCATED_INT = IntRegisterType.unallocated() class-attribute instance-attribute

ZERO = IntRegisterType.from_name('zero') class-attribute instance-attribute

RA = IntRegisterType.from_name('ra') class-attribute instance-attribute

SP = IntRegisterType.from_name('sp') class-attribute instance-attribute

GP = IntRegisterType.from_name('gp') class-attribute instance-attribute

TP = IntRegisterType.from_name('tp') class-attribute instance-attribute

T0 = IntRegisterType.from_name('t0') class-attribute instance-attribute

T1 = IntRegisterType.from_name('t1') class-attribute instance-attribute

T2 = IntRegisterType.from_name('t2') class-attribute instance-attribute

FP = IntRegisterType.from_name('fp') class-attribute instance-attribute

S0 = IntRegisterType.from_name('s0') class-attribute instance-attribute

S1 = IntRegisterType.from_name('s1') class-attribute instance-attribute

A0 = IntRegisterType.from_name('a0') class-attribute instance-attribute

A1 = IntRegisterType.from_name('a1') class-attribute instance-attribute

A2 = IntRegisterType.from_name('a2') class-attribute instance-attribute

A3 = IntRegisterType.from_name('a3') class-attribute instance-attribute

A4 = IntRegisterType.from_name('a4') class-attribute instance-attribute

A5 = IntRegisterType.from_name('a5') class-attribute instance-attribute

A6 = IntRegisterType.from_name('a6') class-attribute instance-attribute

A7 = IntRegisterType.from_name('a7') class-attribute instance-attribute

S2 = IntRegisterType.from_name('s2') class-attribute instance-attribute

S3 = IntRegisterType.from_name('s3') class-attribute instance-attribute

S4 = IntRegisterType.from_name('s4') class-attribute instance-attribute

S5 = IntRegisterType.from_name('s5') class-attribute instance-attribute

S6 = IntRegisterType.from_name('s6') class-attribute instance-attribute

S7 = IntRegisterType.from_name('s7') class-attribute instance-attribute

S8 = IntRegisterType.from_name('s8') class-attribute instance-attribute

S9 = IntRegisterType.from_name('s9') class-attribute instance-attribute

S10 = IntRegisterType.from_name('s10') class-attribute instance-attribute

S11 = IntRegisterType.from_name('s11') class-attribute instance-attribute

T3 = IntRegisterType.from_name('t3') class-attribute instance-attribute

T4 = IntRegisterType.from_name('t4') class-attribute instance-attribute

T5 = IntRegisterType.from_name('t5') class-attribute instance-attribute

T6 = IntRegisterType.from_name('t6') class-attribute instance-attribute

UNALLOCATED_FLOAT = FloatRegisterType.unallocated() class-attribute instance-attribute

FT0 = FloatRegisterType.from_name('ft0') class-attribute instance-attribute

FT1 = FloatRegisterType.from_name('ft1') class-attribute instance-attribute

FT2 = FloatRegisterType.from_name('ft2') class-attribute instance-attribute

FT3 = FloatRegisterType.from_name('ft3') class-attribute instance-attribute

FT4 = FloatRegisterType.from_name('ft4') class-attribute instance-attribute

FT5 = FloatRegisterType.from_name('ft5') class-attribute instance-attribute

FT6 = FloatRegisterType.from_name('ft6') class-attribute instance-attribute

FT7 = FloatRegisterType.from_name('ft7') class-attribute instance-attribute

FS0 = FloatRegisterType.from_name('fs0') class-attribute instance-attribute

FS1 = FloatRegisterType.from_name('fs1') class-attribute instance-attribute

FA0 = FloatRegisterType.from_name('fa0') class-attribute instance-attribute

FA1 = FloatRegisterType.from_name('fa1') class-attribute instance-attribute

FA2 = FloatRegisterType.from_name('fa2') class-attribute instance-attribute

FA3 = FloatRegisterType.from_name('fa3') class-attribute instance-attribute

FA4 = FloatRegisterType.from_name('fa4') class-attribute instance-attribute

FA5 = FloatRegisterType.from_name('fa5') class-attribute instance-attribute

FA6 = FloatRegisterType.from_name('fa6') class-attribute instance-attribute

FA7 = FloatRegisterType.from_name('fa7') class-attribute instance-attribute

FS2 = FloatRegisterType.from_name('fs2') class-attribute instance-attribute

FS3 = FloatRegisterType.from_name('fs3') class-attribute instance-attribute

FS4 = FloatRegisterType.from_name('fs4') class-attribute instance-attribute

FS5 = FloatRegisterType.from_name('fs5') class-attribute instance-attribute

FS6 = FloatRegisterType.from_name('fs6') class-attribute instance-attribute

FS7 = FloatRegisterType.from_name('fs7') class-attribute instance-attribute

FS8 = FloatRegisterType.from_name('fs8') class-attribute instance-attribute

FS9 = FloatRegisterType.from_name('fs9') class-attribute instance-attribute

FS10 = FloatRegisterType.from_name('fs10') class-attribute instance-attribute

FS11 = FloatRegisterType.from_name('fs11') class-attribute instance-attribute

FT8 = FloatRegisterType.from_name('ft8') class-attribute instance-attribute

FT9 = FloatRegisterType.from_name('ft9') class-attribute instance-attribute

FT10 = FloatRegisterType.from_name('ft10') class-attribute instance-attribute

FT11 = FloatRegisterType.from_name('ft11') class-attribute instance-attribute

A = (A0, A1, A2, A3, A4, A5, A6, A7) class-attribute instance-attribute

T = (T0, T1, T2, T3, T4, T5, T6) class-attribute instance-attribute

S = (S0, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11) class-attribute instance-attribute

FA = (FA0, FA1, FA2, FA3, FA4, FA5, FA6, FA7) class-attribute instance-attribute

FT = (FT0, FT1, FT2, FT3, FT4, FT5, FT6, FT7, FT8, FT9, FT10, FT11) class-attribute instance-attribute

FS = (FS0, FS1, FS2, FS3, FS4, FS5, FS6, FS7, FS8, FS9, FS10, FS11) class-attribute instance-attribute

LabelAttr dataclass

Bases: Data[str]

Source code in xdsl/dialects/riscv.py
354
355
356
357
358
359
360
361
362
363
364
365
@irdl_attr_definition
class LabelAttr(Data[str]):
    name = "riscv.label"

    @classmethod
    def parse_parameter(cls, parser: AttrParser) -> str:
        with parser.in_angle_brackets():
            return parser.parse_str_literal()

    def print_parameter(self, printer: Printer) -> None:
        with printer.in_angle_brackets():
            printer.print_string_literal(self.data)

name = 'riscv.label' class-attribute instance-attribute

parse_parameter(parser: AttrParser) -> str classmethod

Source code in xdsl/dialects/riscv.py
358
359
360
361
@classmethod
def parse_parameter(cls, parser: AttrParser) -> str:
    with parser.in_angle_brackets():
        return parser.parse_str_literal()

print_parameter(printer: Printer) -> None

Source code in xdsl/dialects/riscv.py
363
364
365
def print_parameter(self, printer: Printer) -> None:
    with printer.in_angle_brackets():
        printer.print_string_literal(self.data)

RISCVAsmOperation dataclass

Bases: IRDLOperation, OneLineAssemblyPrintable, ABC

Base class for operations that can be a part of RISC-V assembly printing.

Source code in xdsl/dialects/riscv.py
368
369
370
371
class RISCVAsmOperation(IRDLOperation, OneLineAssemblyPrintable, ABC):
    """
    Base class for operations that can be a part of RISC-V assembly printing.
    """

RISCVRegallocOperation dataclass

Bases: HasRegisterConstraints, IRDLOperation, ABC

Base class for operations that can take part in register allocation.

Source code in xdsl/dialects/riscv.py
374
375
376
377
378
379
380
381
382
383
class RISCVRegallocOperation(HasRegisterConstraints, IRDLOperation, ABC):
    """
    Base class for operations that can take part in register allocation.
    """

    def get_register_constraints(self) -> RegisterConstraints:
        # The default register constraints are that all operands are "in", and all
        # results are "out" registers.
        # If some registers are "inout" then this function must be overridden.
        return RegisterConstraints(self.operands, self.results, ())

get_register_constraints() -> RegisterConstraints

Source code in xdsl/dialects/riscv.py
379
380
381
382
383
def get_register_constraints(self) -> RegisterConstraints:
    # The default register constraints are that all operands are "in", and all
    # results are "out" registers.
    # If some registers are "inout" then this function must be overridden.
    return RegisterConstraints(self.operands, self.results, ())

RISCVCustomFormatOperation dataclass

Bases: IRDLOperation, ABC

Base class for RISC-V operations that specialize their custom format.

Source code in xdsl/dialects/riscv.py
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
class RISCVCustomFormatOperation(IRDLOperation, ABC):
    """
    Base class for RISC-V operations that specialize their custom format.
    """

    @classmethod
    def parse(cls, parser: Parser) -> Self:
        args = cls.parse_unresolved_operands(parser)
        custom_attributes = cls.custom_parse_attributes(parser)
        remaining_attributes = parser.parse_optional_attr_dict()
        # TODO ensure distinct keys for attributes
        attributes = custom_attributes | remaining_attributes
        regions = parser.parse_region_list()
        pos = parser.pos
        operand_types, result_types = cls.parse_op_type(parser)
        operands = parser.resolve_operands(args, operand_types, pos)
        return cls.create(
            operands=operands,
            result_types=result_types,
            attributes=attributes,
            regions=regions,
        )

    @classmethod
    def parse_unresolved_operands(cls, parser: Parser) -> list[UnresolvedOperand]:
        """
        Parse a list of comma separated unresolved operands.

        Notice that this method will consume trailing comma.
        """
        if operand := parser.parse_optional_unresolved_operand():
            operands = [operand]
            while parser.parse_optional_punctuation(",") and (
                operand := parser.parse_optional_unresolved_operand()
            ):
                operands.append(operand)
            return operands
        return []

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        """
        Parse attributes with custom syntax. Subclasses may override this method.
        """
        return parser.parse_optional_attr_dict()

    @classmethod
    def parse_op_type(
        cls, parser: Parser
    ) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
        parser.parse_punctuation(":")
        func_type = parser.parse_function_type()
        return func_type.inputs.data, func_type.outputs.data

    def print(self, printer: Printer) -> None:
        if self.operands:
            printer.print_string(" ")
            printer.print_list(self.operands, printer.print_operand)
        printed_attributes = self.custom_print_attributes(printer)
        unprinted_attributes = {
            name: attr
            for name, attr in self.attributes.items()
            if name not in printed_attributes
        }
        printer.print_op_attributes(unprinted_attributes)
        printer.print_regions(self.regions)
        self.print_op_type(printer)

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        """
        Print attributes with custom syntax. Return the names of the attributes printed. Subclasses may override this method.
        """
        printer.print_op_attributes(self.attributes)
        return self.attributes.keys()

    def print_op_type(self, printer: Printer) -> None:
        printer.print_string(" : ")
        printer.print_operation_type(self)

parse(parser: Parser) -> Self classmethod

Source code in xdsl/dialects/riscv.py
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
@classmethod
def parse(cls, parser: Parser) -> Self:
    args = cls.parse_unresolved_operands(parser)
    custom_attributes = cls.custom_parse_attributes(parser)
    remaining_attributes = parser.parse_optional_attr_dict()
    # TODO ensure distinct keys for attributes
    attributes = custom_attributes | remaining_attributes
    regions = parser.parse_region_list()
    pos = parser.pos
    operand_types, result_types = cls.parse_op_type(parser)
    operands = parser.resolve_operands(args, operand_types, pos)
    return cls.create(
        operands=operands,
        result_types=result_types,
        attributes=attributes,
        regions=regions,
    )

parse_unresolved_operands(parser: Parser) -> list[UnresolvedOperand] classmethod

Parse a list of comma separated unresolved operands.

Notice that this method will consume trailing comma.

Source code in xdsl/dialects/riscv.py
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
@classmethod
def parse_unresolved_operands(cls, parser: Parser) -> list[UnresolvedOperand]:
    """
    Parse a list of comma separated unresolved operands.

    Notice that this method will consume trailing comma.
    """
    if operand := parser.parse_optional_unresolved_operand():
        operands = [operand]
        while parser.parse_optional_punctuation(",") and (
            operand := parser.parse_optional_unresolved_operand()
        ):
            operands.append(operand)
        return operands
    return []

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Parse attributes with custom syntax. Subclasses may override this method.

Source code in xdsl/dialects/riscv.py
425
426
427
428
429
430
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    """
    Parse attributes with custom syntax. Subclasses may override this method.
    """
    return parser.parse_optional_attr_dict()

parse_op_type(parser: Parser) -> tuple[Sequence[Attribute], Sequence[Attribute]] classmethod

Source code in xdsl/dialects/riscv.py
432
433
434
435
436
437
438
@classmethod
def parse_op_type(
    cls, parser: Parser
) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
    parser.parse_punctuation(":")
    func_type = parser.parse_function_type()
    return func_type.inputs.data, func_type.outputs.data

print(printer: Printer) -> None

Source code in xdsl/dialects/riscv.py
440
441
442
443
444
445
446
447
448
449
450
451
452
def print(self, printer: Printer) -> None:
    if self.operands:
        printer.print_string(" ")
        printer.print_list(self.operands, printer.print_operand)
    printed_attributes = self.custom_print_attributes(printer)
    unprinted_attributes = {
        name: attr
        for name, attr in self.attributes.items()
        if name not in printed_attributes
    }
    printer.print_op_attributes(unprinted_attributes)
    printer.print_regions(self.regions)
    self.print_op_type(printer)

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Print attributes with custom syntax. Return the names of the attributes printed. Subclasses may override this method.

Source code in xdsl/dialects/riscv.py
454
455
456
457
458
459
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    """
    Print attributes with custom syntax. Return the names of the attributes printed. Subclasses may override this method.
    """
    printer.print_op_attributes(self.attributes)
    return self.attributes.keys()

print_op_type(printer: Printer) -> None

Source code in xdsl/dialects/riscv.py
461
462
463
def print_op_type(self, printer: Printer) -> None:
    printer.print_string(" : ")
    printer.print_operation_type(self)

RISCVInstruction dataclass

Bases: RISCVAsmOperation, RISCVRegallocOperation, ABC

Base class for operations that can be a part of RISC-V assembly printing. Must represent an instruction in the RISC-V instruction set, and have the following format:

name arg0, arg1, arg2 # comment

The name of the operation will be used as the RISC-V assembly instruction name.

Source code in xdsl/dialects/riscv.py
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
class RISCVInstruction(RISCVAsmOperation, RISCVRegallocOperation, ABC):
    """
    Base class for operations that can be a part of RISC-V assembly printing. Must
    represent an instruction in the RISC-V instruction set, and have the following format:

    name arg0, arg1, arg2           # comment

    The name of the operation will be used as the RISC-V assembly instruction name.
    """

    comment = opt_attr_def(StringAttr)
    """
    An optional comment that will be printed along with the instruction.
    """

    @abstractmethod
    def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
        """
        The arguments to the instruction, in the order they should be printed in the
        assembly.
        """
        raise NotImplementedError()

    def assembly_instruction_name(self) -> str:
        """
        By default, the name of the instruction is the same as the name of the operation.
        """

        return Dialect.split_name(self.name)[1]

    def assembly_line(self) -> str | None:
        # default assembly code generator
        instruction_name = self.assembly_instruction_name()
        arg_str = ", ".join(
            _assembly_arg_str(arg)
            for arg in self.assembly_line_args()
            if arg is not None
        )
        return AssemblyPrinter.assembly_line(instruction_name, arg_str, self.comment)

comment = opt_attr_def(StringAttr) class-attribute instance-attribute

An optional comment that will be printed along with the instruction.

assembly_line_args() -> tuple[AssemblyInstructionArg | None, ...] abstractmethod

The arguments to the instruction, in the order they should be printed in the assembly.

Source code in xdsl/dialects/riscv.py
486
487
488
489
490
491
492
@abstractmethod
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    """
    The arguments to the instruction, in the order they should be printed in the
    assembly.
    """
    raise NotImplementedError()

assembly_instruction_name() -> str

By default, the name of the instruction is the same as the name of the operation.

Source code in xdsl/dialects/riscv.py
494
495
496
497
498
499
def assembly_instruction_name(self) -> str:
    """
    By default, the name of the instruction is the same as the name of the operation.
    """

    return Dialect.split_name(self.name)[1]

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
501
502
503
504
505
506
507
508
509
def assembly_line(self) -> str | None:
    # default assembly code generator
    instruction_name = self.assembly_instruction_name()
    arg_str = ", ".join(
        _assembly_arg_str(arg)
        for arg in self.assembly_line_args()
        if arg is not None
    )
    return AssemblyPrinter.assembly_line(instruction_name, arg_str, self.comment)

RdRsRsOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC, Generic[RDInvT, RS1InvT, RS2InvT]

A base class for RISC-V operations that have one destination register, and two source registers.

This is called R-Type in the RISC-V specification.

Source code in xdsl/dialects/riscv.py
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
class RdRsRsOperation(
    RISCVCustomFormatOperation, RISCVInstruction, ABC, Generic[RDInvT, RS1InvT, RS2InvT]
):
    """
    A base class for RISC-V operations that have one destination register, and two source
    registers.

    This is called R-Type in the RISC-V specification.
    """

    rd: OpResult[RDInvT] = result_def(RDInvT)
    rs1 = operand_def(RS1InvT)
    rs2 = operand_def(RS2InvT)

    def __init__(
        self,
        rs1: Operation | SSAValue,
        rs2: Operation | SSAValue,
        *,
        rd: RDInvT = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=[rs1, rs2],
            attributes={
                "comment": comment,
            },
            result_types=[rd],
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.rs1, self.rs2

rd: OpResult[RDInvT] = result_def(RDInvT) class-attribute instance-attribute

rs1 = operand_def(RS1InvT) class-attribute instance-attribute

rs2 = operand_def(RS2InvT) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, rs2: Operation | SSAValue, *, rd: RDInvT = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
def __init__(
    self,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    *,
    rd: RDInvT = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=[rs1, rs2],
        attributes={
            "comment": comment,
        },
        result_types=[rd],
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
579
580
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.rs1, self.rs2

RdRsRsIntegerOperation

Bases: RdRsRsOperation[IntRegisterType, RS1InvT, RS2InvT], ABC, Generic[RS1InvT, RS2InvT]

Source code in xdsl/dialects/riscv.py
583
584
585
586
587
588
589
590
591
592
593
594
class RdRsRsIntegerOperation(
    RdRsRsOperation[IntRegisterType, RS1InvT, RS2InvT], ABC, Generic[RS1InvT, RS2InvT]
):
    def __init__(
        self,
        rs1: Operation | SSAValue,
        rs2: Operation | SSAValue,
        *,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        super().__init__(rs1, rs2, rd=rd, comment=comment)

__init__(rs1: Operation | SSAValue, rs2: Operation | SSAValue, *, rd: IntRegisterType = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
586
587
588
589
590
591
592
593
594
def __init__(
    self,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    *,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    super().__init__(rs1, rs2, rd=rd, comment=comment)

RdRsRsFloatOperation

Bases: RdRsRsOperation[FloatRegisterType, RS1InvT, RS2InvT], ABC, Generic[RS1InvT, RS2InvT]

Source code in xdsl/dialects/riscv.py
597
598
599
600
601
602
603
604
605
606
607
608
class RdRsRsFloatOperation(
    RdRsRsOperation[FloatRegisterType, RS1InvT, RS2InvT], ABC, Generic[RS1InvT, RS2InvT]
):
    def __init__(
        self,
        rs1: Operation | SSAValue,
        rs2: Operation | SSAValue,
        *,
        rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT,
        comment: str | StringAttr | None = None,
    ):
        super().__init__(rs1, rs2, rd=rd, comment=comment)

__init__(rs1: Operation | SSAValue, rs2: Operation | SSAValue, *, rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
600
601
602
603
604
605
606
607
608
def __init__(
    self,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    *,
    rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT,
    comment: str | StringAttr | None = None,
):
    super().__init__(rs1, rs2, rd=rd, comment=comment)

RdRsRsFloatOperationWithFastMath

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have one destination floating-point register, and two source floating-point registers and can be annotated with fastmath flags.

This is called R-Type in the RISC-V specification.

Source code in xdsl/dialects/riscv.py
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
class RdRsRsFloatOperationWithFastMath(
    RISCVCustomFormatOperation, RISCVInstruction, ABC
):
    """
    A base class for RISC-V operations that have one destination floating-point register,
    and two source floating-point registers and can be annotated with fastmath flags.

    This is called R-Type in the RISC-V specification.
    """

    rd = result_def(FloatRegisterType)
    rs1 = operand_def(FloatRegisterType)
    rs2 = operand_def(FloatRegisterType)
    fastmath = opt_attr_def(FastMathFlagsAttr)

    def __init__(
        self,
        rs1: Operation | SSAValue,
        rs2: Operation | SSAValue,
        *,
        rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT,
        fastmath: FastMathFlagsAttr | None = None,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=[rs1, rs2],
            attributes={
                "fastmath": fastmath,
                "comment": comment,
            },
            result_types=[rd],
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.rs1, self.rs2

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        flags = FastMathFlagsAttr("none")
        if parser.parse_optional_keyword("fastmath") is not None:
            flags = FastMathFlagsAttr(FastMathFlagsAttr.parse_parameter(parser))
        attributes["fastmath"] = flags
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        if self.fastmath is not None and self.fastmath != FastMathFlagsAttr("none"):
            printer.print_string(" fastmath")
            self.fastmath.print_parameter(printer)
        return {"fastmath"}

rd = result_def(FloatRegisterType) class-attribute instance-attribute

rs1 = operand_def(FloatRegisterType) class-attribute instance-attribute

rs2 = operand_def(FloatRegisterType) class-attribute instance-attribute

fastmath = opt_attr_def(FastMathFlagsAttr) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, rs2: Operation | SSAValue, *, rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT, fastmath: FastMathFlagsAttr | None = None, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
def __init__(
    self,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    *,
    rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT,
    fastmath: FastMathFlagsAttr | None = None,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=[rs1, rs2],
        attributes={
            "fastmath": fastmath,
            "comment": comment,
        },
        result_types=[rd],
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
647
648
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.rs1, self.rs2

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
650
651
652
653
654
655
656
657
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    flags = FastMathFlagsAttr("none")
    if parser.parse_optional_keyword("fastmath") is not None:
        flags = FastMathFlagsAttr(FastMathFlagsAttr.parse_parameter(parser))
    attributes["fastmath"] = flags
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
659
660
661
662
663
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    if self.fastmath is not None and self.fastmath != FastMathFlagsAttr("none"):
        printer.print_string(" fastmath")
        self.fastmath.print_parameter(printer)
    return {"fastmath"}

RdImmIntegerOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have one destination register, and one immediate operand (e.g. U-Type and J-Type instructions in the RISC-V spec).

Source code in xdsl/dialects/riscv.py
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
class RdImmIntegerOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations that have one destination register, and one
    immediate operand (e.g. U-Type and J-Type instructions in the RISC-V spec).
    """

    rd = result_def(IntRegisterType)
    immediate = attr_def(base(Imm20Attr) | base(LabelAttr))

    def __init__(
        self,
        immediate: int | IntegerAttr | str | LabelAttr,
        *,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(immediate, int):
            immediate = IntegerAttr(immediate, i20)
        elif isinstance(immediate, str):
            immediate = LabelAttr(immediate)
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            result_types=[rd],
            attributes={
                "immediate": immediate,
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["immediate"] = parse_immediate_value(parser, i20)
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(" ")
        print_immediate_value(printer, self.immediate)
        return {"immediate"}

rd = result_def(IntRegisterType) class-attribute instance-attribute

immediate = attr_def(base(Imm20Attr) | base(LabelAttr)) class-attribute instance-attribute

__init__(immediate: int | IntegerAttr | str | LabelAttr, *, rd: IntRegisterType = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
def __init__(
    self,
    immediate: int | IntegerAttr | str | LabelAttr,
    *,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    if isinstance(immediate, int):
        immediate = IntegerAttr(immediate, i20)
    elif isinstance(immediate, str):
        immediate = LabelAttr(immediate)
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        result_types=[rd],
        attributes={
            "immediate": immediate,
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
697
698
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
700
701
702
703
704
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["immediate"] = parse_immediate_value(parser, i20)
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
706
707
708
709
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(" ")
    print_immediate_value(printer, self.immediate)
    return {"immediate"}

RdImmJumpOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

In the RISC-V spec, this is the same as RdImmOperation. For jumps, the rd register is neither an operand, because the stored value is overwritten, nor a result value, because the value in rd is not defined after the jump back. So the rd makes the most sense as an attribute.

Source code in xdsl/dialects/riscv.py
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
class RdImmJumpOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    In the RISC-V spec, this is the same as `RdImmOperation`. For jumps, the `rd` register
    is neither an operand, because the stored value is overwritten, nor a result value,
    because the value in `rd` is not defined after the jump back. So the `rd` makes the
    most sense as an attribute.
    """

    rd = opt_attr_def(IntRegisterType)
    """
    The rd register here is not a register storing the result, rather the register where
    the program counter is stored before jumping.
    """
    immediate = attr_def(base(SImm20Attr) | base(LabelAttr))

    def __init__(
        self,
        immediate: int | SImm20Attr | str | LabelAttr,
        *,
        rd: IntRegisterType | None = None,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(immediate, int):
            immediate = IntegerAttr(immediate, si20)
        elif isinstance(immediate, str):
            immediate = LabelAttr(immediate)
        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            attributes={
                "immediate": immediate,
                "rd": rd,
                "comment": comment,
            }
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
        return self.rd, self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["immediate"] = parse_immediate_value(parser, si20)
        if parser.parse_optional_punctuation(","):
            attributes["rd"] = parser.parse_attribute()
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(" ")
        print_immediate_value(printer, self.immediate)
        if self.rd is not None:
            printer.print_string(", ")
            printer.print_attribute(self.rd)
        return {"immediate", "rd"}

    def print_op_type(self, printer: Printer) -> None:
        return

    @classmethod
    def parse_op_type(
        cls, parser: Parser
    ) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
        return (), ()

rd = opt_attr_def(IntRegisterType) class-attribute instance-attribute

The rd register here is not a register storing the result, rather the register where the program counter is stored before jumping.

immediate = attr_def(base(SImm20Attr) | base(LabelAttr)) class-attribute instance-attribute

__init__(immediate: int | SImm20Attr | str | LabelAttr, *, rd: IntRegisterType | None = None, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
def __init__(
    self,
    immediate: int | SImm20Attr | str | LabelAttr,
    *,
    rd: IntRegisterType | None = None,
    comment: str | StringAttr | None = None,
):
    if isinstance(immediate, int):
        immediate = IntegerAttr(immediate, si20)
    elif isinstance(immediate, str):
        immediate = LabelAttr(immediate)
    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        attributes={
            "immediate": immediate,
            "rd": rd,
            "comment": comment,
        }
    )

assembly_line_args() -> tuple[AssemblyInstructionArg | None, ...]

Source code in xdsl/dialects/riscv.py
748
749
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.rd, self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
751
752
753
754
755
756
757
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["immediate"] = parse_immediate_value(parser, si20)
    if parser.parse_optional_punctuation(","):
        attributes["rd"] = parser.parse_attribute()
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
759
760
761
762
763
764
765
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(" ")
    print_immediate_value(printer, self.immediate)
    if self.rd is not None:
        printer.print_string(", ")
        printer.print_attribute(self.rd)
    return {"immediate", "rd"}

print_op_type(printer: Printer) -> None

Source code in xdsl/dialects/riscv.py
767
768
def print_op_type(self, printer: Printer) -> None:
    return

parse_op_type(parser: Parser) -> tuple[Sequence[Attribute], Sequence[Attribute]] classmethod

Source code in xdsl/dialects/riscv.py
770
771
772
773
774
@classmethod
def parse_op_type(
    cls, parser: Parser
) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
    return (), ()

RdRsImmIntegerOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have one destination register, one source register and one immediate operand.

This is called I-Type in the RISC-V specification.

Source code in xdsl/dialects/riscv.py
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
class RdRsImmIntegerOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations that have one destination register, one source
    register and one immediate operand.

    This is called I-Type in the RISC-V specification.
    """

    rd = result_def(IntRegisterType)
    rs1 = operand_def(IntRegisterType)
    immediate = attr_def(base(SImm12Attr) | base(LabelAttr))

    def __init__(
        self,
        rs1: Operation | SSAValue,
        immediate: int | SImm12Attr | str | LabelAttr,
        *,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(immediate, int):
            immediate = IntegerAttr(immediate, si12)
        elif isinstance(immediate, str):
            immediate = LabelAttr(immediate)

        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            operands=[rs1],
            result_types=[rd],
            attributes={
                "immediate": immediate,
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.rs1, self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["immediate"] = parse_immediate_value(parser, si12)
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(", ")
        print_immediate_value(printer, self.immediate)
        return {"immediate"}

rd = result_def(IntRegisterType) class-attribute instance-attribute

rs1 = operand_def(IntRegisterType) class-attribute instance-attribute

immediate = attr_def(base(SImm12Attr) | base(LabelAttr)) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, immediate: int | SImm12Attr | str | LabelAttr, *, rd: IntRegisterType = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
def __init__(
    self,
    rs1: Operation | SSAValue,
    immediate: int | SImm12Attr | str | LabelAttr,
    *,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    if isinstance(immediate, int):
        immediate = IntegerAttr(immediate, si12)
    elif isinstance(immediate, str):
        immediate = LabelAttr(immediate)

    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        operands=[rs1],
        result_types=[rd],
        attributes={
            "immediate": immediate,
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
813
814
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.rs1, self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
816
817
818
819
820
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["immediate"] = parse_immediate_value(parser, si12)
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
822
823
824
825
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(", ")
    print_immediate_value(printer, self.immediate)
    return {"immediate"}

RdRsImmShiftOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have one destination register, one source register and one immediate operand.

This is called I-Type in the RISC-V specification.

Shifts by a constant are encoded as a specialization of the I-type format. The shift amount is encoded in the lower 5 bits of the I-immediate field for RV32

For RV32I, SLLI, SRLI, and SRAI generate an illegal instruction exception if imm[5] 6 != 0 but the shift amount is encoded in the lower 6 bits of the I-immediate field for RV64I.

Source code in xdsl/dialects/riscv.py
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
class RdRsImmShiftOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations that have one destination register, one source
    register and one immediate operand.

    This is called I-Type in the RISC-V specification.

    Shifts by a constant are encoded as a specialization of the I-type format.
    The shift amount is encoded in the lower 5 bits of the I-immediate field for RV32

    For RV32I, SLLI, SRLI, and SRAI generate an illegal instruction exception if
    imm[5] 6 != 0 but the shift amount is encoded in the lower 6 bits of the I-immediate field for RV64I.
    """

    rd = result_def(IntRegisterType)
    rs1 = operand_def(IntRegisterType)
    immediate = attr_def(base(UImm5Attr) | base(LabelAttr))

    def __init__(
        self,
        rs1: Operation | SSAValue,
        immediate: int | UImm5Attr | str | LabelAttr,
        *,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(immediate, int):
            immediate = IntegerAttr(immediate, ui5)
        elif isinstance(immediate, str):
            immediate = LabelAttr(immediate)

        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            operands=[rs1],
            result_types=[rd],
            attributes={
                "immediate": immediate,
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.rs1, self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["immediate"] = parse_immediate_value(parser, ui5)
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(", ")
        print_immediate_value(printer, self.immediate)
        return {"immediate"}

rd = result_def(IntRegisterType) class-attribute instance-attribute

rs1 = operand_def(IntRegisterType) class-attribute instance-attribute

immediate = attr_def(base(UImm5Attr) | base(LabelAttr)) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, immediate: int | UImm5Attr | str | LabelAttr, *, rd: IntRegisterType = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
def __init__(
    self,
    rs1: Operation | SSAValue,
    immediate: int | UImm5Attr | str | LabelAttr,
    *,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    if isinstance(immediate, int):
        immediate = IntegerAttr(immediate, ui5)
    elif isinstance(immediate, str):
        immediate = LabelAttr(immediate)

    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        operands=[rs1],
        result_types=[rd],
        attributes={
            "immediate": immediate,
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
870
871
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.rs1, self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
873
874
875
876
877
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["immediate"] = parse_immediate_value(parser, ui5)
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
879
880
881
882
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(", ")
    print_immediate_value(printer, self.immediate)
    return {"immediate"}

RdRsImmJumpOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have one destination register, one source register and one immediate operand.

This is called I-Type in the RISC-V specification.

In the RISC-V spec, this is the same as RdRsImmOperation. For jumps, the rd register is neither an operand, because the stored value is overwritten, nor a result value, because the value in rd is not defined after the jump back. So the rd makes the most sense as an attribute.

Source code in xdsl/dialects/riscv.py
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
class RdRsImmJumpOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations that have one destination register, one source
    register and one immediate operand.

    This is called I-Type in the RISC-V specification.

    In the RISC-V spec, this is the same as `RdRsImmOperation`. For jumps, the `rd` register
    is neither an operand, because the stored value is overwritten, nor a result value,
    because the value in `rd` is not defined after the jump back. So the `rd` makes the
    most sense as an attribute.
    """

    rs1 = operand_def(IntRegisterType)
    rd = opt_attr_def(IntRegisterType)
    """
    The rd register here is not a register storing the result, rather the register where
    the program counter is stored before jumping.
    """
    immediate = attr_def(base(SImm12Attr) | base(LabelAttr))

    def __init__(
        self,
        rs1: Operation | SSAValue,
        immediate: int | SImm12Attr | str | LabelAttr,
        *,
        rd: IntRegisterType | None = None,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(immediate, int):
            immediate = IntegerAttr(immediate, si12)
        elif isinstance(immediate, str):
            immediate = LabelAttr(immediate)

        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=[rs1],
            attributes={
                "immediate": immediate,
                "rd": rd,
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
        return self.rd, self.rs1, self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["immediate"] = parse_immediate_value(parser, si12)
        if parser.parse_optional_punctuation(","):
            attributes["rd"] = parser.parse_attribute()
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(", ")
        print_immediate_value(printer, self.immediate)
        if self.rd is not None:
            printer.print_string(", ")
            printer.print_attribute(self.rd)
        return {"immediate", "rd"}

rs1 = operand_def(IntRegisterType) class-attribute instance-attribute

rd = opt_attr_def(IntRegisterType) class-attribute instance-attribute

The rd register here is not a register storing the result, rather the register where the program counter is stored before jumping.

immediate = attr_def(base(SImm12Attr) | base(LabelAttr)) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, immediate: int | SImm12Attr | str | LabelAttr, *, rd: IntRegisterType | None = None, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
def __init__(
    self,
    rs1: Operation | SSAValue,
    immediate: int | SImm12Attr | str | LabelAttr,
    *,
    rd: IntRegisterType | None = None,
    comment: str | StringAttr | None = None,
):
    if isinstance(immediate, int):
        immediate = IntegerAttr(immediate, si12)
    elif isinstance(immediate, str):
        immediate = LabelAttr(immediate)

    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=[rs1],
        attributes={
            "immediate": immediate,
            "rd": rd,
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg | None, ...]

Source code in xdsl/dialects/riscv.py
931
932
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.rd, self.rs1, self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
934
935
936
937
938
939
940
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["immediate"] = parse_immediate_value(parser, si12)
    if parser.parse_optional_punctuation(","):
        attributes["rd"] = parser.parse_attribute()
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
942
943
944
945
946
947
948
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(", ")
    print_immediate_value(printer, self.immediate)
    if self.rd is not None:
        printer.print_string(", ")
        printer.print_attribute(self.rd)
    return {"immediate", "rd"}

RdRsOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC, Generic[RDInvT, RSInvT]

A base class for RISC-V pseudo-instructions that have one destination register and one source register.

Source code in xdsl/dialects/riscv.py
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
class RdRsOperation(
    RISCVCustomFormatOperation, RISCVInstruction, ABC, Generic[RDInvT, RSInvT]
):
    """
    A base class for RISC-V pseudo-instructions that have one destination register and one
    source register.
    """

    rd = result_def(RDInvT)
    rs = operand_def(RSInvT)

    def __init__(
        self,
        rs: Operation | SSAValue,
        *,
        rd: RDInvT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            operands=[rs],
            result_types=[rd],
            attributes={"comment": comment},
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.rs

rd = result_def(RDInvT) class-attribute instance-attribute

rs = operand_def(RSInvT) class-attribute instance-attribute

__init__(rs: Operation | SSAValue, *, rd: RDInvT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
962
963
964
965
966
967
968
969
970
971
972
973
974
975
def __init__(
    self,
    rs: Operation | SSAValue,
    *,
    rd: RDInvT,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        operands=[rs],
        result_types=[rd],
        attributes={"comment": comment},
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
977
978
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.rs

RdRsIntegerOperation

Bases: RdRsOperation[IntRegisterType, RSInvT], ABC, Generic[RSInvT]

Source code in xdsl/dialects/riscv.py
981
982
983
984
985
986
987
988
989
990
991
class RdRsIntegerOperation(
    RdRsOperation[IntRegisterType, RSInvT], ABC, Generic[RSInvT]
):
    def __init__(
        self,
        rs: Operation | SSAValue,
        *,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        super().__init__(rs, rd=rd, comment=comment)

__init__(rs: Operation | SSAValue, *, rd: IntRegisterType = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
984
985
986
987
988
989
990
991
def __init__(
    self,
    rs: Operation | SSAValue,
    *,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    super().__init__(rs, rd=rd, comment=comment)

RdRsFloatOperation

Bases: RdRsOperation[FloatRegisterType, RSInvT], ABC, Generic[RSInvT]

Source code in xdsl/dialects/riscv.py
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
class RdRsFloatOperation(
    RdRsOperation[FloatRegisterType, RSInvT], ABC, Generic[RSInvT]
):
    def __init__(
        self,
        rs: Operation | SSAValue,
        *,
        rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT,
        comment: str | StringAttr | None = None,
    ):
        super().__init__(rs, rd=rd, comment=comment)

__init__(rs: Operation | SSAValue, *, rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
 997
 998
 999
1000
1001
1002
1003
1004
def __init__(
    self,
    rs: Operation | SSAValue,
    *,
    rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT,
    comment: str | StringAttr | None = None,
):
    super().__init__(rs, rd=rd, comment=comment)

RsRsOffIntegerOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have one source register and a destination register, and an offset.

This is called B-Type in the RISC-V specification.

Source code in xdsl/dialects/riscv.py
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
class RsRsOffIntegerOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations that have one source register and a destination
    register, and an offset.

    This is called B-Type in the RISC-V specification.
    """

    rs1 = operand_def(IntRegisterType)
    rs2 = operand_def(IntRegisterType)
    offset = attr_def(base(SImm12Attr) | base(LabelAttr))

    def __init__(
        self,
        rs1: Operation | SSAValue,
        rs2: Operation | SSAValue,
        offset: int | SImm12Attr | LabelAttr,
        *,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(offset, int):
            offset = IntegerAttr(offset, si12)
        if isinstance(offset, str):
            offset = LabelAttr(offset)
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=[rs1, rs2],
            attributes={
                "offset": offset,
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rs1, self.rs2, self.offset

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["offset"] = parse_immediate_value(parser, si12)
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(", ")
        print_immediate_value(printer, self.offset)
        return {"offset"}

rs1 = operand_def(IntRegisterType) class-attribute instance-attribute

rs2 = operand_def(IntRegisterType) class-attribute instance-attribute

offset = attr_def(base(SImm12Attr) | base(LabelAttr)) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, rs2: Operation | SSAValue, offset: int | SImm12Attr | LabelAttr, *, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
def __init__(
    self,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    offset: int | SImm12Attr | LabelAttr,
    *,
    comment: str | StringAttr | None = None,
):
    if isinstance(offset, int):
        offset = IntegerAttr(offset, si12)
    if isinstance(offset, str):
        offset = LabelAttr(offset)
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=[rs1, rs2],
        attributes={
            "offset": offset,
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
1042
1043
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rs1, self.rs2, self.offset

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
1045
1046
1047
1048
1049
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["offset"] = parse_immediate_value(parser, si12)
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
1051
1052
1053
1054
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(", ")
    print_immediate_value(printer, self.offset)
    return {"offset"}

RsRsImmIntegerOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have two source registers and an immediate.

This is called S-Type in the RISC-V specification.

Source code in xdsl/dialects/riscv.py
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
class RsRsImmIntegerOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations that have two source registers and an
    immediate.

    This is called S-Type in the RISC-V specification.
    """

    rs1 = operand_def(IntRegisterType)
    rs2 = operand_def(IntRegisterType)
    immediate = attr_def(SImm12Attr)

    def __init__(
        self,
        rs1: Operation | SSAValue,
        rs2: Operation | SSAValue,
        immediate: int | Imm12Attr | str | LabelAttr,
        *,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(immediate, int):
            immediate = IntegerAttr(immediate, si12)
        elif isinstance(immediate, str):
            immediate = LabelAttr(immediate)
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=[rs1, rs2],
            attributes={
                "immediate": immediate,
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rs1, self.rs2, self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["immediate"] = parse_immediate_value(parser, si12)
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(", ")
        print_immediate_value(printer, self.immediate)
        return {"immediate"}

rs1 = operand_def(IntRegisterType) class-attribute instance-attribute

rs2 = operand_def(IntRegisterType) class-attribute instance-attribute

immediate = attr_def(SImm12Attr) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, rs2: Operation | SSAValue, immediate: int | Imm12Attr | str | LabelAttr, *, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
def __init__(
    self,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    immediate: int | Imm12Attr | str | LabelAttr,
    *,
    comment: str | StringAttr | None = None,
):
    if isinstance(immediate, int):
        immediate = IntegerAttr(immediate, si12)
    elif isinstance(immediate, str):
        immediate = LabelAttr(immediate)
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=[rs1, rs2],
        attributes={
            "immediate": immediate,
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
1092
1093
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rs1, self.rs2, self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
1095
1096
1097
1098
1099
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["immediate"] = parse_immediate_value(parser, si12)
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
1101
1102
1103
1104
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(", ")
    print_immediate_value(printer, self.immediate)
    return {"immediate"}

RsRsIntegerOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have two source registers.

Source code in xdsl/dialects/riscv.py
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
class RsRsIntegerOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations that have two source
    registers.
    """

    rs1 = operand_def(IntRegisterType)
    rs2 = operand_def(IntRegisterType)

    def __init__(
        self,
        rs1: Operation | SSAValue,
        rs2: Operation | SSAValue,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            operands=[rs1, rs2],
            attributes={
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rs1, self.rs2

rs1 = operand_def(IntRegisterType) class-attribute instance-attribute

rs2 = operand_def(IntRegisterType) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, rs2: Operation | SSAValue, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
def __init__(
    self,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        operands=[rs1, rs2],
        attributes={
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
1131
1132
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rs1, self.rs2

NullaryOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have neither sources nor destinations.

Source code in xdsl/dialects/riscv.py
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
class NullaryOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations that have neither sources nor destinations.
    """

    def __init__(
        self,
        *,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            attributes={
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return ()

    @classmethod
    def parse_unresolved_operands(cls, parser: Parser) -> list[UnresolvedOperand]:
        return []

    def print_op_type(self, printer: Printer) -> None:
        return

    @classmethod
    def parse_op_type(
        cls, parser: Parser
    ) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
        return (), ()

__init__(*, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
def __init__(
    self,
    *,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        attributes={
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
1154
1155
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return ()

parse_unresolved_operands(parser: Parser) -> list[UnresolvedOperand] classmethod

Source code in xdsl/dialects/riscv.py
1157
1158
1159
@classmethod
def parse_unresolved_operands(cls, parser: Parser) -> list[UnresolvedOperand]:
    return []

print_op_type(printer: Printer) -> None

Source code in xdsl/dialects/riscv.py
1161
1162
def print_op_type(self, printer: Printer) -> None:
    return

parse_op_type(parser: Parser) -> tuple[Sequence[Attribute], Sequence[Attribute]] classmethod

Source code in xdsl/dialects/riscv.py
1164
1165
1166
1167
1168
@classmethod
def parse_op_type(
    cls, parser: Parser
) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
    return (), ()

CsrReadWriteOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations performing a swap to/from a CSR.

The 'writeonly' attribute controls the actual behaviour of the operation: * when True, the operation writes the rs value to the CSR but never reads it and in this case rd must be allocated to x0 * when False, a proper atomic swap is performed and the previous CSR value is returned in rd

Source code in xdsl/dialects/riscv.py
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
class CsrReadWriteOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations performing a swap to/from a CSR.

    The 'writeonly' attribute controls the actual behaviour of the operation:
    * when True, the operation writes the rs value to the CSR but never reads it and
      in this case rd *must* be allocated to x0
    * when False, a proper atomic swap is performed and the previous CSR value is
      returned in rd
    """

    rd = result_def(IntRegisterType)
    rs1 = operand_def(IntRegisterType)
    csr = attr_def(IntegerAttr)
    writeonly = opt_attr_def(UnitAttr)

    def __init__(
        self,
        rs1: Operation | SSAValue,
        csr: IntegerAttr,
        *,
        writeonly: bool = False,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            operands=[rs1],
            attributes={
                "csr": csr,
                "writeonly": UnitAttr() if writeonly else None,
                "comment": comment,
            },
            result_types=[rd],
        )

    def verify_(self) -> None:
        if not self.writeonly:
            return
        if is_non_zero(self.rd.type):
            raise VerifyException(
                "When in 'writeonly' mode, destination must be register x0 (a.k.a. 'zero'), "
                f"not '{self.rd.type.register_name.data}'"
            )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.csr, self.rs1

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["csr"] = IntegerAttr(
            parser.parse_integer(allow_boolean=False, context_msg="Expected csr"),
            IntegerType(32),
        )
        if parser.parse_optional_punctuation(",") is not None:
            if (flag := parser.parse_str_literal("Expected 'w' flag")) != "w":
                parser.raise_error(f"Expected 'w' flag, got '{flag}'")
            attributes["writeonly"] = UnitAttr()
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(", ")
        self.csr.print_without_type(printer)
        if self.writeonly is not None:
            printer.print_string(', "w"')
        return {"csr", "writeonly"}

rd = result_def(IntRegisterType) class-attribute instance-attribute

rs1 = operand_def(IntRegisterType) class-attribute instance-attribute

csr = attr_def(IntegerAttr) class-attribute instance-attribute

writeonly = opt_attr_def(UnitAttr) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, csr: IntegerAttr, *, writeonly: bool = False, rd: IntRegisterType = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
def __init__(
    self,
    rs1: Operation | SSAValue,
    csr: IntegerAttr,
    *,
    writeonly: bool = False,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        operands=[rs1],
        attributes={
            "csr": csr,
            "writeonly": UnitAttr() if writeonly else None,
            "comment": comment,
        },
        result_types=[rd],
    )

verify_() -> None

Source code in xdsl/dialects/riscv.py
1208
1209
1210
1211
1212
1213
1214
1215
def verify_(self) -> None:
    if not self.writeonly:
        return
    if is_non_zero(self.rd.type):
        raise VerifyException(
            "When in 'writeonly' mode, destination must be register x0 (a.k.a. 'zero'), "
            f"not '{self.rd.type.register_name.data}'"
        )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
1217
1218
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.csr, self.rs1

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["csr"] = IntegerAttr(
        parser.parse_integer(allow_boolean=False, context_msg="Expected csr"),
        IntegerType(32),
    )
    if parser.parse_optional_punctuation(",") is not None:
        if (flag := parser.parse_str_literal("Expected 'w' flag")) != "w":
            parser.raise_error(f"Expected 'w' flag, got '{flag}'")
        attributes["writeonly"] = UnitAttr()
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
1233
1234
1235
1236
1237
1238
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(", ")
    self.csr.print_without_type(printer)
    if self.writeonly is not None:
        printer.print_string(', "w"')
    return {"csr", "writeonly"}

CsrBitwiseOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations performing a masked bitwise operation on the CSR while returning the original value.

The 'readonly' attribute controls the actual behaviour of the operation: * when True, the operation is guaranteed to have no side effects that can be potentially related to writing to a CSR; in this case rs must be allocated to x0 * when False, the bitwise operations is performed and any side effect related to writing to a CSR takes place even if the mask in rs has no actual bits set.

Source code in xdsl/dialects/riscv.py
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
class CsrBitwiseOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations performing a masked bitwise operation on the
    CSR while returning the original value.

    The 'readonly' attribute controls the actual behaviour of the operation:
    * when True, the operation is guaranteed to have no side effects that can
      be potentially related to writing to a CSR; in this case rs *must be
      allocated to x0*
    * when False, the bitwise operations is performed and any side effect related
      to writing to a CSR takes place even if the mask in rs has no actual bits set.
    """

    rd = result_def(IntRegisterType)
    rs1 = operand_def(IntRegisterType)
    csr = attr_def(IntegerAttr)
    readonly = opt_attr_def(UnitAttr)

    def __init__(
        self,
        rs1: Operation | SSAValue,
        csr: IntegerAttr,
        *,
        readonly: bool = False,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            operands=[rs1],
            attributes={
                "csr": csr,
                "readonly": UnitAttr() if readonly else None,
                "comment": comment,
            },
            result_types=[rd],
        )

    def verify_(self) -> None:
        if not self.readonly:
            return
        assert isinstance(self.rs1.type, IntRegisterType)
        if is_non_zero(self.rs1.type):
            raise VerifyException(
                "When in 'readonly' mode, source must be register x0 (a.k.a. 'zero'), "
                f"not '{self.rs1.type.register_name.data}'"
            )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.csr, self.rs1

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["csr"] = IntegerAttr(
            parser.parse_integer(allow_boolean=False, context_msg="Expected csr"),
            IntegerType(32),
        )
        if parser.parse_optional_punctuation(",") is not None:
            if (flag := parser.parse_str_literal("Expected 'r' flag")) != "r":
                parser.raise_error(f"Expected 'r' flag, got '{flag}'")
            attributes["readonly"] = UnitAttr()
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(", ")
        self.csr.print_without_type(printer)
        if self.readonly is not None:
            printer.print_string(', "r"')
        return {"csr", "readonly"}

rd = result_def(IntRegisterType) class-attribute instance-attribute

rs1 = operand_def(IntRegisterType) class-attribute instance-attribute

csr = attr_def(IntegerAttr) class-attribute instance-attribute

readonly = opt_attr_def(UnitAttr) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, csr: IntegerAttr, *, readonly: bool = False, rd: IntRegisterType = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
def __init__(
    self,
    rs1: Operation | SSAValue,
    csr: IntegerAttr,
    *,
    readonly: bool = False,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        operands=[rs1],
        attributes={
            "csr": csr,
            "readonly": UnitAttr() if readonly else None,
            "comment": comment,
        },
        result_types=[rd],
    )

verify_() -> None

Source code in xdsl/dialects/riscv.py
1280
1281
1282
1283
1284
1285
1286
1287
1288
def verify_(self) -> None:
    if not self.readonly:
        return
    assert isinstance(self.rs1.type, IntRegisterType)
    if is_non_zero(self.rs1.type):
        raise VerifyException(
            "When in 'readonly' mode, source must be register x0 (a.k.a. 'zero'), "
            f"not '{self.rs1.type.register_name.data}'"
        )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
1290
1291
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.csr, self.rs1

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["csr"] = IntegerAttr(
        parser.parse_integer(allow_boolean=False, context_msg="Expected csr"),
        IntegerType(32),
    )
    if parser.parse_optional_punctuation(",") is not None:
        if (flag := parser.parse_str_literal("Expected 'r' flag")) != "r":
            parser.raise_error(f"Expected 'r' flag, got '{flag}'")
        attributes["readonly"] = UnitAttr()
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
1306
1307
1308
1309
1310
1311
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(", ")
    self.csr.print_without_type(printer)
    if self.readonly is not None:
        printer.print_string(', "r"')
    return {"csr", "readonly"}

CsrReadWriteImmOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations performing a write immediate to/read from a CSR.

The 'writeonly' attribute controls the actual behaviour of the operation: * when True, the operation writes the rs value to the CSR but never reads it and in this case rd must be allocated to x0 * when False, a proper atomic swap is performed and the previous CSR value is returned in rd

Source code in xdsl/dialects/riscv.py
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
class CsrReadWriteImmOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations performing a write immediate to/read from a CSR.

    The 'writeonly' attribute controls the actual behaviour of the operation:
    * when True, the operation writes the rs value to the CSR but never reads it and
      in this case rd *must* be allocated to x0
    * when False, a proper atomic swap is performed and the previous CSR value is
      returned in rd
    """

    rd = result_def(IntRegisterType)
    csr = attr_def(IntegerAttr)
    immediate = attr_def(IntegerAttr)
    writeonly = opt_attr_def(UnitAttr)

    def __init__(
        self,
        csr: IntegerAttr,
        immediate: IntegerAttr,
        *,
        writeonly: bool = False,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            attributes={
                "csr": csr,
                "immediate": immediate,
                "writeonly": UnitAttr() if writeonly else None,
                "comment": comment,
            },
            result_types=[rd],
        )

    def verify_(self) -> None:
        if self.writeonly is None:
            return
        if is_non_zero(self.rd.type):
            raise VerifyException(
                "When in 'writeonly' mode, destination must be register x0 (a.k.a. 'zero'), "
                f"not '{self.rd.type.register_name.data}'"
            )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
        return self.rd, self.csr, self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["csr"] = IntegerAttr(
            parser.parse_integer(allow_boolean=False, context_msg="Expected csr"),
            IntegerType(32),
        )
        parser.parse_punctuation(",")
        attributes["immediate"] = parse_immediate_value(parser, IntegerType(32))
        if parser.parse_optional_punctuation(",") is not None:
            if (flag := parser.parse_str_literal("Expected 'w' flag")) != "w":
                parser.raise_error(f"Expected 'w' flag, got '{flag}'")
            attributes["writeonly"] = UnitAttr()
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(" ")
        self.csr.print_without_type(printer)
        printer.print_string(", ")
        print_immediate_value(printer, self.immediate)
        if self.writeonly is not None:
            printer.print_string(', "w"')
        return {"csr", "immediate", "writeonly"}

rd = result_def(IntRegisterType) class-attribute instance-attribute

csr = attr_def(IntegerAttr) class-attribute instance-attribute

immediate = attr_def(IntegerAttr) class-attribute instance-attribute

writeonly = opt_attr_def(UnitAttr) class-attribute instance-attribute

__init__(csr: IntegerAttr, immediate: IntegerAttr, *, writeonly: bool = False, rd: IntRegisterType = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
def __init__(
    self,
    csr: IntegerAttr,
    immediate: IntegerAttr,
    *,
    writeonly: bool = False,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        attributes={
            "csr": csr,
            "immediate": immediate,
            "writeonly": UnitAttr() if writeonly else None,
            "comment": comment,
        },
        result_types=[rd],
    )

verify_() -> None

Source code in xdsl/dialects/riscv.py
1351
1352
1353
1354
1355
1356
1357
1358
def verify_(self) -> None:
    if self.writeonly is None:
        return
    if is_non_zero(self.rd.type):
        raise VerifyException(
            "When in 'writeonly' mode, destination must be register x0 (a.k.a. 'zero'), "
            f"not '{self.rd.type.register_name.data}'"
        )

assembly_line_args() -> tuple[AssemblyInstructionArg | None, ...]

Source code in xdsl/dialects/riscv.py
1360
1361
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.rd, self.csr, self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["csr"] = IntegerAttr(
        parser.parse_integer(allow_boolean=False, context_msg="Expected csr"),
        IntegerType(32),
    )
    parser.parse_punctuation(",")
    attributes["immediate"] = parse_immediate_value(parser, IntegerType(32))
    if parser.parse_optional_punctuation(",") is not None:
        if (flag := parser.parse_str_literal("Expected 'w' flag")) != "w":
            parser.raise_error(f"Expected 'w' flag, got '{flag}'")
        attributes["writeonly"] = UnitAttr()
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
1378
1379
1380
1381
1382
1383
1384
1385
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(" ")
    self.csr.print_without_type(printer)
    printer.print_string(", ")
    print_immediate_value(printer, self.immediate)
    if self.writeonly is not None:
        printer.print_string(', "w"')
    return {"csr", "immediate", "writeonly"}

CsrBitwiseImmOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations performing a masked bitwise operation on the CSR while returning the original value. The bitmask is specified in the 'immediate' attribute.

The 'immediate' attribute controls the actual behaviour of the operation: * when equals to zero, the operation is guaranteed to have no side effects that can be potentially related to writing to a CSR; * when not equal to zero, any side effect related to writing to a CSR takes place.

Source code in xdsl/dialects/riscv.py
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
class CsrBitwiseImmOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations performing a masked bitwise operation on the
    CSR while returning the original value. The bitmask is specified in the 'immediate'
    attribute.

    The 'immediate' attribute controls the actual behaviour of the operation:
    * when equals to zero, the operation is guaranteed to have no side effects
      that can be potentially related to writing to a CSR;
    * when not equal to zero, any side effect related to writing to a CSR takes
      place.
    """

    rd = result_def(IntRegisterType)
    csr = attr_def(IntegerAttr)
    immediate = attr_def(IntegerAttr)

    def __init__(
        self,
        csr: IntegerAttr,
        immediate: IntegerAttr,
        *,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            attributes={
                "csr": csr,
                "immediate": immediate,
                "comment": comment,
            },
            result_types=[rd],
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.csr, self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["csr"] = IntegerAttr(
            parser.parse_integer(allow_boolean=False, context_msg="Expected csr"),
            IntegerType(32),
        )
        parser.parse_punctuation(",")
        attributes["immediate"] = parse_immediate_value(parser, IntegerType(32))
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(" ")
        self.csr.print_without_type(printer)
        printer.print_string(", ")
        print_immediate_value(printer, self.immediate)
        return {"csr", "immediate"}

rd = result_def(IntRegisterType) class-attribute instance-attribute

csr = attr_def(IntegerAttr) class-attribute instance-attribute

immediate = attr_def(IntegerAttr) class-attribute instance-attribute

__init__(csr: IntegerAttr, immediate: IntegerAttr, *, rd: IntRegisterType = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
def __init__(
    self,
    csr: IntegerAttr,
    immediate: IntegerAttr,
    *,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        attributes={
            "csr": csr,
            "immediate": immediate,
            "comment": comment,
        },
        result_types=[rd],
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
1424
1425
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.csr, self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["csr"] = IntegerAttr(
        parser.parse_integer(allow_boolean=False, context_msg="Expected csr"),
        IntegerType(32),
    )
    parser.parse_punctuation(",")
    attributes["immediate"] = parse_immediate_value(parser, IntegerType(32))
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
1438
1439
1440
1441
1442
1443
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(" ")
    self.csr.print_without_type(printer)
    printer.print_string(", ")
    print_immediate_value(printer, self.immediate)
    return {"csr", "immediate"}

AddiOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
class AddiOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            AddImmediateConstant,
            AddImmediateZero,
        )

        return (
            AddImmediateZero(),
            AddImmediateConstant(),
        )

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        AddImmediateConstant,
        AddImmediateZero,
    )

    return (
        AddImmediateZero(),
        AddImmediateConstant(),
    )

AddiOp dataclass

Bases: RdRsImmIntegerOperation

Adds the sign-extended 12-bit immediate to register rs1. Arithmetic overflow is ignored and the result is simply the low XLEN bits of the result.

x[rd] = x[rs1] + sext(immediate)

See external documentation.

Source code in xdsl/dialects/riscv.py
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
@irdl_op_definition
class AddiOp(RdRsImmIntegerOperation):
    """
    Adds the sign-extended 12-bit immediate to register rs1.
    Arithmetic overflow is ignored and the result is simply the low XLEN bits of the result.

    x[rd] = x[rs1] + sext(immediate)

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#addi).
    """

    name = "riscv.addi"

    traits = traits_def(Pure(), AddiOpHasCanonicalizationPatternsTrait())

name = 'riscv.addi' class-attribute instance-attribute

traits = traits_def(Pure(), AddiOpHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

SltiOp dataclass

Bases: RdRsImmIntegerOperation

Place the value 1 in register rd if register rs1 is less than the sign-extended immediate when both are treated as signed numbers, else 0 is written to rd.

x[rd] = x[rs1] <s sext(immediate)

See external documentation.

Source code in xdsl/dialects/riscv.py
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
@irdl_op_definition
class SltiOp(RdRsImmIntegerOperation):
    """
    Place the value 1 in register rd if register rs1 is less than the sign-extended
    immediate when both are treated as signed numbers, else 0 is written to rd.

    x[rd] = x[rs1] <s sext(immediate)

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#slti).
    """

    name = "riscv.slti"

name = 'riscv.slti' class-attribute instance-attribute

SltiuOp dataclass

Bases: RdRsImmIntegerOperation

Place the value 1 in register rd if register rs1 is less than the immediate when both are treated as unsigned numbers, else 0 is written to rd.

x[rd] = x[rs1] <u sext(immediate)

See external documentation.

Source code in xdsl/dialects/riscv.py
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
@irdl_op_definition
class SltiuOp(RdRsImmIntegerOperation):
    """
    Place the value 1 in register rd if register rs1 is less than the immediate when
    both are treated as unsigned numbers, else 0 is written to rd.

    x[rd] = x[rs1] <u sext(immediate)

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sltiu).
    """

    name = "riscv.sltiu"

name = 'riscv.sltiu' class-attribute instance-attribute

AndiOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
1511
1512
1513
1514
1515
1516
1517
1518
class AndiOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            AndiImmediate,
        )

        return (AndiImmediate(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
1512
1513
1514
1515
1516
1517
1518
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        AndiImmediate,
    )

    return (AndiImmediate(),)

AndiOp dataclass

Bases: RdRsImmIntegerOperation

Performs bitwise AND on register rs1 and the sign-extended 12-bit immediate and place the result in rd.

x[rd] = x[rs1] & sext(immediate)

See external documentation.

Source code in xdsl/dialects/riscv.py
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
@irdl_op_definition
class AndiOp(RdRsImmIntegerOperation):
    """
    Performs bitwise AND on register rs1 and the sign-extended 12-bit
    immediate and place the result in rd.

    x[rd] = x[rs1] & sext(immediate)

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#andi).
    """

    name = "riscv.andi"
    traits = traits_def(AndiOpHasCanonicalizationPatternsTrait())

name = 'riscv.andi' class-attribute instance-attribute

traits = traits_def(AndiOpHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

OriOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
1536
1537
1538
1539
1540
1541
1542
1543
class OriOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            OriImmediate,
        )

        return (OriImmediate(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
1537
1538
1539
1540
1541
1542
1543
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        OriImmediate,
    )

    return (OriImmediate(),)

OriOp dataclass

Bases: RdRsImmIntegerOperation

Performs bitwise OR on register rs1 and the sign-extended 12-bit immediate and place the result in rd.

x[rd] = x[rs1] | sext(immediate)

See external documentation.

Source code in xdsl/dialects/riscv.py
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
@irdl_op_definition
class OriOp(RdRsImmIntegerOperation):
    """
    Performs bitwise OR on register rs1 and the sign-extended 12-bit immediate and place
    the result in rd.

    x[rd] = x[rs1] | sext(immediate)

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#ori).
    """

    name = "riscv.ori"
    traits = traits_def(OriOpHasCanonicalizationPatternsTrait())

name = 'riscv.ori' class-attribute instance-attribute

traits = traits_def(OriOpHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

XoriOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
1561
1562
1563
1564
1565
1566
1567
1568
class XoriOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            XoriImmediate,
        )

        return (XoriImmediate(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
1562
1563
1564
1565
1566
1567
1568
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        XoriImmediate,
    )

    return (XoriImmediate(),)

XoriOp dataclass

Bases: RdRsImmIntegerOperation

Performs bitwise XOR on register rs1 and the sign-extended 12-bit immediate and place the result in rd.

x[rd] = x[rs1] ^ sext(immediate)

See external documentation.

Source code in xdsl/dialects/riscv.py
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
@irdl_op_definition
class XoriOp(RdRsImmIntegerOperation):
    """
    Performs bitwise XOR on register rs1 and the sign-extended 12-bit immediate and place
    the result in rd.

    x[rd] = x[rs1] ^ sext(immediate)

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#xori).
    """

    name = "riscv.xori"
    traits = traits_def(XoriOpHasCanonicalizationPatternsTrait())

name = 'riscv.xori' class-attribute instance-attribute

traits = traits_def(XoriOpHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

SlliOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
1586
1587
1588
1589
1590
1591
1592
1593
1594
class SlliOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            ShiftLeftbyZero,
            ShiftLeftImmediate,
        )

        return (ShiftLeftImmediate(), ShiftLeftbyZero())

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
1587
1588
1589
1590
1591
1592
1593
1594
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        ShiftLeftbyZero,
        ShiftLeftImmediate,
    )

    return (ShiftLeftImmediate(), ShiftLeftbyZero())

SlliOp dataclass

Bases: RdRsImmShiftOperation

Performs logical left shift on the value in register rs1 by the shift amount held in the lower 5 bits of the immediate.

x[rd] = x[rs1] << shamt

See external documentation.

Source code in xdsl/dialects/riscv.py
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
@irdl_op_definition
class SlliOp(RdRsImmShiftOperation):
    """
    Performs logical left shift on the value in register rs1 by the shift amount
    held in the lower 5 bits of the immediate.

    x[rd] = x[rs1] << shamt

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#slli).
    """

    name = "riscv.slli"

    traits = traits_def(SlliOpHasCanonicalizationPatternsTrait())

name = 'riscv.slli' class-attribute instance-attribute

traits = traits_def(SlliOpHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

SrliOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
1613
1614
1615
1616
1617
1618
1619
1620
1621
class SrliOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            ShiftRightbyZero,
            ShiftRightImmediate,
        )

        return (ShiftRightbyZero(), ShiftRightImmediate())

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
1614
1615
1616
1617
1618
1619
1620
1621
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        ShiftRightbyZero,
        ShiftRightImmediate,
    )

    return (ShiftRightbyZero(), ShiftRightImmediate())

SrliOp dataclass

Bases: RdRsImmShiftOperation

Performs logical right shift on the value in register rs1 by the shift amount held in the lower 5 bits of the immediate.

x[rd] = x[rs1] >>u shamt

See external documentation.

Source code in xdsl/dialects/riscv.py
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
@irdl_op_definition
class SrliOp(RdRsImmShiftOperation):
    """
    Performs logical right shift on the value in register rs1 by the shift amount held
    in the lower 5 bits of the immediate.

    x[rd] = x[rs1] >>u shamt

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#srli).
    """

    name = "riscv.srli"

    traits = traits_def(SrliOpHasCanonicalizationPatternsTrait())

name = 'riscv.srli' class-attribute instance-attribute

traits = traits_def(SrliOpHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

SraiOp dataclass

Bases: RdRsImmShiftOperation

Performs arithmetic right shift on the value in register rs1 by the shift amount held in the lower 5 bits of the immediate.

x[rd] = x[rs1] >>s shamt

See external documentation.

Source code in xdsl/dialects/riscv.py
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
@irdl_op_definition
class SraiOp(RdRsImmShiftOperation):
    """
    Performs arithmetic right shift on the value in register rs1 by the shift amount
    held in the lower 5 bits of the immediate.

    x[rd] = x[rs1] >>s shamt

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#srai).
    """

    name = "riscv.srai"

name = 'riscv.srai' class-attribute instance-attribute

AddiwOp dataclass

Bases: RdRsImmIntegerOperation

Adds the sign-extended 12-bit immediate to register rs1 and produces the proper sign-extension of a 32-bit result in rd. Overflows are ignored and the result is the low 32 bits of the result sign-extended to 64 bits.

x[rd] = sext((x[rs1] + sext(immediate))[31:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
@irdl_op_definition
class AddiwOp(RdRsImmIntegerOperation):
    """
    Adds the sign-extended 12-bit immediate to register rs1 and produces the proper sign-extension of a 32-bit result in rd.
    Overflows are ignored and the result is the low 32 bits of the result sign-extended to 64 bits.
    ```
    x[rd] = sext((x[rs1] + sext(immediate))[31:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rv64i.html#addiw).
    """

    name = "riscv.addiw"

    traits = traits_def(Pure())

name = 'riscv.addiw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SlliwOp dataclass

Bases: RdRsImmShiftOperation

Performs logical left shift on the 32-bit of value in register rs1 by the shift amount held in the lower 5 bits of the immediate.

x[rd] = sext((x[rs1] << shamt)[31:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
@irdl_op_definition
class SlliwOp(RdRsImmShiftOperation):
    """
    Performs logical left shift on the 32-bit of value in register rs1 by the
    shift amount held in the lower 5 bits of the immediate.
    ```
    x[rd] = sext((x[rs1] << shamt)[31:0])
    ```
    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#slliw).
    """

    name = "riscv.slliw"

    traits = traits_def(Pure())

name = 'riscv.slliw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SrliwOp dataclass

Bases: RdRsImmShiftOperation

Performs logical right shift on the 32-bit of value in register rs1 by the shift amount held in the lower 5 bits of the immediate.

x[rd] = sext(x[rs1][31:0] >>u shamt)

See external documentation.

Source code in xdsl/dialects/riscv.py
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
@irdl_op_definition
class SrliwOp(RdRsImmShiftOperation):
    """
    Performs logical right shift on the 32-bit of value in register rs1 by the shift amount held in the
    lower 5 bits of the immediate.
    ```
    x[rd] = sext(x[rs1][31:0] >>u shamt)
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#srliw).
    """

    name = "riscv.srliw"

    traits = traits_def(Pure())

name = 'riscv.srliw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SraiwOp dataclass

Bases: RdRsImmIntegerOperation

Performs arithmetic right shift on the 32-bit of value in register rs1 by the shift amount held in the lower 5 bits of the immediate.

x[rd] = sext(x[rs1][31:0] >>s shamt)

See external documentation.

Source code in xdsl/dialects/riscv.py
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
@irdl_op_definition
class SraiwOp(RdRsImmIntegerOperation):
    """
    Performs arithmetic right shift on the 32-bit of value in register rs1 by the shift amount held
    in the lower 5 bits of the immediate.
    ```
    x[rd] = sext(x[rs1][31:0] >>s shamt)
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sraiw).
    """

    name = "riscv.sraiw"

    traits = traits_def(Pure())

name = 'riscv.sraiw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

AddwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Adds the 32-bit of registers rs1 and 32-bit of register rs2 and stores the result in rd. Arithmetic overflow is ignored and the low 32-bits of the result is sign-extended to 64-bits and written to the destination register.

x[rd] = sext((x[rs1] + x[rs2])[31:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
@irdl_op_definition
class AddwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Adds the 32-bit of registers rs1 and 32-bit of register rs2 and stores the result in rd.
    Arithmetic overflow is ignored and the low 32-bits of the result is sign-extended to 64-bits and
    written to the destination register.
    ```
    x[rd] = sext((x[rs1] + x[rs2])[31:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#addw).
    """

    name = "riscv.addw"

    traits = traits_def(Pure())

name = 'riscv.addw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SubwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Subtract the 32-bit of registers rs1 and 32-bit of register rs2 and stores the result in rd. Arithmetic overflow is ignored and the low 32-bits of the result is sign-extended to 64-bits and written to the destination register.

x[rd] = sext((x[rs1] - x[rs2])[31:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
@irdl_op_definition
class SubwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Subtract the 32-bit of registers rs1 and 32-bit of register rs2 and stores the result in rd.
    Arithmetic overflow is ignored and the low 32-bits of the result is sign-extended to 64-bits
    and written to the destination register.
    ```
    x[rd] = sext((x[rs1] - x[rs2])[31:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#subw).
    """

    name = "riscv.subw"

    traits = traits_def(Pure())

name = 'riscv.subw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SllwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs logical left shift on the low 32-bits value in register rs1 by the shift amount held in the lower 5 bits of register rs2 and produce 32-bit results and written to the destination register rd.

x[rd] = sext((x[rs1] << x[rs2][4:0])[31:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
@irdl_op_definition
class SllwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs logical left shift on the low 32-bits value in register rs1 by the shift amount held
    in the lower 5 bits of register rs2 and produce 32-bit results and written to the destination register rd.
    ```
    x[rd] = sext((x[rs1] << x[rs2][4:0])[31:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sllw).
    """

    name = "riscv.sllw"

    traits = traits_def(Pure())

name = 'riscv.sllw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SrlwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs logical right shift on the low 32-bits value in register rs1 by the shift amount held in the lower 5 bits of register rs2 and produce 32-bit results and written to the destination register rd.

x[rd] = sext(x[rs1][31:0] >>u x[rs2][4:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
@irdl_op_definition
class SrlwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs logical right shift on the low 32-bits value in register rs1 by the shift amount held
    in the lower 5 bits of register rs2 and produce 32-bit results and written to the destination
    register rd.
    ```
    x[rd] = sext(x[rs1][31:0] >>u x[rs2][4:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#srlw).
    """

    name = "riscv.srlw"

    traits = traits_def(Pure())

name = 'riscv.srlw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SrawOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs arithmetic right shift on the low 32-bits value in register rs1 by the shift amount held in the lower 5 bits of register rs2 and produce 32-bit results and written to the destination register rd.

x[rd] = sext(x[rs1][31:0] >>s x[rs2][4:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
@irdl_op_definition
class SrawOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs arithmetic right shift on the low 32-bits value in register rs1 by the shift amount held in the lower
    5 bits of register rs2 and produce 32-bit results and written to the destination register rd.
    ```
    x[rd] = sext(x[rs1][31:0] >>s x[rs2][4:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sraw).
    """

    name = "riscv.sraw"

    traits = traits_def(Pure())

name = 'riscv.sraw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

LuiOp dataclass

Bases: RdImmIntegerOperation

Build 32-bit constants and uses the U-type format. LUI places the U-immediate value in the top 20 bits of the destination register rd, filling in the lowest 12 bits with zeros.

x[rd] = sext(immediate[31:12] << 12)

See external documentation.

Source code in xdsl/dialects/riscv.py
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
@irdl_op_definition
class LuiOp(RdImmIntegerOperation):
    """
    Build 32-bit constants and uses the U-type format. LUI places the U-immediate value
    in the top 20 bits of the destination register rd, filling in the lowest 12 bits with zeros.

    x[rd] = sext(immediate[31:12] << 12)

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#lui).
    """

    name = "riscv.lui"

name = 'riscv.lui' class-attribute instance-attribute

AuipcOp dataclass

Bases: RdImmIntegerOperation

Build pc-relative addresses and uses the U-type format. AUIPC forms a 32-bit offset from the 20-bit U-immediate, filling in the lowest 12 bits with zeros, adds this offset to the pc, then places the result in register rd.

x[rd] = pc + sext(immediate[31:12] << 12)

See external documentation.

Source code in xdsl/dialects/riscv.py
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
@irdl_op_definition
class AuipcOp(RdImmIntegerOperation):
    """
    Build pc-relative addresses and uses the U-type format. AUIPC forms a 32-bit offset
    from the 20-bit U-immediate, filling in the lowest 12 bits with zeros, adds this
    offset to the pc, then places the result in register rd.

    x[rd] = pc + sext(immediate[31:12] << 12)

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#auipc).
    """

    name = "riscv.auipc"

name = 'riscv.auipc' class-attribute instance-attribute

MVHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
1838
1839
1840
1841
1842
1843
1844
1845
class MVHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            RemoveRedundantMv,
        )

        return (RemoveRedundantMv(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
1839
1840
1841
1842
1843
1844
1845
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        RemoveRedundantMv,
    )

    return (RemoveRedundantMv(),)

MVOp dataclass

Bases: RdRsIntegerOperation[IntRegisterType]

A pseudo instruction to copy contents of one int register to another.

Equivalent to addi rd, rs, 0

Source code in xdsl/dialects/riscv.py
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
@irdl_op_definition
class MVOp(RdRsIntegerOperation[IntRegisterType]):
    """
    A pseudo instruction to copy contents of one int register to another.

    Equivalent to `addi rd, rs, 0`
    """

    name = "riscv.mv"

    traits = traits_def(
        Pure(),
        MVHasCanonicalizationPatternsTrait(),
    )

name = 'riscv.mv' class-attribute instance-attribute

traits = traits_def(Pure(), MVHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

SeqzOp dataclass

Bases: RdRsIntegerOperation[IntRegisterType]

A pseudo instruction that sets the destination register to 1 if the source register is equal to zero.

Equivalent to `sltiu rd, rs, 1

Source code in xdsl/dialects/riscv.py
1864
1865
1866
1867
1868
1869
1870
1871
1872
@irdl_op_definition
class SeqzOp(RdRsIntegerOperation[IntRegisterType]):
    """
    A pseudo instruction that sets the destination register to 1 if the source register is equal to zero.

    Equivalent to `sltiu rd, rs, 1
    """

    name = "riscv.seqz"

name = 'riscv.seqz' class-attribute instance-attribute

SnezOp dataclass

Bases: RdRsIntegerOperation[IntRegisterType]

A pseudo instruction that sets the destination register to 1 if the source register is not equal to zero.

Equivalent to sltu rd, x0, rs1

Source code in xdsl/dialects/riscv.py
1875
1876
1877
1878
1879
1880
1881
1882
1883
@irdl_op_definition
class SnezOp(RdRsIntegerOperation[IntRegisterType]):
    """
    A pseudo instruction that sets the destination register to 1 if the source register is not equal to zero.

    Equivalent to `sltu rd, x0, rs1 `
    """

    name = "riscv.snez"

name = 'riscv.snez' class-attribute instance-attribute

ZextBOp dataclass

Bases: RdRsIntegerOperation[IntRegisterType]

A pseudo instruction that zero-extends the least-significant byte of the source to XLEN by copying the into all of the bits more significant than 31.

Equivalent to andi rd, rs1, 255

Source code in xdsl/dialects/riscv.py
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
@irdl_op_definition
class ZextBOp(RdRsIntegerOperation[IntRegisterType]):
    """
    A pseudo instruction that zero-extends the least-significant byte of the source to XLEN by copying the
    into all of the bits more significant than 31.

    Equivalent to `andi rd, rs1, 255`
    """

    name = "riscv.zext.b"

    traits = traits_def(Pure())

name = 'riscv.zext.b' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

ZextWOp dataclass

Bases: RdRsIntegerOperation[IntRegisterType]

A pseudo instruction that zero-extends the least-significant word of the source to XLEN by inserting 0’s into all of the bits more significant than 31.

Equivalent to add.uw rd, rs1, 0

See external documentation

Source code in xdsl/dialects/riscv.py
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
@irdl_op_definition
class ZextWOp(RdRsIntegerOperation[IntRegisterType]):
    """
    A pseudo instruction that zero-extends the least-significant word of the source to XLEN by inserting 0’s
    into all of the bits more significant than 31.

    Equivalent to `add.uw rd, rs1, 0`

    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-add_uw)
    """

    name = "riscv.zext.w"

    traits = traits_def(Pure())

name = 'riscv.zext.w' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SextWOp dataclass

Bases: RdRsIntegerOperation[IntRegisterType]

A pseudo instruction that writes the sign-extension of the lower 32 bits of register rs1 into register rd.

Equivalent to addiw rd, rs, 0

See external documentation.

Source code in xdsl/dialects/riscv.py
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
@irdl_op_definition
class SextWOp(RdRsIntegerOperation[IntRegisterType]):
    """
    A pseudo instruction that writes the sign-extension of the lower 32 bits of register rs1 into register rd.

    Equivalent to `addiw rd, rs, 0 `

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/#_addiw).
    """

    name = "riscv.sext.w"

    traits = traits_def(Pure())

name = 'riscv.sext.w' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

FMVHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
1931
1932
1933
1934
1935
1936
class FMVHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import RemoveRedundantFMv

        return (RemoveRedundantFMv(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
1932
1933
1934
1935
1936
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import RemoveRedundantFMv

    return (RemoveRedundantFMv(),)

FMVOp dataclass

Bases: RdRsFloatOperation[FloatRegisterType]

A pseudo instruction to copy contents of one float register to another.

Equivalent to fsgnj.s rd, rs, rs.

Both clang and gcc emit fsw rs, 0(x); flw rd, 0(x) to copy floats, possibly because storing and loading bits from memory is a lower overhead in practice than reasoning about floating-point values.

Source code in xdsl/dialects/riscv.py
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
@irdl_op_definition
class FMVOp(RdRsFloatOperation[FloatRegisterType]):
    """
    A pseudo instruction to copy contents of one float register to another.

    Equivalent to `fsgnj.s rd, rs, rs`.

    Both clang and gcc emit `fsw rs, 0(x); flw rd, 0(x)` to copy floats, possibly because
    storing and loading bits from memory is a lower overhead in practice than reasoning
    about floating-point values.
    """

    name = "riscv.fmv.s"

    traits = traits_def(
        Pure(),
        FMVHasCanonicalizationPatternsTrait(),
    )

name = 'riscv.fmv.s' class-attribute instance-attribute

traits = traits_def(Pure(), FMVHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

AddOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
1962
1963
1964
1965
1966
1967
1968
1969
1970
class AddOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            AddImmediates,
            AdditionOfSameVariablesToMultiplyByTwo,
        )

        return (AddImmediates(), AdditionOfSameVariablesToMultiplyByTwo())

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
1963
1964
1965
1966
1967
1968
1969
1970
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        AddImmediates,
        AdditionOfSameVariablesToMultiplyByTwo,
    )

    return (AddImmediates(), AdditionOfSameVariablesToMultiplyByTwo())

AddOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Adds the registers rs1 and rs2 and stores the result in rd. Arithmetic overflow is ignored and the result is simply the low XLEN bits of the result.

x[rd] = x[rs1] + x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
@irdl_op_definition
class AddOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Adds the registers rs1 and rs2 and stores the result in rd.
    Arithmetic overflow is ignored and the result is simply the low XLEN bits of the result.

    ```
    x[rd] = x[rs1] + x[rs2]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#add).
    """

    name = "riscv.add"

    traits = traits_def(
        Pure(),
        AddOpHasCanonicalizationPatternsTrait(),
    )

name = 'riscv.add' class-attribute instance-attribute

traits = traits_def(Pure(), AddOpHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

SltOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Place the value 1 in register rd if register rs1 is less than register rs2 when both are treated as signed numbers, else 0 is written to rd.

x[rd] = x[rs1] <s x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
@irdl_op_definition
class SltOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Place the value 1 in register rd if register rs1 is less than register rs2 when both
    are treated as signed numbers, else 0 is written to rd.

    x[rd] = x[rs1] <s x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#slt).
    """

    name = "riscv.slt"

name = 'riscv.slt' class-attribute instance-attribute

SltuOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Place the value 1 in register rd if register rs1 is less than register rs2 when both are treated as unsigned numbers, else 0 is written to rd.

x[rd] = x[rs1] <u x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
@irdl_op_definition
class SltuOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Place the value 1 in register rd if register rs1 is less than register rs2 when both
    are treated as unsigned numbers, else 0 is written to rd.

    x[rd] = x[rs1] <u x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sltu).
    """

    name = "riscv.sltu"

name = 'riscv.sltu' class-attribute instance-attribute

BitwiseAndHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
2022
2023
2024
2025
2026
2027
2028
2029
2030
class BitwiseAndHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            BitwiseAndBySelf,
            BitwiseAndByZero,
        )

        return (BitwiseAndByZero(), BitwiseAndBySelf())

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
2023
2024
2025
2026
2027
2028
2029
2030
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        BitwiseAndBySelf,
        BitwiseAndByZero,
    )

    return (BitwiseAndByZero(), BitwiseAndBySelf())

AndOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs bitwise AND on registers rs1 and rs2 and place the result in rd.

x[rd] = x[rs1] & x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
@irdl_op_definition
class AndOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs bitwise AND on registers rs1 and rs2 and place the result in rd.

    x[rd] = x[rs1] & x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#and).
    """

    name = "riscv.and"

    traits = traits_def(BitwiseAndHasCanonicalizationPatternsTrait())

name = 'riscv.and' class-attribute instance-attribute

traits = traits_def(BitwiseAndHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

BitwiseOrHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
2048
2049
2050
2051
2052
2053
2054
2055
2056
class BitwiseOrHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            BitwiseOrBySelf,
            BitwiseOrByZero,
        )

        return (BitwiseOrByZero(), BitwiseOrBySelf())

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
2049
2050
2051
2052
2053
2054
2055
2056
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        BitwiseOrBySelf,
        BitwiseOrByZero,
    )

    return (BitwiseOrByZero(), BitwiseOrBySelf())

OrOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs bitwise OR on registers rs1 and rs2 and place the result in rd.

x[rd] = x[rs1] | x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
@irdl_op_definition
class OrOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs bitwise OR on registers rs1 and rs2 and place the result in rd.

    x[rd] = x[rs1] | x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#or).
    """

    name = "riscv.or"

    traits = traits_def(BitwiseOrHasCanonicalizationPatternsTrait())

name = 'riscv.or' class-attribute instance-attribute

traits = traits_def(BitwiseOrHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

BitwiseXorHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
2074
2075
2076
2077
2078
2079
2080
2081
2082
class BitwiseXorHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            BitwiseXorByZero,
            XorBySelf,
        )

        return (XorBySelf(), BitwiseXorByZero())

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
2075
2076
2077
2078
2079
2080
2081
2082
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        BitwiseXorByZero,
        XorBySelf,
    )

    return (XorBySelf(), BitwiseXorByZero())

XorOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs bitwise XOR on registers rs1 and rs2 and place the result in rd.

x[rd] = x[rs1] ^ x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
@irdl_op_definition
class XorOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs bitwise XOR on registers rs1 and rs2 and place the result in rd.

    x[rd] = x[rs1] ^ x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#xor).
    """

    name = "riscv.xor"

    traits = traits_def(BitwiseXorHasCanonicalizationPatternsTrait())

name = 'riscv.xor' class-attribute instance-attribute

traits = traits_def(BitwiseXorHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

SllOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs logical left shift on the value in register rs1 by the shift amount held in the lower 5 bits of register rs2.

x[rd] = x[rs1] << x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
@irdl_op_definition
class SllOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs logical left shift on the value in register rs1 by the shift amount
    held in the lower 5 bits of register rs2.

    x[rd] = x[rs1] << x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sll).
    """

    name = "riscv.sll"

name = 'riscv.sll' class-attribute instance-attribute

SrlOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Logical right shift on the value in register rs1 by the shift amount held in the lower 5 bits of register rs2.

x[rd] = x[rs1] >>u x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
@irdl_op_definition
class SrlOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Logical right shift on the value in register rs1 by the shift amount held
    in the lower 5 bits of register rs2.

    x[rd] = x[rs1] >>u x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#srl).
    """

    name = "riscv.srl"

name = 'riscv.srl' class-attribute instance-attribute

SubOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
class SubOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            SubAddi,
            SubBySelf,
            SubImmediates,
        )

        return (SubImmediates(), SubAddi(), SubBySelf())

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
2129
2130
2131
2132
2133
2134
2135
2136
2137
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        SubAddi,
        SubBySelf,
        SubImmediates,
    )

    return (SubImmediates(), SubAddi(), SubBySelf())

SubOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Subtracts the registers rs1 and rs2 and stores the result in rd. Arithmetic overflow is ignored and the result is simply the low XLEN bits of the result.

x[rd] = x[rs1] - x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
@irdl_op_definition
class SubOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Subtracts the registers rs1 and rs2 and stores the result in rd.
    Arithmetic overflow is ignored and the result is simply the low XLEN bits of the result.

    x[rd] = x[rs1] - x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sub).
    """

    name = "riscv.sub"

    traits = traits_def(SubOpHasCanonicalizationPatternsTrait())

name = 'riscv.sub' class-attribute instance-attribute

traits = traits_def(SubOpHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

SraOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs arithmetic right shift on the value in register rs1 by the shift amount held in the lower 5 bits of register rs2.

x[rd] = x[rs1] >>s x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
@irdl_op_definition
class SraOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs arithmetic right shift on the value in register rs1 by the shift amount held
    in the lower 5 bits of register rs2.

    x[rd] = x[rs1] >>s x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sub).
    """

    name = "riscv.sra"

name = 'riscv.sra' class-attribute instance-attribute

NopOp dataclass

Bases: NullaryOperation

Does not change any user-visible state, except for advancing the pc register. Canonical nop is encoded as addi x0, x0, 0.

Source code in xdsl/dialects/riscv.py
2170
2171
2172
2173
2174
2175
2176
2177
@irdl_op_definition
class NopOp(NullaryOperation):
    """
    Does not change any user-visible state, except for advancing the pc register.
    Canonical nop is encoded as addi x0, x0, 0.
    """

    name = "riscv.nop"

name = 'riscv.nop' class-attribute instance-attribute

JalOp dataclass

Bases: RdImmJumpOperation

Jump to address and place return address in rd.

jal mylabel is a pseudoinstruction for jal ra, mylabel

x[rd] = pc+4; pc += sext(offset)

See external documentation.

Source code in xdsl/dialects/riscv.py
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
@irdl_op_definition
class JalOp(RdImmJumpOperation):
    """
    Jump to address and place return address in rd.

    jal mylabel is a pseudoinstruction for jal ra, mylabel

    x[rd] = pc+4; pc += sext(offset)

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#jal).
    """

    name = "riscv.jal"

name = 'riscv.jal' class-attribute instance-attribute

JOp

Bases: RdImmJumpOperation

A pseudo-instruction, for unconditional jumps you don't expect to return from. Is equivalent to JalOp with rd = x0. Used to be a part of the spec, removed in 2.0.

Source code in xdsl/dialects/riscv.py
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
@irdl_op_definition
class JOp(RdImmJumpOperation):
    """
    A pseudo-instruction, for unconditional jumps you don't expect to return from.
    Is equivalent to JalOp with `rd` = `x0`.
    Used to be a part of the spec, removed in 2.0.
    """

    name = "riscv.j"

    def __init__(
        self,
        immediate: int | SImm20Attr | str | LabelAttr,
        *,
        comment: str | StringAttr | None = None,
    ):
        super().__init__(immediate, rd=Registers.ZERO, comment=comment)

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        # J op is a special case of JalOp with zero return register
        return (self.immediate,)

name = 'riscv.j' class-attribute instance-attribute

__init__(immediate: int | SImm20Attr | str | LabelAttr, *, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
2212
2213
2214
2215
2216
2217
2218
def __init__(
    self,
    immediate: int | SImm20Attr | str | LabelAttr,
    *,
    comment: str | StringAttr | None = None,
):
    super().__init__(immediate, rd=Registers.ZERO, comment=comment)

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
2220
2221
2222
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    # J op is a special case of JalOp with zero return register
    return (self.immediate,)

JalrOp dataclass

Bases: RdRsImmJumpOperation

Jump to address and place return address in rd.

t = pc+4
pc = (x[rs1] + sext(offset)) & ~1
x[rd] = t

See external documentation.

Source code in xdsl/dialects/riscv.py
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
@irdl_op_definition
class JalrOp(RdRsImmJumpOperation):
    """
    Jump to address and place return address in rd.

    ```C
    t = pc+4
    pc = (x[rs1] + sext(offset)) & ~1
    x[rd] = t
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#jalr).
    """

    name = "riscv.jalr"

name = 'riscv.jalr' class-attribute instance-attribute

ReturnOp dataclass

Bases: NullaryOperation

Pseudo-op for returning from subroutine.

Equivalent to jalr x0, x1, 0

Source code in xdsl/dialects/riscv.py
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
@irdl_op_definition
class ReturnOp(NullaryOperation):
    """
    Pseudo-op for returning from subroutine.

    Equivalent to `jalr x0, x1, 0`
    """

    name = "riscv.ret"

    traits = traits_def(IsTerminator())

name = 'riscv.ret' class-attribute instance-attribute

traits = traits_def(IsTerminator()) class-attribute instance-attribute

BeqOp dataclass

Bases: RsRsOffIntegerOperation

Take the branch if registers rs1 and rs2 are equal.

if (x[rs1] == x[rs2]) pc += sext(offset)

See external documentation.

Source code in xdsl/dialects/riscv.py
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
@irdl_op_definition
class BeqOp(RsRsOffIntegerOperation):
    """
    Take the branch if registers rs1 and rs2 are equal.

    ```C
    if (x[rs1] == x[rs2]) pc += sext(offset)
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#beq).
    """

    name = "riscv.beq"

name = 'riscv.beq' class-attribute instance-attribute

BneOp dataclass

Bases: RsRsOffIntegerOperation

Take the branch if registers rs1 and rs2 are not equal.

if (x[rs1] != x[rs2]) pc += sext(offset)

See external documentation.

Source code in xdsl/dialects/riscv.py
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
@irdl_op_definition
class BneOp(RsRsOffIntegerOperation):
    """
    Take the branch if registers rs1 and rs2 are not equal.

    ```C
    if (x[rs1] != x[rs2]) pc += sext(offset)
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#bne).
    """

    name = "riscv.bne"

name = 'riscv.bne' class-attribute instance-attribute

BltOp dataclass

Bases: RsRsOffIntegerOperation

Take the branch if registers rs1 is less than rs2, using signed comparison.

if (x[rs1] <s x[rs2]) pc += sext(offset)

See external documentation.

Source code in xdsl/dialects/riscv.py
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
@irdl_op_definition
class BltOp(RsRsOffIntegerOperation):
    """
    Take the branch if registers rs1 is less than rs2, using signed comparison.

    ```C
    if (x[rs1] <s x[rs2]) pc += sext(offset)
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#blt).
    """

    name = "riscv.blt"

name = 'riscv.blt' class-attribute instance-attribute

BgeOp dataclass

Bases: RsRsOffIntegerOperation

Take the branch if registers rs1 is greater than or equal to rs2, using signed comparison.

if (x[rs1] >=s x[rs2]) pc += sext(offset)

See external documentation.

Source code in xdsl/dialects/riscv.py
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
@irdl_op_definition
class BgeOp(RsRsOffIntegerOperation):
    """
    Take the branch if registers rs1 is greater than or equal to rs2, using signed comparison.

    ```C
    if (x[rs1] >=s x[rs2]) pc += sext(offset)
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#bge).
    """

    name = "riscv.bge"

name = 'riscv.bge' class-attribute instance-attribute

BltuOp dataclass

Bases: RsRsOffIntegerOperation

Take the branch if registers rs1 is less than rs2, using unsigned comparison.

if (x[rs1] <u x[rs2]) pc += sext(offset)

See external documentation.

Source code in xdsl/dialects/riscv.py
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
@irdl_op_definition
class BltuOp(RsRsOffIntegerOperation):
    """
    Take the branch if registers rs1 is less than rs2, using unsigned comparison.

    ```C
    if (x[rs1] <u x[rs2]) pc += sext(offset)
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#bltu).
    """

    name = "riscv.bltu"

name = 'riscv.bltu' class-attribute instance-attribute

BgeuOp dataclass

Bases: RsRsOffIntegerOperation

Take the branch if registers rs1 is greater than or equal to rs2, using unsigned comparison.

if (x[rs1] >=u x[rs2]) pc += sext(offset)

See external documentation.

Source code in xdsl/dialects/riscv.py
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
@irdl_op_definition
class BgeuOp(RsRsOffIntegerOperation):
    """
    Take the branch if registers rs1 is greater than or equal to rs2, using unsigned comparison.

    ```C
    if (x[rs1] >=u x[rs2]) pc += sext(offset)
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#bgeu).
    """

    name = "riscv.bgeu"

name = 'riscv.bgeu' class-attribute instance-attribute

LbOp dataclass

Bases: RdRsImmIntegerOperation

Loads a 8-bit value from memory and sign-extends this to XLEN bits before storing it in register rd.

x[rd] = sext(M[x[rs1] + sext(offset)][7:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
@irdl_op_definition
class LbOp(RdRsImmIntegerOperation):
    """
    Loads a 8-bit value from memory and sign-extends this to XLEN bits before
    storing it in register rd.

    ```C
    x[rd] = sext(M[x[rs1] + sext(offset)][7:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#lb).
    """

    name = "riscv.lb"

name = 'riscv.lb' class-attribute instance-attribute

LbuOp dataclass

Bases: RdRsImmIntegerOperation

Loads a 8-bit value from memory and zero-extends this to XLEN bits before storing it in register rd.

x[rd] = M[x[rs1] + sext(offset)][7:0]

See external documentation.

Source code in xdsl/dialects/riscv.py
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
@irdl_op_definition
class LbuOp(RdRsImmIntegerOperation):
    """
    Loads a 8-bit value from memory and zero-extends this to XLEN bits before
    storing it in register rd.

    ```C
    x[rd] = M[x[rs1] + sext(offset)][7:0]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#lbu).
    """

    name = "riscv.lbu"

name = 'riscv.lbu' class-attribute instance-attribute

LhOp dataclass

Bases: RdRsImmIntegerOperation

Loads a 16-bit value from memory and sign-extends this to XLEN bits before storing it in register rd.

x[rd] = sext(M[x[rs1] + sext(offset)][15:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
@irdl_op_definition
class LhOp(RdRsImmIntegerOperation):
    """
    Loads a 16-bit value from memory and sign-extends this to XLEN bits before
    storing it in register rd.

    ```C
    x[rd] = sext(M[x[rs1] + sext(offset)][15:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#lh).
    """

    name = "riscv.lh"

name = 'riscv.lh' class-attribute instance-attribute

LhuOp dataclass

Bases: RdRsImmIntegerOperation

Loads a 16-bit value from memory and zero-extends this to XLEN bits before storing it in register rd.

x[rd] = M[x[rs1] + sext(offset)][15:0]

See external documentation.

Source code in xdsl/dialects/riscv.py
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
@irdl_op_definition
class LhuOp(RdRsImmIntegerOperation):
    """
    Loads a 16-bit value from memory and zero-extends this to XLEN bits before
    storing it in register rd.

    ```C
    x[rd] = M[x[rs1] + sext(offset)][15:0]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#lhu).
    """

    name = "riscv.lhu"

name = 'riscv.lhu' class-attribute instance-attribute

LwOpHasCanonicalizationPatternTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
2417
2418
2419
2420
2421
2422
2423
2424
class LwOpHasCanonicalizationPatternTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            LoadWordWithKnownOffset,
        )

        return (LoadWordWithKnownOffset(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
2418
2419
2420
2421
2422
2423
2424
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        LoadWordWithKnownOffset,
    )

    return (LoadWordWithKnownOffset(),)

LwOp dataclass

Bases: RdRsImmIntegerOperation

Loads a 32-bit value from memory and sign-extends this to XLEN bits before storing it in register rd.

x[rd] = sext(M[x[rs1] + sext(offset)][31:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
@irdl_op_definition
class LwOp(RdRsImmIntegerOperation):
    """
    Loads a 32-bit value from memory and sign-extends this to XLEN bits before
    storing it in register rd.

    ```C
    x[rd] = sext(M[x[rs1] + sext(offset)][31:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#lw).
    """

    name = "riscv.lw"

    traits = traits_def(LwOpHasCanonicalizationPatternTrait())

    def assembly_line(self) -> str | None:
        instruction_name = self.assembly_instruction_name()
        value = _assembly_arg_str(self.rd)
        imm = _assembly_arg_str(self.immediate)
        offset = _assembly_arg_str(self.rs1)
        return AssemblyPrinter.assembly_line(
            instruction_name, f"{value}, {imm}({offset})", self.comment
        )

name = 'riscv.lw' class-attribute instance-attribute

traits = traits_def(LwOpHasCanonicalizationPatternTrait()) class-attribute instance-attribute

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
2444
2445
2446
2447
2448
2449
2450
2451
def assembly_line(self) -> str | None:
    instruction_name = self.assembly_instruction_name()
    value = _assembly_arg_str(self.rd)
    imm = _assembly_arg_str(self.immediate)
    offset = _assembly_arg_str(self.rs1)
    return AssemblyPrinter.assembly_line(
        instruction_name, f"{value}, {imm}({offset})", self.comment
    )

SbOp dataclass

Bases: RsRsImmIntegerOperation

Store 8-bit, values from the low bits of register rs2 to memory.

M[x[rs1] + sext(offset)] = x[rs2][7:0]

See external documentation.

Source code in xdsl/dialects/riscv.py
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
@irdl_op_definition
class SbOp(RsRsImmIntegerOperation):
    """
    Store 8-bit, values from the low bits of register rs2 to memory.

    ```C
    M[x[rs1] + sext(offset)] = x[rs2][7:0]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sb).
    """

    name = "riscv.sb"

name = 'riscv.sb' class-attribute instance-attribute

ShOp dataclass

Bases: RsRsImmIntegerOperation

Store 16-bit, values from the low bits of register rs2 to memory.

M[x[rs1] + sext(offset)] = x[rs2][15:0]

See external documentation.

Source code in xdsl/dialects/riscv.py
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
@irdl_op_definition
class ShOp(RsRsImmIntegerOperation):
    """
    Store 16-bit, values from the low bits of register rs2 to memory.

    ```C
    M[x[rs1] + sext(offset)] = x[rs2][15:0]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sh).

    """

    name = "riscv.sh"

name = 'riscv.sh' class-attribute instance-attribute

SwOpHasCanonicalizationPatternTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
2485
2486
2487
2488
2489
2490
2491
2492
class SwOpHasCanonicalizationPatternTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            StoreWordWithKnownOffset,
        )

        return (StoreWordWithKnownOffset(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
2486
2487
2488
2489
2490
2491
2492
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        StoreWordWithKnownOffset,
    )

    return (StoreWordWithKnownOffset(),)

SwOp dataclass

Bases: RsRsImmIntegerOperation

Store 32-bit, values from the low bits of register rs2 to memory.

M[x[rs1] + sext(offset)] = x[rs2][31:0]

See external documentation.

Source code in xdsl/dialects/riscv.py
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
@irdl_op_definition
class SwOp(RsRsImmIntegerOperation):
    """
    Store 32-bit, values from the low bits of register rs2 to memory.

    ```C
    M[x[rs1] + sext(offset)] = x[rs2][31:0]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#sw).
    """

    name = "riscv.sw"

    traits = traits_def(SwOpHasCanonicalizationPatternTrait())

    def assembly_line(self) -> str | None:
        instruction_name = self.assembly_instruction_name()
        value = _assembly_arg_str(self.rs2)
        imm = _assembly_arg_str(self.immediate)
        offset = _assembly_arg_str(self.rs1)
        return AssemblyPrinter.assembly_line(
            instruction_name, f"{value}, {imm}({offset})", self.comment
        )

name = 'riscv.sw' class-attribute instance-attribute

traits = traits_def(SwOpHasCanonicalizationPatternTrait()) class-attribute instance-attribute

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
2511
2512
2513
2514
2515
2516
2517
2518
def assembly_line(self) -> str | None:
    instruction_name = self.assembly_instruction_name()
    value = _assembly_arg_str(self.rs2)
    imm = _assembly_arg_str(self.immediate)
    offset = _assembly_arg_str(self.rs1)
    return AssemblyPrinter.assembly_line(
        instruction_name, f"{value}, {imm}({offset})", self.comment
    )

CsrrwOp dataclass

Bases: CsrReadWriteOperation

Atomically swaps values in the CSRs and integer registers. CSRRW reads the old value of the CSR, zero-extends the value to XLEN bits, then writes it to integer register rd. The initial value in rs1 is written to the CSR. If the 'writeonly' attribute evaluates to False, then the instruction shall not read the CSR and shall not cause any of the side effects that might occur on a CSR read; in this case rd must be allocated to x0.

t = CSRs[csr]; CSRs[csr] = x[rs1]; x[rd] = t

See external documentation.

Source code in xdsl/dialects/riscv.py
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
@irdl_op_definition
class CsrrwOp(CsrReadWriteOperation):
    """
    Atomically swaps values in the CSRs and integer registers.
    CSRRW reads the old value of the CSR, zero-extends the value to XLEN bits,
    then writes it to integer register rd. The initial value in rs1 is written
    to the CSR. If the 'writeonly' attribute evaluates to False, then the
    instruction shall not read the CSR and shall not cause any of the side effects
    that might occur on a CSR read; in this case rd *must be allocated to x0*.

    t = CSRs[csr]; CSRs[csr] = x[rs1]; x[rd] = t

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#csrrw).
    """

    name = "riscv.csrrw"

name = 'riscv.csrrw' class-attribute instance-attribute

CsrrsOp dataclass

Bases: CsrBitwiseOperation

Reads the value of the CSR, zero-extends the value to XLEN bits, and writes it to integer register rd. The initial value in integer register rs1 is treated as a bit mask that specifies bit positions to be set in the CSR. Any bit that is high in rs1 will cause the corresponding bit to be set in the CSR, if that CSR bit is writable. Other bits in the CSR are unaffected (though CSRs might have side effects when written).

If the 'readonly' attribute evaluates to True, then the instruction will not write to the CSR at all, and so shall not cause any of the side effects that might otherwise occur on a CSR write, such as raising illegal instruction exceptions on accesses to read-only CSRs. Note that if rs1 specifies a register holding a zero value other than x0, the instruction will still attempt to write the unmodified value back to the CSR and will cause any attendant side effects.

t = CSRs[csr]; CSRs[csr] = t | x[rs1]; x[rd] = t

See external documentation.

Source code in xdsl/dialects/riscv.py
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
@irdl_op_definition
class CsrrsOp(CsrBitwiseOperation):
    """
    Reads the value of the CSR, zero-extends the value to XLEN bits, and writes
    it to integer register rd. The initial value in integer register rs1 is treated
    as a bit mask that specifies bit positions to be set in the CSR.
    Any bit that is high in rs1 will cause the corresponding bit to be set in the CSR,
    if that CSR bit is writable. Other bits in the CSR are unaffected (though CSRs might
    have side effects when written).

    If the 'readonly' attribute evaluates to True, then the instruction will not write
    to the CSR at all, and so shall not cause any of the side effects that might otherwise
    occur on a CSR write, such as raising illegal instruction exceptions on accesses to
    read-only CSRs. Note that if rs1 specifies a register holding a zero value other than x0,
    the instruction will still attempt to write the unmodified value back to the CSR and will
    cause any attendant side effects.

    t = CSRs[csr]; CSRs[csr] = t | x[rs1]; x[rd] = t

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#csrrs).
    """

    name = "riscv.csrrs"

name = 'riscv.csrrs' class-attribute instance-attribute

CsrrcOp dataclass

Bases: CsrBitwiseOperation

Reads the value of the CSR, zero-extends the value to XLEN bits, and writes it to integer register rd. The initial value in integer register rs1 is treated as a bit mask that specifies bit positions to be cleared in the CSR. Any bit that is high in rs1 will cause the corresponding bit to be cleared in the CSR, if that CSR bit is writable. Other bits in the CSR are unaffected (though CSRs might have side effects when written).

If the 'readonly' attribute evaluates to True, then the instruction will not write to the CSR at all, and so shall not cause any of the side effects that might otherwise occur on a CSR write, such as raising illegal instruction exceptions on accesses to read-only CSRs. Note that if rs1 specifies a register holding a zero value other than x0, the instruction will still attempt to write the unmodified value back to the CSR and will cause any attendant side effects.

t = CSRs[csr]; CSRs[csr] = t &~x[rs1]; x[rd] = t

See external documentation.

Source code in xdsl/dialects/riscv.py
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
@irdl_op_definition
class CsrrcOp(CsrBitwiseOperation):
    """
    Reads the value of the CSR, zero-extends the value to XLEN bits, and writes
    it to integer register rd. The initial value in integer register rs1 is treated
    as a bit mask that specifies bit positions to be cleared in the CSR.
    Any bit that is high in rs1 will cause the corresponding bit to be cleared in the CSR,
    if that CSR bit is writable. Other bits in the CSR are unaffected (though CSRs might
    have side effects when written).

    If the 'readonly' attribute evaluates to True, then the instruction will not write
    to the CSR at all, and so shall not cause any of the side effects that might otherwise
    occur on a CSR write, such as raising illegal instruction exceptions on accesses to
    read-only CSRs. Note that if rs1 specifies a register holding a zero value other than x0,
    the instruction will still attempt to write the unmodified value back to the CSR and will
    cause any attendant side effects.

    t = CSRs[csr]; CSRs[csr] = t &~x[rs1]; x[rd] = t

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#csrrc).
    """

    name = "riscv.csrrc"

name = 'riscv.csrrc' class-attribute instance-attribute

CsrrwiOp dataclass

Bases: CsrReadWriteImmOperation

Update the CSR using an XLEN-bit value obtained by zero-extending the 'immediate' attribute. If the 'writeonly' attribute evaluates to False, then the instruction shall not read the CSR and shall not cause any of the side effects that might occur on a CSR read; in this case rd must be allocated to x0.

x[rd] = CSRs[csr]; CSRs[csr] = zimm

See external documentation.

Source code in xdsl/dialects/riscv.py
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
@irdl_op_definition
class CsrrwiOp(CsrReadWriteImmOperation):
    """
    Update the CSR using an XLEN-bit value obtained by zero-extending the
    'immediate' attribute.
    If the 'writeonly' attribute evaluates to False, then the
    instruction shall not read the CSR and shall not cause any of the side effects
    that might occur on a CSR read; in this case rd *must be allocated to x0*.

    x[rd] = CSRs[csr]; CSRs[csr] = zimm

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#csrrwi).
    """

    name = "riscv.csrrwi"

name = 'riscv.csrrwi' class-attribute instance-attribute

CsrrsiOp dataclass

Bases: CsrBitwiseImmOperation

Reads the value of the CSR, zero-extends the value to XLEN bits, and writes it to integer register rd. The value in the 'immediate' attribute is treated as a bit mask that specifies bit positions to be set in the CSR. Any bit that is high in it will cause the corresponding bit to be set in the CSR, if that CSR bit is writable. Other bits in the CSR are unaffected (though CSRs might have side effects when written).

If the 'immediate' attribute value is zero, then the instruction will not write to the CSR at all, and so shall not cause any of the side effects that might otherwise occur on a CSR write, such as raising illegal instruction exceptions on accesses to read-only CSRs.

t = CSRs[csr]; CSRs[csr] = t | zimm; x[rd] = t

See external documentation.

Source code in xdsl/dialects/riscv.py
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
@irdl_op_definition
class CsrrsiOp(CsrBitwiseImmOperation):
    """
    Reads the value of the CSR, zero-extends the value to XLEN bits, and writes
    it to integer register rd. The value in the 'immediate' attribute is treated
    as a bit mask that specifies bit positions to be set in the CSR.
    Any bit that is high in it will cause the corresponding bit to be set in the CSR,
    if that CSR bit is writable. Other bits in the CSR are unaffected (though CSRs might
    have side effects when written).

    If the 'immediate' attribute value is zero, then the instruction will not write
    to the CSR at all, and so shall not cause any of the side effects that might otherwise
    occur on a CSR write, such as raising illegal instruction exceptions on accesses to
    read-only CSRs.

    t = CSRs[csr]; CSRs[csr] = t | zimm; x[rd] = t

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#csrrsi).
    """

    name = "riscv.csrrsi"

name = 'riscv.csrrsi' class-attribute instance-attribute

CsrrciOp dataclass

Bases: CsrBitwiseImmOperation

Reads the value of the CSR, zero-extends the value to XLEN bits, and writes it to integer register rd. The value in the 'immediate' attribute is treated as a bit mask that specifies bit positions to be cleared in the CSR. Any bit that is high in rs1 will cause the corresponding bit to be cleared in the CSR, if that CSR bit is writable. Other bits in the CSR are unaffected (though CSRs might have side effects when written).

If the 'immediate' attribute value is zero, then the instruction will not write to the CSR at all, and so shall not cause any of the side effects that might otherwise occur on a CSR write, such as raising illegal instruction exceptions on accesses to read-only CSRs.

t = CSRs[csr]; CSRs[csr] = t &~zimm; x[rd] = t

See external documentation.

Source code in xdsl/dialects/riscv.py
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
@irdl_op_definition
class CsrrciOp(CsrBitwiseImmOperation):
    """
    Reads the value of the CSR, zero-extends the value to XLEN bits, and writes
    it to integer register rd.  The value in the 'immediate' attribute is treated
    as a bit mask that specifies bit positions to be cleared in the CSR.
    Any bit that is high in rs1 will cause the corresponding bit to be cleared in the CSR,
    if that CSR bit is writable. Other bits in the CSR are unaffected (though CSRs might
    have side effects when written).

    If the 'immediate' attribute value is zero, then the instruction will not write
    to the CSR at all, and so shall not cause any of the side effects that might otherwise
    occur on a CSR write, such as raising illegal instruction exceptions on accesses to
    read-only CSRs.

    t = CSRs[csr]; CSRs[csr] = t &~zimm; x[rd] = t

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#csrrci).
    """

    name = "riscv.csrrci"

name = 'riscv.csrrci' class-attribute instance-attribute

MulOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
2664
2665
2666
2667
2668
2669
2670
2671
class MulOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            MultiplyImmediates,
        )

        return (MultiplyImmediates(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
2665
2666
2667
2668
2669
2670
2671
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        MultiplyImmediates,
    )

    return (MultiplyImmediates(),)

MulOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs an XLEN-bit × XLEN-bit multiplication of signed rs1 by signed rs2 and places the lower XLEN bits in the destination register. x[rd] = x[rs1] * x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
@irdl_op_definition
class MulOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs an XLEN-bit × XLEN-bit multiplication of signed rs1 by signed rs2
    and places the lower XLEN bits in the destination register.
    x[rd] = x[rs1] * x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvi.html#add).
    """

    name = "riscv.mul"

    traits = traits_def(MulOpHasCanonicalizationPatternsTrait(), Pure())

name = 'riscv.mul' class-attribute instance-attribute

traits = traits_def(MulOpHasCanonicalizationPatternsTrait(), Pure()) class-attribute instance-attribute

MulhOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs an XLEN-bit × XLEN-bit multiplication of signed rs1 by signed rs2 and places the upper XLEN bits in the destination register. x[rd] = (x[rs1] s×s x[rs2]) >>s XLEN

See external documentation.

Source code in xdsl/dialects/riscv.py
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
@irdl_op_definition
class MulhOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs an XLEN-bit × XLEN-bit multiplication of signed rs1 by signed rs2
    and places the upper XLEN bits in the destination register.
    x[rd] = (x[rs1] s×s x[rs2]) >>s XLEN

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvm.html#mulh).
    """

    name = "riscv.mulh"

name = 'riscv.mulh' class-attribute instance-attribute

MulhsuOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs an XLEN-bit × XLEN-bit multiplication of signed rs1 by unsigned rs2 and places the upper XLEN bits in the destination register. x[rd] = (x[rs1] s × x[rs2]) >>s XLEN

See external documentation.

Source code in xdsl/dialects/riscv.py
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
@irdl_op_definition
class MulhsuOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs an XLEN-bit × XLEN-bit multiplication of signed rs1 by unsigned rs2
    and places the upper XLEN bits in the destination register.
    x[rd] = (x[rs1] s × x[rs2]) >>s XLEN

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvm.html#mulhsu).
    """

    name = "riscv.mulhsu"

name = 'riscv.mulhsu' class-attribute instance-attribute

MulhuOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs an XLEN-bit × XLEN-bit multiplication of unsigned rs1 by unsigned rs2 and places the upper XLEN bits in the destination register. x[rd] = (x[rs1] u × x[rs2]) >>u XLEN

See external documentation.

Source code in xdsl/dialects/riscv.py
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
@irdl_op_definition
class MulhuOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs an XLEN-bit × XLEN-bit multiplication of unsigned rs1 by unsigned rs2
    and places the upper XLEN bits in the destination register.
    x[rd] = (x[rs1] u × x[rs2]) >>u XLEN

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvm.html#mulhu).
    """

    name = "riscv.mulhu"

name = 'riscv.mulhu' class-attribute instance-attribute

MulwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs an 32-bit × 32-bit multiplication of signed rs1 by signed rs2.

x[rd] = (x[rs1] s × x[rs2]) >>s XLEN

See external documentation.

Source code in xdsl/dialects/riscv.py
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
@irdl_op_definition
class MulwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs an 32-bit × 32-bit multiplication of signed rs1 by signed rs2.
    ```
    x[rd] = (x[rs1] s × x[rs2]) >>s XLEN
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvm.html#mulw).
    """

    name = "riscv.mulw"

name = 'riscv.mulw' class-attribute instance-attribute

DivOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
2742
2743
2744
2745
2746
2747
2748
2749
class DivOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            DivideByOneIdentity,
        )

        return (DivideByOneIdentity(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
2743
2744
2745
2746
2747
2748
2749
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        DivideByOneIdentity,
    )

    return (DivideByOneIdentity(),)

DivOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Perform an XLEN bits by XLEN bits signed integer division of rs1 by rs2, rounding towards zero. x[rd] = x[rs1] /s x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
@irdl_op_definition
class DivOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Perform an XLEN bits by XLEN bits signed integer division of rs1 by rs2,
    rounding towards zero.
    x[rd] = x[rs1] /s x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvm.html#div).
    """

    name = "riscv.div"
    traits = traits_def(DivOpHasCanonicalizationPatternsTrait(), Pure())

name = 'riscv.div' class-attribute instance-attribute

traits = traits_def(DivOpHasCanonicalizationPatternsTrait(), Pure()) class-attribute instance-attribute

DivuOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Perform an XLEN bits by XLEN bits unsigned integer division of rs1 by rs2, rounding towards zero. x[rd] = x[rs1] /u x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
@irdl_op_definition
class DivuOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Perform an XLEN bits by XLEN bits unsigned integer division of rs1 by rs2,
    rounding towards zero.
    x[rd] = x[rs1] /u x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvm.html#divu).
    """

    name = "riscv.divu"

name = 'riscv.divu' class-attribute instance-attribute

DivuwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Perform an 32 bits by 32 bits unsigned integer division of rs1 by rs2.

x[rd] = sext(x[rs1][31:0] /u x[rs2][31:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
@irdl_op_definition
class DivuwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Perform an 32 bits by 32 bits unsigned integer division of rs1 by rs2.
    ```
    x[rd] = sext(x[rs1][31:0] /u x[rs2][31:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rv64m.html#divuw).
    """

    name = "riscv.divuw"

name = 'riscv.divuw' class-attribute instance-attribute

DivwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Perform an 32 bits by 32 bits signed integer division of rs1 by rs2.

x[rd] = sext(x[rs1][31:0] /s x[rs2][31:0]

See external documentation.

Source code in xdsl/dialects/riscv.py
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
@irdl_op_definition
class DivwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Perform an 32 bits by 32 bits signed integer division of rs1 by rs2.
    ```
    x[rd] = sext(x[rs1][31:0] /s x[rs2][31:0]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvm.html#divw).
    """

    name = "riscv.divw"

name = 'riscv.divw' class-attribute instance-attribute

RemOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Perform an XLEN bits by XLEN bits signed integer reminder of rs1 by rs2. x[rd] = x[rs1] %s x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
@irdl_op_definition
class RemOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Perform an XLEN bits by XLEN bits signed integer reminder of rs1 by rs2.
    x[rd] = x[rs1] %s x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvm.html#rem).
    """

    name = "riscv.rem"

name = 'riscv.rem' class-attribute instance-attribute

RemuOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Perform an XLEN bits by XLEN bits unsigned integer reminder of rs1 by rs2. x[rd] = x[rs1] %u x[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
@irdl_op_definition
class RemuOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Perform an XLEN bits by XLEN bits unsigned integer reminder of rs1 by rs2.
    x[rd] = x[rs1] %u x[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvm.html#remu).
    """

    name = "riscv.remu"

name = 'riscv.remu' class-attribute instance-attribute

RemuwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Perform an 32 bits by 32 bits unsigned integer reminder of rs1 by rs2.

x[rd] = sext(x[rs1][31:0] %u x[rs2][31:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
@irdl_op_definition
class RemuwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Perform an 32 bits by 32 bits unsigned integer reminder of rs1 by rs2.
    ```
    x[rd] = sext(x[rs1][31:0] %u x[rs2][31:0])
    ```
    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rv64m.html#remuw).
    """

    name = "riscv.remuw"

name = 'riscv.remuw' class-attribute instance-attribute

RemwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Perform an 32 bits by 32 bits signed integer reminder of rs1 by rs2.

x[rd] = sext(x[rs1][31:0] %s x[rs2][31:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
@irdl_op_definition
class RemwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Perform an 32 bits by 32 bits signed integer reminder of rs1 by rs2.
    ```
    x[rd] = sext(x[rs1][31:0] %s x[rs2][31:0])
    ```
    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rv64m.html#remw).
    """

    name = "riscv.remw"

name = 'riscv.remw' class-attribute instance-attribute

RolOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs a rotate left of rs1 by the amount in least-significant log2(XLEN) bits of rs2.

let shamt = if   xlen == 32
                then x[rs2][4..0]
                else x[rs2][5..0];
let result = (x[rs1] << shamt) | (x[rs2] >> (xlen - shamt));
x[rd] = result;

See external documentation.

Source code in xdsl/dialects/riscv.py
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
@irdl_op_definition
class RolOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs a rotate left of rs1 by the amount in least-significant log2(XLEN) bits of rs2.
    ```
    let shamt = if   xlen == 32
                    then x[rs2][4..0]
                    else x[rs2][5..0];
    let result = (x[rs1] << shamt) | (x[rs2] >> (xlen - shamt));
    x[rd] = result;
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-rol).
    """

    name = "riscv.rol"

    traits = traits_def(Pure())

name = 'riscv.rol' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

RorOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Performs a rotate right of rs1 by the amount in least-significant log2(XLEN) bits of rs2.

let shamt = if   xlen == 32
            then x[rs2][4..0]
            else x[rs2][5..0];
let result = (x[rs1] >> shamt) | (x[rs2] << (xlen - shamt));
x[rd] = result;

See external documentation.

Source code in xdsl/dialects/riscv.py
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
@irdl_op_definition
class RorOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Performs a rotate right of rs1 by the amount in least-significant log2(XLEN) bits of rs2.
    ```
    let shamt = if   xlen == 32
                then x[rs2][4..0]
                else x[rs2][5..0];
    let result = (x[rs1] >> shamt) | (x[rs2] << (xlen - shamt));
    x[rd] = result;
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-ror).
    """

    name = "riscv.ror"

    traits = traits_def(Pure())

name = 'riscv.ror' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SextHOp dataclass

Bases: RdRsIntegerOperation[IntRegisterType]

This instruction sign-extends the least-significant halfword in rs to XLEN by copying the most-significant bit in the halfword (i.e., bit 15) to all of the more-significant bits.

x[rd] = EXTS(x[rs][15..0]);

See external documentation.

Source code in xdsl/dialects/riscv.py
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
@irdl_op_definition
class SextHOp(RdRsIntegerOperation[IntRegisterType]):
    """
    This instruction sign-extends the least-significant halfword in rs to XLEN by copying the
    most-significant bit in the halfword (i.e., bit 15) to all of the more-significant bits.
    ```
    x[rd] = EXTS(x[rs][15..0]);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-sext_h).
    """

    name = "riscv.sext.h"

    traits = traits_def(Pure())

name = 'riscv.sext.h' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

ZextHOp dataclass

Bases: RdRsIntegerOperation[IntRegisterType]

This instruction zero-extends the least-significant halfword of the source to XLEN by inserting 0’s into all of the bits more significant than 15.

x[rd] = EXTZ(x[rs][15..0]);

See external documentation.

Source code in xdsl/dialects/riscv.py
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
@irdl_op_definition
class ZextHOp(RdRsIntegerOperation[IntRegisterType]):
    """
    This instruction zero-extends the least-significant halfword of the source to XLEN by inserting
    0’s into all of the bits more significant than 15.
    ```
    x[rd] = EXTZ(x[rs][15..0]);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-zext_h).
    """

    name = "riscv.zext.h"

    traits = traits_def(Pure())

name = 'riscv.zext.h' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SextBOp dataclass

Bases: RdRsIntegerOperation[IntRegisterType]

This instruction sign-extends the least-significant byte in the source to XLEN by copying the most-significant bit in the byte (i.e., bit 7) to all of the more-significant bits.

X[rd] = EXTS(X[rs][7..0]);

See external documentation.

Source code in xdsl/dialects/riscv.py
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
@irdl_op_definition
class SextBOp(RdRsIntegerOperation[IntRegisterType]):
    """
    This instruction sign-extends the least-significant byte in the source to XLEN by copying
    the most-significant bit in the byte (i.e., bit 7) to all of the more-significant bits.
    ```
    X[rd] = EXTS(X[rs][7..0]);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-sext_b).
    """

    name = "riscv.sext.b"

    traits = traits_def(Pure())

name = 'riscv.sext.b' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

BclrOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction returns rs1 with a single bit cleared at the index specified in rs2. The index is read from the lower log2(XLEN) bits of rs2.

let index = X(rs2) & (XLEN - 1);
X(rd) = X(rs1) & ~(1 << index)

See external documentation.

Source code in xdsl/dialects/riscv.py
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
@irdl_op_definition
class BclrOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction returns rs1 with a single bit cleared at the index specified in rs2.
    The index is read from the lower log2(XLEN) bits of rs2.
    ```
    let index = X(rs2) & (XLEN - 1);
    X(rd) = X(rs1) & ~(1 << index)
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-bclr).
    """

    name = "riscv.bclr"

    traits = traits_def(Pure())

name = 'riscv.bclr' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

BclrIOp dataclass

Bases: RdRsImmShiftOperation

This instruction returns rs1 with a single bit cleared at the index specified in shamt. The index is read from the lower log2(XLEN) bits of shamt. For RV32, the encodings corresponding to shamt[5]=1 are reserved.

let index = shamt & (XLEN - 1);
X(rd) = X(rs1) & ~(1 << index)

See external documentation.

Source code in xdsl/dialects/riscv.py
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
@irdl_op_definition
class BclrIOp(RdRsImmShiftOperation):
    """
    This instruction returns rs1 with a single bit cleared at the index specified in shamt.
    The index is read from the lower log2(XLEN) bits of shamt. For RV32, the encodings corresponding
    to shamt[5]=1 are reserved.
    ```
    let index = shamt & (XLEN - 1);
    X(rd) = X(rs1) & ~(1 << index)
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-bclri).
    """

    name = "riscv.bclri"

    traits = traits_def(Pure())

name = 'riscv.bclri' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

BextOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction returns a single bit extracted from rs1 at the index specified in rs2. The index is read from the lower log2(XLEN) bits of rs2.

let index = X(rs2) & (XLEN - 1);
X(rd) = (X(rs1) >> index) & 1;

See external documentation.

Source code in xdsl/dialects/riscv.py
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
@irdl_op_definition
class BextOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction returns a single bit extracted from rs1 at the index specified in rs2.
    The index is read from the lower log2(XLEN) bits of rs2.
    ```
    let index = X(rs2) & (XLEN - 1);
    X(rd) = (X(rs1) >> index) & 1;
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-bext).
    """

    name = "riscv.bext"

    traits = traits_def(Pure())

name = 'riscv.bext' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

BextIOp dataclass

Bases: RdRsImmShiftOperation

This instruction returns a single bit extracted from rs1 at the index specified in rs2. The index is read from the lower log2(XLEN) bits of shamt. For RV32, the encodings corresponding to shamt[5]=1 are reserved.

let index = shamt & (XLEN - 1);
X(rd) = (X(rs1) >> index) & 1;

See external documentation.

Source code in xdsl/dialects/riscv.py
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
@irdl_op_definition
class BextIOp(RdRsImmShiftOperation):
    """
    This instruction returns a single bit extracted from rs1 at the index specified in rs2.
    The index is read from the lower log2(XLEN) bits of shamt. For RV32, the encodings corresponding
    to shamt[5]=1 are reserved.
    ```
    let index = shamt & (XLEN - 1);
    X(rd) = (X(rs1) >> index) & 1;
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-bexti).
    """

    name = "riscv.bexti"

    traits = traits_def(Pure())

name = 'riscv.bexti' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

BinvOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction returns rs1 with a single bit inverted at the index specified in shamt. The index is read from the lower log2(XLEN) bits of shamt. For RV32, the encodings corresponding to shamt[5]=1 are reserved.

let index = shamt & (XLEN - 1);
X(rd) = X(rs1) ^ (1 << index)

See external documentation.

Source code in xdsl/dialects/riscv.py
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
@irdl_op_definition
class BinvOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction returns rs1 with a single bit inverted at the index specified in shamt.
    The index is read from the lower log2(XLEN) bits of shamt. For RV32, the encodings
    corresponding to shamt[5]=1 are reserved.
    ```
    let index = shamt & (XLEN - 1);
    X(rd) = X(rs1) ^ (1 << index)
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-binvi).
    """

    name = "riscv.binv"

    traits = traits_def(Pure())

name = 'riscv.binv' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

BinvIOp dataclass

Bases: RdRsImmShiftOperation

This instruction returns rs1 with a single bit cleared at the index specified in shamt. The index is read from the lower log2(XLEN) bits of shamt. For RV32, the encodings corresponding to shamt[5]=1 are reserved.

let index = shamt & (XLEN - 1);
x[rd] = x[rs1] & ~(1 << index)

See external documentation.

Source code in xdsl/dialects/riscv.py
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
@irdl_op_definition
class BinvIOp(RdRsImmShiftOperation):
    """
    This instruction returns rs1 with a single bit cleared at the index specified in shamt. The index
    is read from the lower log2(XLEN) bits of shamt. For RV32, the encodings corresponding
    to shamt[5]=1 are reserved.
    ```
    let index = shamt & (XLEN - 1);
    x[rd] = x[rs1] & ~(1 << index)
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-binvi).
    """

    name = "riscv.binvi"

    traits = traits_def(Pure())

name = 'riscv.binvi' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

BsetOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction returns rs1 with a single bit set at the index specified in rs2. The index is read from the lower log2(XLEN) bits of rs2.

let index = X(rs2) & (XLEN - 1);
X(rd) = X(rs1) | (1 << index)

See external documentation.

Source code in xdsl/dialects/riscv.py
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
@irdl_op_definition
class BsetOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction returns rs1 with a single bit set at the index specified in rs2.
    The index is read from the lower log2(XLEN) bits of rs2.
    ```
    let index = X(rs2) & (XLEN - 1);
    X(rd) = X(rs1) | (1 << index)
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-bset).
    """

    name = "riscv.bset"

    traits = traits_def(Pure())

name = 'riscv.bset' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

BsetIOp dataclass

Bases: RdRsImmShiftOperation

This instruction returns rs1 with a single bit set at the index specified in shamt. The index is read from the lower log2(XLEN) bits of shamt. For RV32, the encodings corresponding to shamt[5]=1 are reserved.

let index = shamt & (XLEN - 1);
x[rd] = x[rs1] | (1 << index)

See external documentation.

Source code in xdsl/dialects/riscv.py
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
@irdl_op_definition
class BsetIOp(RdRsImmShiftOperation):
    """
    This instruction returns rs1 with a single bit set at the index specified in shamt. The index is read
    from the lower log2(XLEN) bits of shamt. For RV32, the encodings corresponding
    to shamt[5]=1 are reserved.
    ```
    let index = shamt & (XLEN - 1);
    x[rd] = x[rs1] | (1 << index)
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-bseti).
    """

    name = "riscv.bseti"

    traits = traits_def(Pure())

name = 'riscv.bseti' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

RolwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction performs a rotate left on the least-significant word of rs1 by the amount in least-significant 5 bits of rs2. The resulting word value is sign-extended by copying bit 31 to all of the more-significant bits.

let rs1 = EXTZ(X(rs1)[31..0])
let shamt = X(rs2)[4..0];
let result = (rs1 << shamt) | (rs1 >> (32 - shamt));
X(rd) = EXTS(result);

See external documentation.

Source code in xdsl/dialects/riscv.py
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
@irdl_op_definition
class RolwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction performs a rotate left on the least-significant word of rs1 by the amount in
    least-significant 5 bits of rs2. The resulting word value is sign-extended by copying bit 31
    to all of the more-significant bits.
    ```
    let rs1 = EXTZ(X(rs1)[31..0])
    let shamt = X(rs2)[4..0];
    let result = (rs1 << shamt) | (rs1 >> (32 - shamt));
    X(rd) = EXTS(result);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-rolw).
    """

    name = "riscv.rolw"

    traits = traits_def(Pure())

name = 'riscv.rolw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

RorwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction performs a rotate right on the least-significant word of rs1 by the amount in least-significant 5 bits of rs2. The resultant word is sign-extended by copying bit 31 to all of the more-significant bits.

let rs1 = EXTZ(X(rs1)[31..0])
let shamt = X(rs2)[4..0];
let result = (rs1 >> shamt) | (rs1 << (32 - shamt));
X(rd) = EXTS(result);

See external documentation.

Source code in xdsl/dialects/riscv.py
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
@irdl_op_definition
class RorwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction performs a rotate right on the least-significant word of rs1 by the amount in
    least-significant 5 bits of rs2. The resultant word is sign-extended by copying bit 31 to all of
    the more-significant bits.
    ```
    let rs1 = EXTZ(X(rs1)[31..0])
    let shamt = X(rs2)[4..0];
    let result = (rs1 >> shamt) | (rs1 << (32 - shamt));
    X(rd) = EXTS(result);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-rorw).
    """

    name = "riscv.rorw"

    traits = traits_def(Pure())

name = 'riscv.rorw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

RoriOp dataclass

Bases: RdRsImmShiftOperation

This instruction performs a rotate right of rs1 by the amount in the least-significant log2(XLEN) bits of shamt. For RV32, the encodings corresponding to shamt[5]=1 are reserved.

let shamt = if   xlen == 32
                then shamt[4..0]
                else shamt[5..0];
let result = (X(rs1) >> shamt) | (X(rs2) << (xlen - shamt));
X(rd) = result;

See external documentation.

Source code in xdsl/dialects/riscv.py
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
@irdl_op_definition
class RoriOp(RdRsImmShiftOperation):
    """
    This instruction performs a rotate right of rs1 by the amount in the least-significant
    log2(XLEN) bits of shamt. For RV32, the encodings corresponding to shamt[5]=1 are reserved.
    ```
    let shamt = if   xlen == 32
                    then shamt[4..0]
                    else shamt[5..0];
    let result = (X(rs1) >> shamt) | (X(rs2) << (xlen - shamt));
    X(rd) = result;
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-rori).
    """

    name = "riscv.rori"

    traits = traits_def(Pure())

name = 'riscv.rori' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

RoriwOp dataclass

Bases: RdRsImmShiftOperation

This instruction performs a rotate right on the least-significant word of rs1 by the amount in the least-significant log2(XLEN) bits of shamt. The resulting word value is sign-extended by copying bit 31 to all of the more-significant bits.

let rs1 = EXTZ(X(rs1)[31..0];
let result = (rs1 >> shamt[4..0]) | (X(rs1) << (32 - shamt[4..0]));
X(rd) = EXTS(result[31..0]);

See external documentation.

Source code in xdsl/dialects/riscv.py
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
@irdl_op_definition
class RoriwOp(RdRsImmShiftOperation):
    """
    This instruction performs a rotate right on the least-significant word of rs1 by the amount in
    the least-significant log2(XLEN) bits of shamt. The resulting word value is sign-extended by
    copying bit 31 to all of the more-significant bits.
    ```
    let rs1 = EXTZ(X(rs1)[31..0];
    let result = (rs1 >> shamt[4..0]) | (X(rs1) << (32 - shamt[4..0]));
    X(rd) = EXTS(result[31..0]);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-roriw).
    """

    name = "riscv.roriw"

    traits = traits_def(Pure())

name = 'riscv.roriw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

AddUwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction performs an XLEN-wide addition between rs2 and the zero-extended least-significant word of rs1.

let base = X(rs2);
let index = EXTZ(X(rs1)[31..0]);
X(rd) = base + index;

See external documentation.

Source code in xdsl/dialects/riscv.py
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
@irdl_op_definition
class AddUwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction performs an XLEN-wide addition between rs2 and the zero-extended least-significant
    word of rs1.
    ```
    let base = X(rs2);
    let index = EXTZ(X(rs1)[31..0]);
    X(rd) = base + index;
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-add_uw).
    """

    name = "riscv.add.uw"

    traits = traits_def(Pure())

name = 'riscv.add.uw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

Sh1addOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction shifts rs1 to the left by 1 bit and adds it to rs2.

X(rd) = X(rs2) + (X(rs1) << 1);

See external documentation.

Source code in xdsl/dialects/riscv.py
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
@irdl_op_definition
class Sh1addOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction shifts rs1 to the left by 1 bit and adds it to rs2.
    ```
    X(rd) = X(rs2) + (X(rs1) << 1);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-sh1add).
    """

    name = "riscv.sh1add"

    traits = traits_def(Pure())

name = 'riscv.sh1add' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

Sh2addOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction shifts rs1 to the left by 2 places and adds it to rs2.

X(rd) = X(rs2) + (X(rs1) << 2);

See external documentation.

Source code in xdsl/dialects/riscv.py
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
@irdl_op_definition
class Sh2addOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction shifts rs1 to the left by 2 places and adds it to rs2.
    ```
    X(rd) = X(rs2) + (X(rs1) << 2);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-sh2add).
    """

    name = "riscv.sh2add"

    traits = traits_def(Pure())

name = 'riscv.sh2add' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

Sh3addOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction shifts rs1 to the left by 2 places and adds it to rs2.

X(rd) = X(rs2) + (X(rs1) << 3);

See external documentation.

Source code in xdsl/dialects/riscv.py
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
@irdl_op_definition
class Sh3addOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction shifts rs1 to the left by 2 places and adds it to rs2.
    ```
    X(rd) = X(rs2) + (X(rs1) << 3);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-sh3add).
    """

    name = "riscv.sh3add"

    traits = traits_def(Pure())

name = 'riscv.sh3add' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

Sh1addUwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction performs an XLEN-wide addition of two addends. The first addend is rs2. The second addend is the unsigned value formed by extracting the least-significant word of rs1 and shifting it left by 1 place.

let base = x[rs2];
let index = EXTZ(x[rs1][31..0]);
x[rd] = base + (index << 1);

See external documentation.

Source code in xdsl/dialects/riscv.py
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
@irdl_op_definition
class Sh1addUwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction performs an XLEN-wide addition of two addends. The first addend is rs2.
    The second addend is the unsigned value formed by extracting the least-significant word of
    rs1 and shifting it left by 1 place.

    ```
    let base = x[rs2];
    let index = EXTZ(x[rs1][31..0]);
    x[rd] = base + (index << 1);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-sh1add_uw).
    """

    name = "riscv.sh1add.uw"

    traits = traits_def(Pure())

name = 'riscv.sh1add.uw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

Sh2addUwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction performs an XLEN-wide addition of two addends. The first addend is rs2. The second addend is the unsigned value formed by extracting the least-significant word of rs1 and shifting it left by 2 places.

let base = x[rs2];
let index = EXTZ(x[rs1][31..0]);
x[rd] = base + (index << 2);

See external documentation.

Source code in xdsl/dialects/riscv.py
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
@irdl_op_definition
class Sh2addUwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction performs an XLEN-wide addition of two addends. The first addend is rs2.
    The second addend is the unsigned value formed by extracting the least-significant word of rs1
    and shifting it left by 2 places.
    ```
    let base = x[rs2];
    let index = EXTZ(x[rs1][31..0]);
    x[rd] = base + (index << 2);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-sh2add_uw).
    """

    name = "riscv.sh2add.uw"

    traits = traits_def(Pure())

name = 'riscv.sh2add.uw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

Sh3addUwOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction performs an XLEN-wide addition of two addends. The first addend is rs2. The second addend is the unsigned value formed by extracting the least-significant word of rs1 and shifting it left by 3 places.

let base = x[rs2];
let index = EXTZ(x[rs1][31..0]);
x[rd] = base + (index << 3);

See external documentation.

Source code in xdsl/dialects/riscv.py
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
@irdl_op_definition
class Sh3addUwOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction performs an XLEN-wide addition of two addends. The first addend is rs2.
    The second addend is the unsigned value formed by extracting the least-significant word of rs1
    and shifting it left by 3 places.

    ```
    let base = x[rs2];
    let index = EXTZ(x[rs1][31..0]);
    x[rd] = base + (index << 3);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-sh3add_uw).
    """

    name = "riscv.sh3add.uw"

    traits = traits_def(Pure())

name = 'riscv.sh3add.uw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

SlliUwOp dataclass

Bases: RdRsImmShiftOperation

This instruction takes the least-significant word of rs1, zero-extends it, and shifts it left by the immediate.

x[rd] = (EXTZ(x[rs][31..0]) << shamt);

See external documentation.

Source code in xdsl/dialects/riscv.py
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
@irdl_op_definition
class SlliUwOp(RdRsImmShiftOperation):
    """
    This instruction takes the least-significant word of rs1, zero-extends it,
    and shifts it left by the immediate.
    ```
    x[rd] = (EXTZ(x[rs][31..0]) << shamt);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-slli_uw).
    """

    name = "riscv.slli.uw"

    traits = traits_def(Pure())

name = 'riscv.slli.uw' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

AndnOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction performs the bitwise logical AND operation between rs1 and the bitwise inversion of rs2.

X(rd) = X(rs1) & ~X(rs2);

See external documentation.

Source code in xdsl/dialects/riscv.py
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
@irdl_op_definition
class AndnOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction performs the bitwise logical AND operation between rs1 and the bitwise inversion of rs2.
    ```
    X(rd) = X(rs1) & ~X(rs2);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-andn).
    """

    name = "riscv.andn"

    traits = traits_def(Pure())

name = 'riscv.andn' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

OrnOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction performs the bitwise logical OR operation between rs1 and the bitwise inversion of rs2.

X(rd) = X(rs1) | ~X(rs2);

See external documentation.

Source code in xdsl/dialects/riscv.py
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
@irdl_op_definition
class OrnOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction performs the bitwise logical OR operation between rs1 and the bitwise inversion of rs2.
    ```
    X(rd) = X(rs1) | ~X(rs2);
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-orn).
    """

    name = "riscv.orn"

    traits = traits_def(Pure())

name = 'riscv.orn' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

XnorOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction performs the bit-wise exclusive-NOR operation on rs1 and rs2.

X(rd) = ~(X(rs1) ^ X(rs2));

See external documentation.

Source code in xdsl/dialects/riscv.py
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
@irdl_op_definition
class XnorOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction performs the bit-wise exclusive-NOR operation on rs1 and rs2.
    ```
    X(rd) = ~(X(rs1) ^ X(rs2));
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-xnor).
    """

    name = "riscv.xnor"

    traits = traits_def(Pure())

name = 'riscv.xnor' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MaxOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction returns the larger of two signed integers.

let rs1_val = X(rs1);
let rs2_val = X(rs2);

let result = if   rs1_val <_s rs2_val
                then rs2_val
                else rs1_val;
X(rd) = result;

See external documentation.

Source code in xdsl/dialects/riscv.py
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
@irdl_op_definition
class MaxOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction returns the larger of two signed integers.
    ```
    let rs1_val = X(rs1);
    let rs2_val = X(rs2);

    let result = if   rs1_val <_s rs2_val
                    then rs2_val
                    else rs1_val;
    X(rd) = result;
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-max).
    """

    name = "riscv.max"

    traits = traits_def(Pure())

name = 'riscv.max' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MaxUOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction returns the larger of two unsigned integers.

let rs1_val = X(rs1);
let rs2_val = X(rs2);
let result = if   rs1_val <_u rs2_val
             then rs2_val
         else rs1_val;
X(rd) = result;

See external documentation.

Source code in xdsl/dialects/riscv.py
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
@irdl_op_definition
class MaxUOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction returns the larger of two unsigned integers.
    ```
    let rs1_val = X(rs1);
    let rs2_val = X(rs2);
    let result = if   rs1_val <_u rs2_val
                 then rs2_val
             else rs1_val;
    X(rd) = result;
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-maxu).
    """

    name = "riscv.maxu"

    traits = traits_def(Pure())

name = 'riscv.maxu' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MinOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction returns the smaller of two signed integers.

let rs1_val = X(rs1);
let rs2_val = X(rs2);
let result = if   rs1_val <_s rs2_val
             then rs1_val
         else rs2_val;
X(rd) = result;

See external documentation.

Source code in xdsl/dialects/riscv.py
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
@irdl_op_definition
class MinOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction returns the smaller of two signed integers.
    ```
    let rs1_val = X(rs1);
    let rs2_val = X(rs2);
    let result = if   rs1_val <_s rs2_val
                 then rs1_val
             else rs2_val;
    X(rd) = result;
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-min).
    """

    name = "riscv.min"

    traits = traits_def(Pure())

name = 'riscv.min' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MinUOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

This instruction returns the smaller of two unsigned integers.

let rs1_val = X(rs1);
let rs2_val = X(rs2);
let result = if   rs1_val <_u rs2_val
                then rs1_val
                else rs2_val;
X(rd) = result;

See external documentation.

Source code in xdsl/dialects/riscv.py
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
@irdl_op_definition
class MinUOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    This instruction returns the smaller of two unsigned integers.
    ```
    let rs1_val = X(rs1);
    let rs2_val = X(rs2);
    let result = if   rs1_val <_u rs2_val
                    then rs1_val
                    else rs2_val;
    X(rd) = result;
    ```
    See external [documentation](https://five-embeddev.com/riscv-bitmanip/1.0.0/bitmanip.html#insns-minu).
    """

    name = "riscv.minu"

    traits = traits_def(Pure())

name = 'riscv.minu' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

CZeroEqzOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Moves zero to a register rd, if the condition rs2 is equal to zero, otherwise moves rs1 to rd.

See external documentation.

Source code in xdsl/dialects/riscv.py
3439
3440
3441
3442
3443
3444
3445
3446
3447
@irdl_op_definition
class CZeroEqzOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Moves zero to a register rd, if the condition rs2 is equal to zero, otherwise moves rs1 to rd.

    See external [documentation](https://github.com/riscvarchive/riscv-zicond/blob/main/zicondops.adoc).
    """

    name = "riscv.czero.eqz"

name = 'riscv.czero.eqz' class-attribute instance-attribute

CZeroNezOp dataclass

Bases: RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]

Moves zero to a register rd, if the condition rs2 is nonzero, otherwise moves rs1 to rd.

See external documentation.

Source code in xdsl/dialects/riscv.py
3450
3451
3452
3453
3454
3455
3456
3457
3458
@irdl_op_definition
class CZeroNezOp(RdRsRsIntegerOperation[IntRegisterType, IntRegisterType]):
    """
    Moves zero to a register rd, if the condition rs2 is nonzero, otherwise moves rs1 to rd.

    See external [documentation](https://github.com/riscvarchive/riscv-zicond/blob/main/zicondops.adoc).
    """

    name = "riscv.czero.nez"

name = 'riscv.czero.nez' class-attribute instance-attribute

LiOpHasCanonicalizationPatternTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
3467
3468
3469
3470
3471
3472
3473
3474
class LiOpHasCanonicalizationPatternTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            LoadImmediate0,
        )

        return (LoadImmediate0(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
3468
3469
3470
3471
3472
3473
3474
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        LoadImmediate0,
    )

    return (LoadImmediate0(),)

LiOp

Bases: RISCVCustomFormatOperation, RISCVInstruction, ConstantLikeInterface, ABC

Loads a 32-bit immediate into rd.

This is an assembler pseudo-instruction.

See external documentation.

Source code in xdsl/dialects/riscv.py
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
@irdl_op_definition
class LiOp(RISCVCustomFormatOperation, RISCVInstruction, ConstantLikeInterface, ABC):
    """
    Loads a 32-bit immediate into rd.

    This is an assembler pseudo-instruction.

    See external [documentation](https://github.com/riscv-non-isa/riscv-asm-manual/blob/master/riscv-asm.md#load-immediate).
    """

    name = "riscv.li"

    rd = result_def(IntRegisterType)
    immediate = attr_def(base(Imm32Attr) | base(LabelAttr))

    traits = traits_def(Pure(), LiOpHasCanonicalizationPatternTrait())

    def __init__(
        self,
        immediate: int | Imm32Attr | str | LabelAttr,
        *,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(immediate, int):
            immediate = IntegerAttr(immediate, i32)
        elif isinstance(immediate, str):
            immediate = LabelAttr(immediate)
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            result_types=[rd],
            attributes={
                "immediate": immediate,
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.immediate

    def get_constant_value(self):
        return self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["immediate"] = parse_immediate_value(parser, i32)
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(" ")
        print_immediate_value(printer, self.immediate)
        return {"immediate", "fastmath"}

    @classmethod
    def parse_op_type(
        cls, parser: Parser
    ) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
        parser.parse_punctuation(":")
        res_type = parser.parse_attribute()
        return (), (res_type,)

    def print_op_type(self, printer: Printer) -> None:
        printer.print_string(" : ")
        printer.print_attribute(self.rd.type)

name = 'riscv.li' class-attribute instance-attribute

rd = result_def(IntRegisterType) class-attribute instance-attribute

immediate = attr_def(base(Imm32Attr) | base(LabelAttr)) class-attribute instance-attribute

traits = traits_def(Pure(), LiOpHasCanonicalizationPatternTrait()) class-attribute instance-attribute

__init__(immediate: int | Imm32Attr | str | LabelAttr, *, rd: IntRegisterType = Registers.UNALLOCATED_INT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
def __init__(
    self,
    immediate: int | Imm32Attr | str | LabelAttr,
    *,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    comment: str | StringAttr | None = None,
):
    if isinstance(immediate, int):
        immediate = IntegerAttr(immediate, i32)
    elif isinstance(immediate, str):
        immediate = LabelAttr(immediate)
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        result_types=[rd],
        attributes={
            "immediate": immediate,
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
3516
3517
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.immediate

get_constant_value()

Source code in xdsl/dialects/riscv.py
3519
3520
def get_constant_value(self):
    return self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
3522
3523
3524
3525
3526
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["immediate"] = parse_immediate_value(parser, i32)
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
3528
3529
3530
3531
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(" ")
    print_immediate_value(printer, self.immediate)
    return {"immediate", "fastmath"}

parse_op_type(parser: Parser) -> tuple[Sequence[Attribute], Sequence[Attribute]] classmethod

Source code in xdsl/dialects/riscv.py
3533
3534
3535
3536
3537
3538
3539
@classmethod
def parse_op_type(
    cls, parser: Parser
) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
    parser.parse_punctuation(":")
    res_type = parser.parse_attribute()
    return (), (res_type,)

print_op_type(printer: Printer) -> None

Source code in xdsl/dialects/riscv.py
3541
3542
3543
def print_op_type(self, printer: Printer) -> None:
    printer.print_string(" : ")
    printer.print_attribute(self.rd.type)

EcallOp dataclass

Bases: NullaryOperation

The ECALL instruction is used to make a request to the supporting execution environment, which is usually an operating system. The ABI for the system will define how parameters for the environment request are passed, but usually these will be in defined locations in the integer register file.

See external documentation.

Source code in xdsl/dialects/riscv.py
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
@irdl_op_definition
class EcallOp(NullaryOperation):
    """
    The ECALL instruction is used to make a request to the supporting execution
    environment, which is usually an operating system.
    The ABI for the system will define how parameters for the environment
    request are passed, but usually these will be in defined locations in the
    integer register file.

    See external [documentation](https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf).
    """

    name = "riscv.ecall"

name = 'riscv.ecall' class-attribute instance-attribute

LabelOp

Bases: RISCVCustomFormatOperation, RISCVAsmOperation, RISCVRegallocOperation

The label operation is used to emit text labels (e.g. loop:) that are used as branch, unconditional jump targets and symbol offsets.

See external documentation.

Source code in xdsl/dialects/riscv.py
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
@irdl_op_definition
class LabelOp(RISCVCustomFormatOperation, RISCVAsmOperation, RISCVRegallocOperation):
    """
    The label operation is used to emit text labels (e.g. loop:) that are used
    as branch, unconditional jump targets and symbol offsets.

    See external [documentation](https://github.com/riscv-non-isa/riscv-asm-manual/blob/master/riscv-asm.md#labels).
    """

    name = "riscv.label"
    label = attr_def(LabelAttr)
    comment = opt_attr_def(StringAttr)

    def __init__(
        self,
        label: str | LabelAttr,
        *,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(label, str):
            label = LabelAttr(label)
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            attributes={
                "label": label,
                "comment": comment,
            },
        )

    def assembly_line(self) -> str | None:
        return AssemblyPrinter.append_comment(f"{self.label.data}:", self.comment)

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["label"] = LabelAttr(parser.parse_str_literal("Expected label"))
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(" ")
        printer.print_string_literal(self.label.data)
        return {"label"}

    def print_op_type(self, printer: Printer) -> None:
        return

    @classmethod
    def parse_op_type(
        cls, parser: Parser
    ) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
        return (), ()

name = 'riscv.label' class-attribute instance-attribute

label = attr_def(LabelAttr) class-attribute instance-attribute

comment = opt_attr_def(StringAttr) class-attribute instance-attribute

__init__(label: str | LabelAttr, *, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
def __init__(
    self,
    label: str | LabelAttr,
    *,
    comment: str | StringAttr | None = None,
):
    if isinstance(label, str):
        label = LabelAttr(label)
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        attributes={
            "label": label,
            "comment": comment,
        },
    )

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
3592
3593
def assembly_line(self) -> str | None:
    return AssemblyPrinter.append_comment(f"{self.label.data}:", self.comment)

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
3595
3596
3597
3598
3599
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["label"] = LabelAttr(parser.parse_str_literal("Expected label"))
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
3601
3602
3603
3604
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(" ")
    printer.print_string_literal(self.label.data)
    return {"label"}

print_op_type(printer: Printer) -> None

Source code in xdsl/dialects/riscv.py
3606
3607
def print_op_type(self, printer: Printer) -> None:
    return

parse_op_type(parser: Parser) -> tuple[Sequence[Attribute], Sequence[Attribute]] classmethod

Source code in xdsl/dialects/riscv.py
3609
3610
3611
3612
3613
@classmethod
def parse_op_type(
    cls, parser: Parser
) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
    return (), ()

DirectiveOp

Bases: RISCVCustomFormatOperation, RISCVAsmOperation, RISCVRegallocOperation

The directive operation is used to emit assembler directives (e.g. .word; .equ; etc.) without any associated region of assembly code. A more complete list of directives can be found here:

See external documentation.

Source code in xdsl/dialects/riscv.py
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
@irdl_op_definition
class DirectiveOp(
    RISCVCustomFormatOperation, RISCVAsmOperation, RISCVRegallocOperation
):
    """
    The directive operation is used to emit assembler directives (e.g. .word; .equ; etc.)
    without any associated region of assembly code.
    A more complete list of directives can be found here:

    See external [documentation](https://github.com/riscv-non-isa/riscv-asm-manual/blob/master/riscv-asm.md#pseudo-ops).
    """

    name = "riscv.directive"
    directive = attr_def(StringAttr)
    value = opt_attr_def(StringAttr)

    def __init__(
        self,
        directive: str | StringAttr,
        value: str | StringAttr | None,
    ):
        if isinstance(directive, str):
            directive = StringAttr(directive)
        if isinstance(value, str):
            value = StringAttr(value)

        super().__init__(
            attributes={
                "directive": directive,
                "value": value,
            }
        )

    def assembly_line(self) -> str | None:
        if self.value is not None and self.value.data:
            arg_str = _assembly_arg_str(self.value.data)
        else:
            arg_str = ""

        return AssemblyPrinter.assembly_line(
            self.directive.data, arg_str, is_indented=False
        )

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["directive"] = StringAttr(
            parser.parse_str_literal("Expected directive")
        )
        if (value := parser.parse_optional_str_literal()) is not None:
            attributes["value"] = StringAttr(value)
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(" ")
        printer.print_string_literal(self.directive.data)
        if self.value is not None:
            printer.print_string(" ")
            printer.print_string_literal(self.value.data)
        return {"directive", "value"}

    def print_op_type(self, printer: Printer) -> None:
        return

    @classmethod
    def parse_op_type(
        cls, parser: Parser
    ) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
        return (), ()

name = 'riscv.directive' class-attribute instance-attribute

directive = attr_def(StringAttr) class-attribute instance-attribute

value = opt_attr_def(StringAttr) class-attribute instance-attribute

__init__(directive: str | StringAttr, value: str | StringAttr | None)

Source code in xdsl/dialects/riscv.py
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
def __init__(
    self,
    directive: str | StringAttr,
    value: str | StringAttr | None,
):
    if isinstance(directive, str):
        directive = StringAttr(directive)
    if isinstance(value, str):
        value = StringAttr(value)

    super().__init__(
        attributes={
            "directive": directive,
            "value": value,
        }
    )

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
3649
3650
3651
3652
3653
3654
3655
3656
3657
def assembly_line(self) -> str | None:
    if self.value is not None and self.value.data:
        arg_str = _assembly_arg_str(self.value.data)
    else:
        arg_str = ""

    return AssemblyPrinter.assembly_line(
        self.directive.data, arg_str, is_indented=False
    )

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
3659
3660
3661
3662
3663
3664
3665
3666
3667
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["directive"] = StringAttr(
        parser.parse_str_literal("Expected directive")
    )
    if (value := parser.parse_optional_str_literal()) is not None:
        attributes["value"] = StringAttr(value)
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
3669
3670
3671
3672
3673
3674
3675
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(" ")
    printer.print_string_literal(self.directive.data)
    if self.value is not None:
        printer.print_string(" ")
        printer.print_string_literal(self.value.data)
    return {"directive", "value"}

print_op_type(printer: Printer) -> None

Source code in xdsl/dialects/riscv.py
3677
3678
def print_op_type(self, printer: Printer) -> None:
    return

parse_op_type(parser: Parser) -> tuple[Sequence[Attribute], Sequence[Attribute]] classmethod

Source code in xdsl/dialects/riscv.py
3680
3681
3682
3683
3684
@classmethod
def parse_op_type(
    cls, parser: Parser
) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
    return (), ()

AssemblySectionOp

Bases: IRDLOperation, AssemblyPrintable

The directive operation is used to emit assembler directives (e.g. .text; .data; etc.) with the scope of a section.

A more complete list of directives can be found here:

See external documentation.

This operation can have nested operations, corresponding to a section of the assembly.

Source code in xdsl/dialects/riscv.py
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
@irdl_op_definition
class AssemblySectionOp(IRDLOperation, AssemblyPrintable):
    """
    The directive operation is used to emit assembler directives (e.g. .text; .data; etc.)
    with the scope of a section.

    A more complete list of directives can be found here:

    See external [documentation](https://github.com/riscv-non-isa/riscv-asm-manual/blob/master/riscv-asm.md#pseudo-ops).

    This operation can have nested operations, corresponding to a section of the assembly.
    """

    name = "riscv.assembly_section"
    directive = attr_def(StringAttr)
    data = region_def("single_block")

    traits = traits_def(NoTerminator(), IsolatedFromAbove())

    def __init__(
        self,
        directive: str | StringAttr,
        region: Region | None = None,
    ):
        if isinstance(directive, str):
            directive = StringAttr(directive)
        if region is None:
            region = Region(Block())

        super().__init__(
            regions=[region],
            attributes={
                "directive": directive,
            },
        )

    @classmethod
    def parse(cls, parser: Parser) -> AssemblySectionOp:
        directive = parser.parse_str_literal()
        attr_dict = parser.parse_optional_attr_dict_with_keyword(("directive",))
        region = parser.parse_optional_region()

        if region is None:
            region = Region(Block())
        section = AssemblySectionOp(directive, region)
        if attr_dict is not None:
            section.attributes |= attr_dict.data

        return section

    def print(self, printer: Printer) -> None:
        printer.print_string(" ")
        printer.print_string_literal(self.directive.data)
        printer.print_op_attributes(
            self.attributes, reserved_attr_names=("directive",), print_keyword=True
        )
        printer.print_string(" ")
        if self.data.block.ops:
            printer.print_region(self.data)

    def print_assembly(self, printer: AssemblyPrinter) -> None:
        printer.emit_section(self.directive.data)

name = 'riscv.assembly_section' class-attribute instance-attribute

directive = attr_def(StringAttr) class-attribute instance-attribute

data = region_def('single_block') class-attribute instance-attribute

traits = traits_def(NoTerminator(), IsolatedFromAbove()) class-attribute instance-attribute

__init__(directive: str | StringAttr, region: Region | None = None)

Source code in xdsl/dialects/riscv.py
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
def __init__(
    self,
    directive: str | StringAttr,
    region: Region | None = None,
):
    if isinstance(directive, str):
        directive = StringAttr(directive)
    if region is None:
        region = Region(Block())

    super().__init__(
        regions=[region],
        attributes={
            "directive": directive,
        },
    )

parse(parser: Parser) -> AssemblySectionOp classmethod

Source code in xdsl/dialects/riscv.py
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
@classmethod
def parse(cls, parser: Parser) -> AssemblySectionOp:
    directive = parser.parse_str_literal()
    attr_dict = parser.parse_optional_attr_dict_with_keyword(("directive",))
    region = parser.parse_optional_region()

    if region is None:
        region = Region(Block())
    section = AssemblySectionOp(directive, region)
    if attr_dict is not None:
        section.attributes |= attr_dict.data

    return section

print(printer: Printer) -> None

Source code in xdsl/dialects/riscv.py
3737
3738
3739
3740
3741
3742
3743
3744
3745
def print(self, printer: Printer) -> None:
    printer.print_string(" ")
    printer.print_string_literal(self.directive.data)
    printer.print_op_attributes(
        self.attributes, reserved_attr_names=("directive",), print_keyword=True
    )
    printer.print_string(" ")
    if self.data.block.ops:
        printer.print_region(self.data)

print_assembly(printer: AssemblyPrinter) -> None

Source code in xdsl/dialects/riscv.py
3747
3748
def print_assembly(self, printer: AssemblyPrinter) -> None:
    printer.emit_section(self.directive.data)

CustomAssemblyInstructionOp

Bases: RISCVCustomFormatOperation, RISCVInstruction

An instruction with unspecified semantics, that can be printed during assembly emission.

During assembly emission, the results are printed before the operands:

s0 = riscv.GetRegisterOp(Registers.s0).res
s1 = riscv.GetRegisterOp(Registers.s1).res
rs2 = riscv.Registers.s2
rs3 = riscv.Registers.s3
op = CustomAssemblyInstructionOp("my_instr", (s0, s1), (rs2, rs3))

op.assembly_line()   # "my_instr s2, s3, s0, s1"
Source code in xdsl/dialects/riscv.py
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
@irdl_op_definition
class CustomAssemblyInstructionOp(RISCVCustomFormatOperation, RISCVInstruction):
    """
    An instruction with unspecified semantics, that can be printed during assembly
    emission.

    During assembly emission, the results are printed before the operands:

    ``` python
    s0 = riscv.GetRegisterOp(Registers.s0).res
    s1 = riscv.GetRegisterOp(Registers.s1).res
    rs2 = riscv.Registers.s2
    rs3 = riscv.Registers.s3
    op = CustomAssemblyInstructionOp("my_instr", (s0, s1), (rs2, rs3))

    op.assembly_line()   # "my_instr s2, s3, s0, s1"
    ```
    """

    name = "riscv.custom_assembly_instruction"
    inputs = var_operand_def()
    outputs = var_result_def()
    instruction_name = attr_def(StringAttr)
    comment = opt_attr_def(StringAttr)

    def __init__(
        self,
        instruction_name: str | StringAttr,
        inputs: Sequence[SSAValue],
        result_types: Sequence[Attribute],
        *,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(instruction_name, str):
            instruction_name = StringAttr(instruction_name)
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=[inputs],
            result_types=[result_types],
            attributes={
                "instruction_name": instruction_name,
                "comment": comment,
            },
        )

    def assembly_instruction_name(self) -> str:
        return self.instruction_name.data

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return *self.results, *self.operands

name = 'riscv.custom_assembly_instruction' class-attribute instance-attribute

inputs = var_operand_def() class-attribute instance-attribute

outputs = var_result_def() class-attribute instance-attribute

instruction_name = attr_def(StringAttr) class-attribute instance-attribute

comment = opt_attr_def(StringAttr) class-attribute instance-attribute

__init__(instruction_name: str | StringAttr, inputs: Sequence[SSAValue], result_types: Sequence[Attribute], *, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
def __init__(
    self,
    instruction_name: str | StringAttr,
    inputs: Sequence[SSAValue],
    result_types: Sequence[Attribute],
    *,
    comment: str | StringAttr | None = None,
):
    if isinstance(instruction_name, str):
        instruction_name = StringAttr(instruction_name)
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=[inputs],
        result_types=[result_types],
        attributes={
            "instruction_name": instruction_name,
            "comment": comment,
        },
    )

assembly_instruction_name() -> str

Source code in xdsl/dialects/riscv.py
3798
3799
def assembly_instruction_name(self) -> str:
    return self.instruction_name.data

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
3801
3802
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return *self.results, *self.operands

CommentOp

Bases: RISCVCustomFormatOperation, RISCVAsmOperation, RISCVRegallocOperation

Source code in xdsl/dialects/riscv.py
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
@irdl_op_definition
class CommentOp(RISCVCustomFormatOperation, RISCVAsmOperation, RISCVRegallocOperation):
    name = "riscv.comment"
    comment = attr_def(StringAttr)

    def __init__(self, comment: str | StringAttr):
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            attributes={
                "comment": comment,
            },
        )

    def assembly_line(self) -> str | None:
        return f"    # {self.comment.data}"

name = 'riscv.comment' class-attribute instance-attribute

comment = attr_def(StringAttr) class-attribute instance-attribute

__init__(comment: str | StringAttr)

Source code in xdsl/dialects/riscv.py
3810
3811
3812
3813
3814
3815
3816
3817
3818
def __init__(self, comment: str | StringAttr):
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        attributes={
            "comment": comment,
        },
    )

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
3820
3821
def assembly_line(self) -> str | None:
    return f"    # {self.comment.data}"

EbreakOp dataclass

Bases: NullaryOperation

The EBREAK instruction is used by debuggers to cause control to be transferred back to a debugging environment.

See external documentation.

Source code in xdsl/dialects/riscv.py
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
@irdl_op_definition
class EbreakOp(NullaryOperation):
    """
    The EBREAK instruction is used by debuggers to cause control to be
    transferred back to a debugging environment.

    See external [documentation](https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf).
    """

    name = "riscv.ebreak"

name = 'riscv.ebreak' class-attribute instance-attribute

WfiOp dataclass

Bases: NullaryOperation

The Wait for Interrupt instruction (WFI) provides a hint to the implementation that the current hart can be stalled until an interrupt might need servicing.

See external documentation.

Source code in xdsl/dialects/riscv.py
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
@irdl_op_definition
class WfiOp(NullaryOperation):
    """
    The Wait for Interrupt instruction (WFI) provides a hint to the
    implementation that the current hart can be stalled until an
    interrupt might need servicing.

    See external [documentation](https://github.com/riscv/riscv-isa-manual/releases/download/Priv-v1.12/riscv-privileged-20211203.pdf).
    """

    name = "riscv.wfi"

name = 'riscv.wfi' class-attribute instance-attribute

GetAnyRegisterOperation

Bases: RISCVCustomFormatOperation, RISCVAsmOperation, RISCVRegallocOperation, ABC, Generic[RDInvT]

This instruction allows us to create an SSAValue with for a given register name. This is useful for bridging the RISC-V convention that stores the result of function calls in a0 and a1 into SSA form.

For example, to generate this assembly:

jal my_func
add a0 s0 a0

One needs to do the following:

rhs = riscv.GetRegisterOp(Registers.s0).res
riscv.JalOp("my_func")
lhs = riscv.GetRegisterOp(Registers.A0).res
sum = riscv.AddOp(lhs, rhs, Registers.A0).rd
Source code in xdsl/dialects/riscv.py
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
class GetAnyRegisterOperation(
    RISCVCustomFormatOperation,
    RISCVAsmOperation,
    RISCVRegallocOperation,
    ABC,
    Generic[RDInvT],
):
    """
    This instruction allows us to create an SSAValue with for a given register name. This
    is useful for bridging the RISC-V convention that stores the result of function calls
    in `a0` and `a1` into SSA form.

    For example, to generate this assembly:
    ```
    jal my_func
    add a0 s0 a0
    ```

    One needs to do the following:

    ``` python
    rhs = riscv.GetRegisterOp(Registers.s0).res
    riscv.JalOp("my_func")
    lhs = riscv.GetRegisterOp(Registers.A0).res
    sum = riscv.AddOp(lhs, rhs, Registers.A0).rd
    ```
    """

    res = result_def(RDInvT)

    traits = traits_def(Pure())

    def __init__(
        self,
        register_type: RDInvT,
    ):
        super().__init__(result_types=[register_type])

    def assembly_line(self) -> str | None:
        # Don't print assembly for creating a SSA value representing register
        return None

    @classmethod
    def parse_op_type(
        cls, parser: Parser
    ) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
        parser.parse_punctuation(":")
        res_type = parser.parse_attribute()
        return (), (res_type,)

    def print_op_type(self, printer: Printer) -> None:
        printer.print_string(" : ")
        printer.print_attribute(self.res.type)

res = result_def(RDInvT) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

__init__(register_type: RDInvT)

Source code in xdsl/dialects/riscv.py
3886
3887
3888
3889
3890
def __init__(
    self,
    register_type: RDInvT,
):
    super().__init__(result_types=[register_type])

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
3892
3893
3894
def assembly_line(self) -> str | None:
    # Don't print assembly for creating a SSA value representing register
    return None

parse_op_type(parser: Parser) -> tuple[Sequence[Attribute], Sequence[Attribute]] classmethod

Source code in xdsl/dialects/riscv.py
3896
3897
3898
3899
3900
3901
3902
@classmethod
def parse_op_type(
    cls, parser: Parser
) -> tuple[Sequence[Attribute], Sequence[Attribute]]:
    parser.parse_punctuation(":")
    res_type = parser.parse_attribute()
    return (), (res_type,)

print_op_type(printer: Printer) -> None

Source code in xdsl/dialects/riscv.py
3904
3905
3906
def print_op_type(self, printer: Printer) -> None:
    printer.print_string(" : ")
    printer.print_attribute(self.res.type)

GetRegisterOp dataclass

Bases: GetAnyRegisterOperation[IntRegisterType]

Source code in xdsl/dialects/riscv.py
3909
3910
3911
@irdl_op_definition
class GetRegisterOp(GetAnyRegisterOperation[IntRegisterType]):
    name = "riscv.get_register"

name = 'riscv.get_register' class-attribute instance-attribute

GetFloatRegisterOp dataclass

Bases: GetAnyRegisterOperation[FloatRegisterType]

Source code in xdsl/dialects/riscv.py
3914
3915
3916
@irdl_op_definition
class GetFloatRegisterOp(GetAnyRegisterOperation[FloatRegisterType]):
    name = "riscv.get_float_register"

name = 'riscv.get_float_register' class-attribute instance-attribute

ParallelMovOp

Bases: RISCVRegallocOperation

Source code in xdsl/dialects/riscv.py
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
@irdl_op_definition
class ParallelMovOp(RISCVRegallocOperation):
    _L: ClassVar = IntVarConstraint("L", AnyInt())

    name = "riscv.parallel_mov"
    inputs = var_operand_def(RangeOf(RISCVRegisterType).of_length(_L))
    outputs: VarOpResult[RISCVRegisterType] = var_result_def(
        RangeOf(RISCVRegisterType).of_length(_L)
    )
    input_widths = prop_def(DenseArrayBase.constr(i32))
    free_registers = opt_prop_def(ArrayAttr[RISCVRegisterType])

    assembly_format = (
        "$inputs $input_widths attr-dict `:` functional-type($inputs, $outputs)"
    )
    irdl_options = (ParsePropInAttrDict(),)

    def __init__(
        self,
        inputs: Sequence[SSAValue],
        outputs: Sequence[RISCVRegisterType],
        input_widths: DenseArrayBase[I32],
        free_registers: ArrayAttr[RISCVRegisterType] | None = None,
    ):
        super().__init__(
            operands=(inputs,),
            result_types=(outputs,),
            properties={"input_widths": input_widths, "free_registers": free_registers},
        )

    def verify_(self) -> None:
        if len(self.inputs) != len(self.input_widths):
            raise VerifyException(
                "incorrect length for input_widths. "
                "Expected {len(self.inputs)}, found {len(self.input_widths)}."
            )

        input_types = cast(Sequence[RISCVRegisterType], self.inputs.types)
        output_types = cast(Sequence[RISCVRegisterType], self.outputs.types)

        # Check type of register type matches for input and output
        for input_type, output_type in zip(input_types, output_types, strict=True):
            if type(input_type) is not type(output_type):
                raise VerifyException("Input type must match output type.")

        # Check outputs are distinct if allocated and not ZERO
        filtered_outputs = tuple(
            i for i in output_types if i.is_allocated and i != Registers.ZERO
        )
        if len(filtered_outputs) != len(set(filtered_outputs)):
            raise VerifyException("Outputs must be unallocated or distinct.")

name = 'riscv.parallel_mov' class-attribute instance-attribute

inputs = var_operand_def(RangeOf(RISCVRegisterType).of_length(_L)) class-attribute instance-attribute

outputs: VarOpResult[RISCVRegisterType] = var_result_def(RangeOf(RISCVRegisterType).of_length(_L)) class-attribute instance-attribute

input_widths = prop_def(DenseArrayBase.constr(i32)) class-attribute instance-attribute

free_registers = opt_prop_def(ArrayAttr[RISCVRegisterType]) class-attribute instance-attribute

assembly_format = '$inputs $input_widths attr-dict `:` functional-type($inputs, $outputs)' class-attribute instance-attribute

irdl_options = (ParsePropInAttrDict(),) class-attribute instance-attribute

__init__(inputs: Sequence[SSAValue], outputs: Sequence[RISCVRegisterType], input_widths: DenseArrayBase[I32], free_registers: ArrayAttr[RISCVRegisterType] | None = None)

Source code in xdsl/dialects/riscv.py
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
def __init__(
    self,
    inputs: Sequence[SSAValue],
    outputs: Sequence[RISCVRegisterType],
    input_widths: DenseArrayBase[I32],
    free_registers: ArrayAttr[RISCVRegisterType] | None = None,
):
    super().__init__(
        operands=(inputs,),
        result_types=(outputs,),
        properties={"input_widths": input_widths, "free_registers": free_registers},
    )

verify_() -> None

Source code in xdsl/dialects/riscv.py
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
def verify_(self) -> None:
    if len(self.inputs) != len(self.input_widths):
        raise VerifyException(
            "incorrect length for input_widths. "
            "Expected {len(self.inputs)}, found {len(self.input_widths)}."
        )

    input_types = cast(Sequence[RISCVRegisterType], self.inputs.types)
    output_types = cast(Sequence[RISCVRegisterType], self.outputs.types)

    # Check type of register type matches for input and output
    for input_type, output_type in zip(input_types, output_types, strict=True):
        if type(input_type) is not type(output_type):
            raise VerifyException("Input type must match output type.")

    # Check outputs are distinct if allocated and not ZERO
    filtered_outputs = tuple(
        i for i in output_types if i.is_allocated and i != Registers.ZERO
    )
    if len(filtered_outputs) != len(set(filtered_outputs)):
        raise VerifyException("Outputs must be unallocated or distinct.")

RdRsRsRsFloatOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RV32F operations that take three floating-point input registers and a destination register, e.g: fused-multiply-add (FMA) instructions.

Source code in xdsl/dialects/riscv.py
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
class RdRsRsRsFloatOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RV32F operations that take three
    floating-point input registers and a destination register,
    e.g: fused-multiply-add (FMA) instructions.
    """

    rd = result_def(FloatRegisterType)
    rs1 = operand_def(FloatRegisterType)
    rs2 = operand_def(FloatRegisterType)
    rs3 = operand_def(FloatRegisterType)

    traits = traits_def(RegisterAllocatedMemoryEffect())

    def __init__(
        self,
        rs1: Operation | SSAValue,
        rs2: Operation | SSAValue,
        rs3: Operation | SSAValue,
        *,
        rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=[rs1, rs2, rs3],
            attributes={
                "comment": comment,
            },
            result_types=[rd],
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.rs1, self.rs2, self.rs3

rd = result_def(FloatRegisterType) class-attribute instance-attribute

rs1 = operand_def(FloatRegisterType) class-attribute instance-attribute

rs2 = operand_def(FloatRegisterType) class-attribute instance-attribute

rs3 = operand_def(FloatRegisterType) class-attribute instance-attribute

traits = traits_def(RegisterAllocatedMemoryEffect()) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, rs2: Operation | SSAValue, rs3: Operation | SSAValue, *, rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
def __init__(
    self,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    rs3: Operation | SSAValue,
    *,
    rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT,
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=[rs1, rs2, rs3],
        attributes={
            "comment": comment,
        },
        result_types=[rd],
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
4011
4012
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.rs1, self.rs2, self.rs3

RdRsRsFloatFloatIntegerOperationWithFastMath

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have two source floating-point registers with an integer destination register, and can be annotated with fastmath flags.

This is called R-Type in the RISC-V specification.

Source code in xdsl/dialects/riscv.py
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
class RdRsRsFloatFloatIntegerOperationWithFastMath(
    RISCVCustomFormatOperation, RISCVInstruction, ABC
):
    """
    A base class for RISC-V operations that have two source floating-point
    registers with an integer destination register, and can be annotated with fastmath flags.

    This is called R-Type in the RISC-V specification.
    """

    rd = result_def(IntRegisterType)
    rs1 = operand_def(FloatRegisterType)
    rs2 = operand_def(FloatRegisterType)
    fastmath = attr_def(FastMathFlagsAttr)

    def __init__(
        self,
        rs1: Operation | SSAValue,
        rs2: Operation | SSAValue,
        *,
        rd: IntRegisterType = Registers.UNALLOCATED_INT,
        fastmath: FastMathFlagsAttr = FastMathFlagsAttr("none"),
        comment: str | StringAttr | None = None,
    ):
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=[rs1, rs2],
            attributes={
                "comment": comment,
                "fastmath": fastmath,
            },
            result_types=[rd],
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.rs1, self.rs2

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        fast = FastMathFlagsAttr("none")
        if parser.parse_optional_keyword("fastmath") is not None:
            fast = FastMathFlagsAttr(FastMathFlagsAttr.parse_parameter(parser))
        attributes["fastmath"] = fast
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        if self.fastmath != FastMathFlagsAttr("none"):
            printer.print_string(" fastmath")
            self.fastmath.print_parameter(printer)
        return {"fastmath"}

rd = result_def(IntRegisterType) class-attribute instance-attribute

rs1 = operand_def(FloatRegisterType) class-attribute instance-attribute

rs2 = operand_def(FloatRegisterType) class-attribute instance-attribute

fastmath = attr_def(FastMathFlagsAttr) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, rs2: Operation | SSAValue, *, rd: IntRegisterType = Registers.UNALLOCATED_INT, fastmath: FastMathFlagsAttr = FastMathFlagsAttr('none'), comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
def __init__(
    self,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    *,
    rd: IntRegisterType = Registers.UNALLOCATED_INT,
    fastmath: FastMathFlagsAttr = FastMathFlagsAttr("none"),
    comment: str | StringAttr | None = None,
):
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=[rs1, rs2],
        attributes={
            "comment": comment,
            "fastmath": fastmath,
        },
        result_types=[rd],
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
4051
4052
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.rs1, self.rs2

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
4054
4055
4056
4057
4058
4059
4060
4061
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    fast = FastMathFlagsAttr("none")
    if parser.parse_optional_keyword("fastmath") is not None:
        fast = FastMathFlagsAttr(FastMathFlagsAttr.parse_parameter(parser))
    attributes["fastmath"] = fast
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
4063
4064
4065
4066
4067
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    if self.fastmath != FastMathFlagsAttr("none"):
        printer.print_string(" fastmath")
        self.fastmath.print_parameter(printer)
    return {"fastmath"}

RsRsImmFloatOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RV32F operations that have two source registers (one integer and one floating-point) and an immediate.

Source code in xdsl/dialects/riscv.py
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
class RsRsImmFloatOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RV32F operations that have two source registers
    (one integer and one floating-point) and an immediate.
    """

    rs1 = operand_def(IntRegisterType)
    rs2 = operand_def(FloatRegisterType)
    immediate = attr_def(Imm12Attr)

    def __init__(
        self,
        rs1: Operation | SSAValue,
        rs2: Operation | SSAValue,
        immediate: int | Imm12Attr | str | LabelAttr,
        *,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(immediate, int):
            immediate = IntegerAttr(immediate, i12)
        elif isinstance(immediate, str):
            immediate = LabelAttr(immediate)
        if isinstance(comment, str):
            comment = StringAttr(comment)

        super().__init__(
            operands=[rs1, rs2],
            attributes={
                "immediate": immediate,
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rs1, self.rs2, self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["immediate"] = parse_immediate_value(parser, i12)
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(", ")
        print_immediate_value(printer, self.immediate)
        return {"immediate"}

rs1 = operand_def(IntRegisterType) class-attribute instance-attribute

rs2 = operand_def(FloatRegisterType) class-attribute instance-attribute

immediate = attr_def(Imm12Attr) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, rs2: Operation | SSAValue, immediate: int | Imm12Attr | str | LabelAttr, *, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
def __init__(
    self,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    immediate: int | Imm12Attr | str | LabelAttr,
    *,
    comment: str | StringAttr | None = None,
):
    if isinstance(immediate, int):
        immediate = IntegerAttr(immediate, i12)
    elif isinstance(immediate, str):
        immediate = LabelAttr(immediate)
    if isinstance(comment, str):
        comment = StringAttr(comment)

    super().__init__(
        operands=[rs1, rs2],
        attributes={
            "immediate": immediate,
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
4103
4104
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rs1, self.rs2, self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
4106
4107
4108
4109
4110
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["immediate"] = parse_immediate_value(parser, i12)
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
4112
4113
4114
4115
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(", ")
    print_immediate_value(printer, self.immediate)
    return {"immediate"}

RdRsImmFloatOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RV32Foperations that have one floating-point destination register, one source register and one immediate operand.

Source code in xdsl/dialects/riscv.py
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
class RdRsImmFloatOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RV32Foperations that have one floating-point
    destination register, one source register and
    one immediate operand.
    """

    rd = result_def(FloatRegisterType)
    rs1 = operand_def(IntRegisterType)
    immediate = attr_def(base(Imm12Attr) | base(LabelAttr))

    def __init__(
        self,
        rs1: Operation | SSAValue,
        immediate: int | Imm12Attr | str | LabelAttr,
        *,
        rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(immediate, int):
            immediate = IntegerAttr(immediate, i12)
        elif isinstance(immediate, str):
            immediate = LabelAttr(immediate)

        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            operands=[rs1],
            result_types=[rd],
            attributes={
                "immediate": immediate,
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd, self.rs1, self.immediate

    @classmethod
    def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
        attributes = dict[str, Attribute]()
        attributes["immediate"] = parse_immediate_value(parser, i12)
        return attributes

    def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
        printer.print_string(", ")
        print_immediate_value(printer, self.immediate)
        return {"immediate"}

rd = result_def(FloatRegisterType) class-attribute instance-attribute

rs1 = operand_def(IntRegisterType) class-attribute instance-attribute

immediate = attr_def(base(Imm12Attr) | base(LabelAttr)) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, immediate: int | Imm12Attr | str | LabelAttr, *, rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv.py
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
def __init__(
    self,
    rs1: Operation | SSAValue,
    immediate: int | Imm12Attr | str | LabelAttr,
    *,
    rd: FloatRegisterType = Registers.UNALLOCATED_FLOAT,
    comment: str | StringAttr | None = None,
):
    if isinstance(immediate, int):
        immediate = IntegerAttr(immediate, i12)
    elif isinstance(immediate, str):
        immediate = LabelAttr(immediate)

    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        operands=[rs1],
        result_types=[rd],
        attributes={
            "immediate": immediate,
            "comment": comment,
        },
    )

assembly_line_args() -> tuple[AssemblyInstructionArg, ...]

Source code in xdsl/dialects/riscv.py
4153
4154
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd, self.rs1, self.immediate

custom_parse_attributes(parser: Parser) -> dict[str, Attribute] classmethod

Source code in xdsl/dialects/riscv.py
4156
4157
4158
4159
4160
@classmethod
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
    attributes = dict[str, Attribute]()
    attributes["immediate"] = parse_immediate_value(parser, i12)
    return attributes

custom_print_attributes(printer: Printer) -> AbstractSet[str]

Source code in xdsl/dialects/riscv.py
4162
4163
4164
4165
def custom_print_attributes(self, printer: Printer) -> AbstractSet[str]:
    printer.print_string(", ")
    print_immediate_value(printer, self.immediate)
    return {"immediate"}

FMAddSOp dataclass

Bases: RdRsRsRsFloatOperation

Perform single-precision fused multiply addition.

f[rd] = f[rs1]×f[rs2]+f[rs3]

See external documentation.

Source code in xdsl/dialects/riscv.py
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
@irdl_op_definition
class FMAddSOp(RdRsRsRsFloatOperation):
    """
    Perform single-precision fused multiply addition.

    ```C
    f[rd] = f[rs1]×f[rs2]+f[rs3]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmadd-s).
    """

    name = "riscv.fmadd.s"

name = 'riscv.fmadd.s' class-attribute instance-attribute

FMSubSOp dataclass

Bases: RdRsRsRsFloatOperation

Perform single-precision fused multiply substraction.

f[rd] = f[rs1]×f[rs2]+f[rs3]

See external documentation.

Source code in xdsl/dialects/riscv.py
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
@irdl_op_definition
class FMSubSOp(RdRsRsRsFloatOperation):
    """
    Perform single-precision fused multiply substraction.

    ```C
    f[rd] = f[rs1]×f[rs2]+f[rs3]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmsub-s).
    """

    name = "riscv.fmsub.s"

name = 'riscv.fmsub.s' class-attribute instance-attribute

FNMSubSOp dataclass

Bases: RdRsRsRsFloatOperation

Perform single-precision fused multiply substraction.

f[rd] = -f[rs1]×f[rs2]+f[rs3]

See external documentation.

Source code in xdsl/dialects/riscv.py
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
@irdl_op_definition
class FNMSubSOp(RdRsRsRsFloatOperation):
    """
    Perform single-precision fused multiply substraction.

    ```C
    f[rd] = -f[rs1]×f[rs2]+f[rs3]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fnmsub-s).
    """

    name = "riscv.fnmsub.s"

name = 'riscv.fnmsub.s' class-attribute instance-attribute

FNMAddSOp dataclass

Bases: RdRsRsRsFloatOperation

Perform single-precision fused multiply addition.

f[rd] = -f[rs1]×f[rs2]-f[rs3]

See external documentation.

Source code in xdsl/dialects/riscv.py
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
@irdl_op_definition
class FNMAddSOp(RdRsRsRsFloatOperation):
    """
    Perform single-precision fused multiply addition.

    ```C
    f[rd] = -f[rs1]×f[rs2]-f[rs3]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fnmadd-s).
    """

    name = "riscv.fnmadd.s"

name = 'riscv.fnmadd.s' class-attribute instance-attribute

FAddSOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Perform single-precision floating-point addition.

f[rd] = f[rs1]+f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
@irdl_op_definition
class FAddSOp(RdRsRsFloatOperationWithFastMath):
    """
    Perform single-precision floating-point addition.

    ```C
    f[rd] = f[rs1]+f[rs2]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fadd-s).
    """

    name = "riscv.fadd.s"

    traits = traits_def(Pure())

name = 'riscv.fadd.s' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

FSubSOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Perform single-precision floating-point substraction.

f[rd] = f[rs1]-f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
@irdl_op_definition
class FSubSOp(RdRsRsFloatOperationWithFastMath):
    """
    Perform single-precision floating-point substraction.

    ```C
    f[rd] = f[rs1]-f[rs2]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fsub-s).
    """

    name = "riscv.fsub.s"

name = 'riscv.fsub.s' class-attribute instance-attribute

FMulSOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Perform single-precision floating-point multiplication.

f[rd] = f[rs1]×f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
@irdl_op_definition
class FMulSOp(RdRsRsFloatOperationWithFastMath):
    """
    Perform single-precision floating-point multiplication.

    ```C
    f[rd] = f[rs1]×f[rs2]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmul-s).
    """

    name = "riscv.fmul.s"

name = 'riscv.fmul.s' class-attribute instance-attribute

FDivSOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Perform single-precision floating-point division.

f[rd] = f[rs1] / f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
@irdl_op_definition
class FDivSOp(RdRsRsFloatOperationWithFastMath):
    """
    Perform single-precision floating-point division.

    ```C
    f[rd] = f[rs1] / f[rs2]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fdiv-s).
    """

    name = "riscv.fdiv.s"

name = 'riscv.fdiv.s' class-attribute instance-attribute

FSqrtSOp dataclass

Bases: RdRsFloatOperation[FloatRegisterType]

Perform single-precision floating-point square root.

f[rd] = sqrt(f[rs1])

See external documentation.

Source code in xdsl/dialects/riscv.py
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
@irdl_op_definition
class FSqrtSOp(RdRsFloatOperation[FloatRegisterType]):
    """
    Perform single-precision floating-point square root.

    ```C
    f[rd] = sqrt(f[rs1])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fsqrt-s).
    """

    name = "riscv.fsqrt.s"

name = 'riscv.fsqrt.s' class-attribute instance-attribute

FSgnJSOp dataclass

Bases: RdRsRsFloatOperation[FloatRegisterType, FloatRegisterType]

Produce a result that takes all bits except the sign bit from rs1. The result’s sign bit is rs2’s sign bit.

f[rd] = {f[rs2][31], f[rs1][30:0]}

See external documentation.

Source code in xdsl/dialects/riscv.py
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
@irdl_op_definition
class FSgnJSOp(RdRsRsFloatOperation[FloatRegisterType, FloatRegisterType]):
    """
    Produce a result that takes all bits except the sign bit from rs1.
    The result’s sign bit is rs2’s sign bit.

    ```C
    f[rd] = {f[rs2][31], f[rs1][30:0]}
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fsgnj.s).
    """

    name = "riscv.fsgnj.s"

name = 'riscv.fsgnj.s' class-attribute instance-attribute

FSgnJNSOp dataclass

Bases: RdRsRsFloatOperation[FloatRegisterType, FloatRegisterType]

Produce a result that takes all bits except the sign bit from rs1. The result’s sign bit is opposite of rs2’s sign bit.

f[rd] = {~f[rs2][31], f[rs1][30:0]}

See external documentation.

Source code in xdsl/dialects/riscv.py
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
@irdl_op_definition
class FSgnJNSOp(RdRsRsFloatOperation[FloatRegisterType, FloatRegisterType]):
    """
    Produce a result that takes all bits except the sign bit from rs1.
    The result’s sign bit is opposite of rs2’s sign bit.

    ```C
    f[rd] = {~f[rs2][31], f[rs1][30:0]}
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fsgnjn.s).
    """

    name = "riscv.fsgnjn.s"

name = 'riscv.fsgnjn.s' class-attribute instance-attribute

FSgnJXSOp dataclass

Bases: RdRsRsFloatOperation[FloatRegisterType, FloatRegisterType]

Produce a result that takes all bits except the sign bit from rs1. The result’s sign bit is XOR of sign bit of rs1 and rs2.

f[rd] = {f[rs1][31] ^ f[rs2][31], f[rs1][30:0]}

See external documentation.

Source code in xdsl/dialects/riscv.py
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
@irdl_op_definition
class FSgnJXSOp(RdRsRsFloatOperation[FloatRegisterType, FloatRegisterType]):
    """
    Produce a result that takes all bits except the sign bit from rs1.
    The result’s sign bit is XOR of sign bit of rs1 and rs2.

    ```C
    f[rd] = {f[rs1][31] ^ f[rs2][31], f[rs1][30:0]}
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fsgnjx.s).
    """

    name = "riscv.fsgnjx.s"

name = 'riscv.fsgnjx.s' class-attribute instance-attribute

FMinSOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Write the smaller of single precision data in rs1 and rs2 to rd.

f[rd] = min(f[rs1], f[rs2])

See external documentation.

Source code in xdsl/dialects/riscv.py
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
@irdl_op_definition
class FMinSOp(RdRsRsFloatOperationWithFastMath):
    """
    Write the smaller of single precision data in rs1 and rs2 to rd.

    ```C
    f[rd] = min(f[rs1], f[rs2])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmin-s).
    """

    name = "riscv.fmin.s"

name = 'riscv.fmin.s' class-attribute instance-attribute

FMaxSOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Write the larger of single precision data in rs1 and rs2 to rd.

f[rd] = max(f[rs1], f[rs2])

See external documentation.

Source code in xdsl/dialects/riscv.py
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
@irdl_op_definition
class FMaxSOp(RdRsRsFloatOperationWithFastMath):
    """
    Write the larger of single precision data in rs1 and rs2 to rd.

    ```C
    f[rd] = max(f[rs1], f[rs2])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmax-s).
    """

    name = "riscv.fmax.s"

name = 'riscv.fmax.s' class-attribute instance-attribute

FCvtWSOp dataclass

Bases: RdRsIntegerOperation[FloatRegisterType]

Convert a floating-point number in floating-point register rs1 to a signed 32-bit in integer register rd.

x[rd] = sext(s32_{f32}(f[rs1]))

See external documentation.

Source code in xdsl/dialects/riscv.py
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
@irdl_op_definition
class FCvtWSOp(RdRsIntegerOperation[FloatRegisterType]):
    """
    Convert a floating-point number in floating-point register rs1 to a signed 32-bit in integer register rd.

    ```C
    x[rd] = sext(s32_{f32}(f[rs1]))
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fcvt.w.s).
    """

    name = "riscv.fcvt.w.s"

name = 'riscv.fcvt.w.s' class-attribute instance-attribute

FCvtWuSOp dataclass

Bases: RdRsIntegerOperation[FloatRegisterType]

Convert a floating-point number in floating-point register rs1 to a signed 32-bit in unsigned integer register rd.

x[rd] = sext(u32_{f32}(f[rs1]))

See external documentation.

Source code in xdsl/dialects/riscv.py
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
@irdl_op_definition
class FCvtWuSOp(RdRsIntegerOperation[FloatRegisterType]):
    """
    Convert a floating-point number in floating-point register rs1 to a signed 32-bit in unsigned integer register rd.

    ```C
    x[rd] = sext(u32_{f32}(f[rs1]))
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fcvt.wu.s).
    """

    name = "riscv.fcvt.wu.s"

name = 'riscv.fcvt.wu.s' class-attribute instance-attribute

FMvXWOp dataclass

Bases: RdRsIntegerOperation[FloatRegisterType]

Move the single-precision value in floating-point register rs1 represented in IEEE 754-2008 encoding to the lower 32 bits of integer register rd.

x[rd] = sext(f[rs1][31:0])

See external documentation.

Source code in xdsl/dialects/riscv.py
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
@irdl_op_definition
class FMvXWOp(RdRsIntegerOperation[FloatRegisterType]):
    """
    Move the single-precision value in floating-point register rs1 represented in IEEE
    754-2008 encoding to the lower 32 bits of integer register rd.

    ```C
    x[rd] = sext(f[rs1][31:0])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmv.x.w).
    """

    name = "riscv.fmv.x.w"

name = 'riscv.fmv.x.w' class-attribute instance-attribute

FeqSOp dataclass

Bases: RdRsRsFloatFloatIntegerOperationWithFastMath

Performs a quiet equal comparison between floating-point registers rs1 and rs2 and record the Boolean result in integer register rd. Only signaling NaN inputs cause an Invalid Operation exception. The result is 0 if either operand is NaN.

x[rd] = f[rs1] == f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
@irdl_op_definition
class FeqSOp(RdRsRsFloatFloatIntegerOperationWithFastMath):
    """
    Performs a quiet equal comparison between floating-point registers rs1 and rs2 and
    record the Boolean result in integer register rd.
    Only signaling NaN inputs cause an Invalid Operation exception.
    The result is 0 if either operand is NaN.

    x[rd] = f[rs1] == f[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#feq.s).
    """

    name = "riscv.feq.s"

name = 'riscv.feq.s' class-attribute instance-attribute

FltSOp dataclass

Bases: RdRsRsFloatFloatIntegerOperationWithFastMath

Performs a quiet less comparison between floating-point registers rs1 and rs2 and record the Boolean result in integer register rd. Only signaling NaN inputs cause an Invalid Operation exception. The result is 0 if either operand is NaN.

x[rd] = f[rs1] < f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
@irdl_op_definition
class FltSOp(RdRsRsFloatFloatIntegerOperationWithFastMath):
    """
    Performs a quiet less comparison between floating-point registers rs1 and rs2 and
    record the Boolean result in integer register rd.
    Only signaling NaN inputs cause an Invalid Operation exception.
    The result is 0 if either operand is NaN.

    x[rd] = f[rs1] < f[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#flt.s).
    """

    name = "riscv.flt.s"

name = 'riscv.flt.s' class-attribute instance-attribute

FleSOp dataclass

Bases: RdRsRsFloatFloatIntegerOperationWithFastMath

Performs a quiet less or equal comparison between floating-point registers rs1 and rs2 and record the Boolean result in integer register rd. Only signaling NaN inputs cause an Invalid Operation exception. The result is 0 if either operand is NaN.

x[rd] = f[rs1] <= f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
@irdl_op_definition
class FleSOp(RdRsRsFloatFloatIntegerOperationWithFastMath):
    """
    Performs a quiet less or equal comparison between floating-point registers rs1 and
    rs2 and record the Boolean result in integer register rd.
    Only signaling NaN inputs cause an Invalid Operation exception.
    The result is 0 if either operand is NaN.

    x[rd] = f[rs1] <= f[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fle.s).
    """

    name = "riscv.fle.s"

name = 'riscv.fle.s' class-attribute instance-attribute

FClassSOp dataclass

Bases: RdRsIntegerOperation[FloatRegisterType]

Examines the value in floating-point register rs1 and writes to integer register rd a 10-bit mask that indicates the class of the floating-point number. The format of the mask is described in [classify table]_. The corresponding bit in rd will be set if the property is true and clear otherwise. All other bits in rd are cleared. Note that exactly one bit in rd will be set.

x[rd] = classifys(f[rs1])

See external documentation.

Source code in xdsl/dialects/riscv.py
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
@irdl_op_definition
class FClassSOp(RdRsIntegerOperation[FloatRegisterType]):
    """
    Examines the value in floating-point register rs1 and writes to integer register rd
    a 10-bit mask that indicates the class of the floating-point number.
    The format of the mask is described in [classify table]_.
    The corresponding bit in rd will be set if the property is true and clear otherwise.
    All other bits in rd are cleared. Note that exactly one bit in rd will be set.

    x[rd] = classifys(f[rs1])

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fclass.s).
    """

    name = "riscv.fclass.s"

name = 'riscv.fclass.s' class-attribute instance-attribute

FCvtSWOp dataclass

Bases: RdRsFloatOperation[IntRegisterType]

Converts a 32-bit signed integer, in integer register rs1 into a floating-point number in floating-point register rd.

f[rd] = f32_{s32}(x[rs1])

See external documentation.

Source code in xdsl/dialects/riscv.py
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
@irdl_op_definition
class FCvtSWOp(RdRsFloatOperation[IntRegisterType]):
    """
    Converts a 32-bit signed integer, in integer register rs1 into a floating-point number in floating-point register rd.

    ```C
    f[rd] = f32_{s32}(x[rs1])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fcvt.s.w).
    """

    name = "riscv.fcvt.s.w"

name = 'riscv.fcvt.s.w' class-attribute instance-attribute

FCvtSWuOp dataclass

Bases: RdRsFloatOperation[IntRegisterType]

Converts a 32-bit unsigned integer, in integer register rs1 into a floating-point number in floating-point register rd.

f[rd] = f32_{u32}(x[rs1])

See external documentation.

Source code in xdsl/dialects/riscv.py
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
@irdl_op_definition
class FCvtSWuOp(RdRsFloatOperation[IntRegisterType]):
    """
    Converts a 32-bit unsigned integer, in integer register rs1 into a floating-point
    number in floating-point register rd.

    ```C
    f[rd] = f32_{u32}(x[rs1])
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fcvt.s.wu).
    """

    name = "riscv.fcvt.s.wu"

name = 'riscv.fcvt.s.wu' class-attribute instance-attribute

FMvWXOp dataclass

Bases: RdRsFloatOperation[IntRegisterType]

Move the single-precision value encoded in IEEE 754-2008 standard encoding from the lower 32 bits of integer register rs1 to the floating-point register rd.

f[rd] = x[rs1][31:0]

See external documentation.

Source code in xdsl/dialects/riscv.py
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
@irdl_op_definition
class FMvWXOp(RdRsFloatOperation[IntRegisterType]):
    """
    Move the single-precision value encoded in IEEE 754-2008 standard encoding from the
    lower 32 bits of integer register rs1 to the floating-point register rd.

    ```C
    f[rd] = x[rs1][31:0]
    ```


    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmv.w.x).
    """

    name = "riscv.fmv.w.x"

name = 'riscv.fmv.w.x' class-attribute instance-attribute

FLwOpHasCanonicalizationPatternTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
4542
4543
4544
4545
4546
4547
4548
4549
class FLwOpHasCanonicalizationPatternTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            LoadFloatWordWithKnownOffset,
        )

        return (LoadFloatWordWithKnownOffset(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
4543
4544
4545
4546
4547
4548
4549
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        LoadFloatWordWithKnownOffset,
    )

    return (LoadFloatWordWithKnownOffset(),)

FLwOp dataclass

Bases: RdRsImmFloatOperation

Load a single-precision value from memory into floating-point register rd.

f[rd] = M[x[rs1] + sext(offset)][31:0]

See external documentation.

Source code in xdsl/dialects/riscv.py
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
@irdl_op_definition
class FLwOp(RdRsImmFloatOperation):
    """
    Load a single-precision value from memory into floating-point register rd.

    ```C
    f[rd] = M[x[rs1] + sext(offset)][31:0]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#flw).
    """

    name = "riscv.flw"

    traits = traits_def(FLwOpHasCanonicalizationPatternTrait())

    def assembly_line(self) -> str | None:
        instruction_name = self.assembly_instruction_name()
        value = _assembly_arg_str(self.rd)
        imm = _assembly_arg_str(self.immediate)
        offset = _assembly_arg_str(self.rs1)
        return AssemblyPrinter.assembly_line(
            instruction_name, f"{value}, {imm}({offset})", self.comment
        )

name = 'riscv.flw' class-attribute instance-attribute

traits = traits_def(FLwOpHasCanonicalizationPatternTrait()) class-attribute instance-attribute

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
4568
4569
4570
4571
4572
4573
4574
4575
def assembly_line(self) -> str | None:
    instruction_name = self.assembly_instruction_name()
    value = _assembly_arg_str(self.rd)
    imm = _assembly_arg_str(self.immediate)
    offset = _assembly_arg_str(self.rs1)
    return AssemblyPrinter.assembly_line(
        instruction_name, f"{value}, {imm}({offset})", self.comment
    )

FSwOpHasCanonicalizationPatternTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
4578
4579
4580
4581
4582
4583
4584
4585
class FSwOpHasCanonicalizationPatternTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            StoreFloatWordWithKnownOffset,
        )

        return (StoreFloatWordWithKnownOffset(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
4579
4580
4581
4582
4583
4584
4585
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        StoreFloatWordWithKnownOffset,
    )

    return (StoreFloatWordWithKnownOffset(),)

FSwOp dataclass

Bases: RsRsImmFloatOperation

Store a single-precision value from floating-point register rs2 to memory.

M[x[rs1] + offset] = f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
@irdl_op_definition
class FSwOp(RsRsImmFloatOperation):
    """
    Store a single-precision value from floating-point register rs2 to memory.

    M[x[rs1] + offset] = f[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fsw).
    """

    name = "riscv.fsw"

    traits = traits_def(FSwOpHasCanonicalizationPatternTrait())

    def assembly_line(self) -> str | None:
        instruction_name = self.assembly_instruction_name()
        value = _assembly_arg_str(self.rs2)
        imm = _assembly_arg_str(self.immediate)
        offset = _assembly_arg_str(self.rs1)
        return AssemblyPrinter.assembly_line(
            instruction_name, f"{value}, {imm}({offset})", self.comment
        )

name = 'riscv.fsw' class-attribute instance-attribute

traits = traits_def(FSwOpHasCanonicalizationPatternTrait()) class-attribute instance-attribute

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
4602
4603
4604
4605
4606
4607
4608
4609
def assembly_line(self) -> str | None:
    instruction_name = self.assembly_instruction_name()
    value = _assembly_arg_str(self.rs2)
    imm = _assembly_arg_str(self.immediate)
    offset = _assembly_arg_str(self.rs1)
    return AssemblyPrinter.assembly_line(
        instruction_name, f"{value}, {imm}({offset})", self.comment
    )

FMAddDOp dataclass

Bases: RdRsRsRsFloatOperation

Perform double-precision fused multiply addition.

f[rd] = f[rs1]×f[rs2]+f[rs3]

See external documentation.

Source code in xdsl/dialects/riscv.py
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
@irdl_op_definition
class FMAddDOp(RdRsRsRsFloatOperation):
    """
    Perform double-precision fused multiply addition.

    f[rd] = f[rs1]×f[rs2]+f[rs3]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmadd-d).
    """

    name = "riscv.fmadd.d"

    traits = traits_def(Pure())

name = 'riscv.fmadd.d' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

FMSubDOp dataclass

Bases: RdRsRsRsFloatOperation

Perform double-precision fused multiply substraction.

f[rd] = f[rs1]×f[rs2]+f[rs3]

See external documentation.

Source code in xdsl/dialects/riscv.py
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
@irdl_op_definition
class FMSubDOp(RdRsRsRsFloatOperation):
    """
    Perform double-precision fused multiply substraction.

    f[rd] = f[rs1]×f[rs2]+f[rs3]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmsub-d).
    """

    name = "riscv.fmsub.d"

    traits = traits_def(Pure())

name = 'riscv.fmsub.d' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

FuseMultiplyAddDCanonicalizationPatternTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
4647
4648
4649
4650
4651
4652
4653
4654
class FuseMultiplyAddDCanonicalizationPatternTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            FuseMultiplyAddD,
        )

        return (FuseMultiplyAddD(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
4648
4649
4650
4651
4652
4653
4654
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        FuseMultiplyAddD,
    )

    return (FuseMultiplyAddD(),)

FAddDOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Perform double-precision floating-point addition.

f[rd] = f[rs1]+f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
@irdl_op_definition
class FAddDOp(RdRsRsFloatOperationWithFastMath):
    """
    Perform double-precision floating-point addition.

    f[rd] = f[rs1]+f[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fadd-d).
    """

    name = "riscv.fadd.d"

    traits = traits_def(
        Pure(),
        FuseMultiplyAddDCanonicalizationPatternTrait(),
    )

name = 'riscv.fadd.d' class-attribute instance-attribute

traits = traits_def(Pure(), FuseMultiplyAddDCanonicalizationPatternTrait()) class-attribute instance-attribute

FSubDOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Perform double-precision floating-point substraction.

f[rd] = f[rs1]-f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
@irdl_op_definition
class FSubDOp(RdRsRsFloatOperationWithFastMath):
    """
    Perform double-precision floating-point substraction.

    f[rd] = f[rs1]-f[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fsub-d).
    """

    name = "riscv.fsub.d"

    traits = traits_def(Pure())

name = 'riscv.fsub.d' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

FMulDOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Perform double-precision floating-point multiplication.

f[rd] = f[rs1]×f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
@irdl_op_definition
class FMulDOp(RdRsRsFloatOperationWithFastMath):
    """
    Perform double-precision floating-point multiplication.

    f[rd] = f[rs1]×f[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmul-d).
    """

    name = "riscv.fmul.d"

    traits = traits_def(Pure())

name = 'riscv.fmul.d' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

FDivDOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Perform double-precision floating-point division.

f[rd] = f[rs1] / f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
@irdl_op_definition
class FDivDOp(RdRsRsFloatOperationWithFastMath):
    """
    Perform double-precision floating-point division.

    f[rd] = f[rs1] / f[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fdiv-d).
    """

    name = "riscv.fdiv.d"

name = 'riscv.fdiv.d' class-attribute instance-attribute

FLdOpHasCanonicalizationPatternTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
4718
4719
4720
4721
4722
4723
4724
4725
class FLdOpHasCanonicalizationPatternTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            LoadDoubleWithKnownOffset,
        )

        return (LoadDoubleWithKnownOffset(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
4719
4720
4721
4722
4723
4724
4725
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        LoadDoubleWithKnownOffset,
    )

    return (LoadDoubleWithKnownOffset(),)

FMinDOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Write the smaller of double precision data in rs1 and rs2 to rd.

f[rd] = min(f[rs1], f[rs2])

See external documentation.

Source code in xdsl/dialects/riscv.py
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
@irdl_op_definition
class FMinDOp(RdRsRsFloatOperationWithFastMath):
    """
    Write the smaller of double precision data in rs1 and rs2 to rd.

    f[rd] = min(f[rs1], f[rs2])

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmin-d).
    """

    name = "riscv.fmin.d"

    traits = traits_def(Pure())

name = 'riscv.fmin.d' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

FMaxDOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Write the larger of single precision data in rs1 and rs2 to rd.

f[rd] = max(f[rs1], f[rs2])

See external documentation.

Source code in xdsl/dialects/riscv.py
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
@irdl_op_definition
class FMaxDOp(RdRsRsFloatOperationWithFastMath):
    """
    Write the larger of single precision data in rs1 and rs2 to rd.

    f[rd] = max(f[rs1], f[rs2])

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fmax-d).
    """

    name = "riscv.fmax.d"

    traits = traits_def(Pure())

name = 'riscv.fmax.d' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

FCvtDWOp dataclass

Bases: RdRsFloatOperation[IntRegisterType]

Converts a 32-bit signed integer, in integer register rs1 into a double-precision floating-point number in floating-point register rd.

x[rd] = sext(s32_{f64}(f[rs1]))

See external documentation.

Source code in xdsl/dialects/riscv.py
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
@irdl_op_definition
class FCvtDWOp(RdRsFloatOperation[IntRegisterType]):
    """
    Converts a 32-bit signed integer, in integer register rs1 into a double-precision
    floating-point number in floating-point register rd.

    x[rd] = sext(s32_{f64}(f[rs1]))

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fcvt-d-w).
    """

    name = "riscv.fcvt.d.w"

    traits = traits_def(Pure())

name = 'riscv.fcvt.d.w' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

FCvtDWuOp dataclass

Bases: RdRsFloatOperation[IntRegisterType]

Converts a 32-bit unsigned integer, in integer register rs1 into a double-precision floating-point number in floating-point register rd.

f[rd] = f64_{u32}(x[rs1])

See external documentation.

Source code in xdsl/dialects/riscv.py
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
@irdl_op_definition
class FCvtDWuOp(RdRsFloatOperation[IntRegisterType]):
    """
    Converts a 32-bit unsigned integer, in integer register rs1 into a double-precision
    floating-point number in floating-point register rd.

    f[rd] = f64_{u32}(x[rs1])

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fcvt-d-wu).
    """

    name = "riscv.fcvt.d.wu"

    traits = traits_def(Pure())

name = 'riscv.fcvt.d.wu' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

FLdOp dataclass

Bases: RdRsImmFloatOperation

Load a double-precision value from memory into floating-point register rd.

f[rd] = M[x[rs1] + sext(offset)][63:0]

See external documentation.

Source code in xdsl/dialects/riscv.py
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
@irdl_op_definition
class FLdOp(RdRsImmFloatOperation):
    """
    Load a double-precision value from memory into floating-point register rd.

    ```C
    f[rd] = M[x[rs1] + sext(offset)][63:0]
    ```

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fld).
    """

    name = "riscv.fld"

    traits = traits_def(FLdOpHasCanonicalizationPatternTrait())

    def assembly_line(self) -> str | None:
        instruction_name = self.assembly_instruction_name()
        value = _assembly_arg_str(self.rd)
        imm = _assembly_arg_str(self.immediate)
        offset = _assembly_arg_str(self.rs1)
        if isinstance(self.immediate, LabelAttr):
            return AssemblyPrinter.assembly_line(
                instruction_name, f"{value}, {imm}, {offset}", self.comment
            )
        else:
            return AssemblyPrinter.assembly_line(
                instruction_name, f"{value}, {imm}({offset})", self.comment
            )

name = 'riscv.fld' class-attribute instance-attribute

traits = traits_def(FLdOpHasCanonicalizationPatternTrait()) class-attribute instance-attribute

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
def assembly_line(self) -> str | None:
    instruction_name = self.assembly_instruction_name()
    value = _assembly_arg_str(self.rd)
    imm = _assembly_arg_str(self.immediate)
    offset = _assembly_arg_str(self.rs1)
    if isinstance(self.immediate, LabelAttr):
        return AssemblyPrinter.assembly_line(
            instruction_name, f"{value}, {imm}, {offset}", self.comment
        )
    else:
        return AssemblyPrinter.assembly_line(
            instruction_name, f"{value}, {imm}({offset})", self.comment
        )

FSdOpHasCanonicalizationPatternTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
4821
4822
4823
4824
4825
4826
4827
4828
class FSdOpHasCanonicalizationPatternTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            StoreDoubleWithKnownOffset,
        )

        return (StoreDoubleWithKnownOffset(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
4822
4823
4824
4825
4826
4827
4828
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        StoreDoubleWithKnownOffset,
    )

    return (StoreDoubleWithKnownOffset(),)

FSdOp dataclass

Bases: RsRsImmFloatOperation

Store a double-precision value from floating-point register rs2 to memory.

M[x[rs1] + offset] = f[rs2]

See external documentation.

Source code in xdsl/dialects/riscv.py
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
@irdl_op_definition
class FSdOp(RsRsImmFloatOperation):
    """
    Store a double-precision value from floating-point register rs2 to memory.

    M[x[rs1] + offset] = f[rs2]

    See external [documentation](https://msyksphinz-self.github.io/riscv-isadoc/html/rvfd.html#fsw).
    """

    name = "riscv.fsd"

    traits = traits_def(FSdOpHasCanonicalizationPatternTrait())

    def assembly_line(self) -> str | None:
        instruction_name = self.assembly_instruction_name()
        value = _assembly_arg_str(self.rs2)
        imm = _assembly_arg_str(self.immediate)
        offset = _assembly_arg_str(self.rs1)
        return AssemblyPrinter.assembly_line(
            instruction_name, f"{value}, {imm}({offset})", self.comment
        )

name = 'riscv.fsd' class-attribute instance-attribute

traits = traits_def(FSdOpHasCanonicalizationPatternTrait()) class-attribute instance-attribute

assembly_line() -> str | None

Source code in xdsl/dialects/riscv.py
4845
4846
4847
4848
4849
4850
4851
4852
def assembly_line(self) -> str | None:
    instruction_name = self.assembly_instruction_name()
    value = _assembly_arg_str(self.rs2)
    imm = _assembly_arg_str(self.immediate)
    offset = _assembly_arg_str(self.rs1)
    return AssemblyPrinter.assembly_line(
        instruction_name, f"{value}, {imm}({offset})", self.comment
    )

FMvDHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv.py
4855
4856
4857
4858
4859
4860
class FMvDHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import RemoveRedundantFMvD

        return (RemoveRedundantFMvD(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/riscv.py
4856
4857
4858
4859
4860
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import RemoveRedundantFMvD

    return (RemoveRedundantFMvD(),)

FMvDOp dataclass

Bases: RdRsFloatOperation[FloatRegisterType]

A pseudo instruction to copy 64 bits of one float register to another.

Equivalent to fsgnj.d rd, rs, rs.

Source code in xdsl/dialects/riscv.py
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
@irdl_op_definition
class FMvDOp(RdRsFloatOperation[FloatRegisterType]):
    """
    A pseudo instruction to copy 64 bits of one float register to another.

    Equivalent to `fsgnj.d rd, rs, rs`.
    """

    name = "riscv.fmv.d"

    traits = traits_def(
        Pure(),
        FMvDHasCanonicalizationPatternsTrait(),
    )

name = 'riscv.fmv.d' class-attribute instance-attribute

traits = traits_def(Pure(), FMvDHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

VFAddSOp dataclass

Bases: RdRsRsFloatOperation[FloatRegisterType, FloatRegisterType]

Perform a pointwise single-precision floating-point addition over vectors.

If the registers used are FloatRegisterType, they must be 64-bit wide, and contain two 32-bit single-precision floating point values.

Source code in xdsl/dialects/riscv.py
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
@irdl_op_definition
class VFAddSOp(RdRsRsFloatOperation[FloatRegisterType, FloatRegisterType]):
    """
    Perform a pointwise single-precision floating-point addition over vectors.

    If the registers used are FloatRegisterType, they must be 64-bit wide, and contain two
    32-bit single-precision floating point values.
    """

    name = "riscv.vfadd.s"

    traits = traits_def(Pure())

name = 'riscv.vfadd.s' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

VFMulSOp dataclass

Bases: RdRsRsFloatOperation[FloatRegisterType, FloatRegisterType]

Perform a pointwise single-precision floating-point multiplication over vectors.

If the registers used are FloatRegisterType, they must be 64-bit wide, and contain two 32-bit single-precision floating point values.

Source code in xdsl/dialects/riscv.py
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
@irdl_op_definition
class VFMulSOp(RdRsRsFloatOperation[FloatRegisterType, FloatRegisterType]):
    """
    Perform a pointwise single-precision floating-point multiplication over vectors.

    If the registers used are FloatRegisterType, they must be 64-bit wide, and contain two
    32-bit single-precision floating point values.
    """

    name = "riscv.vfmul.s"

    traits = traits_def(Pure())

name = 'riscv.vfmul.s' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

is_non_zero(reg: IntRegisterType) -> bool

Returns True if the register is allocated, and is not the x0/ZERO register.

Source code in xdsl/dialects/riscv.py
81
82
83
84
85
86
87
def is_non_zero(reg: IntRegisterType) -> bool:
    """
    Returns True if the register is allocated, and is not the x0/ZERO register.
    """
    return (
        reg.is_allocated and not isinstance(reg.index, NoneAttr) and reg.index.data != 0
    )

print_assembly(module: ModuleOp, output: IO[str]) -> None

Source code in xdsl/dialects/riscv.py
530
531
532
def print_assembly(module: ModuleOp, output: IO[str]) -> None:
    printer = AssemblyPrinter(stream=output)
    printer.print_module(module)

riscv_code(module: ModuleOp) -> str

Source code in xdsl/dialects/riscv.py
535
536
537
538
def riscv_code(module: ModuleOp) -> str:
    stream = StringIO()
    print_assembly(module, stream)
    return stream.getvalue()

parse_immediate_value(parser: Parser, integer_type: IntegerType | IndexType) -> IntegerAttr[IntegerType | IndexType] | LabelAttr

Source code in xdsl/dialects/riscv.py
4939
4940
4941
4942
4943
4944
4945
def parse_immediate_value(
    parser: Parser, integer_type: IntegerType | IndexType
) -> IntegerAttr[IntegerType | IndexType] | LabelAttr:
    return parser.expect(
        lambda: _parse_optional_immediate_value(parser, integer_type),
        "Expected immediate",
    )

print_immediate_value(printer: Printer, immediate: IntegerAttr | LabelAttr)

Source code in xdsl/dialects/riscv.py
4948
4949
4950
4951
4952
4953
def print_immediate_value(printer: Printer, immediate: IntegerAttr | LabelAttr):
    match immediate:
        case IntegerAttr():
            immediate.print_without_type(printer)
        case LabelAttr():
            printer.print_string_literal(immediate.data)