/// Reads and sums up all eight byte words in the given memory region.
///
/// Arguments:
/// - operation.repeat: the number of operations.
/// - operation.address: optional start address of the memory region. It is
///   chosen randomly if not given.
/// - operation.size: the size of the memory region in bytes.
/// - operation.value: optional eight byte value. If the value is given, then
///   the operation asserts that all read values match the given value.
Reads and sums up all eight byte words in the given memory region.
Arguments:
operation.repeat: the number of operations.
operation.address: optional start address of the memory region. It is
chosen randomly if not given.
operation.size: the size of the memory region in bytes.
operation.value: optional eight byte value. If the value is given, then
the operation asserts that all read values match the given value.
Reads and sums up all eight byte words in the given memory region . Arguments : operation . repeat : the number of operations . operation . address : optional start address of the memory region . It is chosen randomly if not given . operation . size : the size of the memory region in bytes . operation . value : optional eight byte value . If the value is given then the operation asserts that all read values match the given value .
fn read() {
    let operation = operation_from_args();
    let mut sum = 0;
    MEMORY.with(|memory| {
        let memory_ref = memory.borrow();
        let memory = memory_ref.as_slice();
        let repeat = operation.repeat.unwrap_or(1);
        let len = (operation.size + ELEMENT_SIZE - 1) / ELEMENT_SIZE;
        assert!(len <= MEMORY_LEN);
        for _ in 0..repeat {
            let src = operation
                .address
                .unwrap_or_else(|| rand(0, MEMORY_LEN - len + 1) * ELEMENT_SIZE)
                as usize
                / ELEMENT_SIZE;
            #[allow(clippy::needless_range_loop)]
            for i in src..src + len {
                let value = memory[i];
                if let Some(expected_value) = operation.value {
                    if expected_value != value as u8 {
                        trap_with(&format!(
                            "Value mismatch at {}, expected {}, got {}",
                            i * ELEMENT_SIZE,
                            expected_value,
                            value
                        ));
                    }
                }
                sum += value;
            }
        }
    });
    api::reply(sum.to_string().as_bytes());
}
fn read ( ) { let operation = operation_from_args ( ) ; let mut sum = 0 ; MEMORY . with ( | memory | { let memory_ref = memory . borrow ( ) ; let memory = memory_ref . as_slice ( ) ; let repeat = operation . repeat . unwrap_or ( 1 ) ; let len = ( operation . size + ELEMENT_SIZE - 1 ) / ELEMENT_SIZE ; assert ! ( len MEMORY_LEN ) ; for _ in 0 .. repeat { let src = operation . address . unwrap_or_else ( | | rand ( 0 , MEMORY_LEN - len + 1 ) * ELEMENT_SIZE ) as usize / ELEMENT_SIZE ; # [ allow ( clippy needless_range_loop ) ] for i in src .. src + len { let value = memory [ i ] ; if let Some ( expected_value ) = operation . value { if expected_value != value as u8 { trap_with ( & format ! ( " " i ELEMENT_SIZE expected_value value ) ) ; } } sum += value ; } } } ) ; api :: reply ( sum . to_string ( ) . as_bytes ( ) ) ; }
Reads and sums up all eight byte words in the given memory region.
Reads and sums up all eight byte words in the given memory region .