Skip to content

WASM load/stores extensions #757

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

Closed
gnzlbg opened this issue May 8, 2019 · 2 comments
Closed

WASM load/stores extensions #757

gnzlbg opened this issue May 8, 2019 · 2 comments
Labels

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented May 8, 2019

Currently, the WASM v128.load/v128.store intrinsics take a *v128 pointer as its argument, which means they will always assume that the pointer points to a 16 byte boundary.

This isn't always necessarily the case, e.g., when loading 4 f32s from a slice of memory into a v128. Right now, the only way to correctly perform this load, is to first load those 4 f32s into storage aligned to a v128, and then load that into a v128.

The WASM v128.load/v128.store intrincs do, however, support unaligned loads and stores, and for these to be efficient, the alignment hint in memargs needs to be correct. That is, we have to perform the loads with the correct types.

We could add load/store instruction variants for all vector element types, or add two generic load / stores that use the right types instead. E.g.

// Loads from an address aligned to T (otherwise UB)
fn v128_load<T>(m: *const T) -> v128 { 
    if align_of::<T>() >= align_of::<v128>() {
       ptr::read(m as *const v128)
    } else {
       ptr::read_unaligned(m as *const v128)
    }
}

This would work with *const f32 and also *const [f32; 4].

@gnzlbg gnzlbg added the A-wasm32 label May 9, 2019
@sunfishcode
Copy link
Member

I am proposing that the wasm v128.load/v128.store intrinsics be modified to support unaligned accesses -- see my comment here.

@alexcrichton
Copy link
Member

I think this can be closed in favor of rust-lang/rust#74372 (comment). Right now I believe the intrinsic emit alignment hints but usage of ptr::read_unaligned will do what's necessary to get an unaligned load/store.

@Amanieu Amanieu closed this as completed May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants