// 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``). #[no_mangle] pub extern "C" fn sh2_setup(mode: u32) { let cache = mode & 1 != 0; let harness = if mode & 2 != 0 { bench::setup_32x(cache) } else { bench::setup(cache) }; // 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 }