|
1 | | -# SPDX-FileCopyrightText: Copyright (c) <2025> NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 1 | +# SPDX-FileCopyrightText: Copyright (c) <2026> NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
|
12 | 12 | encode_unsized_variadic_operands, encode_sized_variadic_operands, encode_operand |
13 | 13 | ) |
14 | 14 | from .type import encode_typeid, encode_sized_typeid_seq, TypeId |
| 15 | +from .version import BytecodeVersion |
15 | 16 |
|
16 | 17 |
|
17 | 18 | class AtomicRMWMode(enum.Enum): |
@@ -200,6 +201,23 @@ def encode_AssumeOp( |
200 | 201 | return code_builder.new_op() |
201 | 202 |
|
202 | 203 |
|
| 204 | +def encode_Atan2Op( # since 13.2 |
| 205 | + code_builder: CodeBuilder, |
| 206 | + result_type: TypeId, # since 13.2 |
| 207 | + x: Value, # since 13.2 |
| 208 | + y: Value, # since 13.2 |
| 209 | +) -> Value: |
| 210 | + _buf = code_builder.buf |
| 211 | + # Opcode |
| 212 | + encode_varint(110, _buf) |
| 213 | + # Result types |
| 214 | + encode_typeid(result_type, _buf) |
| 215 | + # Operands |
| 216 | + encode_operand(x, _buf) |
| 217 | + encode_operand(y, _buf) |
| 218 | + return code_builder.new_op() |
| 219 | + |
| 220 | + |
203 | 221 | def encode_AtomicCASTkoOp( |
204 | 222 | code_builder: CodeBuilder, |
205 | 223 | result_type: TypeId, |
@@ -676,12 +694,18 @@ def encode_ForOp( |
676 | 694 | upperBound: Value, |
677 | 695 | step: Value, |
678 | 696 | initValues: Sequence[Value], |
| 697 | + unsignedCmp: bool, # since 13.2 |
679 | 698 | ) -> NestedBlockBuilder: |
680 | 699 | _buf = code_builder.buf |
681 | 700 | # Opcode |
682 | 701 | encode_varint(41, _buf) |
683 | 702 | # Variadic result types |
684 | 703 | encode_sized_typeid_seq(result_types, _buf) |
| 704 | + # Flags |
| 705 | + _flag_bits = bool(unsignedCmp) |
| 706 | + assert _flag_bits < 1 or code_builder.version >= BytecodeVersion.V_13_2 |
| 707 | + if code_builder.version >= BytecodeVersion.V_13_2: |
| 708 | + encode_varint(_flag_bits, _buf) |
685 | 709 | # Operands |
686 | 710 | encode_varint(3 + len(initValues), _buf) |
687 | 711 | encode_operand(lowerBound, _buf) |
@@ -1243,12 +1267,18 @@ def encode_NegIOp( |
1243 | 1267 | code_builder: CodeBuilder, |
1244 | 1268 | result_type: TypeId, |
1245 | 1269 | source: Value, |
| 1270 | + overflow: IntegerOverflow, # since 13.2 |
1246 | 1271 | ) -> Value: |
1247 | 1272 | _buf = code_builder.buf |
1248 | 1273 | # Opcode |
1249 | 1274 | encode_varint(80, _buf) |
1250 | 1275 | # Result types |
1251 | 1276 | encode_typeid(result_type, _buf) |
| 1277 | + # Attributes |
| 1278 | + if code_builder.version >= BytecodeVersion.V_13_2: |
| 1279 | + code_builder.encode_opattr_enum(IntegerOverflow, overflow) |
| 1280 | + else: |
| 1281 | + assert overflow == IntegerOverflow.NONE |
1252 | 1282 | # Operands |
1253 | 1283 | encode_operand(source, _buf) |
1254 | 1284 | return code_builder.new_op() |
@@ -1323,22 +1353,37 @@ def encode_PowOp( |
1323 | 1353 | return code_builder.new_op() |
1324 | 1354 |
|
1325 | 1355 |
|
1326 | | -def encode_PrintOp( |
| 1356 | +def encode_PrintTkoOp( |
1327 | 1357 | code_builder: CodeBuilder, |
| 1358 | + result_token_type: Optional[TypeId], # since 13.2 |
1328 | 1359 | args: Sequence[Value], |
| 1360 | + token: Optional[Value], # since 13.2 |
1329 | 1361 | str: str, |
1330 | | -) -> None: |
| 1362 | +) -> Optional[Value]: |
1331 | 1363 | _buf = code_builder.buf |
1332 | 1364 | # Opcode |
1333 | 1365 | encode_varint(85, _buf) |
1334 | 1366 | # Variadic result types |
1335 | | - encode_sized_typeid_seq((), _buf) |
| 1367 | + result_types = [] |
| 1368 | + if code_builder.version >= BytecodeVersion.V_13_2: |
| 1369 | + result_token_idx = len(result_types) |
| 1370 | + result_types.append(result_token_type) |
| 1371 | + else: |
| 1372 | + assert result_token_type is None |
| 1373 | + result_token_idx = None |
| 1374 | + encode_sized_typeid_seq(result_types, _buf) |
| 1375 | + # Flags |
| 1376 | + _flag_bits = (token is not None) |
| 1377 | + assert _flag_bits < 1 or code_builder.version >= BytecodeVersion.V_13_2 |
| 1378 | + if code_builder.version >= BytecodeVersion.V_13_2: |
| 1379 | + encode_varint(_flag_bits, _buf) |
1336 | 1380 | # Attributes |
1337 | 1381 | code_builder.encode_opattr_str(str) |
1338 | 1382 | # Operands |
1339 | | - encode_varint(len(args), _buf) |
1340 | | - encode_unsized_variadic_operands(args, _buf) |
1341 | | - return code_builder.new_op(0) |
| 1383 | + encode_sized_variadic_operands(args, _buf) |
| 1384 | + encode_optional_operand(token, _buf) |
| 1385 | + results = code_builder.new_op(len(result_types)) |
| 1386 | + return None if result_token_idx is None else results[result_token_idx] |
1342 | 1387 |
|
1343 | 1388 |
|
1344 | 1389 | def encode_PtrToIntOp( |
@@ -1726,12 +1771,18 @@ def encode_TanHOp( |
1726 | 1771 | code_builder: CodeBuilder, |
1727 | 1772 | result_type: TypeId, |
1728 | 1773 | source: Value, |
| 1774 | + rounding_mode: RoundingMode, # since 13.2 |
1729 | 1775 | ) -> Value: |
1730 | 1776 | _buf = code_builder.buf |
1731 | 1777 | # Opcode |
1732 | 1778 | encode_varint(106, _buf) |
1733 | 1779 | # Result types |
1734 | 1780 | encode_typeid(result_type, _buf) |
| 1781 | + # Attributes |
| 1782 | + if code_builder.version >= BytecodeVersion.V_13_2: |
| 1783 | + code_builder.encode_opattr_enum(RoundingMode, rounding_mode) |
| 1784 | + else: |
| 1785 | + assert rounding_mode == RoundingMode.FULL |
1735 | 1786 | # Operands |
1736 | 1787 | encode_operand(source, _buf) |
1737 | 1788 | return code_builder.new_op() |
@@ -1818,6 +1869,7 @@ def encode_YieldOp( |
1818 | 1869 | 'encode_AndIOp', |
1819 | 1870 | 'encode_AssertOp', |
1820 | 1871 | 'encode_AssumeOp', |
| 1872 | + 'encode_Atan2Op', |
1821 | 1873 | 'encode_AtomicCASTkoOp', |
1822 | 1874 | 'encode_AtomicRMWTkoOp', |
1823 | 1875 | 'encode_BitcastOp', |
@@ -1878,7 +1930,7 @@ def encode_YieldOp( |
1878 | 1930 | 'encode_OrIOp', |
1879 | 1931 | 'encode_PermuteOp', |
1880 | 1932 | 'encode_PowOp', |
1881 | | - 'encode_PrintOp', |
| 1933 | + 'encode_PrintTkoOp', |
1882 | 1934 | 'encode_PtrToIntOp', |
1883 | 1935 | 'encode_PtrToPtrOp', |
1884 | 1936 | 'encode_ReduceOp', |
|
0 commit comments