Skip to content

WASM load/stores extensions #757

Closed
Closed
@gnzlbg

Description

@gnzlbg

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].

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions