1//===-- Enums.td -------------------------------------------*- tablegen -*-===//
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
8//===----------------------------------------------------------------------===//
10#ifndef LLZK_CAST_ENUMS
11#define LLZK_CAST_ENUMS
13include "mlir/IR/EnumAttr.td"
15def OverflowSemanticsDescription {
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]`.";
22def LLZK_OverflowSemantics
23 : I32EnumAttr<"OverflowSemantics", OverflowSemanticsDescription.r,
25 // Assert (default): Fail when the source value is outside
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
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
38 I32EnumAttrCase<"TRUNCATE", 3, "trunc">,
40 let genSpecializedAttr = 0;
41 let cppNamespace = "::llzk::cast";
44#endif // LLZK_CAST_ENUMS