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

add wasm64 support #974

Closed
wants to merge 1 commit into from
Closed

add wasm64 support #974

wants to merge 1 commit into from

Conversation

devsnek
Copy link
Contributor

@devsnek devsnek commented Dec 30, 2020

rust-lang/rust#80525

I took the approach of adding a new arch::wasm module which covers both wasm32 and wasm64.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Amanieu (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

#[doc(cfg(any(target_arch = "wasm32", target_arch = "wasm64")))]
#[stable(feature = "", since = "0.0.0")]
pub mod wasm {
#[stable(feature = "", since = "0.0.0")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be private. Even x86 and x86_64 are only available on the respective targets despite the fact that x86_64 re-exports everything in x86.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What i was trying to do here was avoid people having to write

#[cfg(target_os = "wasm32")]
use core::arch::wasm32 as wasm;
#[cfg(target_os = "wasm64")]
use core::arch::wasm64 as wasm;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match what we do for x86/x86_64 right now, however, where you only get one or the other. I think that we'll want to stick to a wasm32 and a wasm64 module for now to mirror that. The core::arch module isn't optimized for ergonomic usage, but rather optimized for developers (us) to add intrinsics in a known location.

crates/core_arch/src/lib.rs Outdated Show resolved Hide resolved
crates/core_arch/src/wasm/memory.rs Show resolved Hide resolved
@Amanieu
Copy link
Member

Amanieu commented Dec 31, 2020

cc @alexcrichton

@alexcrichton
Copy link
Member

This looks good to me, thanks! I do think though that there shouldn't be a core::arch::wasm module but instead core::arch::{wasm32, wasm64} modules.

@bors
Copy link
Contributor

bors commented Mar 11, 2021

☔ The latest upstream changes (presumably 8724eb4) made this pull request unmergeable. Please resolve the merge conflicts.

@devsnek devsnek force-pushed the wasm64 branch 3 times, most recently from b025da3 to 1e8e134 Compare April 4, 2021 17:34
@devsnek devsnek marked this pull request as ready for review April 5, 2021 07:03
@devsnek
Copy link
Contributor Author

devsnek commented Apr 5, 2021

I feel very strongly that we should encourage the abstraction of wasm32 and wasm64, both in rust internals and to users of rust. They are not really different targets, and code that specializes on one of them just makes developing for wasm more difficult.

@alexcrichton
Copy link
Member

My thinking here is that wasm should follow established precedent primarily and not try to be that different compared to other platforms. It seems like all the issues for wasm32/wasm64 would be the same in Rust's x86 and x86_64 land as well. Given that hasn't been a huge issue leading to trying to have a unified module I'm not sure that it's worth trying to blaze the trail here with wasm.

@devsnek
Copy link
Contributor Author

devsnek commented Apr 5, 2021

@alexcrichton what if we also include wasm64 here? so we'd have three. I'm open to other approaches but I'm not interested in landing this with no solution.

@joshtriplett
Copy link
Member

If we can actually have the same intrinsics on all targets (using usize), then I think it makes sense to have one module, not two.

@alexcrichton
Copy link
Member

IIRC the x86_64 module reexports everything that has to do with the x86 module, so I would imagine that adding a wasm64 module would do the same thing effectively?

I would definitely want to ensure that, where possible, we use the exact same types across the wasm32/wasm64 modules to enable reexporting. It'd be a bummer if something took an i32 in one and an i64 in the other or something like that.

@devsnek
Copy link
Contributor Author

devsnek commented Apr 5, 2021

From my perspective the more important bit is usage of this. I have to go through and make all the core and std code work with both wasm32 and wasm64, which should (imo) be as simple as s/wasm32/wasm/g, but if we don't combine them here i have to add annoying cfgs everywhere to use the correct intrinsic.

@alexcrichton
Copy link
Member

AFAIK core/std only very lightly use this module, so adding some #[cfg] shouldn't be a monumental task?

@bors
Copy link
Contributor

bors commented Apr 7, 2021

☔ The latest upstream changes (presumably 768b238) made this pull request unmergeable. Please resolve the merge conflicts.

@devsnek
Copy link
Contributor Author

devsnek commented Apr 29, 2021

updated to use bad pattern, pls review. also needs something for the #[stable] thingy, not sure what that is.

@@ -41,7 +41,7 @@
bench_black_box
)]
#![cfg_attr(test, feature(test, abi_vectorcall))]
#![cfg_attr(all(test, target_arch = "wasm32"), feature(wasm_simd))]
#![cfg_attr(all(test, target_arch = "wasm32", target_arch = "wasm64"), feature(wasm_simd))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#![cfg_attr(all(test, target_arch = "wasm32", target_arch = "wasm64"), feature(wasm_simd))]
#![cfg_attr(all(test, any(target_arch = "wasm32", target_arch = "wasm64")), feature(wasm_simd))]

Otherwise this condition will always be false. But then again tests still seem to pass so maybe it isn't needed?

#[link_name = "llvm.wasm.memory.grow"]
fn llvm_memory_grow(mem: u32, pages: isize) -> isize;
#[link_name = "llvm.wasm.memory.size"]
fn llvm_memory_size(mem: u32) -> isize;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does LLVM still accept these intrinsics without the .i32 at the end? I've noticed that we don't actually have any tests for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW the assert_instr on each intrinsic at least asserts that the codegen is correct, but you're right in that I don't think there's any runtime tests for these intrinsics.

/// See the [module documentation](../index.html) for more details.
#[cfg(any(target_arch = "wasm64", doc))]
#[doc(cfg(target_arch = "wasm64"))]
#[stable(feature = "", since = "0.0.0")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be unstable under simd_wasm64 for now.

/// generated in your program. This means to generate a binary without SIMD
/// you'll need to avoid both options above plus calling into any intrinsics
/// in this module.
/// See the [module documentation](../index.html) for more details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This point back to the docs for the arch module, not the wasm module.

//! enable SIMD via either of these mechanisms, you'll still have SIMD
//! generated in your program. This means to generate a binary without SIMD
//! you'll need to avoid both options above plus calling into any intrinsics
//! in this module.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module is private so these docs are not actually visible in the documentation.

@bors
Copy link
Contributor

bors commented May 3, 2021

☔ The latest upstream changes (presumably c313294) made this pull request unmergeable. Please resolve the merge conflicts.

@devsnek
Copy link
Contributor Author

devsnek commented Oct 28, 2021

seems to be replaced by #1240

@devsnek devsnek closed this Oct 28, 2021
@devsnek devsnek deleted the wasm64 branch January 2, 2023 05:48
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

Successfully merging this pull request may close these issues.

8 participants