miden_processor/utils.rs
1use miden_core::Felt;
2// RE-EXPORTS
3// ================================================================================================
4pub use miden_core::utils::*;
5
6/// The number of rows in the execution trace required to compute a permutation of Rescue Prime
7/// Optimized, represented as a field element.
8pub(crate) const HASH_CYCLE_LEN_FELT: Felt =
9 Felt::new(miden_air::trace::chiplets::hasher::HASH_CYCLE_LEN as u64);
10
11// HELPER FUNCTIONS
12// ================================================================================================
13
14/// Splits an element into two field elements containing 32-bit integer values
15#[inline(always)]
16pub(crate) fn split_element(value: Felt) -> (Felt, Felt) {
17 let value = value.as_int();
18 let lo = (value as u32) as u64;
19 let hi = value >> 32;
20 (Felt::new(hi), Felt::new(lo))
21}
22
23/// Splits an element into two 16 bit integer limbs. It assumes that the field element contains a
24/// valid 32-bit integer value.
25pub(crate) fn split_element_u32_into_u16(value: Felt) -> (Felt, Felt) {
26 let (hi, lo) = split_u32_into_u16(value.as_int());
27 (Felt::new(hi as u64), Felt::new(lo as u64))
28}
29
30/// Splits a u64 integer assumed to contain a 32-bit value into two u16 integers.
31///
32/// # Errors
33/// Fails in debug mode if the provided value is not a 32-bit value.
34pub(crate) fn split_u32_into_u16(value: u64) -> (u16, u16) {
35 const U32MAX: u64 = u32::MAX as u64;
36 debug_assert!(value <= U32MAX, "not a 32-bit value");
37
38 let lo = value as u16;
39 let hi = (value >> 16) as u16;
40
41 (hi, lo)
42}