VirtualBox

Changeset 101612 in vbox


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

tstRTArmv8: Check the full 32-bit range of masks. bugref:10371

File:
1 edited

Legend:

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

    r101609 r101612  
    4444#include <iprt/test.h>
    4545#include <iprt/stream.h>
     46#include <iprt/sort.h>
    4647
    4748
     
    6263
    6364
     65/** @callback_method_impl{FNRTSORTCMP}   */
     66static DECLCALLBACK(int) cmpu32(void const *pvElement1, void const *pvElement2, void *pvUser)
     67{
     68    RT_NOREF(pvUser);
     69    if (*(uint32_t const *)pvElement1 < *(uint32_t const *)pvElement2)
     70        return -1;
     71    if (*(uint32_t const *)pvElement1 > *(uint32_t const *)pvElement2)
     72        return 1;
     73    return 0;
     74}
     75
     76
    6477void tstLogicalMask32(void)
    6578{
    6679    RTTestISub("32-bit logical masks");
     80    static uint32_t s_auValidMasks[1312];
     81    unsigned        cValidMasks = 0;
    6782
    6883    /* Test all legal combinations, both directions. */
     
    8095                uint32_t const uImmS = cOneBits | uImmSElmnLength;
    8196                uint32_t const uMask = Armv8A64ConvertImmRImmS2Mask32(uImmS, cRotations);
     97                Assert(cValidMasks < RT_ELEMENTS(s_auValidMasks));
     98                s_auValidMasks[cValidMasks++] = uMask;
    8299
    83100                if (g_cVerbosity > 1)
     
    98115        uImmSElmnLength = (uImmSElmnLength << 1) & 0x3f;
    99116    }
     117
     118    /* Now the other way around. */
     119    RTSortShell(s_auValidMasks, cValidMasks, sizeof(s_auValidMasks[0]), cmpu32, NULL);
     120    unsigned iValidMask     = 0;
     121    uint32_t uNextValidMask = s_auValidMasks[iValidMask];
     122    uint32_t uMask          = 0;
     123    do
     124    {
     125        uint32_t uImmSRev = UINT32_MAX;
     126        uint32_t uImmRRev = UINT32_MAX;
     127        if (!Armv8A64ConvertMask32ToImmRImmS(uMask, &uImmSRev, &uImmRRev))
     128        {
     129            if (RT_LIKELY(uMask < uNextValidMask || iValidMask >= cValidMasks))
     130            { }
     131            else
     132            {
     133                RTTestIFailed("uMask=%#x - false negative\n", uMask);
     134                break;
     135            }
     136        }
     137        else if (RT_LIKELY(uMask == uNextValidMask && iValidMask < cValidMasks))
     138        {
     139            if (iValidMask + 1 < cValidMasks)
     140                uNextValidMask = s_auValidMasks[++iValidMask];
     141            else
     142            {
     143                iValidMask     = cValidMasks;
     144                uNextValidMask = UINT32_MAX;
     145            }
     146        }
     147        else
     148        {
     149            RTTestIFailed("uMask=%#x - false positive\n", uMask);
     150            break;
     151        }
     152    } while (uMask++ < UINT32_MAX);
    100153}
    101154
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