VirtualBox

Changeset 22004 in vbox for trunk/include


Ignore:
Timestamp:
Aug 5, 2009 6:26:53 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
50739
Message:

iprt/asm.h: Added ASMMemIsZeroPage.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asm.h

    r21943 r22004  
    50535053
    50545054/**
     5055 * Checks if a memory page is all zeros.
     5056 *
     5057 * @returns true / false.
     5058 *
     5059 * @param   pvPage      Pointer to the page.  This must be naturally aligned if
     5060 *                      not page aligned.
     5061 */
     5062DECLINLINE(bool) ASMMemIsZeroPage(void const *pvPage)
     5063{
     5064# if 0 /*RT_INLINE_ASM_GNU_STYLE - this is actually slower... */
     5065    union { RTCCUINTREG r; bool f; } uAX;
     5066    RTCCUINTREG xCX, xDI;
     5067   Assert(!((uintptr_t)pvPage & (sizeof(uintptr_t) - 1)));
     5068    __asm__ __volatile__("repe; "
     5069#  ifdef RT_ARCH_AMD64
     5070                         "scasq\n\t"
     5071#  else
     5072                         "scasl\n\t"
     5073#  endif
     5074                         "setnc %%al\n\t"
     5075                         : "=&c" (xCX),
     5076                           "=&D" (xDI),
     5077                           "=&a" (uAX.r)
     5078                         : "mr" (pvPage),
     5079#  ifdef RT_ARCH_AMD64
     5080                         "0" (0x1000/8),
     5081#  else
     5082                         "0" (0x1000/4),
     5083#  endif
     5084                         "1" (pvPage),
     5085                         "2" (0));
     5086    return uAX.f;
     5087# else
     5088   uintptr_t const *puPtr = (uintptr_t const *)pvPage;
     5089   int              cLeft = 0x1000 / sizeof(uintptr_t) / 8;
     5090   Assert(!((uintptr_t)pvPage & (sizeof(uintptr_t) - 1)));
     5091   for (;;)
     5092   {
     5093       if (puPtr[0])        return false;
     5094       if (puPtr[4])        return false;
     5095
     5096       if (puPtr[2])        return false;
     5097       if (puPtr[6])        return false;
     5098
     5099       if (puPtr[1])        return false;
     5100       if (puPtr[5])        return false;
     5101
     5102       if (puPtr[3])        return false;
     5103       if (puPtr[7])        return false;
     5104
     5105       if (!--cLeft)
     5106           return true;
     5107       puPtr += 8;
     5108   }
     5109   return true;
     5110# endif
     5111}
     5112
     5113
     5114/**
    50555115 * Checks if a memory block is filled with the specified byte.
    50565116 *
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette