-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: main
Are you sure you want to change the base?
Override component model Lower::store_list
and Lift::load_list
for f32/f64
#9892
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
Added overrides for
Lower::store_list
andLift::load_list
for floating point numbers to reduce overhead when passing or returninglist<f32>
andlist<f64>
to/from components.I based this on the respective implementation for integers.