Index: trunk/src/VBox/VMM/VMMAll/PGMAllBth.h
===================================================================
--- trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 15227)
+++ trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 15228)
@@ -3054,5 +3054,5 @@
 DECLINLINE(PGMPOOLKIND) PGM_BTH_NAME(CalcPageKind)(const GSTPDE *pPdeSrc, uint32_t cr4)
 {
-#  if PGM_GST_TYPE == PGM_TYPE_AMD64
+#  if PMG_GST_TYPE == PGM_TYPE_AMD64
     if (!pPdeSrc->n.u1Size)
 #  else
@@ -3122,5 +3122,5 @@
 #ifdef PGMPOOL_WITH_MONITORING
     int rc = pgmPoolSyncCR3(pVM);
-    if (RT_UNLIKELY(rc != VINF_SUCCESS))
+    if (rc != VINF_SUCCESS)
         return rc;
 #endif
@@ -3159,9 +3159,4 @@
 #  else /* PGM_SHW_TYPE == PGM_TYPE_PAE */
 #   if PGM_GST_TYPE == PGM_TYPE_32BIT
-    PX86PDEPAE  paPDEDst[4];
-    paPDEDst[0] = pgmShwGetPaePDEPtr(&pVM->pgm.s, UINT32_C(0x00000000));
-    paPDEDst[1] = pgmShwGetPaePDEPtr(&pVM->pgm.s, UINT32_C(0x40000000));
-    paPDEDst[2] = pgmShwGetPaePDEPtr(&pVM->pgm.s, UINT32_C(0x80000000));
-    paPDEDst[3] = pgmShwGetPaePDEPtr(&pVM->pgm.s, UINT32_C(0xc0000000));
     PX86PDEPAE  pPDEDst = NULL;
 #   endif
@@ -3179,11 +3174,10 @@
      * Iterate the the CR3 page.
      */
+    PPGMMAPPING pMapping;
+    unsigned    iPdNoMapping;
     const bool  fRawR0Enabled = EMIsRawRing0Enabled(pVM);
     PPGMPOOL    pPool         = pVM->pgm.s.CTX_SUFF(pPool);
 
     /* Only check mappings if they are supposed to be put into the shadow page table. */
-#  ifndef PGM_WITHOUT_MAPPINGS
-    PPGMMAPPING pMapping;
-    unsigned    iPdNoMapping;
     if (pgmMapAreMappingsEnabled(&pVM->pgm.s))
     {
@@ -3196,13 +3190,8 @@
         iPdNoMapping  = ~0U;
     }
-#  else  /* PGM_WITHOUT_MAPPINGS */
-    Assert(!pgmMapAreMappingsEnabled(&pVM->pgm.s));
-#  endif /* PGM_WITHOUT_MAPPINGS */
 
 #  if PGM_GST_TYPE == PGM_TYPE_PAE
     for (uint64_t iPdpt = 0; iPdpt < GST_PDPE_ENTRIES; iPdpt++)
-#  endif /* PGM_GST_TYPE == PGM_TYPE_PAE */
-    {
-#  if PGM_GST_TYPE == PGM_TYPE_PAE
+    {
         unsigned        iPDSrc;
         X86PDPE         PdpeSrc;
@@ -3232,16 +3221,17 @@
             continue;
         }
-#  endif /* PGM_GST_TYPE == PGM_TYPE_PAE */
-
+#  else  /* PGM_GST_TYPE != PGM_TYPE_PAE */
+    {
+#  endif /* PGM_GST_TYPE != PGM_TYPE_PAE */
         for (unsigned iPD = 0; iPD < RT_ELEMENTS(pPDSrc->a); iPD++)
         {
 #  if PGM_SHW_TYPE == PGM_TYPE_PAE && PGM_GST_TYPE == PGM_TYPE_32BIT
-            if (RT_UNLIKELY((iPD & 255) == 0)) /* Start of new PD. */
-                pPDEDst = paPDEDst[iPD >> 8];
+            if ((iPD & 255) == 0) /* Start of new PD. */
+                pPDEDst = pgmShwGetPaePDEPtr(&pVM->pgm.s, (uint32_t)iPD << GST_PD_SHIFT);
 #  endif
 #  if PGM_SHW_TYPE == PGM_TYPE_32BIT
             Assert(pgmShwGet32BitPDEPtr(&pVM->pgm.s, (uint32_t)iPD << SHW_PD_SHIFT) == pPDEDst);
 #  elif PGM_SHW_TYPE == PGM_TYPE_PAE
-#   if defined(VBOX_STRICT) && !defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) /* Unfortunately not reliable with PGMR0DynMap and multiple VMs. */
+#   if defined(VBOX_STRICT) && !defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0) /* Unfortuantely not reliable with PGMR0DynMap and multiple VMs. */
             RTGCPTR GCPtrStrict = (uint32_t)iPD << GST_PD_SHIFT;
 #    if PGM_GST_TYPE == PGM_TYPE_PAE
@@ -3255,5 +3245,8 @@
                 &&  (PdeSrc.n.u1User || fRawR0Enabled))
             {
-#  ifndef PGM_WITHOUT_MAPPINGS
+#  if    (   PGM_GST_TYPE == PGM_TYPE_32BIT \
+          || PGM_GST_TYPE == PGM_TYPE_PAE) \
+      && !defined(PGM_WITHOUT_MAPPINGS)
+
                 /*
                  * Check for conflicts with GC mappings.
@@ -3262,5 +3255,5 @@
                 if (iPD + iPdpt * X86_PG_PAE_ENTRIES == iPdNoMapping)
 #   else
-                if (RT_UNLIKELY(iPD == iPdNoMapping))
+                if (iPD == iPdNoMapping)
 #   endif
                 {
@@ -3272,5 +3265,5 @@
                         iPD += cPTs - 1;
 #   if PGM_SHW_TYPE != PGM_GST_TYPE /* SHW==PAE && GST==32BIT */
-                        pPDEDst = paPDEDst[(iPD + 1) >> 8];
+                        pPDEDst = pgmShwGetPaePDEPtr(&pVM->pgm.s, (uint32_t)(iPD + 1) << GST_PD_SHIFT);
 #   else
                         pPDEDst += cPTs;
@@ -3301,5 +3294,7 @@
 #   endif /* !IN_RING3 */
                 }
-#  endif /* !PGM_WITHOUT_MAPPINGS */
+#  else  /* (PGM_GST_TYPE != PGM_TYPE_32BIT && PGM_GST_TYPE != PGM_TYPE_PAE) || PGM_WITHOUT_MAPPINGS */
+                Assert(!pgmMapAreMappingsEnabled(&pVM->pgm.s));
+#  endif /* (PGM_GST_TYPE != PGM_TYPE_32BIT && PGM_GST_TYPE != PGM_TYPE_PAE) || PGM_WITHOUT_MAPPINGS */
 
                 /*
@@ -3392,7 +3387,5 @@
                 } /* foreach 2MB PAE PDE in 4MB guest PDE */
             }
-#  ifdef PGM_WITHOUT_MAPPINGS
-            else
-#  elif PGM_GST_TYPE == PGM_TYPE_PAE
+#  if PGM_GST_TYPE == PGM_TYPE_PAE
             else if (iPD + iPdpt * X86_PG_PAE_ENTRIES != iPdNoMapping)
 #  else
@@ -3404,38 +3397,26 @@
                  */
 #  if PGM_SHW_TYPE == PGM_TYPE_PAE && PGM_GST_TYPE == PGM_TYPE_32BIT
-                /* first half */
-                if (pPDEDst->n.u1Present)
+                for (unsigned i = 0, iPdShw = iPD * 2; i < 2; i++, iPdShw++) /* pray that the compiler unrolls this */
+#  elif PGM_GST_TYPE == PGM_TYPE_PAE
+                const unsigned iPdShw = iPD + iPdpt * X86_PG_PAE_ENTRIES;
+#  else
+                const unsigned iPdShw = iPD;
+#  endif
                 {
-                    pgmPoolFree(pVM, pPDEDst->u & SHW_PDE_PG_MASK, SHW_POOL_ROOT_IDX, iPD * 2);
-                    pPDEDst->u = 0;
-                    MY_STAM_COUNTER_INC(&pVM->pgm.s.CTX_MID_Z(Stat,SyncCR3DstFreedSrcNP));
+                    if (pPDEDst->n.u1Present)
+                    {
+                        pgmPoolFree(pVM, pPDEDst->u & SHW_PDE_PG_MASK, SHW_POOL_ROOT_IDX, iPdShw);
+                        pPDEDst->u = 0;
+                        MY_STAM_COUNTER_INC(&pVM->pgm.s.CTX_MID_Z(Stat,SyncCR3DstFreedSrcNP));
+                    }
+                    pPDEDst++;
                 }
-                pPDEDst++;
-                /* second half */
-                if (pPDEDst->n.u1Present)
-                {
-                    pgmPoolFree(pVM, pPDEDst->u & SHW_PDE_PG_MASK, SHW_POOL_ROOT_IDX, iPD * 2 + 1);
-                    pPDEDst->u = 0;
-                    MY_STAM_COUNTER_INC(&pVM->pgm.s.CTX_MID_Z(Stat,SyncCR3DstFreedSrcNP));
-                }
-                pPDEDst++;
-#  else  /* 1:1 */
-                if (pPDEDst->n.u1Present)
-                {
-#   if PGM_GST_TYPE == PGM_TYPE_PAE
-                    const unsigned iPdShw = iPD + iPdpt * X86_PG_PAE_ENTRIES;
-#   else
-                    const unsigned iPdShw = iPD;
-#   endif
-                    pgmPoolFree(pVM, pPDEDst->u & SHW_PDE_PG_MASK, SHW_POOL_ROOT_IDX, iPdShw);
-                    pPDEDst->u = 0;
-                    MY_STAM_COUNTER_INC(&pVM->pgm.s.CTX_MID_Z(Stat,SyncCR3DstFreedSrcNP));
-                }
-                pPDEDst++;
-#  endif /* 1:1 */
             }
-#  ifndef PGM_WITHOUT_MAPPINGS
             else
             {
+#  if    (   PGM_GST_TYPE == PGM_TYPE_32BIT \
+          || PGM_GST_TYPE == PGM_TYPE_PAE)  \
+      && !defined(PGM_WITHOUT_MAPPINGS)
+
                 const unsigned cPTs = pMapping->cb >> GST_PD_SHIFT;
 
@@ -3477,8 +3458,8 @@
                             iPdNoMapping = pMapping ? pMapping->GCPtr >> GST_PD_SHIFT : ~0U;
                             break;
-#   else  /* !IN_RING3 */
+#   else
                             LogFlow(("SyncCR3: detected conflict -> VINF_PGM_SYNC_CR3\n"));
                             return VINF_PGM_SYNC_CR3;
-#   endif /* !IN_RING3 */
+#   endif
                         }
                     }
@@ -3495,5 +3476,5 @@
                 iPD += cPTs - 1;
 #   if PGM_SHW_TYPE != PGM_GST_TYPE /* SHW==PAE && GST==32BIT */
-                pPDEDst = paPDEDst[(iPD + 1) >> 8];
+                pPDEDst = pgmShwGetPaePDEPtr(&pVM->pgm.s, (uint32_t)(iPD + 1) << GST_PD_SHIFT);
 #   else
                 pPDEDst += cPTs;
@@ -3502,6 +3483,8 @@
                 AssertCompile(PGM_GST_TYPE == PGM_TYPE_32BIT && PGM_SHW_TYPE == PGM_TYPE_PAE);
 #   endif
+#  else  /* (PGM_GST_TYPE != PGM_TYPE_32BIT && PGM_GST_TYPE != PGM_TYPE_PAE) || PGM_WITHOUT_MAPPINGS */
+                Assert(!pgmMapAreMappingsEnabled(&pVM->pgm.s));
+#  endif /* (PGM_GST_TYPE != PGM_TYPE_32BIT && PGM_GST_TYPE != PGM_TYPE_PAE) || PGM_WITHOUT_MAPPINGS */
             }
-#  endif /* !PGM_WITHOUT_MAPPINGS */
 
         } /* for iPD */
