LLZK 3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Enums.td
Go to the documentation of this file.
1//===-- Enums.td -------------------------------------------*- tablegen -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2026 Project LLZK
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLZK_CAST_ENUMS
11#define LLZK_CAST_ENUMS
12
13include "mlir/IR/EnumAttr.td"
14
15def OverflowSemanticsDescription {
16 string r =
17 "Specifies how a cast handles a source value outside the target's safe "
18 "range. For a felt target with prime `p`, the safe range is `[0, p-1]`. "
19 "For an index target with bitwidth `N`, it is `[0, 2^(N-1)-1]`.";
20}
21
22def LLZK_OverflowSemantics
23 : I32EnumAttr<"OverflowSemantics", OverflowSemanticsDescription.r,
24 [
25 // Assert (default): Fail when the source value is outside
26 // the safe range.
27 I32EnumAttrCase<"ASSERT", 0, "assert">,
28 // Saturate: Clamp to the safe range.
29 I32EnumAttrCase<"SATURATE", 1, "sat">,
30 // Wrap: Reduce modulo `p` for `tofelt` or modulo
31 // `2^(N-1)` for `toindex`, keeping the result in the
32 // index safe range.
33 I32EnumAttrCase<"WRAP", 2, "wrap">,
34 // Truncate: Keep the low bits. For `tofelt`, keep
35 // `bitwidth(p)` bits, then reduce modulo `p` to stay in
36 // the safe range. For `toindex`, keep `N-1` bits so the
37 // sign bit is zero.
38 I32EnumAttrCase<"TRUNCATE", 3, "trunc">,
39]> {
40 let genSpecializedAttr = 0;
41 let cppNamespace = "::llzk::cast";
42}
43
44#endif // LLZK_CAST_ENUMS