VirtualBox

Changeset 98498 in vbox


Ignore:
Timestamp:
Feb 7, 2023 10:13:45 PM (2 years ago)
Author:
vboxsync
Message:

IPRT/vcc: Working on 64-bit integer support routines for the 32-bit Visual C++ compilers. [forgotten header] bugref:10261

File:
1 edited

Legend:

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

    r98103 r98498  
    5656 *
    5757 * @returns true if they are, false if they aren't.
    58  * @param   pValue          The input and output value.
    59  */
    60 DECLINLINE(bool) RTUInt64IsZero(PRTUINT64U pValue)
     58 * @param   pValue          The value to examine.
     59 */
     60DECLINLINE(bool) RTUInt64IsZero(PCRTUINT64U pValue)
    6161{
    6262#if ARCH_BITS >= 32
     
    7373
    7474/**
     75 * Checks if the sign-bit is set.
     76 * 
     77 * @returns Sign bit.
     78 * @param   pValue              The value to examine.
     79 */
     80DECLINLINE(bool) RTUInt64IsSigned(PCRTUINT64U pValue)
     81{
     82#if ARCH_BITS >= 32
     83    return RT_BOOL(pValue->DWords.dw1 & RT_BIT_32(31));
     84#else
     85    return RT_BOOL(pValue->Words.w3 & ((uint16_t)1 << 15));
     86#endif
     87}
     88
     89
     90/**
    7591 * Set a 128-bit unsigned integer value to zero.
    7692 *
     
    165181    pResult->s.Hi = pValue1->s.Hi - pValue2->s.Hi;
    166182    if (pResult->s.Lo > pValue1->s.Lo)
     183        pResult->s.Hi--;
     184    return pResult;
     185}
     186
     187
     188/**
     189 * Calculates the negated number (special case of subtraction)
     190 *
     191 * @returns pResult
     192 * @param   pResult             The result variable.
     193 * @param   pValue              The value to negate.
     194 */
     195DECLINLINE(PRTUINT64U) RTUInt64Neg(PRTUINT64U pResult, PCRTUINT64U pValue)
     196{
     197    pResult->s.Lo = UINT32_C(0) - pValue->s.Lo;
     198    pResult->s.Hi = UINT32_C(0) - pValue->s.Hi;
     199    if (pResult->s.Lo > UINT32_C(0))
    167200        pResult->s.Hi--;
    168201    return pResult;
     
    311344
    312345DECLINLINE(PRTUINT64U) RTUInt64DivRem(PRTUINT64U pQuotient, PRTUINT64U pRemainder, PCRTUINT64U pValue1, PCRTUINT64U pValue2);
     346DECLINLINE(PRTUINT64U) RTUInt64DivRemSigned(PRTUINT64U pQuotient, PRTUINT64U pRemainder, PCRTUINT64U pValue1, PCRTUINT64U pValue2);
    313347
    314348/**
     
    339373    RTUINT64U Ignored;
    340374    RTUInt64DivRem(&Ignored, pResult, pValue1, pValue2);
     375    return pResult;
     376}
     377
     378
     379/**
     380 * Divides a 64-bit signed integer value by another.
     381 *
     382 * @returns pResult
     383 * @param   pResult             The result variable.
     384 * @param   pValue1             The dividend value.
     385 * @param   pValue2             The divisor value.
     386 */
     387DECLINLINE(PRTUINT64U) RTUInt64DivSigned(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     388{
     389    RTUINT64U Ignored;
     390    return RTUInt64DivRemSigned(pResult, &Ignored, pValue1, pValue2);
     391}
     392
     393
     394/**
     395 * Divides a 64-bit unsigned integer value by another, returning the remainder.
     396 *
     397 * @returns pResult
     398 * @param   pResult             The result variable (remainder).
     399 * @param   pValue1             The dividend value.
     400 * @param   pValue2             The divisor value.
     401 */
     402DECLINLINE(PRTUINT64U) RTUInt64ModSigned(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     403{
     404    RTUINT64U Ignored;
     405    RTUInt64DivRemSigned(&Ignored, pResult, pValue1, pValue2);
    341406    return pResult;
    342407}
     
    619684
    620685/**
     686 * Negates a 64-bit unsigned integer value, returning the result in place.
     687 *
     688 * @returns pValueResult.
     689 * @param   pValueResult    The value and result.
     690 */
     691DECLINLINE(PRTUINT64U) RTUInt64AssignNeg(PRTUINT64U pValueResult)
     692{
     693    pValueResult->s.Lo = UINT32_C(0) - pValueResult->s.Lo;
     694    pValueResult->s.Hi = UINT32_C(0) - pValueResult->s.Hi;
     695    if (pValueResult->s.Lo > UINT32_C(0))
     696        pValueResult->s.Hi--;
     697    return pValueResult;
     698}
     699
     700
     701/**
    621702 * Multiplies two 64-bit unsigned integer values, storing the result in the
    622703 * first.
     
    812893    {
    813894        /* (left shift) */
    814         cBits &= 31;
     895        cBits &= 63;
    815896        if (cBits >= 32)
    816897        {
     
    829910        /* (right shift) */
    830911        cBits = -cBits;
    831         cBits &= 31;
     912        cBits &= 63;
    832913        if (cBits >= 32)
    833914        {
     
    13361417
    13371418
     1419/**
     1420 * Divides a 64-bit signed integer value by another, returning both quotient and
     1421 * remainder.
     1422 *
     1423 * @returns pQuotient, NULL if pValue2 is 0.
     1424 * @param   pQuotient           Where to return the quotient.
     1425 * @param   pRemainder          Where to return the remainder.
     1426 * @param   pValue1             The dividend value.
     1427 * @param   pValue2             The divisor value.
     1428 */
     1429DECLINLINE(PRTUINT64U) RTUInt64DivRemSigned(PRTUINT64U pQuotient, PRTUINT64U pRemainder, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     1430{
     1431    /*
     1432     * If both values are positive, we can do a straight unsigned division.
     1433     */
     1434    if (!RTUInt64IsSigned(pValue1))
     1435    {
     1436        if (!RTUInt64IsSigned(pValue2))
     1437            return RTUInt64DivRem(pQuotient, pRemainder, pValue1, pValue2);
     1438
     1439        /*
     1440         * Negative divisor, Positive dividend:
     1441         *      negate the divisor, do unsigned division, and negate the quotient.
     1442         */
     1443        {
     1444            RTUINT64U NegDivisor;
     1445            RTUInt64DivRem(pQuotient, pRemainder, pValue1, RTUInt64Neg(&NegDivisor, pValue2));
     1446            RTUInt64AssignNeg(pQuotient);
     1447        }
     1448    }
     1449    else
     1450    {
     1451        /* Negate the dividend to get a positive value. */
     1452        RTUINT64U NegDividend;
     1453        RTUInt64Neg(&NegDividend, pValue1);
     1454
     1455        if (!RTUInt64IsSigned(pValue2))
     1456        {
     1457            /*
     1458             * Negative dividend, positive divisor:
     1459             *      Negate the dividend (above), do unsigned division, and negate both quotient and remainder
     1460             */
     1461            RTUInt64DivRem(pQuotient, pRemainder, &NegDividend, pValue2);
     1462            RTUInt64AssignNeg(pQuotient);
     1463        }
     1464        else
     1465        {
     1466            /*
     1467             * Negative dividend, negative divisor:
     1468             *      Negate both dividend (above) and divisor, do unsigned division, and negate the remainder.
     1469             */
     1470            RTUINT64U NegDivisor;
     1471            RTUInt64DivRem(pQuotient, pRemainder, &NegDividend, RTUInt64Neg(&NegDivisor, pValue2));
     1472        }
     1473        RTUInt64AssignNeg(pRemainder);
     1474    }
     1475    return pQuotient;
     1476}
     1477
     1478
    13381479/** @} */
    13391480
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