Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 32 byte alignment of code on xarch #2249

Merged
merged 4 commits into from
Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/coreclr/src/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ TODO: Talk about initializing strutures before use
#endif
#endif

SELECTANY const GUID JITEEVersionIdentifier = { /* 13028353-152c-4886-b05b-fa76ee8169cf */
0x13028353,
0x152c,
0x4886,
{0xb0, 0x5b, 0xfa, 0x76, 0xee, 0x81, 0x69, 0xcf}
SELECTANY const GUID JITEEVersionIdentifier = { /* 96fc0c0a-9f77-450d-9663-ee33ae0fcae8 */
0x96fc0c0a,
0x9f77,
0x450d,
{0x96, 0x63, 0xee, 0x33, 0xae, 0x0f, 0xca, 0xe8}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/inc/corjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ enum CorJitAllocMemFlag
CORJIT_ALLOCMEM_DEFAULT_CODE_ALIGN = 0x00000000, // The code will be use the normal alignment
CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN = 0x00000001, // The code will be 16-byte aligned
CORJIT_ALLOCMEM_FLG_RODATA_16BYTE_ALIGN = 0x00000002, // The read-only data will be 16-byte aligned
CORJIT_ALLOCMEM_FLG_32BYTE_ALIGN = 0x00000004, // The code will be 32-byte aligned
CORJIT_ALLOCMEM_FLG_RODATA_32BYTE_ALIGN = 0x00000008, // The read-only data will be 32-byte aligned
};

inline CorJitAllocMemFlag operator |(CorJitAllocMemFlag a, CorJitAllocMemFlag b)
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/src/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4615,6 +4615,16 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
}
#endif

#ifdef TARGET_XARCH
// For x64/x86, align Tier1 methods to 32 byte boundaries if
// they are larger than 16 bytes and contain a loop.
//
if (emitComp->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER1) && (emitTotalHotCodeSize > 16) && emitComp->fgHasLoops)
{
allocMemFlag = CORJIT_ALLOCMEM_FLG_32BYTE_ALIGN;
}
#endif

if (emitConsDsc.align16)
{
allocMemFlag = static_cast<CorJitAllocMemFlag>(allocMemFlag | CORJIT_ALLOCMEM_FLG_RODATA_16BYTE_ALIGN);
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/tools/Common/JitInterface/CorInfoTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ public enum CorJitAllocMemFlag
CORJIT_ALLOCMEM_DEFAULT_CODE_ALIGN = 0x00000000, // The code will be use the normal alignment
CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN = 0x00000001, // The code will be 16-byte aligned
CORJIT_ALLOCMEM_FLG_RODATA_16BYTE_ALIGN = 0x00000002, // The read-only data will be 16-byte aligned
CORJIT_ALLOCMEM_FLG_32BYTE_ALIGN = 0x00000004, // The code will be 32-byte aligned
CORJIT_ALLOCMEM_FLG_RODATA_32BYTE_ALIGN = 0x00000008, // The read-only data will be 32-byte aligned
}

public enum CorJitFuncKind
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/src/tools/crossgen2/jitinterface/jitwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class CORJIT_FLAGS
uint64_t corJitFlags;
};

static const GUID JITEEVersionIdentifier = { /* 13028353-152c-4886-b05b-fa76ee8169cf */
0x13028353,
0x152c,
0x4886,
{0xb0, 0x5b, 0xfa, 0x76, 0xee, 0x81, 0x69, 0xcf}
static const GUID JITEEVersionIdentifier = { /* 96fc0c0a-9f77-450d-9663-ee33ae0fcae8 */
0x96fc0c0a,
0x9f77,
0x450d,
{0x96, 0x63, 0xee, 0x33, 0xae, 0x0f, 0xca, 0xe8}
};

class Jit
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/src/vm/codeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2551,7 +2551,11 @@ CodeHeader* EEJitManager::allocCode(MethodDesc* pMD, size_t blockSize, size_t re

unsigned alignment = CODE_SIZE_ALIGN;

if ((flag & CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN) != 0)
if ((flag & CORJIT_ALLOCMEM_FLG_32BYTE_ALIGN) != 0)
{
alignment = max(alignment, 32);
}
else if ((flag & CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN) != 0)
{
alignment = max(alignment, 16);
}
Expand Down
19 changes: 16 additions & 3 deletions src/coreclr/src/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12065,7 +12065,11 @@ void CEEJitInfo::allocMem (
S_SIZE_T totalSize = S_SIZE_T(codeSize);

size_t roDataAlignment = sizeof(void*);
if ((flag & CORJIT_ALLOCMEM_FLG_RODATA_16BYTE_ALIGN)!= 0)
if ((flag & CORJIT_ALLOCMEM_FLG_RODATA_32BYTE_ALIGN)!= 0)
{
roDataAlignment = 32;
}
else if ((flag & CORJIT_ALLOCMEM_FLG_RODATA_16BYTE_ALIGN)!= 0)
{
roDataAlignment = 16;
}
Expand All @@ -12075,9 +12079,18 @@ void CEEJitInfo::allocMem (
}
if (roDataSize > 0)
{
size_t codeAlignment = ((flag & CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN)!= 0)
? 16 : sizeof(void*);
size_t codeAlignment = sizeof(void*);

if ((flag & CORJIT_ALLOCMEM_FLG_32BYTE_ALIGN) != 0)
{
codeAlignment = 32;
}
else if ((flag & CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN) != 0)
{
codeAlignment = 16;
}
totalSize.AlignUp(codeAlignment);

if (roDataAlignment > codeAlignment) {
// Add padding to align read-only data.
totalSize += (roDataAlignment - codeAlignment);
Expand Down