Skip to content

Predefine a few math C functions like ldexpf, even without WASI?Β #407

@hrydgard

Description

@hrydgard

When using f32.powf(f32) from a wasm module written in Rust, an unresolved dependency is created on ldexpf.

Maybe should predefine a few functions like this? Here's a working, although not very well tested, implementation:

fn wasm_ldexpf(
    _ctx: &mut wasmer_runtime::Ctx,
    arg: f32,
    exp: i32,
) -> f32 {
    // Construct a float directly with the desired exponent and multiply with it.
    let multiplier : f32 = unsafe { std::mem::transmute((exp + 127) << 23) };
    arg * multiplier
}

fn libc_imports() -> wasmer_runtime::ImportObject {
    wasmer_runtime::imports! {
        "env" => {
            "ldexpf" => wasmer_runtime::func!(wasm_ldexpf),
        },
    }
}

Or alternatively, maybe the LLVM wasm compiler should be fixed to add intrinsics for these...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions