diff options
author | Craig Topper <craig.topper@gmail.com> | 2014-01-06 06:02:58 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2014-01-06 06:02:58 +0000 |
commit | 7ceb54a2a168a60a10c8a49c2858db780ae5f970 (patch) | |
tree | 45e8e50dc3c66c453dca667df5f58634be245eb7 /llvm/lib/Target | |
parent | 13199b17f831cd5354e33d85bee6869ca7cb52d9 (diff) | |
download | bcm5719-llvm-7ceb54a2a168a60a10c8a49c2858db780ae5f970.tar.gz bcm5719-llvm-7ceb54a2a168a60a10c8a49c2858db780ae5f970.zip |
Add OpSize16 bit, for instructions which need 0x66 prefix in 16-bit mode
The 0x66 prefix toggles between 16-bit and 32-bit addressing mode.
So in 32-bit mode it is used to switch to 16-bit addressing mode for the
following instruction, while in 16-bit mode it's the other way round — it's
used to switch to 32-bit mode instead.
Thus, emit the 0x66 prefix byte for OpSize only in 32-bit (and 64-bit) mode,
and introduce a new OpSize16 bit which is used in 16-bit mode instead.
This is just the basic infrastructure for that change; a subsequent patch
will add the new OpSize16 bit to the 32-bit instructions that need it.
Patch from David Woodhouse.
llvm-svn: 198586
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r-- | llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h | 8 | ||||
-rw-r--r-- | llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Target/X86/X86InstrFormats.td | 55 |
3 files changed, 35 insertions, 31 deletions
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h index 9c1ff155511..3de5d8255d3 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h +++ b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h @@ -295,13 +295,15 @@ namespace X86II { // OpSize - Set if this instruction requires an operand size prefix (0x66), // which most often indicates that the instruction operates on 16 bit data - // instead of 32 bit data. + // instead of 32 bit data. OpSize16 in 16 bit mode indicates that the + // instruction operates on 32 bit data instead of 16 bit data. OpSize = 1 << 6, + OpSize16 = 1 << 7, // AsSize - Set if this instruction requires an operand size prefix (0x67), // which most often indicates that the instruction address 16 bit address // instead of 32 bit address (or 32 bit address in 64 bit mode). - AdSize = 1 << 7, + AdSize = 1 << 8, //===------------------------------------------------------------------===// // Op0Mask - There are several prefix bytes that are used to form two byte @@ -309,7 +311,7 @@ namespace X86II { // used to obtain the setting of this field. If no bits in this field is // set, there is no prefix byte for obtaining a multibyte opcode. // - Op0Shift = 8, + Op0Shift = 9, Op0Mask = 0x1F << Op0Shift, // TB - TwoByte - Set if this instruction has a two byte opcode, which diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp index 51b90b1c497..06bce465b52 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp @@ -1191,8 +1191,7 @@ void X86MCCodeEmitter::EmitOpcodePrefix(uint64_t TSFlags, unsigned &CurByte, EmitByte(0x67, CurByte, OS); // Emit the operand size opcode prefix as needed. - // FIXME for is16BitMode(). - if (TSFlags & X86II::OpSize) + if (TSFlags & (is16BitMode(Features) ? X86II::OpSize16 : X86II::OpSize)) EmitByte(0x66, CurByte, OS); bool Need0FPrefix = false; diff --git a/llvm/lib/Target/X86/X86InstrFormats.td b/llvm/lib/Target/X86/X86InstrFormats.td index 857399168bc..ea146b23ed3 100644 --- a/llvm/lib/Target/X86/X86InstrFormats.td +++ b/llvm/lib/Target/X86/X86InstrFormats.td @@ -112,6 +112,7 @@ def CD8VT8 : CD8VForm<7>; // v := 8 // Prefix byte classes which are used to indicate to the ad-hoc machine code // emitter that various prefix bytes are required. class OpSize { bit hasOpSizePrefix = 1; } +class OpSize16 { bit hasOpSize16Prefix = 1; } class AdSize { bit hasAdSizePrefix = 1; } class REX_W { bit hasREX_WPrefix = 1; } class LOCK { bit hasLockPrefix = 1; } @@ -191,6 +192,7 @@ class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins, // AsmString from the parser, but still disassemble. bit hasOpSizePrefix = 0; // Does this inst have a 0x66 prefix? + bit hasOpSize16Prefix = 0;// Does this inst have a 0x66 prefix in 16-bit mode? bit hasAdSizePrefix = 0; // Does this inst have a 0x67 prefix? bits<5> Prefix = 0; // Which prefix byte does this inst have? @@ -222,32 +224,33 @@ class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins, // TSFlags layout should be kept in sync with X86InstrInfo.h. let TSFlags{5-0} = FormBits; let TSFlags{6} = hasOpSizePrefix; - let TSFlags{7} = hasAdSizePrefix; - let TSFlags{12-8} = Prefix; - let TSFlags{13} = hasREX_WPrefix; - let TSFlags{16-14} = ImmT.Value; - let TSFlags{19-17} = FPForm.Value; - let TSFlags{20} = hasLockPrefix; - let TSFlags{22-21} = SegOvrBits; - let TSFlags{24-23} = ExeDomain.Value; - let TSFlags{32-25} = Opcode; - let TSFlags{33} = hasVEXPrefix; - let TSFlags{34} = hasVEX_WPrefix; - let TSFlags{35} = hasVEX_4VPrefix; - let TSFlags{36} = hasVEX_4VOp3Prefix; - let TSFlags{37} = hasVEX_i8ImmReg; - let TSFlags{38} = hasVEX_L; - let TSFlags{39} = ignoresVEX_L; - let TSFlags{40} = hasEVEXPrefix; - let TSFlags{41} = hasEVEX_K; - let TSFlags{42} = hasEVEX_Z; - let TSFlags{43} = hasEVEX_L2; - let TSFlags{44} = hasEVEX_B; - let TSFlags{46-45} = EVEX_CD8E; - let TSFlags{49-47} = EVEX_CD8V; - let TSFlags{50} = has3DNow0F0FOpcode; - let TSFlags{51} = hasMemOp4Prefix; - let TSFlags{52} = hasXOP_Prefix; + let TSFlags{7} = hasOpSize16Prefix; + let TSFlags{8} = hasAdSizePrefix; + let TSFlags{13-9} = Prefix; + let TSFlags{14} = hasREX_WPrefix; + let TSFlags{17-15} = ImmT.Value; + let TSFlags{20-18} = FPForm.Value; + let TSFlags{21} = hasLockPrefix; + let TSFlags{23-22} = SegOvrBits; + let TSFlags{25-24} = ExeDomain.Value; + let TSFlags{33-26} = Opcode; + let TSFlags{34} = hasVEXPrefix; + let TSFlags{35} = hasVEX_WPrefix; + let TSFlags{36} = hasVEX_4VPrefix; + let TSFlags{37} = hasVEX_4VOp3Prefix; + let TSFlags{38} = hasVEX_i8ImmReg; + let TSFlags{39} = hasVEX_L; + let TSFlags{40} = ignoresVEX_L; + let TSFlags{41} = hasEVEXPrefix; + let TSFlags{42} = hasEVEX_K; + let TSFlags{43} = hasEVEX_Z; + let TSFlags{44} = hasEVEX_L2; + let TSFlags{45} = hasEVEX_B; + let TSFlags{47-46} = EVEX_CD8E; + let TSFlags{50-48} = EVEX_CD8V; + let TSFlags{51} = has3DNow0F0FOpcode; + let TSFlags{52} = hasMemOp4Prefix; + let TSFlags{53} = hasXOP_Prefix; } class PseudoI<dag oops, dag iops, list<dag> pattern> |