Add an option to request 16 bytes alignment for read-only data.
authorEugene Rozenfeld <erozen@microsoft.com>
Thu, 23 Jul 2015 00:14:42 +0000 (17:14 -0700)
committerEugene Rozenfeld <erozen@microsoft.com>
Fri, 24 Jul 2015 19:09:31 +0000 (12:09 -0700)
llilc jit needs this to support LLVM floating-point constant pools.

src/inc/corjit.h
src/vm/jitinterface.cpp
src/zap/zapinfo.cpp

index bef6b63..a470d5b 100644 (file)
@@ -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<CorJitAllocMemFlag>(static_cast<int>(a) | static_cast<int>(b));
+}
+
 enum CorJitFuncKind
 {
     CORJIT_FUNC_ROOT,          // The main/root function (always id==0)
index e9fc251..5670694 100644 (file)
@@ -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;
     }
index b21a380..d5bdbab 100644 (file)
@@ -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();
     }