Skip to content

Commit e15ae0d

Browse files
Clean up the x86 assembler API.
The API is inconsistent about when a register must be coerced to an operand and when it can be used as a register. Simplify usage by never requiring it to be wrapped. [email protected] BUG= TEST= Review URL: http://codereview.chromium.org/8086021 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@9507 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent d8fa972 commit e15ae0d

16 files changed

+687
-644
lines changed

src/ia32/assembler-ia32.cc

+16-16
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,23 @@ void CpuFeatures::Probe() {
8888
__ pushfd();
8989
__ push(ecx);
9090
__ push(ebx);
91-
__ mov(ebp, Operand(esp));
91+
__ mov(ebp, esp);
9292

9393
// If we can modify bit 21 of the EFLAGS register, then CPUID is supported.
9494
__ pushfd();
9595
__ pop(eax);
96-
__ mov(edx, Operand(eax));
96+
__ mov(edx, eax);
9797
__ xor_(eax, 0x200000); // Flip bit 21.
9898
__ push(eax);
9999
__ popfd();
100100
__ pushfd();
101101
__ pop(eax);
102-
__ xor_(eax, Operand(edx)); // Different if CPUID is supported.
102+
__ xor_(eax, edx); // Different if CPUID is supported.
103103
__ j(not_zero, &cpuid);
104104

105105
// CPUID not supported. Clear the supported features in edx:eax.
106-
__ xor_(eax, Operand(eax));
107-
__ xor_(edx, Operand(edx));
106+
__ xor_(eax, eax);
107+
__ xor_(edx, edx);
108108
__ jmp(&done);
109109

110110
// Invoke CPUID with 1 in eax to get feature information in
@@ -120,13 +120,13 @@ void CpuFeatures::Probe() {
120120

121121
// Move the result from ecx:edx to edx:eax and make sure to mark the
122122
// CPUID feature as supported.
123-
__ mov(eax, Operand(edx));
123+
__ mov(eax, edx);
124124
__ or_(eax, 1 << CPUID);
125-
__ mov(edx, Operand(ecx));
125+
__ mov(edx, ecx);
126126

127127
// Done.
128128
__ bind(&done);
129-
__ mov(esp, Operand(ebp));
129+
__ mov(esp, ebp);
130130
__ pop(ebx);
131131
__ pop(ecx);
132132
__ popfd();
@@ -772,19 +772,19 @@ void Assembler::cmpb(const Operand& op, int8_t imm8) {
772772
}
773773

774774

775-
void Assembler::cmpb(const Operand& dst, Register src) {
776-
ASSERT(src.is_byte_register());
775+
void Assembler::cmpb(const Operand& op, Register reg) {
776+
ASSERT(reg.is_byte_register());
777777
EnsureSpace ensure_space(this);
778778
EMIT(0x38);
779-
emit_operand(src, dst);
779+
emit_operand(reg, op);
780780
}
781781

782782

783-
void Assembler::cmpb(Register dst, const Operand& src) {
784-
ASSERT(dst.is_byte_register());
783+
void Assembler::cmpb(Register reg, const Operand& op) {
784+
ASSERT(reg.is_byte_register());
785785
EnsureSpace ensure_space(this);
786786
EMIT(0x3A);
787-
emit_operand(dst, src);
787+
emit_operand(reg, op);
788788
}
789789

790790

@@ -1187,10 +1187,10 @@ void Assembler::xor_(Register dst, const Operand& src) {
11871187
}
11881188

11891189

1190-
void Assembler::xor_(const Operand& src, Register dst) {
1190+
void Assembler::xor_(const Operand& dst, Register src) {
11911191
EnsureSpace ensure_space(this);
11921192
EMIT(0x31);
1193-
emit_operand(dst, src);
1193+
emit_operand(src, dst);
11941194
}
11951195

11961196

src/ia32/assembler-ia32.h

+55-15
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,6 @@ enum ScaleFactor {
302302

303303
class Operand BASE_EMBEDDED {
304304
public:
305-
// reg
306-
INLINE(explicit Operand(Register reg));
307-
308305
// XMM reg
309306
INLINE(explicit Operand(XMMRegister xmm_reg));
310307

@@ -357,11 +354,8 @@ class Operand BASE_EMBEDDED {
357354
Register reg() const;
358355

359356
private:
360-
byte buf_[6];
361-
// The number of bytes in buf_.
362-
unsigned int len_;
363-
// Only valid if len_ > 4.
364-
RelocInfo::Mode rmode_;
357+
// reg
358+
INLINE(explicit Operand(Register reg));
365359

366360
// Set the ModRM byte without an encoded 'reg' register. The
367361
// register is encoded later as part of the emit_operand operation.
@@ -371,7 +365,15 @@ class Operand BASE_EMBEDDED {
371365
inline void set_disp8(int8_t disp);
372366
inline void set_dispr(int32_t disp, RelocInfo::Mode rmode);
373367

368+
byte buf_[6];
369+
// The number of bytes in buf_.
370+
unsigned int len_;
371+
// Only valid if len_ > 4.
372+
RelocInfo::Mode rmode_;
373+
374374
friend class Assembler;
375+
friend class MacroAssembler;
376+
friend class LCodeGen;
375377
};
376378

377379

@@ -680,7 +682,9 @@ class Assembler : public AssemblerBase {
680682
void leave();
681683

682684
// Moves
685+
void mov_b(Register dst, Register src) { mov_b(dst, Operand(src)); }
683686
void mov_b(Register dst, const Operand& src);
687+
void mov_b(Register dst, int8_t imm8) { mov_b(Operand(dst), imm8); }
684688
void mov_b(const Operand& dst, int8_t imm8);
685689
void mov_b(const Operand& dst, Register src);
686690

@@ -696,17 +700,24 @@ class Assembler : public AssemblerBase {
696700
void mov(const Operand& dst, Handle<Object> handle);
697701
void mov(const Operand& dst, Register src);
698702

703+
void movsx_b(Register dst, Register src) { movsx_b(dst, Operand(src)); }
699704
void movsx_b(Register dst, const Operand& src);
700705

706+
void movsx_w(Register dst, Register src) { movsx_w(dst, Operand(src)); }
701707
void movsx_w(Register dst, const Operand& src);
702708

709+
void movzx_b(Register dst, Register src) { movzx_b(dst, Operand(src)); }
703710
void movzx_b(Register dst, const Operand& src);
704711

712+
void movzx_w(Register dst, Register src) { movzx_w(dst, Operand(src)); }
705713
void movzx_w(Register dst, const Operand& src);
706714

707715
// Conditional moves
708716
void cmov(Condition cc, Register dst, int32_t imm32);
709717
void cmov(Condition cc, Register dst, Handle<Object> handle);
718+
void cmov(Condition cc, Register dst, Register src) {
719+
cmov(cc, dst, Operand(src));
720+
}
710721
void cmov(Condition cc, Register dst, const Operand& src);
711722

712723
// Flag management.
@@ -724,25 +735,31 @@ class Assembler : public AssemblerBase {
724735
void adc(Register dst, int32_t imm32);
725736
void adc(Register dst, const Operand& src);
726737

738+
void add(Register dst, Register src) { add(dst, Operand(src)); }
727739
void add(Register dst, const Operand& src);
728740
void add(const Operand& dst, Register src);
741+
void add(Register dst, const Immediate& imm) { add(Operand(dst), imm); }
729742
void add(const Operand& dst, const Immediate& x);
730743

731744
void and_(Register dst, int32_t imm32);
732745
void and_(Register dst, const Immediate& x);
746+
void and_(Register dst, Register src) { and_(dst, Operand(src)); }
733747
void and_(Register dst, const Operand& src);
734-
void and_(const Operand& src, Register dst);
748+
void and_(const Operand& dst, Register src);
735749
void and_(const Operand& dst, const Immediate& x);
736750

751+
void cmpb(Register reg, int8_t imm8) { cmpb(Operand(reg), imm8); }
737752
void cmpb(const Operand& op, int8_t imm8);
738-
void cmpb(Register src, const Operand& dst);
739-
void cmpb(const Operand& dst, Register src);
753+
void cmpb(Register reg, const Operand& op);
754+
void cmpb(const Operand& op, Register reg);
740755
void cmpb_al(const Operand& op);
741756
void cmpw_ax(const Operand& op);
742757
void cmpw(const Operand& op, Immediate imm16);
743758
void cmp(Register reg, int32_t imm32);
744759
void cmp(Register reg, Handle<Object> handle);
760+
void cmp(Register reg0, Register reg1) { cmp(reg0, Operand(reg1)); }
745761
void cmp(Register reg, const Operand& op);
762+
void cmp(Register reg, const Immediate& imm) { cmp(Operand(reg), imm); }
746763
void cmp(const Operand& op, const Immediate& imm);
747764
void cmp(const Operand& op, Handle<Object> handle);
748765

@@ -758,6 +775,7 @@ class Assembler : public AssemblerBase {
758775

759776
// Signed multiply instructions.
760777
void imul(Register src); // edx:eax = eax * src.
778+
void imul(Register dst, Register src) { imul(dst, Operand(src)); }
761779
void imul(Register dst, const Operand& src); // dst = dst * src.
762780
void imul(Register dst, Register src, int32_t imm32); // dst = src * imm32.
763781

@@ -774,8 +792,10 @@ class Assembler : public AssemblerBase {
774792
void not_(Register dst);
775793

776794
void or_(Register dst, int32_t imm32);
795+
void or_(Register dst, Register src) { or_(dst, Operand(src)); }
777796
void or_(Register dst, const Operand& src);
778797
void or_(const Operand& dst, Register src);
798+
void or_(Register dst, const Immediate& imm) { or_(Operand(dst), imm); }
779799
void or_(const Operand& dst, const Immediate& x);
780800

781801
void rcl(Register dst, uint8_t imm8);
@@ -786,33 +806,42 @@ class Assembler : public AssemblerBase {
786806

787807
void sbb(Register dst, const Operand& src);
788808

809+
void shld(Register dst, Register src) { shld(dst, Operand(src)); }
789810
void shld(Register dst, const Operand& src);
790811

791812
void shl(Register dst, uint8_t imm8);
792813
void shl_cl(Register dst);
793814

815+
void shrd(Register dst, Register src) { shrd(dst, Operand(src)); }
794816
void shrd(Register dst, const Operand& src);
795817

796818
void shr(Register dst, uint8_t imm8);
797819
void shr_cl(Register dst);
798820

821+
void sub(Register dst, const Immediate& imm) { sub(Operand(dst), imm); }
799822
void sub(const Operand& dst, const Immediate& x);
823+
void sub(Register dst, Register src) { sub(dst, Operand(src)); }
800824
void sub(Register dst, const Operand& src);
801825
void sub(const Operand& dst, Register src);
802826

803827
void test(Register reg, const Immediate& imm);
828+
void test(Register reg0, Register reg1) { test(reg0, Operand(reg1)); }
804829
void test(Register reg, const Operand& op);
805830
void test_b(Register reg, const Operand& op);
806831
void test(const Operand& op, const Immediate& imm);
832+
void test_b(Register reg, uint8_t imm8) { test_b(Operand(reg), imm8); }
807833
void test_b(const Operand& op, uint8_t imm8);
808834

809835
void xor_(Register dst, int32_t imm32);
836+
void xor_(Register dst, Register src) { xor_(dst, Operand(src)); }
810837
void xor_(Register dst, const Operand& src);
811-
void xor_(const Operand& src, Register dst);
838+
void xor_(const Operand& dst, Register src);
839+
void xor_(Register dst, const Immediate& imm) { xor_(Operand(dst), imm); }
812840
void xor_(const Operand& dst, const Immediate& x);
813841

814842
// Bit operations.
815843
void bt(const Operand& dst, Register src);
844+
void bts(Register dst, Register src) { bts(Operand(dst), src); }
816845
void bts(const Operand& dst, Register src);
817846

818847
// Miscellaneous
@@ -843,6 +872,7 @@ class Assembler : public AssemblerBase {
843872
void call(Label* L);
844873
void call(byte* entry, RelocInfo::Mode rmode);
845874
int CallSize(const Operand& adr);
875+
void call(Register reg) { call(Operand(reg)); }
846876
void call(const Operand& adr);
847877
int CallSize(Handle<Code> code, RelocInfo::Mode mode);
848878
void call(Handle<Code> code,
@@ -853,6 +883,7 @@ class Assembler : public AssemblerBase {
853883
// unconditional jump to L
854884
void jmp(Label* L, Label::Distance distance = Label::kFar);
855885
void jmp(byte* entry, RelocInfo::Mode rmode);
886+
void jmp(Register reg) { jmp(Operand(reg)); }
856887
void jmp(const Operand& adr);
857888
void jmp(Handle<Code> code, RelocInfo::Mode rmode);
858889

@@ -937,6 +968,7 @@ class Assembler : public AssemblerBase {
937968
void cvttss2si(Register dst, const Operand& src);
938969
void cvttsd2si(Register dst, const Operand& src);
939970

971+
void cvtsi2sd(XMMRegister dst, Register src) { cvtsi2sd(dst, Operand(src)); }
940972
void cvtsi2sd(XMMRegister dst, const Operand& src);
941973
void cvtss2sd(XMMRegister dst, XMMRegister src);
942974
void cvtsd2ss(XMMRegister dst, XMMRegister src);
@@ -977,12 +1009,14 @@ class Assembler : public AssemblerBase {
9771009
void movdbl(XMMRegister dst, const Operand& src);
9781010
void movdbl(const Operand& dst, XMMRegister src);
9791011

1012+
void movd(XMMRegister dst, Register src) { movd(dst, Operand(src)); }
9801013
void movd(XMMRegister dst, const Operand& src);
981-
void movd(const Operand& src, XMMRegister dst);
1014+
void movd(Register dst, XMMRegister src) { movd(Operand(dst), src); }
1015+
void movd(const Operand& dst, XMMRegister src);
9821016
void movsd(XMMRegister dst, XMMRegister src);
9831017

9841018
void movss(XMMRegister dst, const Operand& src);
985-
void movss(const Operand& src, XMMRegister dst);
1019+
void movss(const Operand& dst, XMMRegister src);
9861020
void movss(XMMRegister dst, XMMRegister src);
9871021

9881022
void pand(XMMRegister dst, XMMRegister src);
@@ -995,11 +1029,17 @@ class Assembler : public AssemblerBase {
9951029
void psrlq(XMMRegister reg, int8_t shift);
9961030
void psrlq(XMMRegister dst, XMMRegister src);
9971031
void pshufd(XMMRegister dst, XMMRegister src, int8_t shuffle);
1032+
void pextrd(Register dst, XMMRegister src, int8_t offset) {
1033+
pextrd(Operand(dst), src, offset);
1034+
}
9981035
void pextrd(const Operand& dst, XMMRegister src, int8_t offset);
1036+
void pinsrd(XMMRegister dst, Register src, int8_t offset) {
1037+
pinsrd(dst, Operand(src), offset);
1038+
}
9991039
void pinsrd(XMMRegister dst, const Operand& src, int8_t offset);
10001040

10011041
// Parallel XMM operations.
1002-
void movntdqa(XMMRegister src, const Operand& dst);
1042+
void movntdqa(XMMRegister dst, const Operand& src);
10031043
void movntdq(const Operand& dst, XMMRegister src);
10041044
// Prefetch src position into cache level.
10051045
// Level 1, 2 or 3 specifies CPU cache level. Level 0 specifies a

0 commit comments

Comments
 (0)