VirtualBox

Ignore:
Timestamp:
Jan 6, 2021 12:47:49 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142117
Message:

IPRT: Added generic ASMMemFirstNonZero C implementations. bugref:9898

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/asm/ASMMemFirstNonZero-generic.cpp

    r87185 r87186  
    3333
    3434
    35 DECLASM(void *) ASMMemFirstMismatchingU8(void const RT_FAR *pv, size_t cb, uint8_t u8) RT_NOTHROW_DEF
     35DECLASM(void RT_FAR *) ASMMemFirstNonZero(void const RT_FAR *pv, size_t cb) RT_NOTHROW_DEF
    3636{
    3737    uint8_t const *pb = (uint8_t const RT_FAR *)pv;
     38
     39    /*
     40     * If we've got a large buffer to search, do it in larger units.
     41     */
     42    if (cb >= sizeof(size_t) * 2)
     43    {
     44        /* Align the pointer: */
     45        while ((uintptr_t)pb & (sizeof(size_t) - 1))
     46        {
     47            if (RT_LIKELY(*pb == 0))
     48            { /* likely */ }
     49            else
     50                return (void RT_FAR *)pb;
     51            cb--;
     52            pb++;
     53        }
     54
     55        /* Scan in size_t sized words: */
     56        while (   cb >= sizeof(size_t)
     57               && *(size_t *)pb == 0)
     58        {
     59            pb += sizeof(size_t);
     60            cb -= sizeof(size_t);
     61        }
     62    }
     63
     64    /*
     65     * Search byte by byte.
     66     */
    3867    for (; cb; cb--, pb++)
    39         if (RT_LIKELY(*pb == u8))
     68        if (RT_LIKELY(*pb == 0))
    4069        { /* likely */ }
    4170        else
    42             return (void *)pb;
     71            return (void RT_FAR *)pb;
     72
    4373    return NULL;
    4474}
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