diff --git a/corelib/src/internal/bounded_int.cairo b/corelib/src/internal/bounded_int.cairo index 0380f5cfee7..4668f9ab12f 100644 --- a/corelib/src/internal/bounded_int.cairo +++ b/corelib/src/internal/bounded_int.cairo @@ -113,56 +113,49 @@ extern fn bounded_int_constrain Result implicits(RangeCheck) nopanic; -/// A helper trait for trimming a `BoundedInt` instance. -pub trait TrimHelper { +/// A helper trait for trimming a `BoundedInt` instance min value. +pub trait TrimMinHelper { + type Target; +} +/// A helper trait for trimming a `BoundedInt` instance max value. +pub trait TrimMaxHelper { type Target; } mod trim_impl { - pub impl Impl< - T, const TRIMMED_VALUE: felt252, const MIN: felt252, const MAX: felt252, - > of super::TrimHelper { + pub impl Min of super::TrimMinHelper { + type Target = super::BoundedInt; + } + pub impl Max of super::TrimMaxHelper { type Target = super::BoundedInt; } } -impl U8TrimBelow = trim_impl::Impl; -impl U8TrimAbove = trim_impl::Impl; -impl I8TrimBelow = trim_impl::Impl; -impl I8TrimAbove = trim_impl::Impl; -impl U16TrimBelow = trim_impl::Impl; -impl U16TrimAbove = trim_impl::Impl; -impl I16TrimBelow = trim_impl::Impl; -impl I16TrimAbove = trim_impl::Impl; -impl U32TrimBelow = trim_impl::Impl; -impl U32TrimAbove = trim_impl::Impl; -impl I32TrimBelow = trim_impl::Impl; -impl I32TrimAbove = trim_impl::Impl; -impl U64TrimBelow = trim_impl::Impl; -impl U64TrimAbove = trim_impl::Impl; -impl I64TrimBelow = - trim_impl::Impl; -impl I64TrimAbove = - trim_impl::Impl; -impl U128TrimBelow = trim_impl::Impl; -impl U128TrimAbove = - trim_impl::Impl< - u128, 0xffffffffffffffffffffffffffffffff, 0, 0xfffffffffffffffffffffffffffffffe, - >; +impl U8TrimBelow = trim_impl::Min; +impl U8TrimAbove = trim_impl::Max; +impl I8TrimBelow = trim_impl::Min; +impl I8TrimAbove = trim_impl::Max; +impl U16TrimBelow = trim_impl::Min; +impl U16TrimAbove = trim_impl::Max; +impl I16TrimBelow = trim_impl::Min; +impl I16TrimAbove = trim_impl::Max; +impl U32TrimBelow = trim_impl::Min; +impl U32TrimAbove = trim_impl::Max; +impl I32TrimBelow = trim_impl::Min; +impl I32TrimAbove = trim_impl::Max; +impl U64TrimBelow = trim_impl::Min; +impl U64TrimAbove = trim_impl::Max; +impl I64TrimBelow = trim_impl::Min; +impl I64TrimAbove = trim_impl::Max; +impl U128TrimBelow = trim_impl::Min; +impl U128TrimAbove = trim_impl::Max; impl I128TrimBelow = - trim_impl::Impl< - i128, - -0x80000000000000000000000000000000, - -0x7fffffffffffffffffffffffffffffff, - 0x7fffffffffffffffffffffffffffffff, - >; + trim_impl::Min; impl I128TrimAbove = - trim_impl::Impl< - i128, - 0x7fffffffffffffffffffffffffffffff, - -0x80000000000000000000000000000000, - 0x7ffffffffffffffffffffffffffffffe, - >; + trim_impl::Max; -extern fn bounded_int_trim>( +extern fn bounded_int_trim_min>( + value: T, +) -> core::internal::OptionRev nopanic; +extern fn bounded_int_trim_max>( value: T, ) -> core::internal::OptionRev nopanic; @@ -272,5 +265,6 @@ impl MulMinusOneNegateHelper> of NegateHelper< pub use { bounded_int_add as add, bounded_int_sub as sub, bounded_int_mul as mul, bounded_int_div_rem as div_rem, bounded_int_constrain as constrain, - bounded_int_is_zero as is_zero, bounded_int_trim as trim, + bounded_int_is_zero as is_zero, bounded_int_trim_min as trim_min, + bounded_int_trim_max as trim_max, }; diff --git a/corelib/src/test/integer_test.cairo b/corelib/src/test/integer_test.cairo index 43a4b3e572a..df5b6217c96 100644 --- a/corelib/src/test/integer_test.cairo +++ b/corelib/src/test/integer_test.cairo @@ -2159,81 +2159,63 @@ mod bounded_int { #[test] fn test_trim() { use core::internal::OptionRev; - assert!(bounded_int::trim::(0) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); - assert!(bounded_int::trim::(0xff) == OptionRev::None); - assert!(bounded_int::trim::(0xfe) == OptionRev::Some(0xfe)); - assert!(bounded_int::trim::(-0x80) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); - assert!(bounded_int::trim::(0x7f) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); - - assert!(bounded_int::trim::(0) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); - assert!(bounded_int::trim::(0xffff) == OptionRev::None); - assert!(bounded_int::trim::(0xfffe) == OptionRev::Some(0xfffe)); - assert!(bounded_int::trim::(-0x8000) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); - assert!(bounded_int::trim::(0x7fff) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); - - assert!(bounded_int::trim::(0) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); - assert!(bounded_int::trim::(0xffffffff) == OptionRev::None); - assert!(bounded_int::trim::(0xfffffffe) == OptionRev::Some(0xfffffffe)); - assert!(bounded_int::trim::(-0x80000000) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); - assert!(bounded_int::trim::(0x7fffffff) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); - - assert!(bounded_int::trim::(0) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_min::(0) == OptionRev::None); + assert!(bounded_int::trim_min::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_max::(0xff) == OptionRev::None); + assert!(bounded_int::trim_max::(0xfe) == OptionRev::Some(0xfe)); + assert!(bounded_int::trim_min::(-0x80) == OptionRev::None); + assert!(bounded_int::trim_min::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_max::(0x7f) == OptionRev::None); + assert!(bounded_int::trim_max::(1) == OptionRev::Some(1)); + + assert!(bounded_int::trim_min::(0) == OptionRev::None); + assert!(bounded_int::trim_min::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_max::(0xffff) == OptionRev::None); + assert!(bounded_int::trim_max::(0xfffe) == OptionRev::Some(0xfffe)); + assert!(bounded_int::trim_min::(-0x8000) == OptionRev::None); + assert!(bounded_int::trim_min::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_max::(0x7fff) == OptionRev::None); + assert!(bounded_int::trim_max::(1) == OptionRev::Some(1)); + + assert!(bounded_int::trim_min::(0) == OptionRev::None); + assert!(bounded_int::trim_min::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_max::(0xffffffff) == OptionRev::None); + assert!(bounded_int::trim_max::(0xfffffffe) == OptionRev::Some(0xfffffffe)); + assert!(bounded_int::trim_min::(-0x80000000) == OptionRev::None); + assert!(bounded_int::trim_min::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_max::(0x7fffffff) == OptionRev::None); + assert!(bounded_int::trim_max::(1) == OptionRev::Some(1)); + + assert!(bounded_int::trim_min::(0) == OptionRev::None); + assert!(bounded_int::trim_min::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_max::(0xffffffffffffffff) == OptionRev::None); assert!( - bounded_int::trim::(0xffffffffffffffff) == OptionRev::None, + bounded_int::trim_max::(0xfffffffffffffffe) == OptionRev::Some(0xfffffffffffffffe), ); - assert!( - bounded_int::trim::< - u64, 0xffffffffffffffff, - >(0xfffffffffffffffe) == OptionRev::Some(0xfffffffffffffffe), - ); - assert!( - bounded_int::trim::(-0x8000000000000000) == OptionRev::None, - ); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); - assert!( - bounded_int::trim::(0x7fffffffffffffff) == OptionRev::None, - ); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_min::(-0x8000000000000000) == OptionRev::None); + assert!(bounded_int::trim_min::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_max::(0x7fffffffffffffff) == OptionRev::None); + assert!(bounded_int::trim_max::(1) == OptionRev::Some(1)); - assert!(bounded_int::trim::(0) == OptionRev::None); - assert!(bounded_int::trim::(1) == OptionRev::Some(1)); + assert!(bounded_int::trim_min::(0) == OptionRev::None); + assert!(bounded_int::trim_min::(1) == OptionRev::Some(1)); assert!( - bounded_int::trim::< - u128, 0xffffffffffffffffffffffffffffffff, - >(0xffffffffffffffffffffffffffffffff) == OptionRev::None, + bounded_int::trim_max::(0xffffffffffffffffffffffffffffffff) == OptionRev::None, ); assert!( - bounded_int::trim::< - u128, 0xffffffffffffffffffffffffffffffff, + bounded_int::trim_max::< + u128, >( 0xfffffffffffffffffffffffffffffffe, ) == OptionRev::Some(0xfffffffffffffffffffffffffffffffe), ); assert!( - bounded_int::trim::< - i128, -0x80000000000000000000000000000000, - >(-0x80000000000000000000000000000000) == OptionRev::None, - ); - assert!( - bounded_int::trim::(1) == OptionRev::Some(1), - ); - assert!( - bounded_int::trim::< - i128, 0x7fffffffffffffffffffffffffffffff, - >(0x7fffffffffffffffffffffffffffffff) == OptionRev::None, + bounded_int::trim_min::(-0x80000000000000000000000000000000) == OptionRev::None, ); + assert!(bounded_int::trim_min::(1) == OptionRev::Some(1)); assert!( - bounded_int::trim::(1) == OptionRev::Some(1), + bounded_int::trim_max::(0x7fffffffffffffffffffffffffffffff) == OptionRev::None, ); + assert!(bounded_int::trim_max::(1) == OptionRev::Some(1)); } } diff --git a/crates/cairo-lang-sierra-ap-change/src/core_libfunc_ap_change.rs b/crates/cairo-lang-sierra-ap-change/src/core_libfunc_ap_change.rs index 175ea1903a5..26ce2125e3b 100644 --- a/crates/cairo-lang-sierra-ap-change/src/core_libfunc_ap_change.rs +++ b/crates/cairo-lang-sierra-ap-change/src/core_libfunc_ap_change.rs @@ -389,7 +389,8 @@ pub fn core_libfunc_ap_change( ApChange::Known(1 + if libfunc.boundary.is_zero() { 0 } else { 1 }), ] } - BoundedIntConcreteLibfunc::Trim(libfunc) => { + BoundedIntConcreteLibfunc::TrimMin(libfunc) + | BoundedIntConcreteLibfunc::TrimMax(libfunc) => { let ap_change = if libfunc.trimmed_value.is_zero() { 0 } else { 1 }; vec![ApChange::Known(ap_change), ApChange::Known(ap_change)] } diff --git a/crates/cairo-lang-sierra-gas/src/core_libfunc_cost_base.rs b/crates/cairo-lang-sierra-gas/src/core_libfunc_cost_base.rs index 1e128140d91..4be904d1271 100644 --- a/crates/cairo-lang-sierra-gas/src/core_libfunc_cost_base.rs +++ b/crates/cairo-lang-sierra-gas/src/core_libfunc_cost_base.rs @@ -504,7 +504,8 @@ pub fn core_libfunc_cost( .into(), ] } - BoundedIntConcreteLibfunc::Trim(libfunc) => { + BoundedIntConcreteLibfunc::TrimMin(libfunc) + | BoundedIntConcreteLibfunc::TrimMax(libfunc) => { let steps: BranchCost = ConstCost::steps(if libfunc.trimmed_value.is_zero() { 1 } else { 2 }).into(); vec![steps.clone(), steps] diff --git a/crates/cairo-lang-sierra-to-casm/src/invocations/int/bounded.rs b/crates/cairo-lang-sierra-to-casm/src/invocations/int/bounded.rs index b39fbeb07cb..972e53c147c 100644 --- a/crates/cairo-lang-sierra-to-casm/src/invocations/int/bounded.rs +++ b/crates/cairo-lang-sierra-to-casm/src/invocations/int/bounded.rs @@ -39,7 +39,10 @@ pub fn build( BoundedIntConcreteLibfunc::Constrain(libfunc) => { build_constrain(builder, &libfunc.boundary) } - BoundedIntConcreteLibfunc::Trim(libfunc) => build_trim(builder, &libfunc.trimmed_value), + BoundedIntConcreteLibfunc::TrimMin(libfunc) + | BoundedIntConcreteLibfunc::TrimMax(libfunc) => { + build_trim(builder, &libfunc.trimmed_value) + } BoundedIntConcreteLibfunc::IsZero(_) => build_is_zero(builder), BoundedIntConcreteLibfunc::WrapNonZero(_) => build_identity(builder), } diff --git a/crates/cairo-lang-sierra/src/extensions/modules/bounded_int.rs b/crates/cairo-lang-sierra/src/extensions/modules/bounded_int.rs index b73fcc53d47..ba8d94b3874 100644 --- a/crates/cairo-lang-sierra/src/extensions/modules/bounded_int.rs +++ b/crates/cairo-lang-sierra/src/extensions/modules/bounded_int.rs @@ -79,7 +79,8 @@ define_libfunc_hierarchy! { Mul(BoundedIntMulLibfunc), DivRem(BoundedIntDivRemLibfunc), Constrain(BoundedIntConstrainLibfunc), - Trim(BoundedIntTrimLibfunc), + TrimMin(BoundedIntTrimLibfunc), + TrimMax(BoundedIntTrimLibfunc), IsZero(BoundedIntIsZeroLibfunc), WrapNonZero(BoundedIntWrapNonZeroLibfunc), }, BoundedIntConcreteLibfunc @@ -388,67 +389,71 @@ impl SignatureBasedConcreteLibfunc for BoundedIntConstrainConcreteLibfunc { /// Libfunc for trimming a BoundedInt by removing `Min` or `Max` from the range. /// The libfunc is also applicable for standard types such as u* and i*. #[derive(Default)] -pub struct BoundedIntTrimLibfunc {} -impl NamedLibfunc for BoundedIntTrimLibfunc { +pub struct BoundedIntTrimLibfunc {} +impl NamedLibfunc for BoundedIntTrimLibfunc { type Concrete = BoundedIntTrimConcreteLibfunc; - const STR_ID: &'static str = "bounded_int_trim"; + const STR_ID: &'static str = + if IS_MAX { "bounded_int_trim_max" } else { "bounded_int_trim_min" }; fn specialize_signature( &self, context: &dyn SignatureSpecializationContext, args: &[GenericArg], ) -> Result { - let (ty, trimmed_value) = match args { - [GenericArg::Type(ty), GenericArg::Value(trimmed_value)] => Ok((ty, trimmed_value)), - [_, _] => Err(SpecializationError::UnsupportedGenericArg), - _ => Err(SpecializationError::WrongNumberOfGenericArgs), - }?; + Ok(Self::Concrete::new::(context, args)?.signature) + } + + fn specialize( + &self, + context: &dyn SpecializationContext, + args: &[GenericArg], + ) -> Result { + Self::Concrete::new::(context.upcast(), args) + } +} + +pub struct BoundedIntTrimConcreteLibfunc { + pub trimmed_value: BigInt, + signature: LibfuncSignature, +} +impl BoundedIntTrimConcreteLibfunc { + fn new( + context: &dyn SignatureSpecializationContext, + args: &[GenericArg], + ) -> Result { + let ty = args_as_single_type(args)?; let ty_info = context.get_type_info(ty.clone())?; - let mut range = Range::from_type_info(&ty_info)?; - if trimmed_value == &range.lower { - range.lower += 1; + let range = Range::from_type_info(&ty_info)?; + let (res_ty, trimmed_value) = if IS_MAX { + ( + bounded_int_ty(context, range.lower.clone(), range.upper.clone() - 2)?, + range.upper - 1, + ) } else { - range.upper -= 1; - require(&range.upper == trimmed_value) - .ok_or(SpecializationError::UnsupportedGenericArg)?; - } + ( + bounded_int_ty(context, range.lower.clone() + 1, range.upper.clone() - 1)?, + range.lower, + ) + }; let ap_change = SierraApChange::Known { new_vars_only: trimmed_value.is_zero() }; - Ok(LibfuncSignature { + let signature = LibfuncSignature { param_signatures: vec![ParamSignature::new(ty.clone())], branch_signatures: vec![ BranchSignature { vars: vec![], ap_change: ap_change.clone() }, BranchSignature { vars: vec![OutputVarInfo { - ty: bounded_int_ty(context, range.lower, range.upper - 1)?, + ty: res_ty, ref_info: OutputVarReferenceInfo::SameAsParam { param_idx: 0 }, }], ap_change, }, ], fallthrough: Some(0), - }) - } - - fn specialize( - &self, - context: &dyn SpecializationContext, - args: &[GenericArg], - ) -> Result { - let trimmed_value = match args { - [GenericArg::Type(_), GenericArg::Value(trimmed_value)] => Ok(trimmed_value.clone()), - [_, _] => Err(SpecializationError::UnsupportedGenericArg), - _ => Err(SpecializationError::WrongNumberOfGenericArgs), - }?; - let context = context.upcast(); - Ok(Self::Concrete { trimmed_value, signature: self.specialize_signature(context, args)? }) + }; + Ok(Self { trimmed_value, signature }) } } - -pub struct BoundedIntTrimConcreteLibfunc { - pub trimmed_value: BigInt, - signature: LibfuncSignature, -} impl SignatureBasedConcreteLibfunc for BoundedIntTrimConcreteLibfunc { fn signature(&self) -> &LibfuncSignature { &self.signature diff --git a/crates/cairo-lang-starknet-classes/src/allowed_libfuncs_lists/all.json b/crates/cairo-lang-starknet-classes/src/allowed_libfuncs_lists/all.json index a4bd46518b8..a4cee384724 100644 --- a/crates/cairo-lang-starknet-classes/src/allowed_libfuncs_lists/all.json +++ b/crates/cairo-lang-starknet-classes/src/allowed_libfuncs_lists/all.json @@ -25,7 +25,8 @@ "bounded_int_is_zero", "bounded_int_mul", "bounded_int_sub", - "bounded_int_trim", + "bounded_int_trim_max", + "bounded_int_trim_min", "bounded_int_wrap_non_zero", "box_forward_snapshot", "branch_align", diff --git a/tests/e2e_test_data/libfuncs/bounded_int b/tests/e2e_test_data/libfuncs/bounded_int index cda5140e51d..ee55a736f84 100644 --- a/tests/e2e_test_data/libfuncs/bounded_int +++ b/tests/e2e_test_data/libfuncs/bounded_int @@ -826,7 +826,7 @@ test::foo@0([0]: BoundedInt<-680564733841876926926749214863536422911, -1>) -> (N //! > ========================================================================== -//! > bounded_int_trim libfunc remove 0 below. +//! > bounded_int_trim_min libfunc remove 0. //! > test_runner_name SmallE2ETestRunner @@ -834,10 +834,10 @@ SmallE2ETestRunner //! > cairo extern type BoundedInt; type Res = core::internal::OptionRev>; -extern fn bounded_int_trim(value: T) -> Res nopanic; +extern fn bounded_int_trim_min(value: T) -> Res nopanic; fn foo(value: u8) -> Res { - bounded_int_trim::<_, 0>(value) + bounded_int_trim_min(value) } //! > casm @@ -855,14 +855,14 @@ type Unit = Struct [storable: true, drop: true, dup: true, zero_sized: type BoundedInt<1, 255> = BoundedInt<1, 255> [storable: true, drop: true, dup: true, zero_sized: false]; type core::internal::OptionRev::> = Enum>, Unit, BoundedInt<1, 255>> [storable: true, drop: true, dup: true, zero_sized: false]; -libfunc bounded_int_trim = bounded_int_trim; +libfunc bounded_int_trim_min = bounded_int_trim_min; libfunc branch_align = branch_align; libfunc struct_construct = struct_construct; libfunc enum_init>, 0> = enum_init>, 0>; libfunc store_temp>> = store_temp>>; libfunc enum_init>, 1> = enum_init>, 1>; -bounded_int_trim([0]) { fallthrough() 6([1]) }; // 0 +bounded_int_trim_min([0]) { fallthrough() 6([1]) }; // 0 branch_align() -> (); // 1 struct_construct() -> ([2]); // 2 enum_init>, 0>([2]) -> ([3]); // 3 @@ -880,7 +880,7 @@ test::foo: OrderedHashMap({Const: 300}) //! > ========================================================================== -//! > bounded_int_trim libfunc remove 0 above. +//! > bounded_int_trim_max libfunc remove 0. //! > test_runner_name SmallE2ETestRunner @@ -888,10 +888,10 @@ SmallE2ETestRunner //! > cairo extern type BoundedInt; type Res = core::internal::OptionRev>; -extern fn bounded_int_trim(value: T) -> Res nopanic; +extern fn bounded_int_trim_max(value: T) -> Res nopanic; fn foo(value: BoundedInt<-0xff, 0>) -> Res { - bounded_int_trim::<_, 0>(value) + bounded_int_trim_max(value) } //! > casm @@ -909,14 +909,14 @@ type Unit = Struct [storable: true, drop: true, dup: true, zero_sized: type BoundedInt<-255, -1> = BoundedInt<-255, -1> [storable: true, drop: true, dup: true, zero_sized: false]; type core::internal::OptionRev::> = Enum>, Unit, BoundedInt<-255, -1>> [storable: true, drop: true, dup: true, zero_sized: false]; -libfunc bounded_int_trim, 0> = bounded_int_trim, 0>; +libfunc bounded_int_trim_max> = bounded_int_trim_max>; libfunc branch_align = branch_align; libfunc struct_construct = struct_construct; libfunc enum_init>, 0> = enum_init>, 0>; libfunc store_temp>> = store_temp>>; libfunc enum_init>, 1> = enum_init>, 1>; -bounded_int_trim, 0>([0]) { fallthrough() 6([1]) }; // 0 +bounded_int_trim_max>([0]) { fallthrough() 6([1]) }; // 0 branch_align() -> (); // 1 struct_construct() -> ([2]); // 2 enum_init>, 0>([2]) -> ([3]); // 3 @@ -934,7 +934,7 @@ test::foo: OrderedHashMap({Const: 300}) //! > ========================================================================== -//! > bounded_int_trim libfunc remove non-0 below. +//! > bounded_int_trim_min libfunc remove non-0. //! > test_runner_name SmallE2ETestRunner @@ -942,10 +942,10 @@ SmallE2ETestRunner //! > cairo extern type BoundedInt; type Res = core::internal::OptionRev>; -extern fn bounded_int_trim(value: T) -> Res nopanic; +extern fn bounded_int_trim_min(value: T) -> Res nopanic; fn foo(value: i8) -> Res { - bounded_int_trim::<_, -0x80>(value) + bounded_int_trim_min(value) } //! > casm @@ -964,14 +964,14 @@ type Unit = Struct [storable: true, drop: true, dup: true, zero_sized: type BoundedInt<-127, 127> = BoundedInt<-127, 127> [storable: true, drop: true, dup: true, zero_sized: false]; type core::internal::OptionRev::> = Enum>, Unit, BoundedInt<-127, 127>> [storable: true, drop: true, dup: true, zero_sized: false]; -libfunc bounded_int_trim = bounded_int_trim; +libfunc bounded_int_trim_min = bounded_int_trim_min; libfunc branch_align = branch_align; libfunc struct_construct = struct_construct; libfunc enum_init>, 0> = enum_init>, 0>; libfunc store_temp>> = store_temp>>; libfunc enum_init>, 1> = enum_init>, 1>; -bounded_int_trim([0]) { fallthrough() 6([1]) }; // 0 +bounded_int_trim_min([0]) { fallthrough() 6([1]) }; // 0 branch_align() -> (); // 1 struct_construct() -> ([2]); // 2 enum_init>, 0>([2]) -> ([3]); // 3 @@ -989,7 +989,7 @@ test::foo: OrderedHashMap({Const: 400}) //! > ========================================================================== -//! > bounded_int_trim libfunc remove non-0 above. +//! > bounded_int_trim_max libfunc remove non-0. //! > test_runner_name SmallE2ETestRunner @@ -997,10 +997,10 @@ SmallE2ETestRunner //! > cairo extern type BoundedInt; type Res = core::internal::OptionRev>; -extern fn bounded_int_trim(value: T) -> Res nopanic; +extern fn bounded_int_trim_max(value: T) -> Res nopanic; fn foo(value: u8) -> Res { - bounded_int_trim::<_, 0xff>(value) + bounded_int_trim_max(value) } //! > casm @@ -1019,14 +1019,14 @@ type Unit = Struct [storable: true, drop: true, dup: true, zero_sized: type BoundedInt<0, 254> = BoundedInt<0, 254> [storable: true, drop: true, dup: true, zero_sized: false]; type core::internal::OptionRev::> = Enum>, Unit, BoundedInt<0, 254>> [storable: true, drop: true, dup: true, zero_sized: false]; -libfunc bounded_int_trim = bounded_int_trim; +libfunc bounded_int_trim_max = bounded_int_trim_max; libfunc branch_align = branch_align; libfunc struct_construct = struct_construct; libfunc enum_init>, 0> = enum_init>, 0>; libfunc store_temp>> = store_temp>>; libfunc enum_init>, 1> = enum_init>, 1>; -bounded_int_trim([0]) { fallthrough() 6([1]) }; // 0 +bounded_int_trim_max([0]) { fallthrough() 6([1]) }; // 0 branch_align() -> (); // 1 struct_construct() -> ([2]); // 2 enum_init>, 0>([2]) -> ([3]); // 3