Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqrt is provided for wasi but not wasm32-unknown-unknown #308

Closed
Lokathor opened this issue Aug 9, 2019 · 4 comments
Closed

sqrt is provided for wasi but not wasm32-unknown-unknown #308

Lokathor opened this issue Aug 9, 2019 · 4 comments

Comments

@Lokathor
Copy link
Contributor

Lokathor commented Aug 9, 2019

Right now the list of no_mangle symbols for wasm32-unknown-unknown doesn't include sqrt. However, the wasi target does expose sqrt. Since a properly compiled sqrt on wasm32 of any type compiles down to a single wasm instruction, I'm not sure why sqrt is exposed for wasi and not for wasm32-unknown-unknown.

This same question applies to any other libm function that's part of wasi but not parts of wasm32-unknown-unknown, though there's so many libm functions i'm not sure of the full list at this time.

@alexcrichton
Copy link
Member

This crate only is here to supply what LLVM generates references to, and LLVM doesn't generate references to a sqrt symbol, so it's not necessary.

The libm intrinsics themselves sometimes call sqrt, so the libm::sqrt function is transitively reachable via the other exposed intrinsics on the wasm32-unknown-unknown target. That's why it's optimized in libm. On wasi the C library provides the symbols instead of this crate.

@Lokathor
Copy link
Contributor Author

Lokathor commented Aug 9, 2019

Ensuring full compiler-builtins support was listed as a general step in the tracking issue shown above towards the process of adding floating point functions into core.

rust-lang/rust#50145 (comment) for the exact comment.

Are you saying that, at least for this particular intrinsic, the compiler-builtins step can be considered "complete" and we could move on to the next step?

@gnzlbg
Copy link

gnzlbg commented Aug 10, 2019

Ensuring full compiler-builtins support was listed as a general step in the tracking issue shown above towards the process of adding floating point functions into core.

@Lokathor as @alexcrichton mentions, we don't need to add anything here to add support of the sqrt function to core for this target. libcore can just call the llvm intrinsic on this platform, and no symbol will ever be generated, so adding something here doesn't solve any problems.

@Lokathor
Copy link
Contributor Author

Okay, cool. I will proceed in the main tracking issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants