-
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
x64: use ByteSink
more liberally in the rex
module
#9505
Conversation
In looking at adding auto-generated assembler code to Cranelift, I've noticed that we pass `MachBuffer` down when it is not always necessary. The `ByteSink` trait (which `MachBuffer` implements) is a simplified view to `put*` bytes into the buffer and it is a bit simpler to use when testing since it is also implemented by `Vec<u8>`. This change propagates the trait to the `rex` module.
Similar to #9504, this is just an attempt at trying to simplify what is needed to actually assemble an instruction. We still need |
self.emit_two_op(sink, enc_g, 0); | ||
} | ||
} | ||
} |
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.
Oh, actually let me remove this: this is for the new assembler but isn't used yet.
pub fn must_always_emit(&self) -> bool { | ||
(self.0 & 2) != 0 | ||
} | ||
|
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.
...and a little bit of code movement.
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 looks fine, thanks!
Re: handling Amode
s and the helper that briefly appeared here: I think we'll need MachBuffer
unavoidably once we have amodes that can refer to labels; that's the semantic thing that MachBuffer gives us above an arbitrary byte sequence. But totally fine to trim the close coupling at lower levels.
I'd love to talk more about the assembler design w.r.t. dependencies -- intuitively I would have thought that MachBuffer
would be an integral part of it, i.e. it's the assembler's way of providing its output (given that assemblers need label references, and to flow through other metadata like trap info and relocs from insts to the code blob), but maybe there's another use-case or need for generalization I'm missing.
I mean, that's how it has to be today. I'm kind of wondering if it should, though: it's nice to be able to "just emit" an instruction into a byte buffer during testing and that's what I've been thinking about. The setup in On the other hand, sometimes it is unavoidable: I've notice that we register traps and labels using a |
Ah! Yeah, that's an interesting idea: lift the whole interface of MachBuffer into a trait, and provide an implementation of that trait for a There are interesting semantic implementations of this though when label references are involved: what should the assembled bytes from a Maybe another way of reading this friction is that we need some convenience APIs? It should be possible to write an
(whew, that is a bit of a mouthful, I see why you want it!) |
In looking at adding auto-generated assembler code to Cranelift, I've noticed that we pass
MachBuffer
down when it is not always necessary. TheByteSink
trait (whichMachBuffer
implements) is a simplified view toput*
bytes into the buffer and it is a bit simpler to use when testing since it is also implemented byVec<u8>
. This change propagates the trait to therex
module.