From 980421ddb7cc79a010785cbf23d51eee14e665a0 Mon Sep 17 00:00:00 2001 From: Eugene Rozenfeld Date: Wed, 22 Jul 2015 17:14:42 -0700 Subject: [PATCH] Add an option to request 16 bytes alignment for read-only data. llilc jit needs this to support LLVM floating-point constant pools. --- src/inc/corjit.h | 6 ++++++ src/vm/jitinterface.cpp | 29 +++++++++++++++++------------ src/zap/zapinfo.cpp | 15 +++++++++++++-- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/inc/corjit.h b/src/inc/corjit.h index bef6b63..a470d5b 100644 --- a/src/inc/corjit.h +++ b/src/inc/corjit.h @@ -300,8 +300,14 @@ 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 }; +inline CorJitAllocMemFlag operator |(CorJitAllocMemFlag a, CorJitAllocMemFlag b) +{ + return static_cast(static_cast(a) | static_cast(b)); +} + enum CorJitFuncKind { CORJIT_FUNC_ROOT, // The main/root function (always id==0) diff --git a/src/vm/jitinterface.cpp b/src/vm/jitinterface.cpp index e9fc251..5670694 100644 --- a/src/vm/jitinterface.cpp +++ b/src/vm/jitinterface.cpp @@ -11623,19 +11623,25 @@ 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) + { + roDataAlignment = 16; + } + else if (roDataSize >= 8) + { + roDataAlignment = 8; + } if (roDataSize > 0) { - totalSize.AlignUp(sizeof(void *)); - totalSize += roDataSize; - -#ifndef _WIN64 - if (roDataSize >= 8) - { - // allocates an extra 4 bytes so that we can - // double align the roData section. - totalSize += 4; + size_t codeAlignment = ((flag & CORJIT_ALLOCMEM_FLG_16BYTE_ALIGN)!= 0) + ? 16 : sizeof(void*); + totalSize.AlignUp(codeAlignment); + if (roDataAlignment > codeAlignment) { + // Add padding to align read-only data. + totalSize += (roDataAlignment - codeAlignment); } -#endif + totalSize += roDataSize; } #ifdef WIN64EXCEPTIONS @@ -11670,8 +11676,7 @@ void CEEJitInfo::allocMem ( if (roDataSize > 0) { - current = (BYTE *)ALIGN_UP(current, (roDataSize >= 8) ? 8 : sizeof(void *)); - + current = (BYTE *)ALIGN_UP(current, roDataAlignment); *roDataBlock = current; current += roDataSize; } diff --git a/src/zap/zapinfo.cpp b/src/zap/zapinfo.cpp index b21a380..d5bdbab 100644 --- a/src/zap/zapinfo.cpp +++ b/src/zap/zapinfo.cpp @@ -1768,8 +1768,19 @@ void ZapInfo::allocMem( if (roDataSize > 0) { - m_pROData = ZapBlobWithRelocs::NewAlignedBlob(m_pImage, NULL, roDataSize, - optForSize || (roDataSize < 8) ? sizeof(TADDR) : 8); + if (flag & CORJIT_ALLOCMEM_FLG_RODATA_16BYTE_ALIGN) + { + align = 16; + } + else if (optForSize || (roDataSize < 8)) + { + align = sizeof(TADDR); + } + else + { + align = 8; + } + m_pROData = ZapBlobWithRelocs::NewAlignedBlob(m_pImage, NULL, roDataSize, align); *roDataBlock = m_pROData->GetData(); } -- 2.7.4