VirtualBox

Changeset 66882 in vbox for trunk


Ignore:
Timestamp:
May 12, 2017 5:58:26 PM (7 years ago)
Author:
vboxsync
Message:

iprt: Added RTUINT256U and RTUINT512U. Hacked up simple formatting methods for each.

Location:
trunk
Files:
4 edited

Legend:

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

    r66764 r66882  
    18341834# define RTStrFormatTypeSetUser                         RT_MANGLER(RTStrFormatTypeSetUser)
    18351835# define RTStrFormatU128                                RT_MANGLER(RTStrFormatU128)
     1836# define RTStrFormatU256                                RT_MANGLER(RTStrFormatU256)
     1837# define RTStrFormatU512                                RT_MANGLER(RTStrFormatU512)
    18361838# define RTStrFormatU16                                 RT_MANGLER(RTStrFormatU16)
    18371839# define RTStrFormatU32                                 RT_MANGLER(RTStrFormatU32)
  • trunk/include/iprt/string.h

    r66732 r66882  
    16031603 * @param   cchPrecision    Precision.
    16041604 * @param   fFlags          Flags, RTSTR_F_XXX.
     1605 * @remarks The current implementation is limited to base 16 and doesn't do
     1606 *          width or precision and probably ignores few flags too.
    16051607 */
    16061608RTDECL(ssize_t) RTStrFormatU128(char *pszBuf, size_t cbBuf, PCRTUINT128U pu128Value, unsigned int uiBase,
    16071609                                signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
     1610
     1611/**
     1612 * Formats an unsigned 256-bit number.
     1613 *
     1614 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
     1615 * @param   pszBuf          The output buffer.
     1616 * @param   cbBuf           The size of the output buffer.
     1617 * @param   pu256Value      The value to format.
     1618 * @param   uiBase          Number representation base.
     1619 * @param   cchWidth        Width.
     1620 * @param   cchPrecision    Precision.
     1621 * @param   fFlags          Flags, RTSTR_F_XXX.
     1622 * @remarks The current implementation is limited to base 16 and doesn't do
     1623 *          width or precision and probably ignores few flags too.
     1624 */
     1625RTDECL(ssize_t) RTStrFormatU256(char *pszBuf, size_t cbBuf, PCRTUINT256U pu256Value, unsigned int uiBase,
     1626                                signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
     1627
     1628/**
     1629 * Formats an unsigned 512-bit number.
     1630 *
     1631 * @returns The length of the formatted number or VERR_BUFFER_OVERFLOW.
     1632 * @param   pszBuf          The output buffer.
     1633 * @param   cbBuf           The size of the output buffer.
     1634 * @param   pu512Value      The value to format.
     1635 * @param   uiBase          Number representation base.
     1636 * @param   cchWidth        Width.
     1637 * @param   cchPrecision    Precision.
     1638 * @param   fFlags          Flags, RTSTR_F_XXX.
     1639 * @remarks The current implementation is limited to base 16 and doesn't do
     1640 *          width or precision and probably ignores few flags too.
     1641 */
     1642RTDECL(ssize_t) RTStrFormatU512(char *pszBuf, size_t cbBuf, PCRTUINT512U pu512Value, unsigned int uiBase,
     1643                                signed int cchWidth, signed int cchPrecision, uint32_t fFlags);
     1644
    16081645
    16091646/**
  • trunk/include/iprt/types.h

    r66880 r66882  
    529529} RTUINT128U;
    530530#pragma pack()
    531 /** Pointer to a 64-bit unsigned integer union. */
     531/** Pointer to a 128-bit unsigned integer union. */
    532532typedef RTUINT128U *PRTUINT128U;
    533 /** Pointer to a const 64-bit unsigned integer union. */
     533/** Pointer to a const 128-bit unsigned integer union. */
    534534typedef const RTUINT128U *PCRTUINT128U;
    535535
     
    549549# define RTUINT128_INIT_C(a_Hi, a_Lo) { { UINT64_C(a_Lo), UINT64_C(a_Hi) } }
    550550#endif
     551
     552
     553/**
     554 * 256-bit unsigned integer union.
     555 */
     556#pragma pack(1)
     557typedef union RTUINT256U
     558{
     559    /** Quad-Word view (first as it's used by RTUINT256_INIT). */
     560    struct
     561    {
     562#ifdef RT_BIG_ENDIAN
     563        uint64_t    qw3;
     564        uint64_t    qw2;
     565        uint64_t    qw1;
     566        uint64_t    qw0;
     567#else
     568        uint64_t    qw0;
     569        uint64_t    qw1;
     570        uint64_t    qw2;
     571        uint64_t    qw3;
     572#endif
     573    } QWords;
     574    /** Double-Word view. */
     575    struct
     576    {
     577#ifdef RT_BIG_ENDIAN
     578        uint32_t    dw7;
     579        uint32_t    dw6;
     580        uint32_t    dw5;
     581        uint32_t    dw4;
     582        uint32_t    dw3;
     583        uint32_t    dw2;
     584        uint32_t    dw1;
     585        uint32_t    dw0;
     586#else
     587        uint32_t    dw0;
     588        uint32_t    dw1;
     589        uint32_t    dw2;
     590        uint32_t    dw3;
     591        uint32_t    dw4;
     592        uint32_t    dw5;
     593        uint32_t    dw6;
     594        uint32_t    dw7;
     595#endif
     596    } DWords;
     597    /** Word view. */
     598    struct
     599    {
     600#ifdef RT_BIG_ENDIAN
     601        uint16_t    w15;
     602        uint16_t    w14;
     603        uint16_t    w13;
     604        uint16_t    w12;
     605        uint16_t    w11;
     606        uint16_t    w10;
     607        uint16_t    w9;
     608        uint16_t    w8;
     609        uint16_t    w7;
     610        uint16_t    w6;
     611        uint16_t    w5;
     612        uint16_t    w4;
     613        uint16_t    w3;
     614        uint16_t    w2;
     615        uint16_t    w1;
     616        uint16_t    w0;
     617#else
     618        uint16_t    w0;
     619        uint16_t    w1;
     620        uint16_t    w2;
     621        uint16_t    w3;
     622        uint16_t    w4;
     623        uint16_t    w5;
     624        uint16_t    w6;
     625        uint16_t    w7;
     626        uint16_t    w8;
     627        uint16_t    w9;
     628        uint16_t    w10;
     629        uint16_t    w11;
     630        uint16_t    w12;
     631        uint16_t    w13;
     632        uint16_t    w14;
     633        uint16_t    w15;
     634#endif
     635    } Words;
     636
     637    /** Double-Quad-Word view. */
     638    struct
     639    {
     640#ifdef RT_BIG_ENDIAN
     641        RTUINT128U  dqw1;
     642        RTUINT128U  dqw0;
     643#else
     644        RTUINT128U  dqw0;
     645        RTUINT128U  dqw1;
     646#endif
     647    } DQWords;
     648
     649    /** 128-bit view. */
     650    RTUINT128U  au128[2];
     651    /** 64-bit view. */
     652    uint64_t    au64[4];
     653    /** 32-bit view. */
     654    uint32_t    au32[8];
     655    /** 16-bit view. */
     656    uint16_t    au16[16];
     657    /** 8-bit view. */
     658    uint8_t     au8[32];
     659} RTUINT256U;
     660#pragma pack()
     661/** Pointer to a 256-bit unsigned integer union. */
     662typedef RTUINT256U *PRTUINT256U;
     663/** Pointer to a const 256-bit unsigned integer union. */
     664typedef const RTUINT256U *PCRTUINT256U;
     665
     666/** @def RTUINT256_INIT
     667 * Portable RTUINT256U initializer. */
     668#ifdef RT_BIG_ENDIAN
     669# define RTUINT256_INIT(a_Qw3, a_Qw2, a_Qw1, a_Qw0)   { { a_Qw3, a_Qw2, a_Qw1, a_Qw0 } }
     670#else
     671# define RTUINT256_INIT(a_Qw3, a_Qw2, a_Qw1, a_Qw0)   { { a_Qw0, a_Qw1, a_Qw2, a_Qw3 } }
     672#endif
     673
     674/** @def RTUINT256_INIT_C
     675 * Portable RTUINT256U initializer for 64-bit constants. */
     676#define RTUINT256_INIT_C(a_Qw3, a_Qw2, a_Qw1, a_Qw0)  \
     677    RTUINT256_INIT(UINT64_C(a_Qw3), UINT64_C(a_Qw2), UINT64_C(a_Qw1), UINT64_C(a_Qw0))
     678
     679
     680/**
     681 * 512-bit unsigned integer union.
     682 */
     683#pragma pack(1)
     684typedef union RTUINT512U
     685{
     686    /** Quad-Word view (first as it's used by RTUINT512_INIT). */
     687    struct
     688    {
     689#ifdef RT_BIG_ENDIAN
     690        uint64_t    qw7;
     691        uint64_t    qw6;
     692        uint64_t    qw5;
     693        uint64_t    qw4;
     694        uint64_t    qw3;
     695        uint64_t    qw2;
     696        uint64_t    qw1;
     697        uint64_t    qw0;
     698#else
     699        uint64_t    qw0;
     700        uint64_t    qw1;
     701        uint64_t    qw2;
     702        uint64_t    qw3;
     703        uint64_t    qw4;
     704        uint64_t    qw5;
     705        uint64_t    qw6;
     706        uint64_t    qw7;
     707#endif
     708    } QWords;
     709    /** Double-Word view. */
     710    struct
     711    {
     712#ifdef RT_BIG_ENDIAN
     713        uint32_t    dw15;
     714        uint32_t    dw14;
     715        uint32_t    dw13;
     716        uint32_t    dw12;
     717        uint32_t    dw11;
     718        uint32_t    dw10;
     719        uint32_t    dw9;
     720        uint32_t    dw8;
     721        uint32_t    dw7;
     722        uint32_t    dw6;
     723        uint32_t    dw5;
     724        uint32_t    dw4;
     725        uint32_t    dw3;
     726        uint32_t    dw2;
     727        uint32_t    dw1;
     728        uint32_t    dw0;
     729#else
     730        uint32_t    dw0;
     731        uint32_t    dw1;
     732        uint32_t    dw2;
     733        uint32_t    dw3;
     734        uint32_t    dw4;
     735        uint32_t    dw5;
     736        uint32_t    dw6;
     737        uint32_t    dw7;
     738        uint32_t    dw8;
     739        uint32_t    dw9;
     740        uint32_t    dw10;
     741        uint32_t    dw11;
     742        uint32_t    dw12;
     743        uint32_t    dw13;
     744        uint32_t    dw14;
     745        uint32_t    dw15;
     746#endif
     747    } DWords;
     748    /** Word view. */
     749    struct
     750    {
     751#ifdef RT_BIG_ENDIAN
     752        uint16_t    w31;
     753        uint16_t    w30;
     754        uint16_t    w29;
     755        uint16_t    w28;
     756        uint16_t    w27;
     757        uint16_t    w26;
     758        uint16_t    w25;
     759        uint16_t    w24;
     760        uint16_t    w23;
     761        uint16_t    w22;
     762        uint16_t    w21;
     763        uint16_t    w20;
     764        uint16_t    w19;
     765        uint16_t    w18;
     766        uint16_t    w17;
     767        uint16_t    w16;
     768        uint16_t    w15;
     769        uint16_t    w14;
     770        uint16_t    w13;
     771        uint16_t    w12;
     772        uint16_t    w11;
     773        uint16_t    w10;
     774        uint16_t    w9;
     775        uint16_t    w8;
     776        uint16_t    w7;
     777        uint16_t    w6;
     778        uint16_t    w5;
     779        uint16_t    w4;
     780        uint16_t    w3;
     781        uint16_t    w2;
     782        uint16_t    w1;
     783        uint16_t    w0;
     784#else
     785        uint16_t    w0;
     786        uint16_t    w1;
     787        uint16_t    w2;
     788        uint16_t    w3;
     789        uint16_t    w4;
     790        uint16_t    w5;
     791        uint16_t    w6;
     792        uint16_t    w7;
     793        uint16_t    w8;
     794        uint16_t    w9;
     795        uint16_t    w10;
     796        uint16_t    w11;
     797        uint16_t    w12;
     798        uint16_t    w13;
     799        uint16_t    w14;
     800        uint16_t    w15;
     801        uint16_t    w16;
     802        uint16_t    w17;
     803        uint16_t    w18;
     804        uint16_t    w19;
     805        uint16_t    w20;
     806        uint16_t    w21;
     807        uint16_t    w22;
     808        uint16_t    w23;
     809        uint16_t    w24;
     810        uint16_t    w25;
     811        uint16_t    w26;
     812        uint16_t    w27;
     813        uint16_t    w28;
     814        uint16_t    w29;
     815        uint16_t    w30;
     816        uint16_t    w31;
     817#endif
     818    } Words;
     819
     820    /** Double-Quad-Word view. */
     821    struct
     822    {
     823#ifdef RT_BIG_ENDIAN
     824        RTUINT128U  dqw3;
     825        RTUINT128U  dqw2;
     826        RTUINT128U  dqw1;
     827        RTUINT128U  dqw0;
     828#else
     829        RTUINT128U  dqw0;
     830        RTUINT128U  dqw1;
     831        RTUINT128U  dqw2;
     832        RTUINT128U  dqw3;
     833#endif
     834    } DQWords;
     835
     836    /** Octo-Word view. */
     837    struct
     838    {
     839#ifdef RT_BIG_ENDIAN
     840        RTUINT256U  ow3;
     841        RTUINT256U  ow2;
     842        RTUINT256U  ow1;
     843        RTUINT256U  ow0;
     844#else
     845        RTUINT256U  ow0;
     846        RTUINT256U  ow1;
     847        RTUINT256U  ow2;
     848        RTUINT256U  ow3;
     849#endif
     850    } OWords;
     851
     852    /** 256-bit view. */
     853    RTUINT256U  au256[2];
     854    /** 128-bit view. */
     855    RTUINT128U  au128[4];
     856    /** 64-bit view. */
     857    uint64_t    au64[8];
     858    /** 32-bit view. */
     859    uint32_t    au32[16];
     860    /** 16-bit view. */
     861    uint16_t    au16[32];
     862    /** 8-bit view. */
     863    uint8_t     au8[64];
     864} RTUINT512U;
     865#pragma pack()
     866/** Pointer to a 512-bit unsigned integer union. */
     867typedef RTUINT512U *PRTUINT512U;
     868/** Pointer to a const 512-bit unsigned integer union. */
     869typedef const RTUINT512U *PCRTUINT512U;
     870
     871/** @def RTUINT512_INIT
     872 * Portable RTUINT512U initializer. */
     873#ifdef RT_BIG_ENDIAN
     874# define RTUINT512_INIT(a_Qw7, a_Qw6, a_Qw5, a_Qw4, a_Qw3, a_Qw2, a_Qw1, a_Qw0) \
     875    { { a_Qw7, a_Qw6, a_Qw5, a_Qw4, a_Qw3, a_Qw2, a_Qw1, a_Qw0 } }
     876#else
     877# define RTUINT512_INIT(a_Qw7, a_Qw6, a_Qw5, a_Qw4, a_Qw3, a_Qw2, a_Qw1, a_Qw0) \
     878    { { a_Qw0, a_Qw1, a_Qw2, a_Qw3, a_Qw4, a_Qw5, a_Qw6, a_Qw7 } }
     879#endif
     880
     881/** @def RTUINT512_INIT_C
     882 * Portable RTUINT512U initializer for 64-bit constants. */
     883#define RTUINT512_INIT_C(a_Qw7, a_Qw6, a_Qw5, a_Qw4, a_Qw3, a_Qw2, a_Qw1, a_Qw0) \
     884    RTUINT512_INIT(UINT64_C(a_Qw7), UINT64_C(a_Qw6), UINT64_C(a_Qw5), UINT64_C(a_Qw4), \
     885                   UINT64_C(a_Qw3), UINT64_C(a_Qw2), UINT64_C(a_Qw1), UINT64_C(a_Qw0))
    551886
    552887
  • trunk/src/VBox/Runtime/common/string/strformatnum.cpp

    r62477 r66882  
    172172
    173173
     174RTDECL(ssize_t) RTStrFormatU256(char *pszBuf, size_t cbBuf, PCRTUINT256U pu256, unsigned int uiBase,
     175                                signed int cchWidth, signed int cchPrecision, uint32_t fFlags)
     176{
     177    NOREF(cchWidth); NOREF(cchPrecision);
     178    if (uiBase != 16)
     179        fFlags |= RTSTR_F_SPECIAL;
     180    fFlags &= ~RTSTR_F_BIT_MASK;
     181
     182    char szTmp[64+32+32+32];
     183    char *pszTmp = cbBuf >= sizeof(szTmp) ? pszBuf : szTmp;
     184    size_t cchResult = RTStrFormatNumber(szTmp, pu256->QWords.qw3, 16, 0, 0, fFlags | RTSTR_F_64BIT);
     185    cchResult += RTStrFormatNumber(&pszTmp[cchResult], pu256->QWords.qw2, 16, 8, 0,
     186                                   (fFlags | RTSTR_F_64BIT | RTSTR_F_ZEROPAD) & ~RTSTR_F_SPECIAL);
     187    cchResult += RTStrFormatNumber(&pszTmp[cchResult], pu256->QWords.qw1, 16, 8, 0,
     188                                   (fFlags | RTSTR_F_64BIT | RTSTR_F_ZEROPAD) & ~RTSTR_F_SPECIAL);
     189    cchResult += RTStrFormatNumber(&pszTmp[cchResult], pu256->QWords.qw0, 16, 8, 0,
     190                                   (fFlags | RTSTR_F_64BIT | RTSTR_F_ZEROPAD) & ~RTSTR_F_SPECIAL);
     191    if (pszTmp == pszBuf)
     192        return cchResult;
     193    int rc = RTStrCopy(pszBuf, cbBuf, pszTmp);
     194    if (RT_SUCCESS(rc))
     195        return cchResult;
     196    return rc;
     197}
     198
     199
     200RTDECL(ssize_t) RTStrFormatU512(char *pszBuf, size_t cbBuf, PCRTUINT512U pu512, unsigned int uiBase,
     201                                signed int cchWidth, signed int cchPrecision, uint32_t fFlags)
     202{
     203    NOREF(cchWidth); NOREF(cchPrecision);
     204    if (uiBase != 16)
     205        fFlags |= RTSTR_F_SPECIAL;
     206    fFlags &= ~RTSTR_F_BIT_MASK;
     207
     208    char szTmp[64+32+32+32 + 32+32+32+32];
     209    char *pszTmp = cbBuf >= sizeof(szTmp) ? pszBuf : szTmp;
     210    size_t cchResult = RTStrFormatNumber(szTmp, pu512->QWords.qw7, 16, 0, 0, fFlags | RTSTR_F_64BIT);
     211    cchResult += RTStrFormatNumber(&pszTmp[cchResult], pu512->QWords.qw6, 16, 8, 0,
     212                                   (fFlags | RTSTR_F_64BIT | RTSTR_F_ZEROPAD) & ~RTSTR_F_SPECIAL);
     213    cchResult += RTStrFormatNumber(&pszTmp[cchResult], pu512->QWords.qw5, 16, 8, 0,
     214                                   (fFlags | RTSTR_F_64BIT | RTSTR_F_ZEROPAD) & ~RTSTR_F_SPECIAL);
     215    cchResult += RTStrFormatNumber(&pszTmp[cchResult], pu512->QWords.qw4, 16, 8, 0,
     216                                   (fFlags | RTSTR_F_64BIT | RTSTR_F_ZEROPAD) & ~RTSTR_F_SPECIAL);
     217    cchResult += RTStrFormatNumber(&pszTmp[cchResult], pu512->QWords.qw3, 16, 8, 0,
     218                                   (fFlags | RTSTR_F_64BIT | RTSTR_F_ZEROPAD) & ~RTSTR_F_SPECIAL);
     219    cchResult += RTStrFormatNumber(&pszTmp[cchResult], pu512->QWords.qw2, 16, 8, 0,
     220                                   (fFlags | RTSTR_F_64BIT | RTSTR_F_ZEROPAD) & ~RTSTR_F_SPECIAL);
     221    cchResult += RTStrFormatNumber(&pszTmp[cchResult], pu512->QWords.qw1, 16, 8, 0,
     222                                   (fFlags | RTSTR_F_64BIT | RTSTR_F_ZEROPAD) & ~RTSTR_F_SPECIAL);
     223    cchResult += RTStrFormatNumber(&pszTmp[cchResult], pu512->QWords.qw0, 16, 8, 0,
     224                                   (fFlags | RTSTR_F_64BIT | RTSTR_F_ZEROPAD) & ~RTSTR_F_SPECIAL);
     225    if (pszTmp == pszBuf)
     226        return cchResult;
     227    int rc = RTStrCopy(pszBuf, cbBuf, pszTmp);
     228    if (RT_SUCCESS(rc))
     229        return cchResult;
     230    return rc;
     231}
     232
     233
    174234RTDECL(ssize_t) RTStrFormatR80u2(char *pszBuf, size_t cbBuf, PCRTFLOAT80U2 pr80Value, signed int cchWidth,
    175235                                 signed int cchPrecision, uint32_t fFlags)
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