Skip to content

Riscv snitch

riscv_snitch

ALLOWED_FREP_OP_TYPES: tuple[type[Operation], ...] = (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, VFSubSOp, VFCpkASSOp, VFMacSOp, VFSumSOp, VFMulHOp, VFAddHOp, VFSubHOp, VFMaxSOp], []) module-attribute

ScfgwOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/riscv_snitch.py
83
84
85
86
87
88
89
90
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
84
85
86
87
88
89
90
@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
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
@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(MemoryWriteEffect(), ScfgwOpHasCanonicalizationPatternsTrait())

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

traits = traits_def(MemoryWriteEffect(), 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
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
151
152
153
154
155
156
157
158
@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])

    traits = traits_def(MemoryWriteEffect())

    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

traits = traits_def(MemoryWriteEffect()) 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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
146
147
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
149
150
151
152
153
@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
155
156
157
158
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
@irdl_op_definition
class FrepYieldOp(
    AbstractYieldOperation[Attribute], RISCVAsmOperation, RISCVRegallocOperation
):
    name = "riscv_snitch.frep_yield"

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

    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), RegisterAllocatedMemoryEffect())) class-attribute instance-attribute

assembly_line() -> str | None

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

ReadOp

Bases: RISCVAsmOperation, RISCVRegallocOperation

Source code in xdsl/dialects/riscv_snitch.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
@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)"

    # Reads from memory and updates stream state
    traits = traits_def(
        MemoryWriteEffect(), MemoryReadEffect(), RegisterAllocatedMemoryEffect()
    )

    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

    @override
    def iter_excluded_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

traits = traits_def(MemoryWriteEffect(), MemoryReadEffect(), RegisterAllocatedMemoryEffect()) class-attribute instance-attribute

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

Source code in xdsl/dialects/riscv_snitch.py
195
196
197
198
199
200
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
202
203
def assembly_line(self) -> str | None:
    return None

iter_excluded_registers()

Source code in xdsl/dialects/riscv_snitch.py
205
206
207
208
209
210
211
@override
def iter_excluded_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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
@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)"

    # Writes to memory and updates stream state
    traits = traits_def(MemoryWriteEffect(), RegisterAllocatedMemoryEffect())

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

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

    @override
    def iter_excluded_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

traits = traits_def(MemoryWriteEffect(), RegisterAllocatedMemoryEffect()) class-attribute instance-attribute

__init__(value: SSAValue, stream: SSAValue)

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

assembly_line() -> str | None

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

iter_excluded_registers()

Source code in xdsl/dialects/riscv_snitch.py
234
235
236
237
238
239
240
@override
def iter_excluded_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
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
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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
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), RecursiveMemoryEffect())
    )

    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 is_valid_frep_body_op(instruction):
                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), RecursiveMemoryEffect())) 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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
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
356
357
358
359
360
361
362
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
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
@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
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
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
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
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 is_valid_frep_body_op(instruction):
            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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
@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
560
561
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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
@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
591
592
def assembly_instruction_name(self) -> str:
    return "frep.i"

GetStreamOp

Bases: RISCVAsmOperation, RISCVRegallocOperation

Source code in xdsl/dialects/riscv_snitch.py
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
@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))
    )

    traits = traits_def(NoMemoryEffect())

    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

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

__init__(result_type: Attribute)

Source code in xdsl/dialects/riscv_snitch.py
606
607
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
609
610
611
612
613
@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
615
616
617
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
619
620
def assembly_line(self) -> str | None:
    return None

DMSourceOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
@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}"),
        MemoryWriteEffect(),
    )

    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}'), MemoryWriteEffect()) class-attribute instance-attribute

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

Source code in xdsl/dialects/riscv_snitch.py
644
645
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
647
648
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.ptrlo, self.ptrhi

DMDestinationOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
@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}"),
        MemoryWriteEffect(),
    )

    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}'), MemoryWriteEffect()) class-attribute instance-attribute

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

Source code in xdsl/dialects/riscv_snitch.py
665
666
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
668
669
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.ptrlo, self.ptrhi

DMStrideOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
@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}"),
        MemoryWriteEffect(),
    )

    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}'), MemoryWriteEffect()) class-attribute instance-attribute

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

Source code in xdsl/dialects/riscv_snitch.py
686
687
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
689
690
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.srcstrd, self.dststrd

DMRepOp

Bases: RISCVInstruction

Source code in xdsl/dialects/riscv_snitch.py
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
@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"),
        MemoryWriteEffect(),
    )

    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'), MemoryWriteEffect()) class-attribute instance-attribute

__init__(reps: SSAValue | Operation)

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

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

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

DMCopyOp

Bases: RISCVInstruction

DMCPY and DMCPYI initiate an asynchronous data movement with the parameters configured by the previous DM instructions. A transfer id is placed in register rd, which is necessary to later check for transfer completion. size contains the number of consecutive bytes to transfer. For multi-dimensional transfers this is the size of the innermost dimension.

Source code in xdsl/dialects/riscv_snitch.py
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
@irdl_op_definition
class DMCopyOp(RISCVInstruction):
    """
    DMCPY and DMCPYI initiate an asynchronous data movement with the parameters
    configured by the previous DM instructions. A transfer id is placed in register rd,
    which is necessary to later check for transfer completion. size contains the number
    of consecutive bytes to transfer. For multi-dimensional transfers this is the size
    of the innermost dimension.
    """

    name = "riscv_snitch.dmcpy"

    dest = result_def(riscv.IntRegisterType)
    size = operand_def(riscv.IntRegisterType)
    config = operand_def(riscv.IntRegisterType)
    """
    config* determines the following parameters of the
    transfer:

    | Bit(s)     | Field         | Description                                            |
    |------------|---------------|--------------------------------------------------------|
    | config[0]  | decouple_rw   | Decouple the handshakes of the read and write channels |
    | config[1]  | enable_2d     | Enable two-dimensional transfer                        |
    | config[4:2]| channel_sel   | Selects the DMA backend if a multi-channel DMA is used |
    """

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

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

    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

config* determines the following parameters of the transfer:

Bit(s) Field Description
config[0] decouple_rw Decouple the handshakes of the read and write channels
config[1] enable_2d Enable two-dimensional transfer
config[4:2] channel_sel Selects the DMA backend if a multi-channel DMA is used

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}'), MemoryReadEffect(), MemoryWriteEffect()) 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
749
750
751
752
753
754
755
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
757
758
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
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
@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}"),
        MemoryReadEffect(),
    )

    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}'), MemoryReadEffect()) class-attribute instance-attribute

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

Source code in xdsl/dialects/riscv_snitch.py
775
776
777
778
779
780
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
782
783
def assembly_line_args(self) -> tuple[AssemblyInstructionArg | None, ...]:
    return self.dest, self.status

DMCopyImmOp

Bases: RISCVInstruction

DMCPY and DMCPYI initiate an asynchronous data movement with the parameters configured by the previous DM instructions. A transfer id is placed in register rd, which is necessary to later check for transfer completion. size contains the number of consecutive bytes to transfer. For multi-dimensional transfers this is the size of the innermost dimension.

Source code in xdsl/dialects/riscv_snitch.py
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
826
827
828
829
830
831
832
833
834
835
836
837
@irdl_op_definition
class DMCopyImmOp(RISCVInstruction):
    """
    DMCPY and DMCPYI initiate an asynchronous data movement with the parameters
    configured by the previous DM instructions. A transfer id is placed in register rd,
    which is necessary to later check for transfer completion. size contains the number
    of consecutive bytes to transfer. For multi-dimensional transfers this is the size
    of the innermost dimension.
    """

    name = "riscv_snitch.dmcpyi"

    dest = result_def(riscv.IntRegisterType)
    size = operand_def(riscv.IntRegisterType)
    config = prop_def(IntegerAttr[UI5])
    """
    config* determines the following parameters of the
    transfer:

    | Bit(s)     | Field         | Description                                            |
    |------------|---------------|--------------------------------------------------------|
    | config[0]  | decouple_rw   | Decouple the handshakes of the read and write channels |
    | config[1]  | enable_2d     | Enable two-dimensional transfer                        |
    | config[4:2]| channel_sel   | Selects the DMA backend if a multi-channel DMA is used |
    """

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

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

    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

config* determines the following parameters of the transfer:

Bit(s) Field Description
config[0] decouple_rw Decouple the handshakes of the read and write channels
config[1] enable_2d Enable two-dimensional transfer
config[4:2] channel_sel Selects the DMA backend if a multi-channel DMA is used

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}'), MemoryReadEffect(), MemoryWriteEffect()) 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
822
823
824
825
826
827
828
829
830
831
832
833
834
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
836
837
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
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
@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}"),
        MemoryReadEffect(),
    )

    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}'), MemoryReadEffect()) class-attribute instance-attribute

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

Source code in xdsl/dialects/riscv_snitch.py
854
855
856
857
858
859
860
861
862
863
864
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
866
867
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
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
@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(AlwaysSpeculatable())

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

traits = traits_def(AlwaysSpeculatable()) 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
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
@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(AlwaysSpeculatable())

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

traits = traits_def(AlwaysSpeculatable()) 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
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
@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(AlwaysSpeculatable())

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

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

VFSubSOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Performs vectorial subtraction 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
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
@irdl_op_definition
class VFSubSOp(riscv.RdRsRsFloatOperationWithFastMath):
    """
    Performs vectorial subtraction 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.vfsub.s"

    traits = traits_def(AlwaysSpeculatable())

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

traits = traits_def(AlwaysSpeculatable()) 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
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
@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(AlwaysSpeculatable())

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

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

VFSubHOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Performs vectorial subtraction 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
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
@irdl_op_definition
class VFSubHOp(riscv.RdRsRsFloatOperationWithFastMath):
    """
    Performs vectorial subtraction 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.vfsub.h"

    traits = traits_def(AlwaysSpeculatable())

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

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

VFMulHOp dataclass

Bases: RdRsRsFloatOperationWithFastMath

Performs vectorial multiplication 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
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
@irdl_op_definition
class VFMulHOp(riscv.RdRsRsFloatOperationWithFastMath):
    """
    Performs vectorial multiplication 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.vfmul.h"

    traits = traits_def(AlwaysSpeculatable())

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

traits = traits_def(AlwaysSpeculatable()) 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
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
@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(AlwaysSpeculatable())

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

traits = traits_def(AlwaysSpeculatable()) 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
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
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
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)

    traits = traits_def(AlwaysSpeculatable())

    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

traits = traits_def(AlwaysSpeculatable()) 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
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
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
1080
1081
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
1083
1084
1085
1086
1087
1088
1089
1090
@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
1092
1093
1094
1095
1096
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
1098
1099
1100
1101
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
1104
1105
1106
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
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
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)

    traits = traits_def(AlwaysSpeculatable())

    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

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

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

Source code in xdsl/dialects/riscv_snitch.py
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
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
1140
1141
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
1143
1144
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
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
@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"

name = 'riscv_snitch.vfmac.s' 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
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
@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"

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

is_valid_frep_body_op(operation: Operation) -> bool

Helper method to determine whether the frep loop on the Snitch core can contain the given operation. frep loops can only contain instructions that are executed on the FPU, and only contain memory effects via ReadOp / WriteOp. We also allow UnrealizedConversionCastOp to support partial lowering of dialects.

Source code in xdsl/dialects/riscv_snitch.py
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
def is_valid_frep_body_op(operation: Operation) -> bool:
    """
    Helper method to determine whether the `frep` loop on the Snitch core can contain
    the given operation.
    `frep` loops can only contain instructions that are executed on the FPU, and only
    contain memory effects via `ReadOp` / `WriteOp`.
    We also allow `UnrealizedConversionCastOp` to support partial lowering of dialects.
    """
    if isinstance(operation, ALLOWED_FREP_OP_TYPES):
        # Exceptions to the rules
        return True

    effects = get_effects(operation)

    if effects is None:
        # No effects interface
        return False

    # All effects are on float registers
    return all(
        isinstance(effect.resource, RegisterResource)
        and isinstance(effect.resource.register, FloatRegisterType)
        for effect in effects
    )