1//===-- Ops.td ---------------------------------------------*- tablegen -*-===//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
8//===----------------------------------------------------------------------===//
13include "llzk/Dialect/Shared/Types.td"
14include "llzk/Dialect/Cast/IR/Dialect.td"
15include "llzk/Dialect/Felt/IR/Types.td"
16include "llzk/Dialect/Function/IR/OpTraits.td"
18include "mlir/IR/OpBase.td"
19include "mlir/Interfaces/SideEffectInterfaces.td"
20include "mlir/IR/SymbolInterfaces.td"
22def LLZK_IntToFeltOp : Op<CastDialect, "tofelt", [Pure]> {
23 let summary = "convert an integer into a field element";
25 This operation converts a supported integer type value into a field element value.
30 %0 = bool.cmp lt(%a, %b)
31 %1 = cast.tofelt %0 : i1
35 let arguments = (ins AnyLLZKIntType:$value);
36 let results = (outs LLZK_FeltType:$result);
37 let assemblyFormat = [{ $value `:` type($value) attr-dict }];
40def LLZK_FeltToIndexOp : Op<CastDialect, "toindex", [Pure, NotFieldNative]> {
41 let summary = "convert a field element into an index";
43 This operation converts a field element value into an index value to allow use
44 as an array index or loop bound.
49 %1 = array.read %b[%0]
53 let arguments = (ins LLZK_FeltType:$value);
54 let results = (outs Index:$result);
55 let assemblyFormat = [{ $value attr-dict }];
58#endif // LLZK_CAST_OPS