Avoid memmove when emitting operands in the assembler

and get rid of the mutability of the Operand byte buffer.
Review URL: http://codereview.chromium.org/18656

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1123 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
kasperl@chromium.org 2009-01-22 12:12:15 +00:00
parent 6bd6376588
commit 5fdc70b80d
3 changed files with 18 additions and 17 deletions

View File

@ -270,8 +270,7 @@ void Assembler::emit_disp(Label* L, Displacement::Type type) {
}
void Operand::set_modrm(int mod, // reg == 0
Register rm) {
void Operand::set_modrm(int mod, Register rm) {
ASSERT((mod & -4) == 0);
buf_[0] = mod << 6 | rm.code();
len_ = 1;

View File

@ -255,12 +255,6 @@ void Operand::set_disp8(int8_t disp) {
}
void Operand::set_reg(Register reg) const {
ASSERT(len_ > 0);
buf_[0] = (buf_[0] & ~0x38) | static_cast<byte>(reg.code() << 3);
}
bool Operand::is_reg(Register reg) const {
return ((buf_[0] & 0xF8) == 0xC0) // addressing mode is register only.
&& ((buf_[0] & 0x07) == reg.code()); // register codes match.
@ -2098,10 +2092,18 @@ void Assembler::emit_arith(int sel, Operand dst, const Immediate& x) {
void Assembler::emit_operand(Register reg, const Operand& adr) {
adr.set_reg(reg);
memmove(pc_, adr.buf_, adr.len_);
pc_ += adr.len_;
if (adr.len_ >= sizeof(int32_t) && adr.rmode_ != RelocInfo::NONE) {
const unsigned length = adr.len_;
ASSERT(length > 0);
// Emit updated ModRM byte containing the given register.
pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3);
// Emit the rest of the encoded operand.
for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i];
pc_ += length;
// Emit relocation information if necessary.
if (length >= sizeof(int32_t) && adr.rmode_ != RelocInfo::NONE) {
pc_ -= sizeof(int32_t); // pc_ must be *at* disp32
RecordRelocInfo(adr.rmode_);
pc_ += sizeof(int32_t);

View File

@ -260,19 +260,19 @@ class Operand BASE_EMBEDDED {
bool is_reg(Register reg) const;
private:
// Mutable because reg in ModR/M byte is set by Assembler via set_reg().
mutable byte buf_[6];
byte buf_[6];
// The number of bytes in buf_.
unsigned int len_;
// Only valid if len_ > 4.
RelocInfo::Mode rmode_;
inline void set_modrm(int mod, // reg == 0
Register rm);
// Set the ModRM byte without an encoded 'reg' register. The
// register is encoded later as part of the emit_operand operation.
inline void set_modrm(int mod, Register rm);
inline void set_sib(ScaleFactor scale, Register index, Register base);
inline void set_disp8(int8_t disp);
inline void set_dispr(int32_t disp, RelocInfo::Mode rmode);
inline void set_reg(Register reg) const;
friend class Assembler;
};