Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit fdf40be

Browse files
committed
Merging r261365:
------------------------------------------------------------------------ r261365 | hans | 2016-02-19 13:26:31 -0800 (Fri, 19 Feb 2016) | 3 lines Revert r253557 "Alternative to long nops for X86 CPUs, by Andrey Turetsky" Turns out the new nop sequences aren't actually nops on x86_64 (PR26554). ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_38@261366 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 413ee9f commit fdf40be

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,15 @@ class X86ELFObjectWriter : public MCELFObjectTargetWriter {
6969
class X86AsmBackend : public MCAsmBackend {
7070
const StringRef CPU;
7171
bool HasNopl;
72-
uint64_t MaxNopLength;
72+
const uint64_t MaxNopLength;
7373
public:
74-
X86AsmBackend(const Target &T, StringRef CPU) : MCAsmBackend(), CPU(CPU) {
74+
X86AsmBackend(const Target &T, StringRef CPU)
75+
: MCAsmBackend(), CPU(CPU), MaxNopLength(CPU == "slm" ? 7 : 15) {
7576
HasNopl = CPU != "generic" && CPU != "i386" && CPU != "i486" &&
7677
CPU != "i586" && CPU != "pentium" && CPU != "pentium-mmx" &&
7778
CPU != "i686" && CPU != "k6" && CPU != "k6-2" && CPU != "k6-3" &&
7879
CPU != "geode" && CPU != "winchip-c6" && CPU != "winchip2" &&
7980
CPU != "c3" && CPU != "c3-2";
80-
// Max length of true long nop instruction is 15 bytes.
81-
// Max length of long nop replacement instruction is 7 bytes.
82-
// Taking into account SilverMont architecture features max length of nops
83-
// is reduced for it to achieve better performance.
84-
MaxNopLength = (!HasNopl || CPU == "slm") ? 7 : 15;
8581
}
8682

8783
unsigned getNumFixupKinds() const override {
@@ -299,7 +295,7 @@ void X86AsmBackend::relaxInstruction(const MCInst &Inst, MCInst &Res) const {
299295
/// bytes.
300296
/// \return - true on success, false on failure
301297
bool X86AsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
302-
static const uint8_t TrueNops[10][10] = {
298+
static const uint8_t Nops[10][10] = {
303299
// nop
304300
{0x90},
305301
// xchg %ax,%ax
@@ -322,31 +318,17 @@ bool X86AsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
322318
{0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00},
323319
};
324320

325-
// Alternative nop instructions for CPUs which don't support long nops.
326-
static const uint8_t AltNops[7][10] = {
327-
// nop
328-
{0x90},
329-
// xchg %ax,%ax
330-
{0x66, 0x90},
331-
// lea 0x0(%esi),%esi
332-
{0x8d, 0x76, 0x00},
333-
// lea 0x0(%esi),%esi
334-
{0x8d, 0x74, 0x26, 0x00},
335-
// nop + lea 0x0(%esi),%esi
336-
{0x90, 0x8d, 0x74, 0x26, 0x00},
337-
// lea 0x0(%esi),%esi
338-
{0x8d, 0xb6, 0x00, 0x00, 0x00, 0x00 },
339-
// lea 0x0(%esi),%esi
340-
{0x8d, 0xb4, 0x26, 0x00, 0x00, 0x00, 0x00},
341-
};
342-
343-
// Select the right NOP table.
344-
// FIXME: Can we get if CPU supports long nops from the subtarget somehow?
345-
const uint8_t (*Nops)[10] = HasNopl ? TrueNops : AltNops;
346-
assert(HasNopl || MaxNopLength <= 7);
321+
// This CPU doesn't support long nops. If needed add more.
322+
// FIXME: Can we get this from the subtarget somehow?
323+
// FIXME: We could generated something better than plain 0x90.
324+
if (!HasNopl) {
325+
for (uint64_t i = 0; i < Count; ++i)
326+
OW->write8(0x90);
327+
return true;
328+
}
347329

348-
// Emit as many largest nops as needed, then emit a nop of the remaining
349-
// length.
330+
// 15 is the longest single nop instruction. Emit as many 15-byte nops as
331+
// needed, then emit a nop of the remaining length.
350332
do {
351333
const uint8_t ThisNopLength = (uint8_t) std::min(Count, MaxNopLength);
352334
const uint8_t Prefixes = ThisNopLength <= 10 ? 0 : ThisNopLength - 10;

test/MC/X86/x86_nop.s

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ inc %eax
2222
inc %eax
2323

2424
// CHECK: 0: 40 incl %eax
25-
// CHECK: 1: 8d b4 26 00 00 00 00 leal (%esi), %esi
25+
// CHECK: 1: 90 nop
26+
// CHECK: 2: 90 nop
27+
// CHECK: 3: 90 nop
28+
// CHECK: 4: 90 nop
29+
// CHECK: 5: 90 nop
30+
// CHECK: 6: 90 nop
31+
// CHECK: 7: 90 nop
2632
// CHECK: 8: 40 incl %eax
2733

2834

0 commit comments

Comments
 (0)