miden_processor/utils.rs
1use alloc::vec::Vec;
2
3use miden_core::Felt;
4// RE-EXPORTS
5// ================================================================================================
6pub use miden_core::utils::*;
7
8// HELPER FUNCTIONS
9// ================================================================================================
10
11/// Returns the number of rows in the provided execution trace assumed to be in column-major form
12/// and contain at least one column.
13pub(crate) fn get_trace_len(trace: &[Vec<Felt>]) -> usize {
14 trace[0].len()
15}
16
17/// Splits an element into two field elements containing 32-bit integer values
18#[inline(always)]
19pub(crate) fn split_element(value: Felt) -> (Felt, Felt) {
20 let value = value.as_int();
21 let lo = (value as u32) as u64;
22 let hi = value >> 32;
23 (Felt::new(hi), Felt::new(lo))
24}
25
26/// Splits an element into two 16 bit integer limbs. It assumes that the field element contains a
27/// valid 32-bit integer value.
28pub(crate) fn split_element_u32_into_u16(value: Felt) -> (Felt, Felt) {
29 let (hi, lo) = split_u32_into_u16(value.as_int());
30 (Felt::new(hi as u64), Felt::new(lo as u64))
31}
32
33/// Splits a u64 integer assumed to contain a 32-bit value into two u16 integers.
34///
35/// # Errors
36/// Fails in debug mode if the provided value is not a 32-bit value.
37pub(crate) fn split_u32_into_u16(value: u64) -> (u16, u16) {
38 const U32MAX: u64 = u32::MAX as u64;
39 debug_assert!(value <= U32MAX, "not a 32-bit value");
40
41 let lo = value as u16;
42 let hi = (value >> 16) as u16;
43
44 (hi, lo)
45}