Skip to content

Commit

Permalink
Merge pull request dotnet/coreclr#8382 from BruceForstall/FixShift
Browse files Browse the repository at this point in the history
Fix x86 encoder to use 64-bit type to accumulate opcode/prefix bits

Commit migrated from dotnet/coreclr@392748e
  • Loading branch information
BruceForstall committed Dec 1, 2016
2 parents 7321c9c + 5d676e1 commit 8255363
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 149 deletions.
60 changes: 57 additions & 3 deletions src/coreclr/src/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6038,7 +6038,7 @@ unsigned char emitter::emitOutputLong(BYTE* dst, ssize_t val)
#ifdef DEBUG
if (emitComp->opts.dspEmit)
{
printf("; emit_long 0%08XH\n", val);
printf("; emit_long 0%08XH\n", (int)val);
}
#ifdef _TARGET_AMD64_
// if we're emitting code bytes, ensure that we've already emitted the rex prefix!
Expand All @@ -6062,16 +6062,70 @@ unsigned char emitter::emitOutputSizeT(BYTE* dst, ssize_t val)
if (emitComp->opts.dspEmit)
{
#ifdef _TARGET_AMD64_
printf("; emit_size_t 0%016llXH\n", (size_t)val);
printf("; emit_size_t 0%016llXH\n", val);
#else // _TARGET_AMD64_
printf("; emit_size_t 0%08XH\n", (size_t)val);
printf("; emit_size_t 0%08XH\n", val);
#endif // _TARGET_AMD64_
}
#endif // DEBUG

return sizeof(size_t);
}

//------------------------------------------------------------------------
// Wrappers to emitOutputByte, emitOutputWord, emitOutputLong, emitOutputSizeT
// that take unsigned __int64 or size_t type instead of ssize_t. Used on RyuJIT/x86.
//
// Arguments:
// dst - passed through
// val - passed through
//
// Return Value:
// Same as wrapped function.
//

#if !defined(LEGACY_BACKEND) && defined(_TARGET_X86_)
unsigned char emitter::emitOutputByte(BYTE* dst, size_t val)
{
return emitOutputByte(dst, (ssize_t)val);
}

unsigned char emitter::emitOutputWord(BYTE* dst, size_t val)
{
return emitOutputWord(dst, (ssize_t)val);
}

unsigned char emitter::emitOutputLong(BYTE* dst, size_t val)
{
return emitOutputLong(dst, (ssize_t)val);
}

unsigned char emitter::emitOutputSizeT(BYTE* dst, size_t val)
{
return emitOutputSizeT(dst, (ssize_t)val);
}

unsigned char emitter::emitOutputByte(BYTE* dst, unsigned __int64 val)
{
return emitOutputByte(dst, (ssize_t)val);
}

unsigned char emitter::emitOutputWord(BYTE* dst, unsigned __int64 val)
{
return emitOutputWord(dst, (ssize_t)val);
}

unsigned char emitter::emitOutputLong(BYTE* dst, unsigned __int64 val)
{
return emitOutputLong(dst, (ssize_t)val);
}

unsigned char emitter::emitOutputSizeT(BYTE* dst, unsigned __int64 val)
{
return emitOutputSizeT(dst, (ssize_t)val);
}
#endif // !defined(LEGACY_BACKEND) && defined(_TARGET_X86_)

/*****************************************************************************
*
* Given a block cookie and a code position, return the actual code offset;
Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/src/jit/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,18 @@ class emitter
unsigned char emitOutputLong(BYTE* dst, ssize_t val);
unsigned char emitOutputSizeT(BYTE* dst, ssize_t val);

#if !defined(LEGACY_BACKEND) && defined(_TARGET_X86_)
unsigned char emitOutputByte(BYTE* dst, size_t val);
unsigned char emitOutputWord(BYTE* dst, size_t val);
unsigned char emitOutputLong(BYTE* dst, size_t val);
unsigned char emitOutputSizeT(BYTE* dst, size_t val);

unsigned char emitOutputByte(BYTE* dst, unsigned __int64 val);
unsigned char emitOutputWord(BYTE* dst, unsigned __int64 val);
unsigned char emitOutputLong(BYTE* dst, unsigned __int64 val);
unsigned char emitOutputSizeT(BYTE* dst, unsigned __int64 val);
#endif // !defined(LEGACY_BACKEND) && defined(_TARGET_X86_)

size_t emitIssue1Instr(insGroup* ig, instrDesc* id, BYTE** dp);
size_t emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp);

Expand Down
Loading

0 comments on commit 8255363

Please sign in to comment.