Skip to content

Comb

comb

The comb dialect provides a collection of operations that define a mid-level compiler IR for combinational logic. It is designed to be easy to analyze and transform, and be a flexible and extensible substrate that may be extended with higher level dialects mixed into it.

Up to date as of CIRCT commit 2e23cda6c2cbedb118b92fab755f1e36d80b13f5.

See external documentation.

ICMP_COMPARISON_OPERATIONS = ['eq', 'ne', 'slt', 'sle', 'sgt', 'sge', 'ult', 'ule', 'ugt', 'uge'] module-attribute

Comb = Dialect('comb', [AddOp, MulOp, DivUOp, DivSOp, ModUOp, ModSOp, ShlOp, ShrUOp, ShrSOp, SubOp, AndOp, OrOp, XorOp, ICmpOp, ParityOp, ExtractOp, ConcatOp, ReplicateOp, MuxOp]) module-attribute

BinCombOperation

Bases: IRDLOperation, ABC

A binary comb operation. It has two operands and one result, all of the same integer type.

Source code in xdsl/dialects/comb.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
class BinCombOperation(IRDLOperation, ABC):
    """
    A binary comb operation. It has two operands and one
    result, all of the same integer type.
    """

    T: ClassVar = VarConstraint("T", base(IntegerType))

    lhs = operand_def(T)
    rhs = operand_def(T)
    result = result_def(T)
    """
    "All operations are defined in the expected way for 2-state (binary) logic. However, comb is
    used for operations which have extended truth table for non-2-state logic for various target
    languages. The two_state variable describes if we are using 2-state (binary) logic or not."
    """
    two_state = opt_attr_def(UnitAttr)

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
        result_type: Attribute | None = None,
    ):
        if result_type is None:
            result_type = SSAValue.get(operand1).type
        super().__init__(operands=[operand1, operand2], result_types=[result_type])

    @classmethod
    def parse(cls, parser: Parser):
        lhs = parser.parse_unresolved_operand()
        parser.parse_punctuation(",")
        rhs = parser.parse_unresolved_operand()
        parser.parse_punctuation(":")
        result_type = parser.parse_type()
        (lhs, rhs) = parser.resolve_operands([lhs, rhs], 2 * [result_type], parser.pos)
        return cls(lhs, rhs, result_type)

    def print(self, printer: Printer):
        printer.print_string(" ")
        printer.print_ssa_value(self.lhs)
        printer.print_string(", ")
        printer.print_ssa_value(self.rhs)
        printer.print_string(" : ")
        printer.print_attribute(self.result.type)

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

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

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

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

"All operations are defined in the expected way for 2-state (binary) logic. However, comb is used for operations which have extended truth table for non-2-state logic for various target languages. The two_state variable describes if we are using 2-state (binary) logic or not."

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

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue, result_type: Attribute | None = None)

Source code in xdsl/dialects/comb.py
72
73
74
75
76
77
78
79
80
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
    result_type: Attribute | None = None,
):
    if result_type is None:
        result_type = SSAValue.get(operand1).type
    super().__init__(operands=[operand1, operand2], result_types=[result_type])

parse(parser: Parser) classmethod

Source code in xdsl/dialects/comb.py
82
83
84
85
86
87
88
89
90
@classmethod
def parse(cls, parser: Parser):
    lhs = parser.parse_unresolved_operand()
    parser.parse_punctuation(",")
    rhs = parser.parse_unresolved_operand()
    parser.parse_punctuation(":")
    result_type = parser.parse_type()
    (lhs, rhs) = parser.resolve_operands([lhs, rhs], 2 * [result_type], parser.pos)
    return cls(lhs, rhs, result_type)

print(printer: Printer)

Source code in xdsl/dialects/comb.py
92
93
94
95
96
97
98
def print(self, printer: Printer):
    printer.print_string(" ")
    printer.print_ssa_value(self.lhs)
    printer.print_string(", ")
    printer.print_ssa_value(self.rhs)
    printer.print_string(" : ")
    printer.print_attribute(self.result.type)

VariadicCombOperation

Bases: IRDLOperation, ABC

A variadic comb operation. It has a variadic number of operands, and a single result, all of the same integer type.

Source code in xdsl/dialects/comb.py
101
102
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
class VariadicCombOperation(IRDLOperation, ABC):
    """
    A variadic comb operation. It has a variadic number of operands, and a single
    result, all of the same integer type.
    """

    T: ClassVar = VarConstraint("T", base(IntegerType))

    inputs = var_operand_def(T)
    result = result_def(T)
    """
    "All operations are defined in the expected way for 2-state (binary) logic. However, comb is
    used for operations which have extended truth table for non-2-state logic for various target
    languages. The two_state variable describes if we are using 2-state (binary) logic or not."
    """
    two_state = opt_attr_def(UnitAttr)

    def __init__(
        self,
        input_list: Sequence[Operation | SSAValue],
        result_type: Attribute | None = None,
    ):
        if result_type is None:
            if len(input_list) == 0:
                raise ValueError("cannot infer type from zero inputs")
            result_type = SSAValue.get(input_list[0]).type
        super().__init__(operands=[input_list], result_types=[result_type])

    def verify_(self) -> None:
        if len(self.inputs) == 0:
            raise VerifyException("op expected 1 or more operands, but found 0")

    @classmethod
    def parse(cls, parser: Parser):
        inputs = parser.parse_comma_separated_list(
            parser.Delimiter.NONE, parser.parse_unresolved_operand
        )
        parser.parse_punctuation(":")
        result_type = parser.parse_type()
        inputs = parser.resolve_operands(
            inputs, len(inputs) * [result_type], parser.pos
        )
        return cls.create(operands=inputs, result_types=[result_type])

    def print(self, printer: Printer):
        printer.print_string(" ")
        printer.print_list(self.inputs, printer.print_ssa_value)
        printer.print_string(" : ")
        printer.print_attribute(self.result.type)

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

inputs = var_operand_def(T) class-attribute instance-attribute

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

"All operations are defined in the expected way for 2-state (binary) logic. However, comb is used for operations which have extended truth table for non-2-state logic for various target languages. The two_state variable describes if we are using 2-state (binary) logic or not."

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

__init__(input_list: Sequence[Operation | SSAValue], result_type: Attribute | None = None)

Source code in xdsl/dialects/comb.py
118
119
120
121
122
123
124
125
126
127
def __init__(
    self,
    input_list: Sequence[Operation | SSAValue],
    result_type: Attribute | None = None,
):
    if result_type is None:
        if len(input_list) == 0:
            raise ValueError("cannot infer type from zero inputs")
        result_type = SSAValue.get(input_list[0]).type
    super().__init__(operands=[input_list], result_types=[result_type])

verify_() -> None

Source code in xdsl/dialects/comb.py
129
130
131
def verify_(self) -> None:
    if len(self.inputs) == 0:
        raise VerifyException("op expected 1 or more operands, but found 0")

parse(parser: Parser) classmethod

Source code in xdsl/dialects/comb.py
133
134
135
136
137
138
139
140
141
142
143
@classmethod
def parse(cls, parser: Parser):
    inputs = parser.parse_comma_separated_list(
        parser.Delimiter.NONE, parser.parse_unresolved_operand
    )
    parser.parse_punctuation(":")
    result_type = parser.parse_type()
    inputs = parser.resolve_operands(
        inputs, len(inputs) * [result_type], parser.pos
    )
    return cls.create(operands=inputs, result_types=[result_type])

print(printer: Printer)

Source code in xdsl/dialects/comb.py
145
146
147
148
149
def print(self, printer: Printer):
    printer.print_string(" ")
    printer.print_list(self.inputs, printer.print_ssa_value)
    printer.print_string(" : ")
    printer.print_attribute(self.result.type)

AddOp dataclass

Bases: VariadicCombOperation

Addition

Source code in xdsl/dialects/comb.py
152
153
154
155
156
@irdl_op_definition
class AddOp(VariadicCombOperation):
    """Addition"""

    name = "comb.add"

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

MulOp dataclass

Bases: VariadicCombOperation

Multiplication

Source code in xdsl/dialects/comb.py
159
160
161
162
163
@irdl_op_definition
class MulOp(VariadicCombOperation):
    """Multiplication"""

    name = "comb.mul"

name = 'comb.mul' class-attribute instance-attribute

DivUOp dataclass

Bases: BinCombOperation

Unsigned division

Source code in xdsl/dialects/comb.py
166
167
168
169
170
@irdl_op_definition
class DivUOp(BinCombOperation):
    """Unsigned division"""

    name = "comb.divu"

name = 'comb.divu' class-attribute instance-attribute

DivSOp dataclass

Bases: BinCombOperation

Signed division

Source code in xdsl/dialects/comb.py
173
174
175
176
177
@irdl_op_definition
class DivSOp(BinCombOperation):
    """Signed division"""

    name = "comb.divs"

name = 'comb.divs' class-attribute instance-attribute

ModUOp dataclass

Bases: BinCombOperation

Unsigned remainder

Source code in xdsl/dialects/comb.py
180
181
182
183
184
@irdl_op_definition
class ModUOp(BinCombOperation):
    """Unsigned remainder"""

    name = "comb.modu"

name = 'comb.modu' class-attribute instance-attribute

ModSOp dataclass

Bases: BinCombOperation

Signed remainder

Source code in xdsl/dialects/comb.py
187
188
189
190
191
@irdl_op_definition
class ModSOp(BinCombOperation):
    """Signed remainder"""

    name = "comb.mods"

name = 'comb.mods' class-attribute instance-attribute

ShlOp dataclass

Bases: BinCombOperation

Left shift

Source code in xdsl/dialects/comb.py
194
195
196
197
198
@irdl_op_definition
class ShlOp(BinCombOperation):
    """Left shift"""

    name = "comb.shl"

name = 'comb.shl' class-attribute instance-attribute

ShrUOp dataclass

Bases: BinCombOperation

Unsigned right shift

Source code in xdsl/dialects/comb.py
201
202
203
204
205
@irdl_op_definition
class ShrUOp(BinCombOperation):
    """Unsigned right shift"""

    name = "comb.shru"

name = 'comb.shru' class-attribute instance-attribute

ShrSOp dataclass

Bases: BinCombOperation

Signed right shift

Source code in xdsl/dialects/comb.py
208
209
210
211
212
@irdl_op_definition
class ShrSOp(BinCombOperation):
    """Signed right shift"""

    name = "comb.shrs"

name = 'comb.shrs' class-attribute instance-attribute

SubOp dataclass

Bases: BinCombOperation

Subtraction

Source code in xdsl/dialects/comb.py
215
216
217
218
219
@irdl_op_definition
class SubOp(BinCombOperation):
    """Subtraction"""

    name = "comb.sub"

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

AndOp dataclass

Bases: VariadicCombOperation

Bitwise and

Source code in xdsl/dialects/comb.py
222
223
224
225
226
@irdl_op_definition
class AndOp(VariadicCombOperation):
    """Bitwise and"""

    name = "comb.and"

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

OrOp dataclass

Bases: VariadicCombOperation

Bitwise or

Source code in xdsl/dialects/comb.py
229
230
231
232
233
@irdl_op_definition
class OrOp(VariadicCombOperation):
    """Bitwise or"""

    name = "comb.or"

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

XorOp dataclass

Bases: VariadicCombOperation

Bitwise xor

Source code in xdsl/dialects/comb.py
236
237
238
239
240
@irdl_op_definition
class XorOp(VariadicCombOperation):
    """Bitwise xor"""

    name = "comb.xor"

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

ICmpOp

Bases: IRDLOperation, ABC

Integer comparison: A generic comparison operation, operation definitions inherit this class.

The first argument to these comparison operations is the type of comparison being performed, the following comparisons are supported:

  • equal (mnemonic: "eq"; integer value: 0)
  • not equal (mnemonic: "ne"; integer value: 1)
  • signed less than (mnemonic: "slt"; integer value: 2)
  • signed less than or equal (mnemonic: "sle"; integer value: 3)
  • signed greater than (mnemonic: "sgt"; integer value: 4)
  • signed greater than or equal (mnemonic: "sge"; integer value: 5)
  • unsigned less than (mnemonic: "ult"; integer value: 6)
  • unsigned less than or equal (mnemonic: "ule"; integer value: 7)
  • unsigned greater than (mnemonic: "ugt"; integer value: 8)
  • unsigned greater than or equal (mnemonic: "uge"; integer value: 9)
Source code in xdsl/dialects/comb.py
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
@irdl_op_definition
class ICmpOp(IRDLOperation, ABC):
    """Integer comparison: A generic comparison operation, operation definitions inherit this class.

    The first argument to these comparison operations is the type of comparison
    being performed, the following comparisons are supported:

    -   equal (mnemonic: `"eq"`; integer value: `0`)
    -   not equal (mnemonic: `"ne"`; integer value: `1`)
    -   signed less than (mnemonic: `"slt"`; integer value: `2`)
    -   signed less than or equal (mnemonic: `"sle"`; integer value: `3`)
    -   signed greater than (mnemonic: `"sgt"`; integer value: `4`)
    -   signed greater than or equal (mnemonic: `"sge"`; integer value: `5`)
    -   unsigned less than (mnemonic: `"ult"`; integer value: `6`)
    -   unsigned less than or equal (mnemonic: `"ule"`; integer value: `7`)
    -   unsigned greater than (mnemonic: `"ugt"`; integer value: `8`)
    -   unsigned greater than or equal (mnemonic: `"uge"`; integer value: `9`)
    """

    name = "comb.icmp"

    T: ClassVar = VarConstraint("T", base(IntegerType))

    predicate = attr_def(IntegerAttr[I64])
    lhs = operand_def(T)
    rhs = operand_def(T)
    result = result_def(IntegerType(1))

    two_state = opt_attr_def(UnitAttr, attr_name="twoState")

    @staticmethod
    def _get_comparison_predicate(
        mnemonic: str, comparison_operations: dict[str, int]
    ) -> int:
        if mnemonic in comparison_operations:
            return comparison_operations[mnemonic]
        else:
            raise VerifyException(f"Unknown comparison mnemonic: {mnemonic}")

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
        arg: int | str | IntegerAttr[IntegerType],
        has_two_state_semantics: bool = False,
    ):
        operand1 = SSAValue.get(operand1)
        operand2 = SSAValue.get(operand2)

        if isinstance(arg, str):
            cmpi_comparison_operations = {
                "eq": 0,
                "ne": 1,
                "slt": 2,
                "sle": 3,
                "sgt": 4,
                "sge": 5,
                "ult": 6,
                "ule": 7,
                "ugt": 8,
                "uge": 9,
            }
            arg = ICmpOp._get_comparison_predicate(arg, cmpi_comparison_operations)
        if not isinstance(arg, IntegerAttr):
            arg = IntegerAttr.from_int_and_width(arg, 64)

        attrs: dict[str, Attribute] = {"predicate": arg}
        if has_two_state_semantics:
            attrs["twoState"] = UnitAttr()

        return super().__init__(
            operands=[operand1, operand2],
            result_types=[IntegerType(1)],
            attributes=attrs,
        )

    @classmethod
    def parse(cls, parser: Parser):
        has_two_state_semantics = parser.parse_optional_keyword("bin") is not None
        arg = parser.parse_identifier()
        operand1 = parser.parse_unresolved_operand()
        parser.parse_punctuation(",")
        operand2 = parser.parse_unresolved_operand()
        parser.parse_punctuation(":")
        input_type = parser.parse_type()
        (operand1, operand2) = parser.resolve_operands(
            [operand1, operand2], 2 * [input_type], parser.pos
        )

        return cls(operand1, operand2, arg, has_two_state_semantics)

    def print(self, printer: Printer):
        printer.print_string(" ")
        if self.two_state is not None:
            printer.print_string("bin ")
        printer.print_string(ICMP_COMPARISON_OPERATIONS[self.predicate.value.data])
        printer.print_string(" ")
        printer.print_operand(self.lhs)
        printer.print_string(", ")
        printer.print_operand(self.rhs)
        printer.print_string(" : ")
        printer.print_attribute(self.lhs.type)

name = 'comb.icmp' class-attribute instance-attribute

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

predicate = attr_def(IntegerAttr[I64]) class-attribute instance-attribute

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

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

result = result_def(IntegerType(1)) class-attribute instance-attribute

two_state = opt_attr_def(UnitAttr, attr_name='twoState') class-attribute instance-attribute

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue, arg: int | str | IntegerAttr[IntegerType], has_two_state_semantics: bool = False)

Source code in xdsl/dialects/comb.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
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
    arg: int | str | IntegerAttr[IntegerType],
    has_two_state_semantics: bool = False,
):
    operand1 = SSAValue.get(operand1)
    operand2 = SSAValue.get(operand2)

    if isinstance(arg, str):
        cmpi_comparison_operations = {
            "eq": 0,
            "ne": 1,
            "slt": 2,
            "sle": 3,
            "sgt": 4,
            "sge": 5,
            "ult": 6,
            "ule": 7,
            "ugt": 8,
            "uge": 9,
        }
        arg = ICmpOp._get_comparison_predicate(arg, cmpi_comparison_operations)
    if not isinstance(arg, IntegerAttr):
        arg = IntegerAttr.from_int_and_width(arg, 64)

    attrs: dict[str, Attribute] = {"predicate": arg}
    if has_two_state_semantics:
        attrs["twoState"] = UnitAttr()

    return super().__init__(
        operands=[operand1, operand2],
        result_types=[IntegerType(1)],
        attributes=attrs,
    )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/comb.py
319
320
321
322
323
324
325
326
327
328
329
330
331
332
@classmethod
def parse(cls, parser: Parser):
    has_two_state_semantics = parser.parse_optional_keyword("bin") is not None
    arg = parser.parse_identifier()
    operand1 = parser.parse_unresolved_operand()
    parser.parse_punctuation(",")
    operand2 = parser.parse_unresolved_operand()
    parser.parse_punctuation(":")
    input_type = parser.parse_type()
    (operand1, operand2) = parser.resolve_operands(
        [operand1, operand2], 2 * [input_type], parser.pos
    )

    return cls(operand1, operand2, arg, has_two_state_semantics)

print(printer: Printer)

Source code in xdsl/dialects/comb.py
334
335
336
337
338
339
340
341
342
343
344
def print(self, printer: Printer):
    printer.print_string(" ")
    if self.two_state is not None:
        printer.print_string("bin ")
    printer.print_string(ICMP_COMPARISON_OPERATIONS[self.predicate.value.data])
    printer.print_string(" ")
    printer.print_operand(self.lhs)
    printer.print_string(", ")
    printer.print_operand(self.rhs)
    printer.print_string(" : ")
    printer.print_attribute(self.lhs.type)

ParityOp

Bases: IRDLOperation

Parity

Source code in xdsl/dialects/comb.py
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
@irdl_op_definition
class ParityOp(IRDLOperation):
    """Parity"""

    name = "comb.parity"

    input = operand_def(IntegerType)
    result = result_def(IntegerType(1))

    two_state = opt_attr_def(UnitAttr, attr_name="twoState")

    def __init__(
        self, operand: Operation | SSAValue, two_state: UnitAttr | None = None
    ):
        operand = SSAValue.get(operand)
        return super().__init__(
            attributes={"twoState": two_state},
            operands=[operand],
            result_types=[operand.type],
        )

    @classmethod
    def parse(cls, parser: Parser):
        two_state = None
        if parser.parse_optional_keyword("bin") is not None:
            two_state = UnitAttr()
        op = parser.parse_unresolved_operand()
        parser.parse_punctuation(":")
        result_type = parser.parse_type()
        op = parser.resolve_operand(op, result_type)
        return cls(op, two_state)

    def print(self, printer: Printer):
        printer.print_string(" ")
        if self.two_state is not None:
            printer.print_string("bin ")
        printer.print_ssa_value(self.input)
        printer.print_string(" : ")
        printer.print_attribute(self.result.type)

name = 'comb.parity' class-attribute instance-attribute

input = operand_def(IntegerType) class-attribute instance-attribute

result = result_def(IntegerType(1)) class-attribute instance-attribute

two_state = opt_attr_def(UnitAttr, attr_name='twoState') class-attribute instance-attribute

__init__(operand: Operation | SSAValue, two_state: UnitAttr | None = None)

Source code in xdsl/dialects/comb.py
358
359
360
361
362
363
364
365
366
def __init__(
    self, operand: Operation | SSAValue, two_state: UnitAttr | None = None
):
    operand = SSAValue.get(operand)
    return super().__init__(
        attributes={"twoState": two_state},
        operands=[operand],
        result_types=[operand.type],
    )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/comb.py
368
369
370
371
372
373
374
375
376
377
@classmethod
def parse(cls, parser: Parser):
    two_state = None
    if parser.parse_optional_keyword("bin") is not None:
        two_state = UnitAttr()
    op = parser.parse_unresolved_operand()
    parser.parse_punctuation(":")
    result_type = parser.parse_type()
    op = parser.resolve_operand(op, result_type)
    return cls(op, two_state)

print(printer: Printer)

Source code in xdsl/dialects/comb.py
379
380
381
382
383
384
385
def print(self, printer: Printer):
    printer.print_string(" ")
    if self.two_state is not None:
        printer.print_string("bin ")
    printer.print_ssa_value(self.input)
    printer.print_string(" : ")
    printer.print_attribute(self.result.type)

ExtractOp

Bases: IRDLOperation

Extract a range of bits into a smaller value, low_bit specifies the lowest bit included. Result is the size of the value to extract.

|-----------------| input l low bit <--------> result

Source code in xdsl/dialects/comb.py
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
@irdl_op_definition
class ExtractOp(IRDLOperation):
    """
    Extract a range of bits into a smaller value, low_bit
    specifies the lowest bit included. Result is the size
    of the value to extract.

    |-----------------|   input
           l              low bit
           <-------->     result
    """

    name = "comb.extract"

    input = operand_def(IntegerType)
    low_bit = attr_def(IntegerAttr[I32], attr_name="lowBit")
    result = result_def(IntegerType)

    def __init__(
        self,
        operand: Operation | SSAValue,
        low_bit: IntegerAttr[IntegerType],
        result_type: IntegerType,
    ):
        operand = SSAValue.get(operand)
        return super().__init__(
            attributes={"lowBit": low_bit},
            operands=[operand],
            result_types=[result_type],
        )

    def verify_(self) -> None:
        assert isa(self.input.type, IntegerType)
        assert isinstance(self.result.type, IntegerType)
        if (
            self.low_bit.value.data + self.result.type.width.data
            > self.input.type.width.data + 1
        ):
            raise VerifyException(
                f"output width {self.result.type.width.data} is "
                f"too large for input of width "
                f"{self.input.type.width.data} (included low bit "
                f"is at {self.low_bit.value.data})"
            )

    @classmethod
    def parse(cls, parser: Parser):
        op = parser.parse_unresolved_operand()
        parser.parse_keyword("from")
        bit = parser.parse_integer()
        parser.parse_punctuation(":")
        result_type = parser.parse_function_type()
        if len(result_type.inputs.data) != 1 or len(result_type.outputs.data) != 1:
            parser.raise_error(
                "expected exactly one input and exactly one output types"
            )
        if not isa(result_type.outputs.data[0], IntegerType):
            parser.raise_error(
                f"expected output to be an integer type, got '{result_type.outputs.data[0]}'"
            )
        (op,) = parser.resolve_operands([op], result_type.inputs.data, parser.pos)
        return cls(op, IntegerAttr(bit, 32), result_type.outputs.data[0])

    def print(self, printer: Printer):
        printer.print_string(" ")
        printer.print_ssa_value(self.input)
        printer.print_string(f" from {self.low_bit.value.data} : ")
        printer.print_function_type([self.input.type], [self.result.type])

name = 'comb.extract' class-attribute instance-attribute

input = operand_def(IntegerType) class-attribute instance-attribute

low_bit = attr_def(IntegerAttr[I32], attr_name='lowBit') class-attribute instance-attribute

result = result_def(IntegerType) class-attribute instance-attribute

__init__(operand: Operation | SSAValue, low_bit: IntegerAttr[IntegerType], result_type: IntegerType)

Source code in xdsl/dialects/comb.py
406
407
408
409
410
411
412
413
414
415
416
417
def __init__(
    self,
    operand: Operation | SSAValue,
    low_bit: IntegerAttr[IntegerType],
    result_type: IntegerType,
):
    operand = SSAValue.get(operand)
    return super().__init__(
        attributes={"lowBit": low_bit},
        operands=[operand],
        result_types=[result_type],
    )

verify_() -> None

Source code in xdsl/dialects/comb.py
419
420
421
422
423
424
425
426
427
428
429
430
431
def verify_(self) -> None:
    assert isa(self.input.type, IntegerType)
    assert isinstance(self.result.type, IntegerType)
    if (
        self.low_bit.value.data + self.result.type.width.data
        > self.input.type.width.data + 1
    ):
        raise VerifyException(
            f"output width {self.result.type.width.data} is "
            f"too large for input of width "
            f"{self.input.type.width.data} (included low bit "
            f"is at {self.low_bit.value.data})"
        )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/comb.py
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
@classmethod
def parse(cls, parser: Parser):
    op = parser.parse_unresolved_operand()
    parser.parse_keyword("from")
    bit = parser.parse_integer()
    parser.parse_punctuation(":")
    result_type = parser.parse_function_type()
    if len(result_type.inputs.data) != 1 or len(result_type.outputs.data) != 1:
        parser.raise_error(
            "expected exactly one input and exactly one output types"
        )
    if not isa(result_type.outputs.data[0], IntegerType):
        parser.raise_error(
            f"expected output to be an integer type, got '{result_type.outputs.data[0]}'"
        )
    (op,) = parser.resolve_operands([op], result_type.inputs.data, parser.pos)
    return cls(op, IntegerAttr(bit, 32), result_type.outputs.data[0])

print(printer: Printer)

Source code in xdsl/dialects/comb.py
451
452
453
454
455
def print(self, printer: Printer):
    printer.print_string(" ")
    printer.print_ssa_value(self.input)
    printer.print_string(f" from {self.low_bit.value.data} : ")
    printer.print_function_type([self.input.type], [self.result.type])

ConcatOp

Bases: IRDLOperation

Concatenate a variadic list of operands together.

Source code in xdsl/dialects/comb.py
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
@irdl_op_definition
class ConcatOp(IRDLOperation):
    """
    Concatenate a variadic list of operands together.
    """

    name = "comb.concat"

    inputs = var_operand_def(IntegerType)
    result = result_def(IntegerType)

    def __init__(self, ops: Sequence[SSAValue | Operation], target_type: IntegerType):
        return super().__init__(operands=[ops], result_types=[target_type])

    @staticmethod
    def from_int_values(inputs: Sequence[SSAValue]) -> "ConcatOp | None":
        """
        Concatenates the provided values, in order. Returns None if the provided
        values are not integers.
        """
        sum_of_width = _get_sum_of_int_width([inp.type for inp in inputs])
        if sum_of_width is None:
            return None
        return ConcatOp(inputs, IntegerType(sum_of_width))

    def verify_(self) -> None:
        sum_of_width = _get_sum_of_int_width(self.inputs.types)
        assert sum_of_width is not None
        assert isinstance(self.result.type, IntegerType)
        if sum_of_width != self.result.type.width.data:
            raise VerifyException(
                f"Sum of integer width ({sum_of_width}) "
                f"is different from result "
                f"width ({self.result.type.width.data})"
            )

    @classmethod
    def parse(cls, parser: Parser):
        inputs = parser.parse_comma_separated_list(
            parser.Delimiter.NONE, parser.parse_unresolved_operand
        )
        parser.parse_punctuation(":")
        input_types = parser.parse_comma_separated_list(
            parser.Delimiter.NONE, parser.parse_type
        )
        sum_of_width = _get_sum_of_int_width(input_types)
        if sum_of_width is None:
            parser.raise_error("expected only integer types as input")
        inputs = parser.resolve_operands(inputs, input_types, parser.pos)
        return cls.create(operands=inputs, result_types=[IntegerType(sum_of_width)])

    def print(self, printer: Printer):
        printer.print_string(" ")
        printer.print_list(self.inputs, printer.print_ssa_value)
        printer.print_string(" : ")
        printer.print_list(self.inputs.types, printer.print_attribute)

name = 'comb.concat' class-attribute instance-attribute

inputs = var_operand_def(IntegerType) class-attribute instance-attribute

result = result_def(IntegerType) class-attribute instance-attribute

__init__(ops: Sequence[SSAValue | Operation], target_type: IntegerType)

Source code in xdsl/dialects/comb.py
482
483
def __init__(self, ops: Sequence[SSAValue | Operation], target_type: IntegerType):
    return super().__init__(operands=[ops], result_types=[target_type])

from_int_values(inputs: Sequence[SSAValue]) -> ConcatOp | None staticmethod

Concatenates the provided values, in order. Returns None if the provided values are not integers.

Source code in xdsl/dialects/comb.py
485
486
487
488
489
490
491
492
493
494
@staticmethod
def from_int_values(inputs: Sequence[SSAValue]) -> "ConcatOp | None":
    """
    Concatenates the provided values, in order. Returns None if the provided
    values are not integers.
    """
    sum_of_width = _get_sum_of_int_width([inp.type for inp in inputs])
    if sum_of_width is None:
        return None
    return ConcatOp(inputs, IntegerType(sum_of_width))

verify_() -> None

Source code in xdsl/dialects/comb.py
496
497
498
499
500
501
502
503
504
505
def verify_(self) -> None:
    sum_of_width = _get_sum_of_int_width(self.inputs.types)
    assert sum_of_width is not None
    assert isinstance(self.result.type, IntegerType)
    if sum_of_width != self.result.type.width.data:
        raise VerifyException(
            f"Sum of integer width ({sum_of_width}) "
            f"is different from result "
            f"width ({self.result.type.width.data})"
        )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/comb.py
507
508
509
510
511
512
513
514
515
516
517
518
519
520
@classmethod
def parse(cls, parser: Parser):
    inputs = parser.parse_comma_separated_list(
        parser.Delimiter.NONE, parser.parse_unresolved_operand
    )
    parser.parse_punctuation(":")
    input_types = parser.parse_comma_separated_list(
        parser.Delimiter.NONE, parser.parse_type
    )
    sum_of_width = _get_sum_of_int_width(input_types)
    if sum_of_width is None:
        parser.raise_error("expected only integer types as input")
    inputs = parser.resolve_operands(inputs, input_types, parser.pos)
    return cls.create(operands=inputs, result_types=[IntegerType(sum_of_width)])

print(printer: Printer)

Source code in xdsl/dialects/comb.py
522
523
524
525
526
def print(self, printer: Printer):
    printer.print_string(" ")
    printer.print_list(self.inputs, printer.print_ssa_value)
    printer.print_string(" : ")
    printer.print_list(self.inputs.types, printer.print_attribute)

ReplicateOp

Bases: IRDLOperation

Concatenate the operand a constant number of times.

Source code in xdsl/dialects/comb.py
529
530
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
@irdl_op_definition
class ReplicateOp(IRDLOperation):
    """
    Concatenate the operand a constant number of times.
    """

    name = "comb.replicate"

    input = operand_def(IntegerType)
    result = result_def(IntegerType)

    def __init__(self, op: SSAValue | Operation, target_type: IntegerType):
        return super().__init__(operands=[op], result_types=[target_type])

    @classmethod
    def parse(cls, parser: Parser):
        op = parser.parse_unresolved_operand()
        parser.parse_punctuation(":")
        fun_type = parser.parse_function_type()
        operands = parser.resolve_operands([op], fun_type.inputs.data, parser.pos)
        return cls.create(operands=operands, result_types=fun_type.outputs.data)

    def print(self, printer: Printer):
        printer.print_string(" ")
        printer.print_ssa_value(self.input)
        printer.print_string(" : ")
        printer.print_function_type((self.input.type,), (self.result.type,))

name = 'comb.replicate' class-attribute instance-attribute

input = operand_def(IntegerType) class-attribute instance-attribute

result = result_def(IntegerType) class-attribute instance-attribute

__init__(op: SSAValue | Operation, target_type: IntegerType)

Source code in xdsl/dialects/comb.py
540
541
def __init__(self, op: SSAValue | Operation, target_type: IntegerType):
    return super().__init__(operands=[op], result_types=[target_type])

parse(parser: Parser) classmethod

Source code in xdsl/dialects/comb.py
543
544
545
546
547
548
549
@classmethod
def parse(cls, parser: Parser):
    op = parser.parse_unresolved_operand()
    parser.parse_punctuation(":")
    fun_type = parser.parse_function_type()
    operands = parser.resolve_operands([op], fun_type.inputs.data, parser.pos)
    return cls.create(operands=operands, result_types=fun_type.outputs.data)

print(printer: Printer)

Source code in xdsl/dialects/comb.py
551
552
553
554
555
def print(self, printer: Printer):
    printer.print_string(" ")
    printer.print_ssa_value(self.input)
    printer.print_string(" : ")
    printer.print_function_type((self.input.type,), (self.result.type,))

MuxOp

Bases: IRDLOperation

Select between two values based on a condition.

Source code in xdsl/dialects/comb.py
558
559
560
561
562
563
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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
@irdl_op_definition
class MuxOp(IRDLOperation):
    """
    Select between two values based on a condition.
    """

    name = "comb.mux"

    T: ClassVar = VarConstraint("T", base(TypeAttribute))

    cond = operand_def(IntegerType(1))
    true_value = operand_def(T)
    false_value = operand_def(T)
    result = result_def(T)

    def __init__(
        self,
        condition: Operation | SSAValue,
        true_val: Operation | SSAValue,
        false_val: Operation | SSAValue,
    ):
        operand2 = SSAValue.get(true_val)
        return super().__init__(
            operands=[condition, true_val, false_val], result_types=[operand2.type]
        )

    @classmethod
    def parse(cls, parser: Parser):
        condition = parser.parse_unresolved_operand()
        parser.parse_punctuation(",")
        true_val = parser.parse_unresolved_operand()
        parser.parse_punctuation(",")
        false_val = parser.parse_unresolved_operand()
        parser.parse_punctuation(":")
        result_type = parser.parse_type()
        (condition, true_val, false_val) = parser.resolve_operands(
            [condition, true_val, false_val],
            [IntegerType(1), result_type, result_type],
            parser.pos,
        )
        return cls(condition, true_val, false_val)

    def print(self, printer: Printer):
        printer.print_string(" ")
        printer.print_operand(self.cond)
        printer.print_string(", ")
        printer.print_operand(self.true_value)
        printer.print_string(", ")
        printer.print_operand(self.false_value)
        printer.print_string(" : ")
        printer.print_attribute(self.result.type)

name = 'comb.mux' class-attribute instance-attribute

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

cond = operand_def(IntegerType(1)) class-attribute instance-attribute

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

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

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

__init__(condition: Operation | SSAValue, true_val: Operation | SSAValue, false_val: Operation | SSAValue)

Source code in xdsl/dialects/comb.py
573
574
575
576
577
578
579
580
581
582
def __init__(
    self,
    condition: Operation | SSAValue,
    true_val: Operation | SSAValue,
    false_val: Operation | SSAValue,
):
    operand2 = SSAValue.get(true_val)
    return super().__init__(
        operands=[condition, true_val, false_val], result_types=[operand2.type]
    )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/comb.py
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
@classmethod
def parse(cls, parser: Parser):
    condition = parser.parse_unresolved_operand()
    parser.parse_punctuation(",")
    true_val = parser.parse_unresolved_operand()
    parser.parse_punctuation(",")
    false_val = parser.parse_unresolved_operand()
    parser.parse_punctuation(":")
    result_type = parser.parse_type()
    (condition, true_val, false_val) = parser.resolve_operands(
        [condition, true_val, false_val],
        [IntegerType(1), result_type, result_type],
        parser.pos,
    )
    return cls(condition, true_val, false_val)

print(printer: Printer)

Source code in xdsl/dialects/comb.py
600
601
602
603
604
605
606
607
608
def print(self, printer: Printer):
    printer.print_string(" ")
    printer.print_operand(self.cond)
    printer.print_string(", ")
    printer.print_operand(self.true_value)
    printer.print_string(", ")
    printer.print_operand(self.false_value)
    printer.print_string(" : ")
    printer.print_attribute(self.result.type)