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

Override component model Lower::store_list and Lift::load_list for f32/f64 #9892

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kaivol
Copy link

@kaivol kaivol commented Dec 23, 2024

Added overrides for Lower::store_list and Lift::load_list for floating point numbers to reduce overhead when passing or returning list<f32> and list<f64> to/from components.

I based this on the respective implementation for integers.

@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Dec 23, 2024
@dicej dicej self-assigned this Jan 2, 2025
Copy link
Contributor

@dicej dicej left a comment

Choose a reason for hiding this comment

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

Thanks for this! Looks reasonable to me overall; see my comments inline regarding the details.

// alignment and sizing meaning that these assertions here are
// not truly necessary but are instead double-checks.
//
// Note that we're casting a `[u8]` slice to `[$integer]` (with
Copy link
Contributor

Choose a reason for hiding this comment

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

This paragraph (and the code that follows) refers to $integer, but we really care about $float, right? We should rewrite this to talk about floating point numbers instead of integers, e.g. "all u8 patterns are valid $float patterns since $float is a IEEE 754 floating point type."

let byte_size = list.len * mem::size_of::<$integer>();
let bytes = &cx.memory()[list.ptr..][..byte_size];

// The canonical ABI requires that everything is aligned to its
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, these comments should be updated to discuss floating point types rather than integer types.

// case as all `u8` patterns are valid `$integer` patterns
// since `$integer` is an integral type.
let dst = &mut cx.as_slice_mut()[offset..][..items.len() * Self::SIZE32];
let (before, middle, end) = unsafe { dst.align_to_mut::<$integer>() };
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let (before, middle, end) = unsafe { dst.align_to_mut::<$integer>() };
let (before, middle, end) = unsafe { dst.align_to_mut::<$float>() };

Presumably the alignment of e.g. f32 and u32 should be the same, but we might as well be precise here (and in similar code below).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants