VirtualBox

Changeset 101613 in vbox


Ignore:
Timestamp:
Oct 27, 2023 8:41:10 AM (11 months ago)
Author:
vboxsync
Message:

tstRTArmv8: Do random check of 64-bit range of masks. bugref:10371

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTArmv8.cpp

    r101612 r101613  
    4343
    4444#include <iprt/test.h>
     45#include <iprt/rand.h>
    4546#include <iprt/stream.h>
    4647#include <iprt/sort.h>
     
    7576
    7677
     78/** @callback_method_impl{FNRTSORTCMP}   */
     79static DECLCALLBACK(int) cmpu64(void const *pvElement1, void const *pvElement2, void *pvUser)
     80{
     81    RT_NOREF(pvUser);
     82    if (*(uint64_t const *)pvElement1 < *(uint64_t const *)pvElement2)
     83        return -1;
     84    if (*(uint64_t const *)pvElement1 > *(uint64_t const *)pvElement2)
     85        return 1;
     86    return 0;
     87}
     88
     89
     90static unsigned BinarySearchU64(uint64_t uValue, uint64_t const *pauEntries, unsigned idxEnd)
     91{
     92    unsigned idxStart = 0;
     93    for (;;)
     94    {
     95        unsigned const idx    = (idxEnd - idxStart) / 2 + idxStart;
     96        uint64_t const uEntry = pauEntries[idx];
     97        if (uValue < uEntry)
     98        {
     99            if (idx > idxStart)
     100                idxEnd = idx;
     101            else
     102                return ~0U;
     103        }
     104        else if (uValue > uEntry)
     105        {
     106            if (idx + 1 < idxEnd)
     107                idxStart = idx + 1;
     108            else
     109                return ~0U;
     110        }
     111        else
     112            return idx;
     113    }
     114}
     115
     116
    77117void tstLogicalMask32(void)
    78118{
     
    95135                uint32_t const uImmS = cOneBits | uImmSElmnLength;
    96136                uint32_t const uMask = Armv8A64ConvertImmRImmS2Mask32(uImmS, cRotations);
    97                 Assert(cValidMasks < RT_ELEMENTS(s_auValidMasks));
     137                RTTESTI_CHECK_RETV(cValidMasks < RT_ELEMENTS(s_auValidMasks));
    98138                s_auValidMasks[cValidMasks++] = uMask;
    99139
     
    157197{
    158198    RTTestISub("64-bit logical masks");
     199    static uint64_t s_auValidMasks[5376];
     200    unsigned        cValidMasks = 0;
    159201
    160202    /* Test all legal combinations, both directions. */
     
    172214                uint32_t const uImmS = cOneBits | uImmSElmnLength;
    173215                uint64_t const uMask = Armv8A64ConvertImmRImmS2Mask64(uImmS, cRotations);
     216                RTTESTI_CHECK_RETV(cValidMasks < RT_ELEMENTS(s_auValidMasks));
     217                s_auValidMasks[cValidMasks++] = uMask;
     218
    174219                if (g_cVerbosity > 1)
    175220                    RTPrintf("%016llx %s size=%02u length=%02u rotation=%02u N=%u immr=%s imms=%s\n",
     
    191236            uImmSElmnLength = 0x40;
    192237    }
     238
     239    /* Now the other way around, using random masks. */
     240    RTSortShell(s_auValidMasks, cValidMasks, sizeof(s_auValidMasks[0]), cmpu64, NULL);
     241
     242    for (unsigned iRand = 0; iRand < _32M; iRand++)
     243    {
     244        uint64_t const uMask    = RTRandU64();
     245        unsigned const idxMask  = BinarySearchU64(uMask, s_auValidMasks, cValidMasks);
     246        uint32_t       uImmSRev = UINT32_MAX;
     247        uint32_t       uImmRRev = UINT32_MAX;
     248        if (!Armv8A64ConvertMask64ToImmRImmS(uMask, &uImmSRev, &uImmRRev))
     249        {
     250            if (RT_LIKELY(idxMask == ~0U))
     251            { }
     252            else
     253            {
     254                RTTestIFailed("uMask=%#018llx - false negative\n", uMask);
     255                break;
     256            }
     257        }
     258        else if (RT_LIKELY(idxMask < cValidMasks))
     259        { /* likely */ }
     260        else
     261        {
     262            RTTestIFailed("uMask=%#018llx - false positive\n", uMask);
     263            break;
     264        }
     265    }
    193266}
    194267
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