-
Notifications
You must be signed in to change notification settings - Fork 352
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
implement the write_bytes() intrinsic #148
Conversation
Travis is failing because the build is broken on the latest nightly.
|
src/terminator/intrinsic.rs
Outdated
|
||
let count = self.value_to_primval(arg_vals[2], usize)?.to_u64()?; | ||
for _ in 0..count { | ||
self.write_value_to_ptr(val_full, ptr, ty)?; |
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.
I don't think this is going to work properly for non-primitive types, especially when they are larger than u128
.
I would rather eliminate all the pattern
/val_full
code and replace it with a simple loop with size * count
iterations, writing a single val_byte
each iteration.
Can you also add a test where ty
is something like a struct with at least 3 fields (so our ByVal
/ByValPair
optimizations definitely won't take effect)?
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.
I would rather eliminate all the pattern/val_full code and replace it with a simple loop with size * count iterations, writing a single val_byte each iteration.
Actually, I think you could do a lower-level let bytes = self.memory.get_bytes_mut(ptr, size * count, ty_align);
and then do a loop simply assigning the bytes directly. This would be much more efficient than repeatedly calling a single-byte write function on Memory
which would do a lot of checks. It should be even more efficient than the val_full
code.
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.
Memory::get_bytes_mut()
is private and therefore inaccessible here. Shall I make it public?
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.
I've pushed a commit that updates to a simple loop with size * count
iterations.
I shied away from using get_bytes_mut()
for now.
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.
Ah, true. Just now when I was looking for a public wrapper, I noticed Memory::write_repeat
which even does the loop for you.
The only thing I'm unsure about is the alignment requirement. write_repeat
assumes no alignment requirement (align = 1), but I'm not sure if this write_bytes
intrinsic should require the alignment of the type it's parameterized over.
Perhaps we could do:
self.memory.check_align(ptr, size * count, ty_align);
self.memory.write_repeat(ptr, val_byte, size * count);
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.
Cool! Done.
No description provided.