Skip to content

Bigint

bigint

Dialect for unlimited precision integers with Python int semantics.

bigint = BigIntegerType() module-attribute

BigInt = Dialect('bigint', [ConstantOp, TruncateToIntOp, AddOp, SubOp, MulOp, FloorDivOp, ModOp, PowOp, LShiftOp, RShiftOp, BitOrOp, BitXorOp, BitAndOp, DivOp, EqOp, NeqOp, GtOp, GteOp, LtOp, LteOp], [BigIntegerType]) module-attribute

BigIntegerType dataclass

Bases: ParametrizedAttribute, TypeAttribute

Type for unlimited precision integers, with Python int semantics.

Source code in xdsl/dialects/bigint.py
35
36
37
38
39
@irdl_attr_definition
class BigIntegerType(ParametrizedAttribute, TypeAttribute):
    """Type for unlimited precision integers, with Python `int` semantics."""

    name = "bigint.bigint"

name = 'bigint.bigint' class-attribute instance-attribute

BinaryOperation

Bases: IRDLOperation, ABC

Binary operation where all operands and results are bigints.

Source code in xdsl/dialects/bigint.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class BinaryOperation(IRDLOperation, abc.ABC):
    """Binary operation where all operands and results are `bigint`s."""

    lhs = operand_def(bigint)
    rhs = operand_def(bigint)
    result = result_def(bigint)

    assembly_format = "$lhs `,` $rhs attr-dict `:` type($result)"

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
    ):
        super().__init__(operands=[operand1, operand2], result_types=[bigint])

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

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

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

assembly_format = '$lhs `,` $rhs attr-dict `:` type($result)' class-attribute instance-attribute

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue)

Source code in xdsl/dialects/bigint.py
54
55
56
57
58
59
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
):
    super().__init__(operands=[operand1, operand2], result_types=[bigint])

ConstantOp

Bases: IRDLOperation

Source code in xdsl/dialects/bigint.py
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
99
@irdl_op_definition
class ConstantOp(IRDLOperation):
    name = "bigint.constant"
    result = result_def(bigint)
    value = prop_def(IntAttr)

    traits = traits_def(ConstantLike(), HasFolder(), Pure())

    @classmethod
    def parse(cls, parser: Parser):
        integer = parser.parse_integer()
        attrDict = parser.parse_optional_attr_dict()
        return cls(value=IntAttr(integer), attrs=attrDict)

    def print(self, printer: Printer):
        printer.print_string(" ")
        printer.print_int(self.value.data)
        if self.attributes:
            printer.print_string(" ")
            printer.print_attr_dict(self.attributes)

    def __init__(
        self,
        value: IntAttr | int,
        attrs: dict[str, Attribute] | None = None,
    ):
        if isinstance(value, int):
            value = IntAttr(value)

        super().__init__(
            operands=[],
            result_types=[bigint],
            properties={"value": value},
            attributes=attrs,
        )

    def fold(self) -> Sequence[SSAValue | Attribute] | None:
        return (self.value,)

name = 'bigint.constant' class-attribute instance-attribute

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

value = prop_def(IntAttr) class-attribute instance-attribute

traits = traits_def(ConstantLike(), HasFolder(), Pure()) class-attribute instance-attribute

parse(parser: Parser) classmethod

Source code in xdsl/dialects/bigint.py
70
71
72
73
74
@classmethod
def parse(cls, parser: Parser):
    integer = parser.parse_integer()
    attrDict = parser.parse_optional_attr_dict()
    return cls(value=IntAttr(integer), attrs=attrDict)

print(printer: Printer)

Source code in xdsl/dialects/bigint.py
76
77
78
79
80
81
def print(self, printer: Printer):
    printer.print_string(" ")
    printer.print_int(self.value.data)
    if self.attributes:
        printer.print_string(" ")
        printer.print_attr_dict(self.attributes)

__init__(value: IntAttr | int, attrs: dict[str, Attribute] | None = None)

Source code in xdsl/dialects/bigint.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def __init__(
    self,
    value: IntAttr | int,
    attrs: dict[str, Attribute] | None = None,
):
    if isinstance(value, int):
        value = IntAttr(value)

    super().__init__(
        operands=[],
        result_types=[bigint],
        properties={"value": value},
        attributes=attrs,
    )

fold() -> Sequence[SSAValue | Attribute] | None

Source code in xdsl/dialects/bigint.py
98
99
def fold(self) -> Sequence[SSAValue | Attribute] | None:
    return (self.value,)

TruncateToIntOp

Bases: IRDLOperation

Source code in xdsl/dialects/bigint.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@irdl_op_definition
class TruncateToIntOp(IRDLOperation):
    name = "bigint.truncate_to_int"
    result = result_def(IntegerType)
    value = operand_def(bigint)

    traits = traits_def(Pure())

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

    def __init__(
        self,
        value: Operation | SSAValue,
        type: IntegerType = IntegerType(64),
    ):
        super().__init__(operands=[value], result_types=[type])

name = 'bigint.truncate_to_int' class-attribute instance-attribute

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

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

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

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

__init__(value: Operation | SSAValue, type: IntegerType = IntegerType(64))

Source code in xdsl/dialects/bigint.py
112
113
114
115
116
117
def __init__(
    self,
    value: Operation | SSAValue,
    type: IntegerType = IntegerType(64),
):
    super().__init__(operands=[value], result_types=[type])

AddOp dataclass

Bases: BinaryOperation

Add two bigints.

Source code in xdsl/dialects/bigint.py
120
121
122
123
124
125
126
127
128
129
130
@irdl_op_definition
class AddOp(BinaryOperation):
    """Add two `bigint`s."""

    name = "bigint.add"

    traits = traits_def(
        Pure(),
        Commutative(),
        SameOperandsAndResultType(),
    )

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

traits = traits_def(Pure(), Commutative(), SameOperandsAndResultType()) class-attribute instance-attribute

SubOp dataclass

Bases: BinaryOperation

Subtract two bigints.

Source code in xdsl/dialects/bigint.py
133
134
135
136
137
138
139
140
141
142
143
@irdl_op_definition
class SubOp(BinaryOperation):
    """Subtract two `bigint`s."""

    name = "bigint.sub"

    traits = traits_def(
        Pure(),
        Commutative(),
        SameOperandsAndResultType(),
    )

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

traits = traits_def(Pure(), Commutative(), SameOperandsAndResultType()) class-attribute instance-attribute

MulOp dataclass

Bases: BinaryOperation

Multiply two bigints.

Source code in xdsl/dialects/bigint.py
146
147
148
149
150
151
152
153
154
155
156
@irdl_op_definition
class MulOp(BinaryOperation):
    """Multiply two `bigint`s."""

    name = "bigint.mul"

    traits = traits_def(
        Pure(),
        Commutative(),
        SameOperandsAndResultType(),
    )

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

traits = traits_def(Pure(), Commutative(), SameOperandsAndResultType()) class-attribute instance-attribute

FloorDivOp dataclass

Bases: BinaryOperation

Floor divide two bigints, rounding down to the nearest integer.

Source code in xdsl/dialects/bigint.py
159
160
161
162
163
164
165
166
167
168
@irdl_op_definition
class FloorDivOp(BinaryOperation):
    """Floor divide two `bigint`s, rounding down to the nearest integer."""

    name = "bigint.floordiv"

    traits = traits_def(
        Pure(),
        SameOperandsAndResultType(),
    )

name = 'bigint.floordiv' class-attribute instance-attribute

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

ModOp dataclass

Bases: BinaryOperation

Modulo two bigints, taking the sign of the divisor.

Source code in xdsl/dialects/bigint.py
171
172
173
174
175
176
177
178
179
180
@irdl_op_definition
class ModOp(BinaryOperation):
    """Modulo two `bigint`s, taking the sign of the divisor."""

    name = "bigint.mod"

    traits = traits_def(
        Pure(),
        SameOperandsAndResultType(),
    )

name = 'bigint.mod' class-attribute instance-attribute

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

PowOp dataclass

Bases: BinaryOperation

Exponentiate a bigint by another.

Source code in xdsl/dialects/bigint.py
183
184
185
186
187
188
189
190
191
192
@irdl_op_definition
class PowOp(BinaryOperation):
    """Exponentiate a `bigint` by another."""

    name = "bigint.pow"

    traits = traits_def(
        Pure(),
        SameOperandsAndResultType(),
    )

name = 'bigint.pow' class-attribute instance-attribute

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

LShiftOp dataclass

Bases: BinaryOperation

Left shift a bigint by another.

Source code in xdsl/dialects/bigint.py
195
196
197
198
199
200
201
202
203
204
@irdl_op_definition
class LShiftOp(BinaryOperation):
    """Left shift a `bigint` by another."""

    name = "bigint.lshift"

    traits = traits_def(
        Pure(),
        SameOperandsAndResultType(),
    )

name = 'bigint.lshift' class-attribute instance-attribute

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

RShiftOp dataclass

Bases: BinaryOperation

Right shift a bigint by another.

Source code in xdsl/dialects/bigint.py
207
208
209
210
211
212
213
214
215
216
@irdl_op_definition
class RShiftOp(BinaryOperation):
    """Right shift a `bigint` by another."""

    name = "bigint.rshift"

    traits = traits_def(
        Pure(),
        SameOperandsAndResultType(),
    )

name = 'bigint.rshift' class-attribute instance-attribute

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

BitOrOp dataclass

Bases: BinaryOperation

Bitwise OR a bigint with another.

Source code in xdsl/dialects/bigint.py
219
220
221
222
223
224
225
226
227
228
229
@irdl_op_definition
class BitOrOp(BinaryOperation):
    """Bitwise OR a `bigint` with another."""

    name = "bigint.bitor"

    traits = traits_def(
        Pure(),
        Commutative(),
        SameOperandsAndResultType(),
    )

name = 'bigint.bitor' class-attribute instance-attribute

traits = traits_def(Pure(), Commutative(), SameOperandsAndResultType()) class-attribute instance-attribute

BitXorOp dataclass

Bases: BinaryOperation

Bitwise XOR a bigint with another.

Source code in xdsl/dialects/bigint.py
232
233
234
235
236
237
238
239
240
241
242
@irdl_op_definition
class BitXorOp(BinaryOperation):
    """Bitwise XOR a `bigint` with another."""

    name = "bigint.bitxor"

    traits = traits_def(
        Pure(),
        Commutative(),
        SameOperandsAndResultType(),
    )

name = 'bigint.bitxor' class-attribute instance-attribute

traits = traits_def(Pure(), Commutative(), SameOperandsAndResultType()) class-attribute instance-attribute

BitAndOp dataclass

Bases: BinaryOperation

Bitwise AND a bigint with another.

Source code in xdsl/dialects/bigint.py
245
246
247
248
249
250
251
252
253
254
255
@irdl_op_definition
class BitAndOp(BinaryOperation):
    """Bitwise AND a `bigint` with another."""

    name = "bigint.bitand"

    traits = traits_def(
        Pure(),
        Commutative(),
        SameOperandsAndResultType(),
    )

name = 'bigint.bitand' class-attribute instance-attribute

traits = traits_def(Pure(), Commutative(), SameOperandsAndResultType()) class-attribute instance-attribute

DivOp

Bases: IRDLOperation

Divide two bigints, yielding a 64-bit floating point type.

Note that this operation follows Python semantics, for example by rounding to minus infinity.

Source code in xdsl/dialects/bigint.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
@irdl_op_definition
class DivOp(IRDLOperation):
    """Divide two `bigint`s, yielding a 64-bit floating point type.

    Note that this operation follows Python semantics, for example by rounding
    to minus infinity.
    """

    name = "bigint.div"

    lhs = operand_def(bigint)
    rhs = operand_def(bigint)
    result = result_def(f64)

    assembly_format = "$lhs `,` $rhs attr-dict `:` type($result)"

    traits = traits_def(
        Pure(),
    )

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
    ):
        super().__init__(operands=[operand1, operand2], result_types=[f64])

name = 'bigint.div' class-attribute instance-attribute

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

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

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

assembly_format = '$lhs `,` $rhs attr-dict `:` type($result)' class-attribute instance-attribute

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

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue)

Source code in xdsl/dialects/bigint.py
278
279
280
281
282
283
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
):
    super().__init__(operands=[operand1, operand2], result_types=[f64])

ComparisonOperation

Bases: IRDLOperation, ABC

Binary operation comparing two bigints and returning a boolean.

Source code in xdsl/dialects/bigint.py
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
class ComparisonOperation(IRDLOperation, abc.ABC):
    """Binary operation comparing two `bigint`s and returning a boolean."""

    lhs = operand_def(bigint)
    rhs = operand_def(bigint)
    result = result_def(i1)

    assembly_format = "$lhs `,` $rhs attr-dict `:` type($result)"

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
    ):
        super().__init__(operands=[operand1, operand2], result_types=[i1])

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

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

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

assembly_format = '$lhs `,` $rhs attr-dict `:` type($result)' class-attribute instance-attribute

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue)

Source code in xdsl/dialects/bigint.py
295
296
297
298
299
300
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
):
    super().__init__(operands=[operand1, operand2], result_types=[i1])

EqOp dataclass

Bases: ComparisonOperation

Check equality of two bigints.

Source code in xdsl/dialects/bigint.py
303
304
305
306
307
308
309
310
311
312
@irdl_op_definition
class EqOp(ComparisonOperation):
    """Check equality of two `bigint`s."""

    name = "bigint.eq"

    traits = traits_def(
        Pure(),
        Commutative(),
    )

name = 'bigint.eq' class-attribute instance-attribute

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

NeqOp dataclass

Bases: ComparisonOperation

Check inequality of two bigints.

Source code in xdsl/dialects/bigint.py
315
316
317
318
319
320
321
322
323
324
@irdl_op_definition
class NeqOp(ComparisonOperation):
    """Check inequality of two `bigint`s."""

    name = "bigint.neq"

    traits = traits_def(
        Pure(),
        Commutative(),
    )

name = 'bigint.neq' class-attribute instance-attribute

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

GtOp dataclass

Bases: ComparisonOperation

Check if one bigint is greater than another.

Source code in xdsl/dialects/bigint.py
327
328
329
330
331
332
333
334
335
@irdl_op_definition
class GtOp(ComparisonOperation):
    """Check if one `bigint` is greater than another."""

    name = "bigint.gt"

    traits = traits_def(
        Pure(),
    )

name = 'bigint.gt' class-attribute instance-attribute

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

GteOp dataclass

Bases: ComparisonOperation

Check if one bigint is greater than or equal to another.

Source code in xdsl/dialects/bigint.py
338
339
340
341
342
343
344
345
346
@irdl_op_definition
class GteOp(ComparisonOperation):
    """Check if one `bigint` is greater than or equal to another."""

    name = "bigint.gte"

    traits = traits_def(
        Pure(),
    )

name = 'bigint.gte' class-attribute instance-attribute

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

LtOp dataclass

Bases: ComparisonOperation

Check if one bigint is less than another.

Source code in xdsl/dialects/bigint.py
349
350
351
352
353
354
355
356
357
@irdl_op_definition
class LtOp(ComparisonOperation):
    """Check if one `bigint` is less than another."""

    name = "bigint.lt"

    traits = traits_def(
        Pure(),
    )

name = 'bigint.lt' class-attribute instance-attribute

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

LteOp dataclass

Bases: ComparisonOperation

Check if one bigint is less than or equal to another.

Source code in xdsl/dialects/bigint.py
360
361
362
363
364
365
366
367
368
@irdl_op_definition
class LteOp(ComparisonOperation):
    """Check if one `bigint` is less than or equal to another."""

    name = "bigint.lte"

    traits = traits_def(
        Pure(),
    )

name = 'bigint.lte' class-attribute instance-attribute

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