Skip to content

Riscv snitch

riscv_snitch

ALLOWED_FREP_OP_TYPES = (FrepYieldOp, ReadOp, WriteOp, UnrealizedConversionCastOp) module-attribute

I3: TypeAlias = IntegerType[Literal[3]] module-attribute

I4: TypeAlias = IntegerType[Literal[4]] module-attribute

i3 = I3(3) module-attribute

i4 = I4(4) module-attribute

RISCV_Snitch = Dialect('riscv_snitch', [ScfgwOp, ScfgwiOp, FrepOuterOp, FrepInnerOp, FrepYieldOp, ReadOp, WriteOp, GetStreamOp, DMSourceOp, DMDestinationOp, DMStrideOp, DMRepOp, DMCopyOp, DMCopyImmOp, DMStatOp, DMStatImmOp, VFMulSOp, VFAddSOp, VFCpkASSOp, VFMacSOp, VFSumSOp, VFAddHOp, VFMaxSOp], []) module-attribute

ScfgwOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv_snitch.py
77
78
79
80
81
82
83
84
class ScfgwOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.riscv import (
            ScfgwOpUsingImmediate,
        )

        return (ScfgwOpUsingImmediate(),)

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

Source code in xdsl/dialects/riscv_snitch.py
78
79
80
81
82
83
84
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.riscv import (
        ScfgwOpUsingImmediate,
    )

    return (ScfgwOpUsingImmediate(),)

ScfgwOp dataclass

Bases: RsRsIntegerOperation

Write the value in rs1 to the Snitch stream configuration location pointed by rs2 in the memory-mapped address space.

This is a RISC-V ISA extension, part of the `Xssr' extension.

See external documentation.

Source code in xdsl/dialects/riscv_snitch.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
@irdl_op_definition
class ScfgwOp(RsRsIntegerOperation):
    """
    Write the value in rs1 to the Snitch stream configuration
    location pointed by rs2 in the memory-mapped address space.

    This is a RISC-V ISA extension, part of the `Xssr' extension.

    See external [documentation](https://pulp-platform.github.io/snitch/rm/custom_instructions/).
    """

    name = "riscv_snitch.scfgw"

    traits = traits_def(ScfgwOpHasCanonicalizationPatternsTrait())

name = 'riscv_snitch.scfgw' class-attribute instance-attribute

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

ScfgwiOp

Bases: RISCVCustomFormatOperation, RISCVInstruction

Write the value in rs to the Snitch stream configuration location pointed by immediate value in the memory-mapped address space.

This is a RISC-V ISA extension, part of the `Xssr' extension.

See external documentation.

Source code in xdsl/dialects/riscv_snitch.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
@irdl_op_definition
class ScfgwiOp(RISCVCustomFormatOperation, RISCVInstruction):
    """
    Write the value in rs to the Snitch stream configuration location pointed by
    immediate value in the memory-mapped address space.

    This is a RISC-V ISA extension, part of the `Xssr' extension.

    See external [documentation](https://pulp-platform.github.io/snitch/rm/custom_instructions/).
    """

    name = "riscv_snitch.scfgwi"

    rs1 = operand_def(IntRegisterType)
    immediate = attr_def(IntegerAttr[SI12])

    def __init__(
        self,
        rs1: Operation | SSAValue,
        immediate: int | IntegerAttr[SI12],
        *,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(immediate, int):
            immediate = IntegerAttr(immediate, si12)
        if isinstance(comment, str):
            comment = StringAttr(comment)
        super().__init__(
            operands=[rs1],
            attributes={
                "immediate": immediate,
                "comment": comment,
            },
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return 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) -> set[str]:
        printer.print_string(", ")
        print_immediate_value(printer, self.immediate)
        return {"immediate"}

name = 'riscv_snitch.scfgwi' class-attribute instance-attribute

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

immediate = attr_def(IntegerAttr[SI12]) class-attribute instance-attribute

__init__(rs1: Operation | SSAValue, immediate: int | IntegerAttr[SI12], *, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv_snitch.py
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def __init__(
    self,
    rs1: Operation | SSAValue,
    immediate: int | IntegerAttr[SI12],
    *,
    comment: str | StringAttr | None = None,
):
    if isinstance(immediate, int):
        immediate = IntegerAttr(immediate, si12)
    if isinstance(comment, str):
        comment = StringAttr(comment)
    super().__init__(
        operands=[rs1],
        attributes={
            "immediate": immediate,
            "comment": comment,
        },
    )

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

Source code in xdsl/dialects/riscv_snitch.py
138
139
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rs1, self.immediate

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

Source code in xdsl/dialects/riscv_snitch.py
141
142
143
144
145
@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) -> set[str]

Source code in xdsl/dialects/riscv_snitch.py
147
148
149
150
def custom_print_attributes(self, printer: Printer) -> set[str]:
    printer.print_string(", ")
    print_immediate_value(printer, self.immediate)
    return {"immediate"}

FrepYieldOp dataclass

Bases: AbstractYieldOperation[Attribute], RISCVAsmOperation, RISCVRegallocOperation

Source code in xdsl/dialects/riscv_snitch.py
153
154
155
156
157
158
159
160
161
162
163
164
@irdl_op_definition
class FrepYieldOp(
    AbstractYieldOperation[Attribute], RISCVAsmOperation, RISCVRegallocOperation
):
    name = "riscv_snitch.frep_yield"

    traits = lazy_traits_def(
        lambda: (IsTerminator(), HasParent(FrepInnerOp, FrepOuterOp))
    )

    def assembly_line(self) -> str | None:
        return None

name = 'riscv_snitch.frep_yield' class-attribute instance-attribute

traits = lazy_traits_def(lambda: (IsTerminator(), HasParent(FrepInnerOp, FrepOuterOp))) class-attribute instance-attribute

assembly_line() -> str | None

Source code in xdsl/dialects/riscv_snitch.py
163
164
def assembly_line(self) -> str | None:
    return None

ReadOp

Bases: RISCVAsmOperation, RISCVRegallocOperation

Source code in xdsl/dialects/riscv_snitch.py
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
@irdl_op_definition
class ReadOp(RISCVAsmOperation, RISCVRegallocOperation):
    name = "riscv_snitch.read"

    T: ClassVar = VarConstraint("T", AnyAttr())

    stream = operand_def(snitch.ReadableStreamType.constr(T))
    res = result_def(T)

    assembly_format = "`from` $stream attr-dict `:` type($res)"

    def __init__(self, stream_val: SSAValue, result_type: Attribute | None = None):
        if result_type is None:
            assert isinstance(stream_type := stream_val.type, snitch.ReadableStreamType)
            stream_type = cast(snitch.ReadableStreamType[Attribute], stream_type)
            result_type = stream_type.element_type
        super().__init__(operands=[stream_val], result_types=[result_type])

    def assembly_line(self) -> str | None:
        return None

    def iter_used_registers(self):
        # When streaming, FT0, FT1, and FT2 cannot be used as general-purpose float
        # registers
        yield riscv.Registers.FT0
        yield riscv.Registers.FT1
        yield riscv.Registers.FT2

name = 'riscv_snitch.read' class-attribute instance-attribute

T: ClassVar = VarConstraint('T', AnyAttr()) class-attribute instance-attribute

stream = operand_def(snitch.ReadableStreamType.constr(T)) class-attribute instance-attribute

res = result_def(T) class-attribute instance-attribute

assembly_format = '`from` $stream attr-dict `:` type($res)' class-attribute instance-attribute

__init__(stream_val: SSAValue, result_type: Attribute | None = None)

Source code in xdsl/dialects/riscv_snitch.py
178
179
180
181
182
183
def __init__(self, stream_val: SSAValue, result_type: Attribute | None = None):
    if result_type is None:
        assert isinstance(stream_type := stream_val.type, snitch.ReadableStreamType)
        stream_type = cast(snitch.ReadableStreamType[Attribute], stream_type)
        result_type = stream_type.element_type
    super().__init__(operands=[stream_val], result_types=[result_type])

assembly_line() -> str | None

Source code in xdsl/dialects/riscv_snitch.py
185
186
def assembly_line(self) -> str | None:
    return None

iter_used_registers()

Source code in xdsl/dialects/riscv_snitch.py
188
189
190
191
192
193
def iter_used_registers(self):
    # When streaming, FT0, FT1, and FT2 cannot be used as general-purpose float
    # registers
    yield riscv.Registers.FT0
    yield riscv.Registers.FT1
    yield riscv.Registers.FT2

WriteOp

Bases: RISCVAsmOperation, RISCVRegallocOperation

Source code in xdsl/dialects/riscv_snitch.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
@irdl_op_definition
class WriteOp(RISCVAsmOperation, RISCVRegallocOperation):
    name = "riscv_snitch.write"

    T: ClassVar = VarConstraint("T", AnyAttr())

    value = operand_def(T)
    stream = operand_def(snitch.WritableStreamType.constr(T))

    assembly_format = "$value `to` $stream attr-dict `:` type($value)"

    def __init__(self, value: SSAValue, stream: SSAValue):
        super().__init__(operands=[value, stream])

    def assembly_line(self) -> str | None:
        return None

    def iter_used_registers(self):
        # When streaming, FT0, FT1, and FT2 cannot be used as general-purpose float
        # registers
        yield riscv.Registers.FT0
        yield riscv.Registers.FT1
        yield riscv.Registers.FT2

name = 'riscv_snitch.write' class-attribute instance-attribute

T: ClassVar = VarConstraint('T', AnyAttr()) class-attribute instance-attribute

value = operand_def(T) class-attribute instance-attribute

stream = operand_def(snitch.WritableStreamType.constr(T)) class-attribute instance-attribute

assembly_format = '$value `to` $stream attr-dict `:` type($value)' class-attribute instance-attribute

__init__(value: SSAValue, stream: SSAValue)

Source code in xdsl/dialects/riscv_snitch.py
207
208
def __init__(self, value: SSAValue, stream: SSAValue):
    super().__init__(operands=[value, stream])

assembly_line() -> str | None

Source code in xdsl/dialects/riscv_snitch.py
210
211
def assembly_line(self) -> str | None:
    return None

iter_used_registers()

Source code in xdsl/dialects/riscv_snitch.py
213
214
215
216
217
218
def iter_used_registers(self):
    # When streaming, FT0, FT1, and FT2 cannot be used as general-purpose float
    # registers
    yield riscv.Registers.FT0
    yield riscv.Registers.FT1
    yield riscv.Registers.FT2

FRepOperation

Bases: RISCVInstruction

The frep instruction marks the beginning of a floating-point kernel which should be repeated. It indicates how many subsequent instructions are stored in the sequence buffer, how often and how (operand staggering, repetition mode) each instruction is going to be repeated.

Snitch paper: See external documentation.

Source code in xdsl/dialects/riscv_snitch.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
class FRepOperation(RISCVInstruction):
    """
    The frep instruction marks the beginning of a floating-point kernel which should be
    repeated. It indicates how many subsequent instructions are stored in the sequence
    buffer, how often and how (operand staggering, repetition mode) each instruction is
    going to be repeated.

    Snitch paper: See external [documentation](https://arxiv.org/abs/2002.10143).
    """

    max_rep = operand_def(IntRegisterType)
    """Number of times to repeat the instructions."""
    body = region_def("single_block")
    """
    Instructions to repeat, containing maximum 15 instructions, with no side effects.
    """
    iter_args = var_operand_def(riscv.RISCVRegisterType)
    """
    Loop-carried variable initial values.
    """
    stagger_mask = attr_def(
        IntegerAttr[I4],
        default_value=IntegerAttr(0, i4),
    )
    """
    4 bits for each operand (rs1 rs2 rs3 rd). If the bit is set, the corresponding operand
    is staggered.
    """
    stagger_count = attr_def(
        IntegerAttr[I3],
        default_value=IntegerAttr(0, i3),
    )
    """
    3 bits, indicating for how many iterations the stagger should increment before it
    wraps again (up to 23 = 8).
    """
    res = var_result_def(riscv.RISCVRegisterType)
    """
    Loop-carried variable initial values.
    """

    traits = lazy_traits_def(lambda: (SingleBlockImplicitTerminator(FrepYieldOp),))

    def __init__(
        self,
        max_rep: SSAValue | Operation,
        body: Sequence[Operation] | Sequence[Block] | Region,
        iter_args: Sequence[SSAValue | Operation] = (),
        stagger_mask: IntegerAttr[I4] | None = None,
        stagger_count: IntegerAttr[I3] | None = None,
    ):
        if stagger_mask is None:
            stagger_mask = IntegerAttr(0, i4)
        if stagger_count is None:
            stagger_count = IntegerAttr(0, i3)
        super().__init__(
            operands=(max_rep, iter_args),
            result_types=[[SSAValue.get(a).type for a in iter_args]],
            regions=(body,),
            attributes={
                "stagger_mask": stagger_mask,
                "stagger_count": stagger_count,
            },
        )

    @property
    def max_inst(self) -> int:
        """
        Number of instructions to be repeated.
        """
        return len([op for op in self.body.ops if isinstance(op, RISCVInstruction)])

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
        return (
            self.max_rep,
            str(self.max_inst),
            self.stagger_mask,
            self.stagger_count,
        )

    @classmethod
    def parse(cls, parser: Parser) -> Self:
        max_rep = parser.parse_operand()
        if parser.parse_optional_punctuation(","):
            stagger_mask = parser.parse_integer(False, False)
            parser.parse_punctuation(",")
            stagger_count = parser.parse_integer(False, False)
        else:
            stagger_mask = 0
            stagger_count = 0

        remaining_attributes = parser.parse_optional_attr_dict_with_keyword()

        # Parse iteration arguments
        pos = parser.pos
        unresolved_iter_args: list[Parser.UnresolvedArgument] = []
        iter_arg_unresolved_operands: list[UnresolvedOperand] = []
        iter_arg_types: list[Attribute] = []
        if parser.parse_optional_characters("iter_args"):
            for iter_arg, iter_arg_operand in parser.parse_comma_separated_list(
                Parser.Delimiter.PAREN, lambda: parse_assignment(parser)
            ):
                unresolved_iter_args.append(iter_arg)
                iter_arg_unresolved_operands.append(iter_arg_operand)
            parser.parse_characters("->")
            iter_arg_types = parser.parse_comma_separated_list(
                Parser.Delimiter.PAREN, parser.parse_attribute
            )

        iter_arg_operands = parser.resolve_operands(
            iter_arg_unresolved_operands, iter_arg_types, pos
        )

        # Set block argument types
        iter_args = [
            u_arg.resolve(t) for u_arg, t in zip(unresolved_iter_args, iter_arg_types)
        ]

        body = parser.parse_region(iter_args)

        frep = cls(
            max_rep,
            body,
            iter_arg_operands,
            IntegerAttr(stagger_mask, i4),
            IntegerAttr(stagger_count, i3),
        )
        if remaining_attributes is not None:
            frep.attributes |= remaining_attributes.data

        for trait in frep.get_traits_of_type(SingleBlockImplicitTerminator):
            ensure_terminator(frep, trait)

        return frep

    def print(self, printer: Printer) -> None:
        printer.print_string(" ")
        printer.print_ssa_value(self.max_rep)
        if self.stagger_count.value.data and self.stagger_mask.value.data:
            printer.print_string(", ")
            printer.print_int(self.stagger_count.value.data)
            printer.print_string(", ")
            printer.print_int(self.stagger_mask.value.data)

        printer.print_op_attributes(
            self.attributes, reserved_attr_names=("stagger_count", "stagger_mask")
        )
        printer.print_string(" ")

        block = self.body.block

        yield_op = block.last_op
        print_block_terminators = not isinstance(yield_op, FrepYieldOp) or bool(
            yield_op.operands
        )

        if iter_args := block.args:
            printer.print_string("iter_args(")
            printer.print_list(
                zip(iter_args, self.iter_args),
                lambda pair: print_assignment(printer, *pair),
            )
            printer.print_string(") -> (")
            printer.print_list((a.type for a in iter_args), printer.print_attribute)
            printer.print_string(") ")

        printer.print_region(
            self.body,
            print_entry_block_args=False,
            print_block_terminators=print_block_terminators,
        )

    def verify_(self) -> None:
        if self.stagger_count.value.data:
            raise VerifyException("Non-zero stagger count currently unsupported")
        if self.stagger_mask.value.data:
            raise VerifyException("Non-zero stagger mask currently unsupported")
        for instruction in self.body.ops:
            if not instruction.has_trait(Pure) and not isinstance(
                instruction, ALLOWED_FREP_OP_TYPES
            ):
                raise VerifyException(
                    "Frep operation body may not contain instructions "
                    f"with side-effects, found {instruction.name}"
                )
        if len(self.iter_args) != len(self.body.block.args):
            raise VerifyException(
                f"Wrong number of block arguments, expected {len(self.iter_args)}, got "
                f"{len(self.body.block.args)}. The body must have the induction "
                f"variable and loop-carried variables as arguments."
            )
        for idx, (arg, block_arg) in enumerate(
            zip(self.iter_args, self.body.block.args)
        ):
            if block_arg.type != arg.type:
                raise VerifyException(
                    f"Block argument {idx} has wrong type, expected {arg.type}, "
                    f"got {block_arg.type}. Arguments after the "
                    f"induction variable must match the carried variables."
                )
        if len(self.body.ops) > 0 and isinstance(
            yieldop := self.body.block.last_op, FrepYieldOp
        ):
            if len(yieldop.arguments) != len(self.iter_args):
                raise VerifyException(
                    f"Expected {len(self.iter_args)} args, got {len(yieldop.arguments)}. "
                    f"The riscv_scf.frep must yield its carried variables."
                )
            for iter_arg, yield_arg in zip(self.iter_args, yieldop.arguments):
                if iter_arg.type != yield_arg.type:
                    raise VerifyException(
                        f"Expected {iter_arg.type}, got {yield_arg.type}. The "
                        f"riscv_snitch.frep's riscv_snitch.frep_yield must match carried"
                        f"variables types."
                    )

    def allocate_registers(self, allocator: BlockAllocator) -> None:
        # Allocate values used inside the body but defined outside.
        # Their scope lasts for the whole body execution scope
        live_ins = allocator.live_ins_per_block[self.body.block]
        for live_in in live_ins:
            allocator.allocate_value(live_in)

        yield_op = self.body.block.last_op
        assert yield_op is not None, (
            "last op of riscv_snitch.frep_outer and riscv_snitch.frep_inner is guaranteed"
            " to be riscv_scf.Yield"
        )
        block_args = self.body.block.args

        # The loop-carried variables are trickier
        # The for op operand, block arg, and yield operand must have the same type
        for block_arg, operand, yield_operand, op_result in zip(
            block_args, self.iter_args, yield_op.operands, self.results
        ):
            allocator.allocate_values_same_reg(
                (block_arg, operand, yield_operand, op_result)
            )

        allocator.allocate_value(self.max_rep)

        # Reserve the loop carried variables for allocation within the body
        regs = self.iter_args.types
        assert all(isinstance(reg, RISCVRegisterType) for reg in regs)
        regs = cast(tuple[RISCVRegisterType, ...], regs)
        with allocator.available_registers.reserve_registers(regs):
            allocator.allocate_block(self.body.block)

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

Number of times to repeat the instructions.

body = region_def('single_block') class-attribute instance-attribute

Instructions to repeat, containing maximum 15 instructions, with no side effects.

iter_args = var_operand_def(riscv.RISCVRegisterType) class-attribute instance-attribute

Loop-carried variable initial values.

stagger_mask = attr_def(IntegerAttr[I4], default_value=(IntegerAttr(0, i4))) class-attribute instance-attribute

4 bits for each operand (rs1 rs2 rs3 rd). If the bit is set, the corresponding operand is staggered.

stagger_count = attr_def(IntegerAttr[I3], default_value=(IntegerAttr(0, i3))) class-attribute instance-attribute

3 bits, indicating for how many iterations the stagger should increment before it wraps again (up to 23 = 8).

res = var_result_def(riscv.RISCVRegisterType) class-attribute instance-attribute

Loop-carried variable initial values.

traits = lazy_traits_def(lambda: (SingleBlockImplicitTerminator(FrepYieldOp),)) class-attribute instance-attribute

max_inst: int property

Number of instructions to be repeated.

__init__(max_rep: SSAValue | Operation, body: Sequence[Operation] | Sequence[Block] | Region, iter_args: Sequence[SSAValue | Operation] = (), stagger_mask: IntegerAttr[I4] | None = None, stagger_count: IntegerAttr[I3] | None = None)

Source code in xdsl/dialects/riscv_snitch.py
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
def __init__(
    self,
    max_rep: SSAValue | Operation,
    body: Sequence[Operation] | Sequence[Block] | Region,
    iter_args: Sequence[SSAValue | Operation] = (),
    stagger_mask: IntegerAttr[I4] | None = None,
    stagger_count: IntegerAttr[I3] | None = None,
):
    if stagger_mask is None:
        stagger_mask = IntegerAttr(0, i4)
    if stagger_count is None:
        stagger_count = IntegerAttr(0, i3)
    super().__init__(
        operands=(max_rep, iter_args),
        result_types=[[SSAValue.get(a).type for a in iter_args]],
        regions=(body,),
        attributes={
            "stagger_mask": stagger_mask,
            "stagger_count": stagger_count,
        },
    )

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

Source code in xdsl/dialects/riscv_snitch.py
306
307
308
309
310
311
312
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return (
        self.max_rep,
        str(self.max_inst),
        self.stagger_mask,
        self.stagger_count,
    )

parse(parser: Parser) -> Self classmethod

Source code in xdsl/dialects/riscv_snitch.py
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
@classmethod
def parse(cls, parser: Parser) -> Self:
    max_rep = parser.parse_operand()
    if parser.parse_optional_punctuation(","):
        stagger_mask = parser.parse_integer(False, False)
        parser.parse_punctuation(",")
        stagger_count = parser.parse_integer(False, False)
    else:
        stagger_mask = 0
        stagger_count = 0

    remaining_attributes = parser.parse_optional_attr_dict_with_keyword()

    # Parse iteration arguments
    pos = parser.pos
    unresolved_iter_args: list[Parser.UnresolvedArgument] = []
    iter_arg_unresolved_operands: list[UnresolvedOperand] = []
    iter_arg_types: list[Attribute] = []
    if parser.parse_optional_characters("iter_args"):
        for iter_arg, iter_arg_operand in parser.parse_comma_separated_list(
            Parser.Delimiter.PAREN, lambda: parse_assignment(parser)
        ):
            unresolved_iter_args.append(iter_arg)
            iter_arg_unresolved_operands.append(iter_arg_operand)
        parser.parse_characters("->")
        iter_arg_types = parser.parse_comma_separated_list(
            Parser.Delimiter.PAREN, parser.parse_attribute
        )

    iter_arg_operands = parser.resolve_operands(
        iter_arg_unresolved_operands, iter_arg_types, pos
    )

    # Set block argument types
    iter_args = [
        u_arg.resolve(t) for u_arg, t in zip(unresolved_iter_args, iter_arg_types)
    ]

    body = parser.parse_region(iter_args)

    frep = cls(
        max_rep,
        body,
        iter_arg_operands,
        IntegerAttr(stagger_mask, i4),
        IntegerAttr(stagger_count, i3),
    )
    if remaining_attributes is not None:
        frep.attributes |= remaining_attributes.data

    for trait in frep.get_traits_of_type(SingleBlockImplicitTerminator):
        ensure_terminator(frep, trait)

    return frep

print(printer: Printer) -> None

Source code in xdsl/dialects/riscv_snitch.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
def print(self, printer: Printer) -> None:
    printer.print_string(" ")
    printer.print_ssa_value(self.max_rep)
    if self.stagger_count.value.data and self.stagger_mask.value.data:
        printer.print_string(", ")
        printer.print_int(self.stagger_count.value.data)
        printer.print_string(", ")
        printer.print_int(self.stagger_mask.value.data)

    printer.print_op_attributes(
        self.attributes, reserved_attr_names=("stagger_count", "stagger_mask")
    )
    printer.print_string(" ")

    block = self.body.block

    yield_op = block.last_op
    print_block_terminators = not isinstance(yield_op, FrepYieldOp) or bool(
        yield_op.operands
    )

    if iter_args := block.args:
        printer.print_string("iter_args(")
        printer.print_list(
            zip(iter_args, self.iter_args),
            lambda pair: print_assignment(printer, *pair),
        )
        printer.print_string(") -> (")
        printer.print_list((a.type for a in iter_args), printer.print_attribute)
        printer.print_string(") ")

    printer.print_region(
        self.body,
        print_entry_block_args=False,
        print_block_terminators=print_block_terminators,
    )

verify_() -> None

Source code in xdsl/dialects/riscv_snitch.py
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
def verify_(self) -> None:
    if self.stagger_count.value.data:
        raise VerifyException("Non-zero stagger count currently unsupported")
    if self.stagger_mask.value.data:
        raise VerifyException("Non-zero stagger mask currently unsupported")
    for instruction in self.body.ops:
        if not instruction.has_trait(Pure) and not isinstance(
            instruction, ALLOWED_FREP_OP_TYPES
        ):
            raise VerifyException(
                "Frep operation body may not contain instructions "
                f"with side-effects, found {instruction.name}"
            )
    if len(self.iter_args) != len(self.body.block.args):
        raise VerifyException(
            f"Wrong number of block arguments, expected {len(self.iter_args)}, got "
            f"{len(self.body.block.args)}. The body must have the induction "
            f"variable and loop-carried variables as arguments."
        )
    for idx, (arg, block_arg) in enumerate(
        zip(self.iter_args, self.body.block.args)
    ):
        if block_arg.type != arg.type:
            raise VerifyException(
                f"Block argument {idx} has wrong type, expected {arg.type}, "
                f"got {block_arg.type}. Arguments after the "
                f"induction variable must match the carried variables."
            )
    if len(self.body.ops) > 0 and isinstance(
        yieldop := self.body.block.last_op, FrepYieldOp
    ):
        if len(yieldop.arguments) != len(self.iter_args):
            raise VerifyException(
                f"Expected {len(self.iter_args)} args, got {len(yieldop.arguments)}. "
                f"The riscv_scf.frep must yield its carried variables."
            )
        for iter_arg, yield_arg in zip(self.iter_args, yieldop.arguments):
            if iter_arg.type != yield_arg.type:
                raise VerifyException(
                    f"Expected {iter_arg.type}, got {yield_arg.type}. The "
                    f"riscv_snitch.frep's riscv_snitch.frep_yield must match carried"
                    f"variables types."
                )

allocate_registers(allocator: BlockAllocator) -> None

Source code in xdsl/dialects/riscv_snitch.py
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
def allocate_registers(self, allocator: BlockAllocator) -> None:
    # Allocate values used inside the body but defined outside.
    # Their scope lasts for the whole body execution scope
    live_ins = allocator.live_ins_per_block[self.body.block]
    for live_in in live_ins:
        allocator.allocate_value(live_in)

    yield_op = self.body.block.last_op
    assert yield_op is not None, (
        "last op of riscv_snitch.frep_outer and riscv_snitch.frep_inner is guaranteed"
        " to be riscv_scf.Yield"
    )
    block_args = self.body.block.args

    # The loop-carried variables are trickier
    # The for op operand, block arg, and yield operand must have the same type
    for block_arg, operand, yield_operand, op_result in zip(
        block_args, self.iter_args, yield_op.operands, self.results
    ):
        allocator.allocate_values_same_reg(
            (block_arg, operand, yield_operand, op_result)
        )

    allocator.allocate_value(self.max_rep)

    # Reserve the loop carried variables for allocation within the body
    regs = self.iter_args.types
    assert all(isinstance(reg, RISCVRegisterType) for reg in regs)
    regs = cast(tuple[RISCVRegisterType, ...], regs)
    with allocator.available_registers.reserve_registers(regs):
        allocator.allocate_block(self.body.block)

FrepOuterOp dataclass

Bases: FRepOperation

Repeats the instruction in the body as if the body were the body of a for loop, for example:

# Repeat 4 times, stagger 1, period 2
li a0, 4
frep.o a0, 2, 1, 0b1010
fadd.d fa0, ft0, ft2
fmul.d fa0, ft3, fa0

is equivalent to:

fadd.d fa0, ft0, ft2
fmul.d fa0, ft3, fa0
fadd.d fa1, ft0, ft3
fmul.d fa1, ft3, fa1
fadd.d fa0, ft0, ft2
fmul.d fa0, ft3, fa0
fadd.d fa1, ft0, ft3
fmul.d fa1, ft3, fa1
Source code in xdsl/dialects/riscv_snitch.py
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
510
511
512
513
@irdl_op_definition
class FrepOuterOp(FRepOperation):
    """
    Repeats the instruction in the body as if the body were the body of a for loop, for
    example:

    ```
    # Repeat 4 times, stagger 1, period 2
    li a0, 4
    frep.o a0, 2, 1, 0b1010
    fadd.d fa0, ft0, ft2
    fmul.d fa0, ft3, fa0
    ```

    is equivalent to:
    ```
    fadd.d fa0, ft0, ft2
    fmul.d fa0, ft3, fa0
    fadd.d fa1, ft0, ft3
    fmul.d fa1, ft3, fa1
    fadd.d fa0, ft0, ft2
    fmul.d fa0, ft3, fa0
    fadd.d fa1, ft0, ft3
    fmul.d fa1, ft3, fa1
    ```
    """

    name = "riscv_snitch.frep_outer"

    def assembly_instruction_name(self) -> str:
        return "frep.o"

name = 'riscv_snitch.frep_outer' class-attribute instance-attribute

assembly_instruction_name() -> str

Source code in xdsl/dialects/riscv_snitch.py
512
513
def assembly_instruction_name(self) -> str:
    return "frep.o"

FrepInnerOp dataclass

Bases: FRepOperation

Repeats the instruction in the body, as if each were in its own body of a for loop, for example:

# Repeat three times, stagger 2, period 2
li a0, 3
frep.i a0, 2, 2, 0b0100
fadd.d fa0, ft0, ft2
fmul.d fa0, ft3, fa0

is equivalent to:

fadd.d fa0, ft0, ft2
fadd.d fa0, ft1, ft3
fadd.d fa0, ft2, ft3
fmul.d fa0, ft3, fa0
fmul.d fa0, ft4, fa0
fmul.d fa0, ft5, fa0
Source code in xdsl/dialects/riscv_snitch.py
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
@irdl_op_definition
class FrepInnerOp(FRepOperation):
    """
    Repeats the instruction in the body, as if each were in its own body of a for loop,
    for example:

    ```
    # Repeat three times, stagger 2, period 2
    li a0, 3
    frep.i a0, 2, 2, 0b0100
    fadd.d fa0, ft0, ft2
    fmul.d fa0, ft3, fa0
    ```

    is equivalent to:
    ```
    fadd.d fa0, ft0, ft2
    fadd.d fa0, ft1, ft3
    fadd.d fa0, ft2, ft3
    fmul.d fa0, ft3, fa0
    fmul.d fa0, ft4, fa0
    fmul.d fa0, ft5, fa0
    ```
    """

    name = "riscv_snitch.frep_inner"

    def assembly_instruction_name(self) -> str:
        return "frep.i"

name = 'riscv_snitch.frep_inner' class-attribute instance-attribute

assembly_instruction_name() -> str

Source code in xdsl/dialects/riscv_snitch.py
543
544
def assembly_instruction_name(self) -> str:
    return "frep.i"

GetStreamOp

Bases: RISCVAsmOperation, RISCVRegallocOperation

Source code in xdsl/dialects/riscv_snitch.py
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
@irdl_op_definition
class GetStreamOp(RISCVAsmOperation, RISCVRegallocOperation):
    name = "riscv_snitch.get_stream"

    stream = result_def(
        snitch.ReadableStreamType.constr(BaseAttr(riscv.FloatRegisterType))
        | snitch.WritableStreamType.constr(BaseAttr(riscv.FloatRegisterType))
    )

    def __init__(self, result_type: Attribute):
        super().__init__(result_types=[result_type])

    @classmethod
    def parse(cls, parser: Parser) -> GetStreamOp:
        parser.parse_punctuation(":")
        result_type = parser.parse_attribute()
        return GetStreamOp(result_type)

    def print(self, printer: Printer):
        printer.print_string(" : ")
        printer.print_attribute(self.stream.type)

    def assembly_line(self) -> str | None:
        return None

name = 'riscv_snitch.get_stream' class-attribute instance-attribute

stream = result_def(snitch.ReadableStreamType.constr(BaseAttr(riscv.FloatRegisterType)) | snitch.WritableStreamType.constr(BaseAttr(riscv.FloatRegisterType))) class-attribute instance-attribute

__init__(result_type: Attribute)

Source code in xdsl/dialects/riscv_snitch.py
556
557
def __init__(self, result_type: Attribute):
    super().__init__(result_types=[result_type])

parse(parser: Parser) -> GetStreamOp classmethod

Source code in xdsl/dialects/riscv_snitch.py
559
560
561
562
563
@classmethod
def parse(cls, parser: Parser) -> GetStreamOp:
    parser.parse_punctuation(":")
    result_type = parser.parse_attribute()
    return GetStreamOp(result_type)

print(printer: Printer)

Source code in xdsl/dialects/riscv_snitch.py
565
566
567
def print(self, printer: Printer):
    printer.print_string(" : ")
    printer.print_attribute(self.stream.type)

assembly_line() -> str | None

Source code in xdsl/dialects/riscv_snitch.py
569
570
def assembly_line(self) -> str | None:
    return None

DMSourceOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
@irdl_op_definition
class DMSourceOp(RISCVInstruction):
    name = "riscv_snitch.dmsrc"

    ptrlo = operand_def(riscv.IntRegisterType)
    ptrhi = operand_def(riscv.IntRegisterType)

    assembly_format = "$ptrlo `,` $ptrhi attr-dict `:` `(` type($ptrlo) `,` type($ptrhi) `)` `->` `(` `)`"

    traits = traits_def(
        StaticInsnRepresentation(insn=".insn r 0x2b, 0, 0, x0, {0}, {1}")
    )

    def __init__(self, ptrlo: SSAValue | Operation, ptrhi: SSAValue | Operation):
        super().__init__(operands=[ptrlo, ptrhi])

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

name = 'riscv_snitch.dmsrc' class-attribute instance-attribute

ptrlo = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

ptrhi = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

assembly_format = '$ptrlo `,` $ptrhi attr-dict `:` `(` type($ptrlo) `,` type($ptrhi) `)` `->` `(` `)`' class-attribute instance-attribute

traits = traits_def(StaticInsnRepresentation(insn='.insn r 0x2b, 0, 0, x0, {0}, {1}')) class-attribute instance-attribute

__init__(ptrlo: SSAValue | Operation, ptrhi: SSAValue | Operation)

Source code in xdsl/dialects/riscv_snitch.py
593
594
def __init__(self, ptrlo: SSAValue | Operation, ptrhi: SSAValue | Operation):
    super().__init__(operands=[ptrlo, ptrhi])

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

Source code in xdsl/dialects/riscv_snitch.py
596
597
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.ptrlo, self.ptrhi

DMDestinationOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
@irdl_op_definition
class DMDestinationOp(RISCVInstruction):
    name = "riscv_snitch.dmdst"

    ptrlo = operand_def(riscv.IntRegisterType)
    ptrhi = operand_def(riscv.IntRegisterType)

    assembly_format = "$ptrlo `,` $ptrhi attr-dict `:` `(` type($ptrlo) `,` type($ptrhi) `)` `->` `(` `)`"

    traits = traits_def(
        StaticInsnRepresentation(insn=".insn r 0x2b, 0, 1, x0, {0}, {1}")
    )

    def __init__(self, ptrlo: SSAValue | Operation, ptrhi: SSAValue | Operation):
        super().__init__(operands=[ptrlo, ptrhi])

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

name = 'riscv_snitch.dmdst' class-attribute instance-attribute

ptrlo = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

ptrhi = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

assembly_format = '$ptrlo `,` $ptrhi attr-dict `:` `(` type($ptrlo) `,` type($ptrhi) `)` `->` `(` `)`' class-attribute instance-attribute

traits = traits_def(StaticInsnRepresentation(insn='.insn r 0x2b, 0, 1, x0, {0}, {1}')) class-attribute instance-attribute

__init__(ptrlo: SSAValue | Operation, ptrhi: SSAValue | Operation)

Source code in xdsl/dialects/riscv_snitch.py
613
614
def __init__(self, ptrlo: SSAValue | Operation, ptrhi: SSAValue | Operation):
    super().__init__(operands=[ptrlo, ptrhi])

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

Source code in xdsl/dialects/riscv_snitch.py
616
617
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.ptrlo, self.ptrhi

DMStrideOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
@irdl_op_definition
class DMStrideOp(RISCVInstruction):
    name = "riscv_snitch.dmstr"

    srcstrd = operand_def(riscv.IntRegisterType)
    dststrd = operand_def(riscv.IntRegisterType)

    assembly_format = "$srcstrd `,` $dststrd attr-dict `:` `(` type($srcstrd) `,` type($dststrd) `)` `->` `(` `)`"

    traits = traits_def(
        StaticInsnRepresentation(insn=".insn r 0x2b, 0, 6, x0, {0}, {1}")
    )

    def __init__(self, srcstrd: SSAValue | Operation, dststrd: SSAValue | Operation):
        super().__init__(operands=[srcstrd, dststrd])

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

name = 'riscv_snitch.dmstr' class-attribute instance-attribute

srcstrd = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

dststrd = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

assembly_format = '$srcstrd `,` $dststrd attr-dict `:` `(` type($srcstrd) `,` type($dststrd) `)` `->` `(` `)`' class-attribute instance-attribute

traits = traits_def(StaticInsnRepresentation(insn='.insn r 0x2b, 0, 6, x0, {0}, {1}')) class-attribute instance-attribute

__init__(srcstrd: SSAValue | Operation, dststrd: SSAValue | Operation)

Source code in xdsl/dialects/riscv_snitch.py
633
634
def __init__(self, srcstrd: SSAValue | Operation, dststrd: SSAValue | Operation):
    super().__init__(operands=[srcstrd, dststrd])

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

Source code in xdsl/dialects/riscv_snitch.py
636
637
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.srcstrd, self.dststrd

DMRepOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
@irdl_op_definition
class DMRepOp(RISCVInstruction):
    name = "riscv_snitch.dmrep"

    reps = operand_def(riscv.IntRegisterType)

    assembly_format = "$reps attr-dict `:` `(` type($reps) `)` `->` `(` `)`"

    traits = traits_def(
        StaticInsnRepresentation(insn=".insn r 0x2b, 0, 7, x0, {0}, x0")
    )

    def __init__(self, reps: SSAValue | Operation):
        super().__init__(operands=[reps])

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

name = 'riscv_snitch.dmrep' class-attribute instance-attribute

reps = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

assembly_format = '$reps attr-dict `:` `(` type($reps) `)` `->` `(` `)`' class-attribute instance-attribute

traits = traits_def(StaticInsnRepresentation(insn='.insn r 0x2b, 0, 7, x0, {0}, x0')) class-attribute instance-attribute

__init__(reps: SSAValue | Operation)

Source code in xdsl/dialects/riscv_snitch.py
652
653
def __init__(self, reps: SSAValue | Operation):
    super().__init__(operands=[reps])

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

Source code in xdsl/dialects/riscv_snitch.py
655
656
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return (self.reps,)

DMCopyOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
@irdl_op_definition
class DMCopyOp(RISCVInstruction):
    name = "riscv_snitch.dmcpy"

    dest = result_def(riscv.IntRegisterType)
    size = operand_def(riscv.IntRegisterType)
    config = operand_def(riscv.IntRegisterType)

    assembly_format = (
        "$size `,` $config attr-dict `:` functional-type(operands, results)"
    )

    traits = traits_def(
        StaticInsnRepresentation(insn=".insn r 0x2b, 0, 3, {0}, {1}, {2}")
    )

    def __init__(
        self,
        size: SSAValue | Operation,
        config: SSAValue | Operation,
        result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT,
    ):
        super().__init__(operands=[size, config], result_types=[result_type])

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
        return self.dest, self.size, self.config

name = 'riscv_snitch.dmcpy' class-attribute instance-attribute

dest = result_def(riscv.IntRegisterType) class-attribute instance-attribute

size = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

config = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

assembly_format = '$size `,` $config attr-dict `:` functional-type(operands, results)' class-attribute instance-attribute

traits = traits_def(StaticInsnRepresentation(insn='.insn r 0x2b, 0, 3, {0}, {1}, {2}')) class-attribute instance-attribute

__init__(size: SSAValue | Operation, config: SSAValue | Operation, result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT)

Source code in xdsl/dialects/riscv_snitch.py
675
676
677
678
679
680
681
def __init__(
    self,
    size: SSAValue | Operation,
    config: SSAValue | Operation,
    result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT,
):
    super().__init__(operands=[size, config], result_types=[result_type])

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

Source code in xdsl/dialects/riscv_snitch.py
683
684
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.dest, self.size, self.config

DMStatOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
@irdl_op_definition
class DMStatOp(RISCVInstruction):
    name = "riscv_snitch.dmstat"

    dest = result_def(riscv.IntRegisterType)
    status = operand_def(riscv.IntRegisterType)

    assembly_format = "$status attr-dict `:` functional-type(operands, results)"

    traits = traits_def(
        StaticInsnRepresentation(insn=".insn r 0x2b, 0, 5, {0}, {1}, {2}")
    )

    def __init__(
        self,
        status: SSAValue | Operation,
        result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT,
    ):
        super().__init__(operands=[status], result_types=[result_type])

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

name = 'riscv_snitch.dmstat' class-attribute instance-attribute

dest = result_def(riscv.IntRegisterType) class-attribute instance-attribute

status = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

assembly_format = '$status attr-dict `:` functional-type(operands, results)' class-attribute instance-attribute

traits = traits_def(StaticInsnRepresentation(insn='.insn r 0x2b, 0, 5, {0}, {1}, {2}')) class-attribute instance-attribute

__init__(status: SSAValue | Operation, result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT)

Source code in xdsl/dialects/riscv_snitch.py
700
701
702
703
704
705
def __init__(
    self,
    status: SSAValue | Operation,
    result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT,
):
    super().__init__(operands=[status], result_types=[result_type])

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

Source code in xdsl/dialects/riscv_snitch.py
707
708
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.dest, self.status

DMCopyImmOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
711
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
@irdl_op_definition
class DMCopyImmOp(RISCVInstruction):
    name = "riscv_snitch.dmcpyi"

    dest = result_def(riscv.IntRegisterType)
    size = operand_def(riscv.IntRegisterType)
    config = prop_def(IntegerAttr[UI5])

    assembly_format = (
        "$size `,` $config attr-dict `:` functional-type(operands, results)"
    )

    traits = traits_def(
        StaticInsnRepresentation(insn=".insn r 0x2b, 0, 2, {0}, {1}, {2}")
    )

    def __init__(
        self,
        size: SSAValue | Operation,
        config: int | IntegerAttr[UI5],
        result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT,
    ):
        if isinstance(config, int):
            config = IntegerAttr(config, ui5)
        super().__init__(
            operands=[size],
            properties={"config": config},
            result_types=[result_type],
        )

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
        return self.dest, self.size, self.config

name = 'riscv_snitch.dmcpyi' class-attribute instance-attribute

dest = result_def(riscv.IntRegisterType) class-attribute instance-attribute

size = operand_def(riscv.IntRegisterType) class-attribute instance-attribute

config = prop_def(IntegerAttr[UI5]) class-attribute instance-attribute

assembly_format = '$size `,` $config attr-dict `:` functional-type(operands, results)' class-attribute instance-attribute

traits = traits_def(StaticInsnRepresentation(insn='.insn r 0x2b, 0, 2, {0}, {1}, {2}')) class-attribute instance-attribute

__init__(size: SSAValue | Operation, config: int | IntegerAttr[UI5], result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT)

Source code in xdsl/dialects/riscv_snitch.py
727
728
729
730
731
732
733
734
735
736
737
738
739
def __init__(
    self,
    size: SSAValue | Operation,
    config: int | IntegerAttr[UI5],
    result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT,
):
    if isinstance(config, int):
        config = IntegerAttr(config, ui5)
    super().__init__(
        operands=[size],
        properties={"config": config},
        result_types=[result_type],
    )

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

Source code in xdsl/dialects/riscv_snitch.py
741
742
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.dest, self.size, self.config

DMStatImmOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
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
@irdl_op_definition
class DMStatImmOp(RISCVInstruction):
    name = "riscv_snitch.dmstati"

    dest = result_def(riscv.IntRegisterType)
    status = prop_def(IntegerAttr[UI5])

    assembly_format = "$status attr-dict `:` `(` `)` `->` type($dest)"

    traits = traits_def(
        StaticInsnRepresentation(insn=".insn r 0x2b, 0, 4, {0}, {1}, {2}")
    )

    def __init__(
        self,
        status: int | IntegerAttr[UI5],
        result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT,
    ):
        if isinstance(status, int):
            status = IntegerAttr(status, ui5)
        super().__init__(
            properties={"status": status},
            result_types=[result_type],
        )

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

name = 'riscv_snitch.dmstati' class-attribute instance-attribute

dest = result_def(riscv.IntRegisterType) class-attribute instance-attribute

status = prop_def(IntegerAttr[UI5]) class-attribute instance-attribute

assembly_format = '$status attr-dict `:` `(` `)` `->` type($dest)' class-attribute instance-attribute

traits = traits_def(StaticInsnRepresentation(insn='.insn r 0x2b, 0, 4, {0}, {1}, {2}')) class-attribute instance-attribute

__init__(status: int | IntegerAttr[UI5], result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT)

Source code in xdsl/dialects/riscv_snitch.py
758
759
760
761
762
763
764
765
766
767
768
def __init__(
    self,
    status: int | IntegerAttr[UI5],
    result_type: IntRegisterType = riscv.Registers.UNALLOCATED_INT,
):
    if isinstance(status, int):
        status = IntegerAttr(status, ui5)
    super().__init__(
        properties={"status": status},
        result_types=[result_type],
    )

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

Source code in xdsl/dialects/riscv_snitch.py
770
771
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.dest, self.status

VFCpkASSOp dataclass

Bases: RdRsRsOperation[FloatRegisterType, FloatRegisterType, FloatRegisterType]

Packs two scalar f32 values from rs1 and rs2 and packs the result as two adjacent entries into the vectorial 2xf32 rd operand, such as:

f[rd][lo] = f[rs1]
f[rd][hi] = f[rs2]
Source code in xdsl/dialects/riscv_snitch.py
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
@irdl_op_definition
class VFCpkASSOp(
    RdRsRsOperation[FloatRegisterType, FloatRegisterType, FloatRegisterType]
):
    """
    Packs two scalar f32 values from rs1 and rs2 and packs the result as two adjacent
    entries into the vectorial 2xf32 rd operand, such as:

    ```C
    f[rd][lo] = f[rs1]
    f[rd][hi] = f[rs2]
    ```
    """

    name = "riscv_snitch.vfcpka.s.s"

    traits = traits_def(Pure())

name = 'riscv_snitch.vfcpka.s.s' class-attribute instance-attribute

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

VFMulSOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Performs vectorial multiplication of corresponding f32 values from rs1 and rs2 and stores the results in the corresponding f32 lanes into the vectorial 2xf32 rd operand, such as:

f[rd][lo] = f[rs1][lo] * f[rs2][lo]
f[rd][hi] = f[rs1][hi] * f[rs2][hi]
Source code in xdsl/dialects/riscv_snitch.py
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
@irdl_op_definition
class VFMulSOp(riscv.RdRsRsFloatOperationWithFastMath):
    """
    Performs vectorial multiplication of corresponding f32 values from
    rs1 and rs2 and stores the results in the corresponding f32 lanes
    into the vectorial 2xf32 rd operand, such as:

    ```C
    f[rd][lo] = f[rs1][lo] * f[rs2][lo]
    f[rd][hi] = f[rs1][hi] * f[rs2][hi]
    ```
    """

    name = "riscv_snitch.vfmul.s"

    traits = traits_def(Pure())

name = 'riscv_snitch.vfmul.s' class-attribute instance-attribute

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

VFAddSOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Performs vectorial addition of corresponding f32 values from rs1 and rs2 and stores the results in the corresponding f32 lanes into the vectorial 2xf32 rd operand, such as:

f[rd][lo] = f[rs1][lo] + f[rs2][lo]
f[rd][hi] = f[rs1][hi] + f[rs2][hi]
Source code in xdsl/dialects/riscv_snitch.py
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
@irdl_op_definition
class VFAddSOp(riscv.RdRsRsFloatOperationWithFastMath):
    """
    Performs vectorial addition of corresponding f32 values from
    rs1 and rs2 and stores the results in the corresponding f32 lanes
    into the vectorial 2xf32 rd operand, such as:

    ```C
    f[rd][lo] = f[rs1][lo] + f[rs2][lo]
    f[rd][hi] = f[rs1][hi] + f[rs2][hi]
    ```
    """

    name = "riscv_snitch.vfadd.s"

    traits = traits_def(Pure())

name = 'riscv_snitch.vfadd.s' class-attribute instance-attribute

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

VFAddHOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Performs vectorial addition of corresponding f16 values from rs1 and rs2 and stores the results in the corresponding f16 lanes into the vectorial 4xf16 rd operand, such as:

f[rd][0] = f[rs1][0] + f[rs2][0]
f[rd][1] = f[rs1][1] + f[rs2][1]
f[rd][2] = f[rs1][2] + f[rs2][2]
f[rd][3] = f[rs1][3] + f[rs2][3]
Source code in xdsl/dialects/riscv_snitch.py
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
@irdl_op_definition
class VFAddHOp(riscv.RdRsRsFloatOperationWithFastMath):
    """
    Performs vectorial addition of corresponding f16 values from
    rs1 and rs2 and stores the results in the corresponding f16 lanes
    into the vectorial 4xf16 rd operand, such as:

    ```C
    f[rd][0] = f[rs1][0] + f[rs2][0]
    f[rd][1] = f[rs1][1] + f[rs2][1]
    f[rd][2] = f[rs1][2] + f[rs2][2]
    f[rd][3] = f[rs1][3] + f[rs2][3]
    ```
    """

    name = "riscv_snitch.vfadd.h"

    traits = traits_def(Pure())

name = 'riscv_snitch.vfadd.h' class-attribute instance-attribute

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

VFMaxSOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Performs vectorial maximum of corresponding f32 values from rs1 and rs2 and stores the results in the corresponding f32 lanes into the vectorial 2xf32 rd operand, such as:

f[rd][lo] = max(f[rs1][lo], f[rs2][lo])
f[rd][hi] = max(f[rs1][hi], f[rs2][hi])
Source code in xdsl/dialects/riscv_snitch.py
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
@irdl_op_definition
class VFMaxSOp(riscv.RdRsRsFloatOperationWithFastMath):
    """
    Performs vectorial maximum of corresponding f32 values from
    rs1 and rs2 and stores the results in the corresponding f32 lanes
    into the vectorial 2xf32 rd operand, such as:

    ```C
    f[rd][lo] = max(f[rs1][lo], f[rs2][lo])
    f[rd][hi] = max(f[rs1][hi], f[rs2][hi])
    ```
    """

    name = "riscv_snitch.vfmax.s"

    traits = traits_def(Pure())

name = 'riscv_snitch.vfmax.s' class-attribute instance-attribute

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

RdRsRsAccumulatingFloatOperationWithFastMath

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

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

Source code in xdsl/dialects/riscv_snitch.py
881
882
883
884
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
class RdRsRsAccumulatingFloatOperationWithFastMath(
    RISCVCustomFormatOperation, RISCVInstruction, ABC
):
    """
    A base class for RISC-V operations that have one destination floating-point register,
    that also acts as a source register, and two source floating-point registers and can
    be annotated with fastmath flags.
    """

    SAME_FLOAT_REGISTER_TYPE: ClassVar = VarConstraint(
        "SAME_FLOAT_REGISTER_TYPE", base(FloatRegisterType)
    )

    rd_out = result_def(SAME_FLOAT_REGISTER_TYPE)
    rd_in = operand_def(SAME_FLOAT_REGISTER_TYPE)
    rs1 = operand_def(FloatRegisterType)
    rs2 = operand_def(FloatRegisterType)

    fastmath = opt_attr_def(FastMathFlagsAttr)

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

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

    def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
        return self.rd_in, 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) -> set[str]:
        if self.fastmath is not None and self.fastmath != FastMathFlagsAttr("none"):
            printer.print_string(" fastmath")
            self.fastmath.print_parameter(printer)
        return {"fastmath"}

    def get_register_constraints(self) -> RegisterConstraints:
        return RegisterConstraints(
            (self.rs1, self.rs2), (), ((self.rd_in, self.rd_out),)
        )

SAME_FLOAT_REGISTER_TYPE: ClassVar = VarConstraint('SAME_FLOAT_REGISTER_TYPE', base(FloatRegisterType)) class-attribute instance-attribute

rd_out = result_def(SAME_FLOAT_REGISTER_TYPE) class-attribute instance-attribute

rd_in = operand_def(SAME_FLOAT_REGISTER_TYPE) 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__(rd: Operation | SSAValue, rs1: Operation | SSAValue, rs2: Operation | SSAValue, *, fastmath: FastMathFlagsAttr | None = None, comment: str | StringAttr | None = None)

Source code in xdsl/dialects/riscv_snitch.py
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
def __init__(
    self,
    rd: Operation | SSAValue,
    rs1: Operation | SSAValue,
    rs2: Operation | SSAValue,
    *,
    fastmath: FastMathFlagsAttr | None = None,
    comment: str | StringAttr | None = None,
):
    if isinstance(rd, Operation):
        rd = SSAValue.get(rd)
    if isinstance(comment, str):
        comment = StringAttr(comment)

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

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

Source code in xdsl/dialects/riscv_snitch.py
924
925
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd_in, self.rs1, self.rs2

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

Source code in xdsl/dialects/riscv_snitch.py
927
928
929
930
931
932
933
934
@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) -> set[str]

Source code in xdsl/dialects/riscv_snitch.py
936
937
938
939
940
def custom_print_attributes(self, printer: Printer) -> set[str]:
    if self.fastmath is not None and self.fastmath != FastMathFlagsAttr("none"):
        printer.print_string(" fastmath")
        self.fastmath.print_parameter(printer)
    return {"fastmath"}

get_register_constraints() -> RegisterConstraints

Source code in xdsl/dialects/riscv_snitch.py
942
943
944
945
def get_register_constraints(self) -> RegisterConstraints:
    return RegisterConstraints(
        (self.rs1, self.rs2), (), ((self.rd_in, self.rd_out),)
    )

RdRsAccumulatingFloatOperation

Bases: RISCVCustomFormatOperation, RISCVInstruction, ABC

A base class for RISC-V operations that have one destination floating-point register, that also acts as a source register, and a source floating-point register.

Source code in xdsl/dialects/riscv_snitch.py
948
949
950
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
979
980
981
982
983
984
985
986
class RdRsAccumulatingFloatOperation(RISCVCustomFormatOperation, RISCVInstruction, ABC):
    """
    A base class for RISC-V operations that have one destination floating-point register,
    that also acts as a source register, and a source floating-point register.
    """

    SAME_FLOAT_REGISTER_TYPE: ClassVar = VarConstraint(
        "SAME_FLOAT_REGISTER_TYPE", base(FloatRegisterType)
    )

    rd_out = result_def(SAME_FLOAT_REGISTER_TYPE)
    rd_in = operand_def(SAME_FLOAT_REGISTER_TYPE)
    rs = operand_def(FloatRegisterType)

    def __init__(
        self,
        rd: Operation | SSAValue,
        rs: Operation | SSAValue,
        *,
        comment: str | StringAttr | None = None,
    ):
        if isinstance(rd, Operation):
            rd = SSAValue.get(rd)
        if isinstance(comment, str):
            comment = StringAttr(comment)

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

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

    def get_register_constraints(self) -> RegisterConstraints:
        return RegisterConstraints((self.rs,), (), ((self.rd_in, self.rd_out),))

SAME_FLOAT_REGISTER_TYPE: ClassVar = VarConstraint('SAME_FLOAT_REGISTER_TYPE', base(FloatRegisterType)) class-attribute instance-attribute

rd_out = result_def(SAME_FLOAT_REGISTER_TYPE) class-attribute instance-attribute

rd_in = operand_def(SAME_FLOAT_REGISTER_TYPE) class-attribute instance-attribute

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

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

Source code in xdsl/dialects/riscv_snitch.py
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
def __init__(
    self,
    rd: Operation | SSAValue,
    rs: Operation | SSAValue,
    *,
    comment: str | StringAttr | None = None,
):
    if isinstance(rd, Operation):
        rd = SSAValue.get(rd)
    if isinstance(comment, str):
        comment = StringAttr(comment)

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

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

Source code in xdsl/dialects/riscv_snitch.py
982
983
def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
    return self.rd_in, self.rs

get_register_constraints() -> RegisterConstraints

Source code in xdsl/dialects/riscv_snitch.py
985
986
def get_register_constraints(self) -> RegisterConstraints:
    return RegisterConstraints((self.rs,), (), ((self.rd_in, self.rd_out),))

VFMacSOp dataclass

Bases: RdRsRsAccumulatingFloatOperationWithFastMath

Performs vectorial multiplication of corresponding f32 values from rs1 and rs2 and accumulates the results in the corresponding f32 lanes into the vectorial 2xf32 rd operand, such as:

f[rd][lo] = f[rs1][lo] * f[rs2][lo] + f[rd][lo]
f[rd][hi] = f[rs1][hi] * f[rs2][hi] + f[rd][hi]
Source code in xdsl/dialects/riscv_snitch.py
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
@irdl_op_definition
class VFMacSOp(RdRsRsAccumulatingFloatOperationWithFastMath):
    """
    Performs vectorial multiplication of corresponding f32 values from
    rs1 and rs2 and accumulates the results in the corresponding f32 lanes
    into the vectorial 2xf32 rd operand, such as:

    ```C
    f[rd][lo] = f[rs1][lo] * f[rs2][lo] + f[rd][lo]
    f[rd][hi] = f[rs1][hi] * f[rs2][hi] + f[rd][hi]
    ```
    """

    name = "riscv_snitch.vfmac.s"

    traits = traits_def(Pure())

name = 'riscv_snitch.vfmac.s' class-attribute instance-attribute

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

VFSumSOp dataclass

Bases: RdRsAccumulatingFloatOperation

Performs sum of f32 values from rs and accumulates the result in the lower f32 value of the rd operand:

f[rd][lo] = f[rs][hi] + f[rs][lo] + f[rd][lo]
Source code in xdsl/dialects/riscv_snitch.py
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
@irdl_op_definition
class VFSumSOp(RdRsAccumulatingFloatOperation):
    """
    Performs sum of f32 values from rs and accumulates the result in the lower f32 value
    of the rd operand:

    ```C
    f[rd][lo] = f[rs][hi] + f[rs][lo] + f[rd][lo]
    ```
    """

    name = "riscv_snitch.vfsum.s"

    traits = traits_def(Pure())

name = 'riscv_snitch.vfsum.s' class-attribute instance-attribute

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