https://github.com/chipshort/wasm-float-transpiler
(Experimental) Softfloats for WebAssembly
https://github.com/chipshort/wasm-float-transpiler
Last synced: about 1 year ago
JSON representation
(Experimental) Softfloats for WebAssembly
- Host: GitHub
- URL: https://github.com/chipshort/wasm-float-transpiler
- Owner: chipshort
- Created: 2022-11-04T21:00:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-11T14:32:10.000Z (almost 3 years ago)
- Last Synced: 2025-03-28T02:45:43.560Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 116 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Wasm Float Transpiler
Converts a `wasm` file with floating point instructions (`f32`, `f64`) to one without such instructions.
The instructions are replaced with deterministic software implementations of these instructions.
# Usage
In order to include the softfloat implementation in your project,
choose one of the `wasm-soft-float-*` backend crates as a dependency and include it in your build by adding a
`pub use wasm_soft_floats_*::*;` to your project.
Check out the [backends](./backends) folder for the complete set of backend options and their supported operations.
Your best bet is probably `wasm-soft-float-bs` based on the Berkeley Softfloat library. It covers almost all instructions.
Example `lib.rs`:
```rust
pub use wasm_soft_float_bs::*;
#[no_mangle]
pub extern "C" fn test(a: f32, b: f32) -> f32 {
a + b
}
```
Then compile your project and call `wasm-float-transpiler` on your `wasm` file, like this:
```bash
wasm-float-transpiler my_project.wasm output.wasm
```
The resulting `output.wasm` file now contains your finished WebAssembly without any trace of floating
point operations and with only the softfloat functions that you actually use.
# Example
Check out the [examples](./examples) folder.
To compile the examples run:
```bash
cd examples
cargo build --target wasm32-unknown-unknown --release --workspace
cd ..
```
To then transpile the resulting wasm, run:
```bash
cargo run -p wasm-float-transpiler -- ./examples/target/wasm32-unknown-unknown/release/basic_wasm_float.wasm output.wasm
```