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

implement the write_bytes() intrinsic #148

Merged
merged 5 commits into from
Mar 14, 2017

Conversation

dwrensha
Copy link
Contributor

No description provided.

@dwrensha
Copy link
Contributor Author

Travis is failing because the build is broken on the latest nightly.

cargo test succeeds for me on nightly-2017-02-22.


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)?;
Copy link
Member

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)?

Copy link
Member

@solson solson Mar 14, 2017

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Member

@solson solson Mar 14, 2017

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);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool! Done.

@solson solson merged commit 5c82b64 into rust-lang:master Mar 14, 2017
@solson
Copy link
Member

solson commented Mar 14, 2017

(Merging despite the failure since as @dwrensha noted above, master build is broken anyway until #147 is merged.)

@dwrensha Thanks for the PR!

@dwrensha dwrensha deleted the write-bytes-intrinsic branch March 14, 2017 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants