// SPDX-License-Identifier: MIT //! The browser's number: the harness_speed workload (``bench.rs``) exported from a //! wasm32-unknown-unknown build, for ``scripts/wasm_bench.mjs`` to time under Node. //! No bindings crate: plain C-ABI exports. use crate::bench; use crate::harness::Harness; static mut HARNESS: Option = None; /// A fresh harness: bit 0 the cache on, bit 1 (-fast) the 32X's bus (``bench::setup_32x``), /// bits 2 and 3 the cached interpreter and its trust mode (feature ``block-cache``). #[no_mangle] pub extern "C" fn sh2_setup(mode: u32) { let cache = mode & 1 != 0; #[allow(unused_mut)] let mut harness = if mode & 2 != 0 { bench::setup_32x(cache) } else { bench::setup(cache) }; // bit 2: the cached interpreter (a build with the block-cache feature), bit 3 its trust mode #[cfg(feature = "block-cache")] { harness.chip.blocks.enabled = mode & 4 != 0; harness.chip.blocks.verify = mode & 8 == 0; } // SAFETY: wasm32-unknown-unknown is single-threaded; the exports are called in turn. unsafe { *std::ptr::addr_of_mut!(HARNESS) = Some(harness) }; } /// ``steps`` instructions; returns the low 32 bits of the chip's clock. #[no_mangle] pub extern "C" fn sh2_run(steps: u32) -> u32 { // SAFETY: as above. let harness = unsafe { (*std::ptr::addr_of_mut!(HARNESS)).as_mut().expect("sh2_setup first") }; bench::run(harness, steps as u64) as u32 }