// 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, the cache on (1) or off (0). #[no_mangle] pub extern "C" fn sh2_setup(cache: u32) { // SAFETY: wasm32-unknown-unknown is single-threaded; the exports are called in turn. unsafe { *std::ptr::addr_of_mut!(HARNESS) = Some(bench::setup(cache != 0)) }; } /// ``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 }