VirtualBox

Changeset 60482 in vbox for trunk


Ignore:
Timestamp:
Apr 14, 2016 12:50:47 AM (9 years ago)
Author:
vboxsync
Message:

iprt/uint64.h: Converted uint128.h to RTUINT64U 64-bit for ancient compilers.

Location:
trunk/include/iprt
Files:
1 edited
1 copied

Legend:

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

    r57978 r60482  
    2929#include <iprt/cdefs.h>
    3030#include <iprt/types.h>
    31 #include <iprt/err.h>
    3231#include <iprt/asm.h>
    3332#ifdef RT_ARCH_AMD64
     
    449448DECLINLINE(PRTUINT128U) RTUInt128BooleanNot(PRTUINT128U pResult, PCRTUINT128U pValue)
    450449{
     450    pResult->s.Lo = pValue->s.Lo || pValue->s.Hi ? 0 : 1;
    451451    pResult->s.Hi = 0;
    452     pResult->s.Lo = pValue->s.Lo || pValue->s.Hi ? 0 : 1;
    453452    return pResult;
    454453}
     
    559558
    560559/**
    561  * Assigns a 16-bit unsigned integer value to 128-bit unsigned integer.
     560 * Assigns a 32-bit unsigned integer value to 128-bit unsigned integer.
    562561 *
    563562 * @returns pValueResult
  • trunk/include/iprt/uint64.h

    r60406 r60482  
    11/** @file
    2  * IPRT - RTUINT128U & uint128_t methods.
     2 * IPRT - RTUINT64U methods for old 32-bit and 16-bit compilers.
    33 */
    44
    55/*
    6  * Copyright (C) 2011-2015 Oracle Corporation
     6 * Copyright (C) 2011-2016 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2424 */
    2525
    26 #ifndef ___iprt_uint128_h
    27 #define ___iprt_uint128_h
     26#ifndef ___iprt_uint64_h
     27#define ___iprt_uint64_h
    2828
    2929#include <iprt/cdefs.h>
    3030#include <iprt/types.h>
    31 #include <iprt/err.h>
    3231#include <iprt/asm.h>
    33 #ifdef RT_ARCH_AMD64
    34 # include <iprt/asm-math.h>
    35 #endif
    3632
    3733RT_C_DECLS_BEGIN
    3834
    39 /** @defgroup grp_rt_uint128 RTUInt128 - 128-bit Unsigned Integer Methods
     35/** @defgroup grp_rt_uint64 RTUInt64 - 64-bit Unsigned Integer Methods for ancient compilers
    4036 * @ingroup grp_rt
    4137 * @{
     
    4945 * @param   pValue          The input and output value.
    5046 */
    51 DECLINLINE(bool) RTUInt128IsZero(PRTUINT128U pValue)
    52 {
    53 #if ARCH_BITS >= 64
    54     return pValue->s.Hi == 0
    55         && pValue->s.Lo == 0;
    56 #else
    57     return pValue->DWords.dw0 == 0
    58         && pValue->DWords.dw1 == 0
    59         && pValue->DWords.dw2 == 0
    60         && pValue->DWords.dw3 == 0;
     47DECLINLINE(bool) RTUInt64IsZero(PRTUINT64U pValue)
     48{
     49#if ARCH_BITS >= 32
     50    return pValue->s.Lo == 0
     51        && pValue->s.Hi == 0;
     52#else
     53    return pValue->Words.w0 == 0
     54        && pValue->Words.w1 == 0
     55        && pValue->Words.w2 == 0
     56        && pValue->Words.w3 == 0;
    6157#endif
    6258}
     
    6965 * @param   pResult             The result variable.
    7066 */
    71 DECLINLINE(PRTUINT128U) RTUInt128SetZero(PRTUINT128U pResult)
    72 {
    73 #if ARCH_BITS >= 64
     67DECLINLINE(PRTUINT64U) RTUInt64SetZero(PRTUINT64U pResult)
     68{
     69#if ARCH_BITS >= 32
    7470    pResult->s.Hi = 0;
    7571    pResult->s.Lo = 0;
    7672#else
    77     pResult->DWords.dw0 = 0;
    78     pResult->DWords.dw1 = 0;
    79     pResult->DWords.dw2 = 0;
    80     pResult->DWords.dw3 = 0;
    81 #endif
    82     return pResult;
    83 }
    84 
    85 
    86 /**
    87  * Set a 128-bit unsigned integer value to the maximum value.
    88  *
    89  * @returns pResult
    90  * @param   pResult             The result variable.
    91  */
    92 DECLINLINE(PRTUINT128U) RTUInt128SetMax(PRTUINT128U pResult)
    93 {
    94 #if ARCH_BITS >= 64
    95     pResult->s.Hi = UINT64_MAX;
    96     pResult->s.Lo = UINT64_MAX;
    97 #else
    98     pResult->DWords.dw0 = UINT32_MAX;
    99     pResult->DWords.dw1 = UINT32_MAX;
    100     pResult->DWords.dw2 = UINT32_MAX;
    101     pResult->DWords.dw3 = UINT32_MAX;
    102 #endif
    103     return pResult;
    104 }
    105 
    106 
    107 
    108 
    109 /**
    110  * Adds two 128-bit unsigned integer values.
     73    pResult->Words.w0 = 0;
     74    pResult->Words.w1 = 0;
     75    pResult->Words.w2 = 0;
     76    pResult->Words.w3 = 0;
     77#endif
     78    return pResult;
     79}
     80
     81
     82/**
     83 * Set a 32-bit unsigned integer value to the maximum value.
     84 *
     85 * @returns pResult
     86 * @param   pResult             The result variable.
     87 */
     88DECLINLINE(PRTUINT64U) RTUInt64SetMax(PRTUINT64U pResult)
     89{
     90#if ARCH_BITS >= 32
     91    pResult->s.Hi = UINT32_MAX;
     92    pResult->s.Lo = UINT32_MAX;
     93#else
     94    pResult->Words.w0 = UINT16_MAX;
     95    pResult->Words.w1 = UINT16_MAX;
     96    pResult->Words.w2 = UINT16_MAX;
     97    pResult->Words.w3 = UINT16_MAX;
     98#endif
     99    return pResult;
     100}
     101
     102
     103
     104
     105/**
     106 * Adds two 64-bit unsigned integer values.
    111107 *
    112108 * @returns pResult
     
    115111 * @param   pValue2             The second value.
    116112 */
    117 DECLINLINE(PRTUINT128U) RTUInt128Add(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)
     113DECLINLINE(PRTUINT64U) RTUInt64Add(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
    118114{
    119115    pResult->s.Hi = pValue1->s.Hi + pValue2->s.Hi;
     
    126122
    127123/**
    128  * Adds a 128-bit and a 64-bit unsigned integer values.
     124 * Adds a 64-bit and a 32-bit unsigned integer values.
    129125 *
    130126 * @returns pResult
    131127 * @param   pResult             The result variable.
    132128 * @param   pValue1             The first value.
    133  * @param   uValue2             The second value, 64-bit.
    134  */
    135 DECLINLINE(PRTUINT128U) RTUInt128AddU64(PRTUINT128U pResult, PCRTUINT128U pValue1, uint64_t uValue2)
     129 * @param   uValue2             The second value, 32-bit.
     130 */
     131DECLINLINE(PRTUINT64U) RTUInt64AddU32(PRTUINT64U pResult, PCRTUINT64U pValue1, uint32_t uValue2)
    136132{
    137133    pResult->s.Hi = pValue1->s.Hi;
     
    144140
    145141/**
    146  * Subtracts a 128-bit unsigned integer value from another.
     142 * Subtracts a 64-bit unsigned integer value from another.
    147143 *
    148144 * @returns pResult
     
    151147 * @param   pValue2             The subtrahend value.
    152148 */
    153 DECLINLINE(PRTUINT128U) RTUInt128Sub(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)
     149DECLINLINE(PRTUINT64U) RTUInt64Sub(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
    154150{
    155151    pResult->s.Lo = pValue1->s.Lo - pValue2->s.Lo;
     
    162158
    163159/**
    164  * Multiplies two 128-bit unsigned integer values.
     160 * Multiplies two 64-bit unsigned integer values.
    165161 *
    166162 * @returns pResult
     
    169165 * @param   pValue2             The second value.
    170166 */
    171 DECLINLINE(PRTUINT128U) RTUInt128Mul(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)
    172 {
    173     RTUINT64U uTmp;
    174 
    175     /* multiply all dwords in v1 by v2.dw0. */
    176     pResult->s.Lo = (uint64_t)pValue1->DWords.dw0 * pValue2->DWords.dw0;
    177 
    178     uTmp.u = (uint64_t)pValue1->DWords.dw1 * pValue2->DWords.dw0;
    179     pResult->DWords.dw3 = 0;
    180     pResult->DWords.dw2 = uTmp.DWords.dw1;
    181     pResult->DWords.dw1 += uTmp.DWords.dw0;
    182     if (pResult->DWords.dw1 < uTmp.DWords.dw0)
    183         if (pResult->DWords.dw2++ == UINT32_MAX)
    184             pResult->DWords.dw3++;
    185 
    186     pResult->s.Hi += (uint64_t)pValue1->DWords.dw2 * pValue2->DWords.dw0;
    187     pResult->DWords.dw3     += pValue1->DWords.dw3 * pValue2->DWords.dw0;
    188 
    189     /* multiply dw0, dw1 & dw2 in v1 by v2.dw1. */
    190     uTmp.u = (uint64_t)pValue1->DWords.dw0 * pValue2->DWords.dw1;
    191     pResult->DWords.dw1 += uTmp.DWords.dw0;
    192     if (pResult->DWords.dw1 < uTmp.DWords.dw0)
    193         if (pResult->DWords.dw2++ == UINT32_MAX)
    194             pResult->DWords.dw3++;
    195 
    196     pResult->DWords.dw2 += uTmp.DWords.dw1;
    197     if (pResult->DWords.dw2 < uTmp.DWords.dw1)
    198         pResult->DWords.dw3++;
    199 
    200     pResult->s.Hi += (uint64_t)pValue1->DWords.dw1 * pValue2->DWords.dw1;
    201     pResult->DWords.dw3     += pValue1->DWords.dw2 * pValue2->DWords.dw1;
    202 
    203     /* multiply dw0 & dw1 in v1 by v2.dw2. */
    204     pResult->s.Hi += (uint64_t)pValue1->DWords.dw0 * pValue2->DWords.dw2;
    205     pResult->DWords.dw3     += pValue1->DWords.dw1 * pValue2->DWords.dw2;
    206 
    207     /* multiply dw0 in v1 by v2.dw3. */
    208     pResult->DWords.dw3     += pValue1->DWords.dw0 * pValue2->DWords.dw3;
    209 
    210     return pResult;
    211 }
    212 
    213 
    214 /**
    215  * Multiplies an 128-bit unsigned integer by a 64-bit unsigned integer value.
     167DECLINLINE(PRTUINT64U) RTUInt64Mul(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     168{
     169    RTUINT32U uTmp;
     170
     171    /* multiply all words in v1 by v2.w0. */
     172    pResult->s.Lo = (uint32_t)pValue1->Words.w0 * pValue2->Words.w0;
     173
     174    uTmp.u = (uint32_t)pValue1->Words.w1 * pValue2->Words.w0;
     175    pResult->Words.w3 = 0;
     176    pResult->Words.w2 = uTmp.Words.w1;
     177    pResult->Words.w1 += uTmp.Words.w0;
     178    if (pResult->Words.w1 < uTmp.Words.w0)
     179        if (pResult->Words.w2++ == UINT16_MAX)
     180            pResult->Words.w3++;
     181
     182    pResult->s.Hi += (uint32_t)pValue1->Words.w2 * pValue2->Words.w0;
     183    pResult->Words.w3       += pValue1->Words.w3 * pValue2->Words.w0;
     184
     185    /* multiply w0, w1 & w2 in v1 by v2.w1. */
     186    uTmp.u = (uint32_t)pValue1->Words.w0 * pValue2->Words.w1;
     187    pResult->Words.w1 += uTmp.Words.w0;
     188    if (pResult->Words.w1 < uTmp.Words.w0)
     189        if (pResult->Words.w2++ == UINT16_MAX)
     190            pResult->Words.w3++;
     191
     192    pResult->Words.w2 += uTmp.Words.w1;
     193    if (pResult->Words.w2 < uTmp.Words.w1)
     194        pResult->Words.w3++;
     195
     196    pResult->s.Hi += (uint32_t)pValue1->Words.w1 * pValue2->Words.w1;
     197    pResult->Words.w3       += pValue1->Words.w2 * pValue2->Words.w1;
     198
     199    /* multiply w0 & w1 in v1 by v2.w2. */
     200    pResult->s.Hi += (uint32_t)pValue1->Words.w0 * pValue2->Words.w2;
     201    pResult->Words.w3       += pValue1->Words.w1 * pValue2->Words.w2;
     202
     203    /* multiply w0 in v1 by v2.w3. */
     204    pResult->Words.w3       += pValue1->Words.w0 * pValue2->Words.w3;
     205
     206    return pResult;
     207}
     208
     209
     210/**
     211 * Multiplies an 64-bit unsigned integer by a 32-bit unsigned integer value.
    216212 *
    217213 * @returns pResult
    218214 * @param   pResult             The result variable.
    219215 * @param   pValue1             The first value.
    220  * @param   uValue2             The second value, 64-bit.
    221  */
    222 #if defined(RT_ARCH_AMD64)
    223 RTDECL(PRTUINT128U) RTUInt128MulByU64(PRTUINT128U pResult, PCRTUINT128U pValue1, uint64_t uValue2);
    224 #else
    225 DECLINLINE(PRTUINT128U) RTUInt128MulByU64(PRTUINT128U pResult, PCRTUINT128U pValue1, uint64_t uValue2)
    226 {
    227     uint32_t const uLoValue2 = (uint32_t)uValue2;
    228     uint32_t const uHiValue2 = (uint32_t)(uValue2 >> 32);
    229     RTUINT64U uTmp;
    230 
    231     /* multiply all dwords in v1 by uLoValue1. */
    232     pResult->s.Lo = (uint64_t)pValue1->DWords.dw0 * uLoValue2;
    233 
    234     uTmp.u = (uint64_t)pValue1->DWords.dw1 * uLoValue2;
    235     pResult->DWords.dw3 = 0;
    236     pResult->DWords.dw2 = uTmp.DWords.dw1;
    237     pResult->DWords.dw1 += uTmp.DWords.dw0;
    238     if (pResult->DWords.dw1 < uTmp.DWords.dw0)
    239         if (pResult->DWords.dw2++ == UINT32_MAX)
    240             pResult->DWords.dw3++;
    241 
    242     pResult->s.Hi += (uint64_t)pValue1->DWords.dw2 * uLoValue2;
    243     pResult->DWords.dw3     += pValue1->DWords.dw3 * uLoValue2;
    244 
    245     /* multiply dw0, dw1 & dw2 in v1 by uHiValue2. */
    246     uTmp.u = (uint64_t)pValue1->DWords.dw0 * uHiValue2;
    247     pResult->DWords.dw1 += uTmp.DWords.dw0;
    248     if (pResult->DWords.dw1 < uTmp.DWords.dw0)
    249         if (pResult->DWords.dw2++ == UINT32_MAX)
    250             pResult->DWords.dw3++;
    251 
    252     pResult->DWords.dw2 += uTmp.DWords.dw1;
    253     if (pResult->DWords.dw2 < uTmp.DWords.dw1)
    254         pResult->DWords.dw3++;
    255 
    256     pResult->s.Hi += (uint64_t)pValue1->DWords.dw1 * uHiValue2;
    257     pResult->DWords.dw3     += pValue1->DWords.dw2 * uHiValue2;
    258 
    259     return pResult;
    260 }
    261 #endif
    262 
    263 
    264 /**
    265  * Multiplies two 64-bit unsigned integer values with 128-bit precision.
    266  *
    267  * @returns pResult
    268  * @param   pResult             The result variable.
    269  * @param   uValue1             The first value. 64-bit.
    270  * @param   uValue2             The second value, 64-bit.
    271  */
    272 DECLINLINE(PRTUINT128U) RTUInt128MulU64ByU64(PRTUINT128U pResult, uint64_t uValue1, uint64_t uValue2)
    273 {
    274 #ifdef RT_ARCH_AMD64
    275     pResult->s.Lo = ASMMult2xU64Ret2xU64(uValue1, uValue2, &pResult->s.Hi);
    276 #else
    277     uint32_t const uLoValue1 = (uint32_t)uValue1;
    278     uint32_t const uHiValue1 = (uint32_t)(uValue1 >> 32);
    279     uint32_t const uLoValue2 = (uint32_t)uValue2;
    280     uint32_t const uHiValue2 = (uint32_t)(uValue2 >> 32);
    281     RTUINT64U uTmp;
     216 * @param   uValue2             The second value, 32-bit.
     217 */
     218DECLINLINE(PRTUINT64U) RTUInt64MulByU32(PRTUINT64U pResult, PCRTUINT64U pValue1, uint32_t uValue2)
     219{
     220    uint16_t const uLoValue2 = (uint16_t)uValue2;
     221    uint16_t const uHiValue2 = (uint16_t)(uValue2 >> 16);
     222    RTUINT32U uTmp;
     223
     224    /* multiply all words in v1 by uLoValue1. */
     225    pResult->s.Lo = (uint32_t)pValue1->Words.w0 * uLoValue2;
     226
     227    uTmp.u = (uint32_t)pValue1->Words.w1 * uLoValue2;
     228    pResult->Words.w3 = 0;
     229    pResult->Words.w2 = uTmp.Words.w1;
     230    pResult->Words.w1 += uTmp.Words.w0;
     231    if (pResult->Words.w1 < uTmp.Words.w0)
     232        if (pResult->Words.w2++ == UINT16_MAX)
     233            pResult->Words.w3++;
     234
     235    pResult->s.Hi += (uint32_t)pValue1->Words.w2 * uLoValue2;
     236    pResult->Words.w3       += pValue1->Words.w3 * uLoValue2;
     237
     238    /* multiply w0, w1 & w2 in v1 by uHiValue2. */
     239    uTmp.u = (uint32_t)pValue1->Words.w0 * uHiValue2;
     240    pResult->Words.w1 += uTmp.Words.w0;
     241    if (pResult->Words.w1 < uTmp.Words.w0)
     242        if (pResult->Words.w2++ == UINT16_MAX)
     243            pResult->Words.w3++;
     244
     245    pResult->Words.w2 += uTmp.Words.w1;
     246    if (pResult->Words.w2 < uTmp.Words.w1)
     247        pResult->Words.w3++;
     248
     249    pResult->s.Hi += (uint32_t)pValue1->Words.w1 * uHiValue2;
     250    pResult->Words.w3     += pValue1->Words.w2 * uHiValue2;
     251
     252    return pResult;
     253}
     254
     255
     256/**
     257 * Multiplies two 32-bit unsigned integer values with 64-bit precision.
     258 *
     259 * @returns pResult
     260 * @param   pResult             The result variable.
     261 * @param   uValue1             The first value. 32-bit.
     262 * @param   uValue2             The second value, 32-bit.
     263 */
     264DECLINLINE(PRTUINT64U) RTUInt64MulU32ByU32(PRTUINT64U pResult, uint32_t uValue1, uint32_t uValue2)
     265{
     266    uint16_t const uLoValue1 = (uint16_t)uValue1;
     267    uint16_t const uHiValue1 = (uint16_t)(uValue1 >> 16);
     268    uint16_t const uLoValue2 = (uint16_t)uValue2;
     269    uint16_t const uHiValue2 = (uint16_t)(uValue2 >> 16);
     270    RTUINT32U uTmp;
    282271
    283272    /* Multiply uLoValue1 and uHiValue1 by uLoValue1. */
    284     pResult->s.Lo = (uint64_t)uLoValue1 * uLoValue2;
    285 
    286     uTmp.u = (uint64_t)uHiValue1 * uLoValue2;
    287     pResult->DWords.dw3 = 0;
    288     pResult->DWords.dw2 = uTmp.DWords.dw1;
    289     pResult->DWords.dw1 += uTmp.DWords.dw0;
    290     if (pResult->DWords.dw1 < uTmp.DWords.dw0)
    291         if (pResult->DWords.dw2++ == UINT32_MAX)
    292             pResult->DWords.dw3++;
     273    pResult->s.Lo = (uint32_t)uLoValue1 * uLoValue2;
     274
     275    uTmp.u = (uint32_t)uHiValue1 * uLoValue2;
     276    pResult->Words.w3 = 0;
     277    pResult->Words.w2 = uTmp.Words.w1;
     278    pResult->Words.w1 += uTmp.Words.w0;
     279    if (pResult->Words.w1 < uTmp.Words.w0)
     280        if (pResult->Words.w2++ == UINT16_MAX)
     281            pResult->Words.w3++;
    293282
    294283    /* Multiply uLoValue1 and uHiValue1 by uHiValue2. */
    295     uTmp.u = (uint64_t)uLoValue1 * uHiValue2;
    296     pResult->DWords.dw1 += uTmp.DWords.dw0;
    297     if (pResult->DWords.dw1 < uTmp.DWords.dw0)
    298         if (pResult->DWords.dw2++ == UINT32_MAX)
    299             pResult->DWords.dw3++;
    300 
    301     pResult->DWords.dw2 += uTmp.DWords.dw1;
    302     if (pResult->DWords.dw2 < uTmp.DWords.dw1)
    303         pResult->DWords.dw3++;
    304 
    305     pResult->s.Hi += (uint64_t)uHiValue1 * uHiValue2;
    306 #endif
    307     return pResult;
    308 }
    309 
    310 
    311 DECLINLINE(PRTUINT128U) RTUInt128DivRem(PRTUINT128U pQuotient, PRTUINT128U pRemainder, PCRTUINT128U pValue1, PCRTUINT128U pValue2);
    312 
    313 /**
    314  * Divides a 128-bit unsigned integer value by another.
     284    uTmp.u = (uint32_t)uLoValue1 * uHiValue2;
     285    pResult->Words.w1 += uTmp.Words.w0;
     286    if (pResult->Words.w1 < uTmp.Words.w0)
     287        if (pResult->Words.w2++ == UINT16_MAX)
     288            pResult->Words.w3++;
     289
     290    pResult->Words.w2 += uTmp.Words.w1;
     291    if (pResult->Words.w2 < uTmp.Words.w1)
     292        pResult->Words.w3++;
     293
     294    pResult->s.Hi += (uint32_t)uHiValue1 * uHiValue2;
     295    return pResult;
     296}
     297
     298
     299DECLINLINE(PRTUINT64U) RTUInt64DivRem(PRTUINT64U pQuotient, PRTUINT64U pRemainder, PCRTUINT64U pValue1, PCRTUINT64U pValue2);
     300
     301/**
     302 * Divides a 64-bit unsigned integer value by another.
    315303 *
    316304 * @returns pResult
     
    319307 * @param   pValue2             The divisor value.
    320308 */
    321 DECLINLINE(PRTUINT128U) RTUInt128Div(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)
    322 {
    323     RTUINT128U Ignored;
    324     return RTUInt128DivRem(pResult, &Ignored, pValue1, pValue2);
    325 }
    326 
    327 
    328 /**
    329  * Divides a 128-bit unsigned integer value by another, returning the remainder.
     309DECLINLINE(PRTUINT64U) RTUInt64Div(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     310{
     311    RTUINT64U Ignored;
     312    return RTUInt64DivRem(pResult, &Ignored, pValue1, pValue2);
     313}
     314
     315
     316/**
     317 * Divides a 64-bit unsigned integer value by another, returning the remainder.
    330318 *
    331319 * @returns pResult
     
    334322 * @param   pValue2             The divisor value.
    335323 */
    336 DECLINLINE(PRTUINT128U) RTUInt128Mod(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)
    337 {
    338     RTUINT128U Ignored;
    339     RTUInt128DivRem(&Ignored, pResult, pValue1, pValue2);
    340     return pResult;
    341 }
    342 
    343 
    344 /**
    345  * Bitwise AND of two 128-bit unsigned integer values.
     324DECLINLINE(PRTUINT64U) RTUInt64Mod(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     325{
     326    RTUINT64U Ignored;
     327    RTUInt64DivRem(&Ignored, pResult, pValue1, pValue2);
     328    return pResult;
     329}
     330
     331
     332/**
     333 * Bitwise AND of two 64-bit unsigned integer values.
    346334 *
    347335 * @returns pResult
     
    350338 * @param   pValue2             The second value.
    351339 */
    352 DECLINLINE(PRTUINT128U) RTUInt128And(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)
     340DECLINLINE(PRTUINT64U) RTUInt64And(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
    353341{
    354342    pResult->s.Hi = pValue1->s.Hi & pValue2->s.Hi;
     
    359347
    360348/**
    361  * Bitwise OR of two 128-bit unsigned integer values.
     349 * Bitwise OR of two 64-bit unsigned integer values.
    362350 *
    363351 * @returns pResult
     
    366354 * @param   pValue2             The second value.
    367355 */
    368 DECLINLINE(PRTUINT128U) RTUInt128Or( PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)
     356DECLINLINE(PRTUINT64U) RTUInt64Or( PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
    369357{
    370358    pResult->s.Hi = pValue1->s.Hi | pValue2->s.Hi;
     
    375363
    376364/**
    377  * Bitwise XOR of two 128-bit unsigned integer values.
     365 * Bitwise XOR of two 64-bit unsigned integer values.
    378366 *
    379367 * @returns pResult
     
    382370 * @param   pValue2             The second value.
    383371 */
    384 DECLINLINE(PRTUINT128U) RTUInt128Xor(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)
     372DECLINLINE(PRTUINT64U) RTUInt64Xor(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
    385373{
    386374    pResult->s.Hi = pValue1->s.Hi ^ pValue2->s.Hi;
     
    391379
    392380/**
    393  * Shifts a 128-bit unsigned integer value @a cBits to the left.
     381 * Shifts a 64-bit unsigned integer value @a cBits to the left.
    394382 *
    395383 * @returns pResult
     
    398386 * @param   cBits               The number of bits to shift it.
    399387 */
    400 DECLINLINE(PRTUINT128U) RTUInt128ShiftLeft(PRTUINT128U pResult, PCRTUINT128U pValue, int cBits)
    401 {
    402     cBits &= 127;
    403     if (cBits < 64)
     388DECLINLINE(PRTUINT64U) RTUInt64ShiftLeft(PRTUINT64U pResult, PCRTUINT64U pValue, int cBits)
     389{
     390    cBits &= 63;
     391    if (cBits < 32)
    404392    {
    405393        pResult->s.Lo = pValue->s.Lo << cBits;
    406         pResult->s.Hi = (pValue->s.Hi << cBits) | (pValue->s.Lo >> (64 - cBits));
     394        pResult->s.Hi = (pValue->s.Hi << cBits) | (pValue->s.Lo >> (32 - cBits));
    407395    }
    408396    else
    409397    {
    410398        pResult->s.Lo = 0;
    411         pResult->s.Hi = pValue->s.Lo << (cBits - 64);
    412     }
    413     return pResult;
    414 }
    415 
    416 
    417 /**
    418  * Shifts a 128-bit unsigned integer value @a cBits to the right.
     399        pResult->s.Hi = pValue->s.Lo << (cBits - 32);
     400    }
     401    return pResult;
     402}
     403
     404
     405/**
     406 * Shifts a 64-bit unsigned integer value @a cBits to the right.
    419407 *
    420408 * @returns pResult
     
    423411 * @param   cBits               The number of bits to shift it.
    424412 */
    425 DECLINLINE(PRTUINT128U) RTUInt128ShiftRight(PRTUINT128U pResult, PCRTUINT128U pValue, int cBits)
    426 {
    427     cBits &= 127;
    428     if (cBits < 64)
     413DECLINLINE(PRTUINT64U) RTUInt64ShiftRight(PRTUINT64U pResult, PCRTUINT64U pValue, int cBits)
     414{
     415    cBits &= 63;
     416    if (cBits < 32)
    429417    {
    430418        pResult->s.Hi = pValue->s.Hi >> cBits;
    431         pResult->s.Lo = (pValue->s.Lo >> cBits) | (pValue->s.Hi << (64 - cBits));
     419        pResult->s.Lo = (pValue->s.Lo >> cBits) | (pValue->s.Hi << (32 - cBits));
    432420    }
    433421    else
    434422    {
    435423        pResult->s.Hi = 0;
    436         pResult->s.Lo = pValue->s.Hi >> (cBits - 64);
     424        pResult->s.Lo = pValue->s.Hi >> (cBits - 32);
    437425    }
    438426    return pResult;
     
    447435 * @param   pValue              The value.
    448436 */
    449 DECLINLINE(PRTUINT128U) RTUInt128BooleanNot(PRTUINT128U pResult, PCRTUINT128U pValue)
    450 {
     437DECLINLINE(PRTUINT64U) RTUInt64BooleanNot(PRTUINT64U pResult, PCRTUINT64U pValue)
     438{
     439    pResult->s.Lo = pValue->s.Lo || pValue->s.Hi ? 0 : 1;
    451440    pResult->s.Hi = 0;
    452     pResult->s.Lo = pValue->s.Lo || pValue->s.Hi ? 0 : 1;
    453     return pResult;
    454 }
    455 
    456 
    457 /**
    458  * Bitwise not (flips each bit of the 128 bits).
     441    return pResult;
     442}
     443
     444
     445/**
     446 * Bitwise not (flips each bit of the 64 bits).
    459447 *
    460448 * @returns pResult.
     
    462450 * @param   pValue              The value.
    463451 */
    464 DECLINLINE(PRTUINT128U) RTUInt128BitwiseNot(PRTUINT128U pResult, PCRTUINT128U pValue)
     452DECLINLINE(PRTUINT64U) RTUInt64BitwiseNot(PRTUINT64U pResult, PCRTUINT64U pValue)
    465453{
    466454    pResult->s.Hi = ~pValue->s.Hi;
     
    471459
    472460/**
    473  * Assigns one 128-bit unsigned integer value to another.
     461 * Assigns one 64-bit unsigned integer value to another.
    474462 *
    475463 * @returns pResult
     
    477465 * @param   pValue              The value to assign.
    478466 */
    479 DECLINLINE(PRTUINT128U) RTUInt128Assign(PRTUINT128U pResult, PCRTUINT128U pValue)
    480 {
    481 #if ARCH_BITS >= 64
     467DECLINLINE(PRTUINT64U) RTUInt64Assign(PRTUINT64U pResult, PCRTUINT64U pValue)
     468{
     469#if ARCH_BITS >= 32
    482470    pResult->s.Hi = pValue->s.Hi;
    483471    pResult->s.Lo = pValue->s.Lo;
    484472#else
    485     pResult->DWords.dw0 = pValue->DWords.dw0;
    486     pResult->DWords.dw1 = pValue->DWords.dw1;
    487     pResult->DWords.dw2 = pValue->DWords.dw2;
    488     pResult->DWords.dw3 = pValue->DWords.dw3;
    489 #endif
    490     return pResult;
    491 }
    492 
    493 
    494 /**
    495  * Assigns a boolean value to 128-bit unsigned integer.
     473    pResult->Words.w0 = pValue->Words.w0;
     474    pResult->Words.w1 = pValue->Words.w1;
     475    pResult->Words.w2 = pValue->Words.w2;
     476    pResult->Words.w3 = pValue->Words.w3;
     477#endif
     478    return pResult;
     479}
     480
     481
     482/**
     483 * Assigns a boolean value to 64-bit unsigned integer.
    496484 *
    497485 * @returns pValueResult
     
    499487 * @param   fValue              The boolean value.
    500488 */
    501 DECLINLINE(PRTUINT128U) RTUInt128AssignBoolean(PRTUINT128U pValueResult, bool fValue)
    502 {
    503 #if ARCH_BITS >= 64
     489DECLINLINE(PRTUINT64U) RTUInt64AssignBoolean(PRTUINT64U pValueResult, bool fValue)
     490{
     491#if ARCH_BITS >= 32
    504492    pValueResult->s.Lo = fValue;
    505493    pValueResult->s.Hi = 0;
    506494#else
    507     pValueResult->DWords.dw0 = fValue;
    508     pValueResult->DWords.dw1 = 0;
    509     pValueResult->DWords.dw2 = 0;
    510     pValueResult->DWords.dw3 = 0;
     495    pValueResult->Words.w0 = fValue;
     496    pValueResult->Words.w1 = 0;
     497    pValueResult->Words.w2 = 0;
     498    pValueResult->Words.w3 = 0;
    511499#endif
    512500    return pValueResult;
     
    515503
    516504/**
    517  * Assigns a 8-bit unsigned integer value to 128-bit unsigned integer.
     505 * Assigns a 8-bit unsigned integer value to 64-bit unsigned integer.
    518506 *
    519507 * @returns pValueResult
     
    521509 * @param   u8Value             The 8-bit unsigned integer value.
    522510 */
    523 DECLINLINE(PRTUINT128U) RTUInt128AssignU8(PRTUINT128U pValueResult, uint8_t u8Value)
    524 {
    525 #if ARCH_BITS >= 64
     511DECLINLINE(PRTUINT64U) RTUInt64AssignU8(PRTUINT64U pValueResult, uint8_t u8Value)
     512{
     513#if ARCH_BITS >= 32
    526514    pValueResult->s.Lo = u8Value;
    527515    pValueResult->s.Hi = 0;
    528516#else
    529     pValueResult->DWords.dw0 = u8Value;
    530     pValueResult->DWords.dw1 = 0;
    531     pValueResult->DWords.dw2 = 0;
    532     pValueResult->DWords.dw3 = 0;
     517    pValueResult->Words.w0 = u8Value;
     518    pValueResult->Words.w1 = 0;
     519    pValueResult->Words.w2 = 0;
     520    pValueResult->Words.w3 = 0;
    533521#endif
    534522    return pValueResult;
     
    537525
    538526/**
    539  * Assigns a 16-bit unsigned integer value to 128-bit unsigned integer.
     527 * Assigns a 16-bit unsigned integer value to 64-bit unsigned integer.
    540528 *
    541529 * @returns pValueResult
     
    543531 * @param   u16Value            The 16-bit unsigned integer value.
    544532 */
    545 DECLINLINE(PRTUINT128U) RTUInt128AssignU16(PRTUINT128U pValueResult, uint16_t u16Value)
    546 {
    547 #if ARCH_BITS >= 64
     533DECLINLINE(PRTUINT64U) RTUInt64AssignU16(PRTUINT64U pValueResult, uint16_t u16Value)
     534{
     535#if ARCH_BITS >= 32
    548536    pValueResult->s.Lo = u16Value;
    549537    pValueResult->s.Hi = 0;
    550538#else
    551     pValueResult->DWords.dw0 = u16Value;
    552     pValueResult->DWords.dw1 = 0;
    553     pValueResult->DWords.dw2 = 0;
    554     pValueResult->DWords.dw3 = 0;
     539    pValueResult->Words.w0 = u16Value;
     540    pValueResult->Words.w1 = 0;
     541    pValueResult->Words.w2 = 0;
     542    pValueResult->Words.w3 = 0;
    555543#endif
    556544    return pValueResult;
     
    559547
    560548/**
    561  * Assigns a 16-bit unsigned integer value to 128-bit unsigned integer.
     549 * Assigns a 32-bit unsigned integer value to 64-bit unsigned integer.
    562550 *
    563551 * @returns pValueResult
     
    565553 * @param   u32Value            The 32-bit unsigned integer value.
    566554 */
    567 DECLINLINE(PRTUINT128U) RTUInt128AssignU32(PRTUINT128U pValueResult, uint32_t u32Value)
    568 {
    569 #if ARCH_BITS >= 64
     555DECLINLINE(PRTUINT64U) RTUInt64AssignU32(PRTUINT64U pValueResult, uint32_t u32Value)
     556{
     557#if ARCH_BITS >= 32
    570558    pValueResult->s.Lo = u32Value;
    571559    pValueResult->s.Hi = 0;
    572560#else
    573     pValueResult->DWords.dw0 = u32Value;
    574     pValueResult->DWords.dw1 = 0;
    575     pValueResult->DWords.dw2 = 0;
    576     pValueResult->DWords.dw3 = 0;
     561    pValueResult->Words.w0 = (uint16_t)u32Value;
     562    pValueResult->Words.w1 = u32Value >> 16;
     563    pValueResult->Words.w2 = 0;
     564    pValueResult->Words.w3 = 0;
    577565#endif
    578566    return pValueResult;
     
    581569
    582570/**
    583  * Assigns a 64-bit unsigned integer value to 128-bit unsigned integer.
    584  *
    585  * @returns pValueResult
    586  * @param   pValueResult        The result variable.
    587  * @param   u64Value            The 64-bit unsigned integer value.
    588  */
    589 DECLINLINE(PRTUINT128U) RTUInt128AssignU64(PRTUINT128U pValueResult, uint64_t u64Value)
    590 {
    591     pValueResult->s.Lo = u64Value;
    592     pValueResult->s.Hi = 0;
    593     return pValueResult;
    594 }
    595 
    596 
    597 /**
    598  * Adds two 128-bit unsigned integer values, storing the result in the first.
     571 * Adds two 64-bit unsigned integer values, storing the result in the first.
    599572 *
    600573 * @returns pValue1Result.
     
    602575 * @param   pValue2         The second value.
    603576 */
    604 DECLINLINE(PRTUINT128U) RTUInt128AssignAdd(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)
    605 {
    606     uint64_t const uTmp = pValue1Result->s.Lo;
     577DECLINLINE(PRTUINT64U) RTUInt64AssignAdd(PRTUINT64U pValue1Result, PCRTUINT64U pValue2)
     578{
     579    uint32_t const uTmp = pValue1Result->s.Lo;
    607580    pValue1Result->s.Lo += pValue2->s.Lo;
    608581    if (pValue1Result->s.Lo < uTmp)
     
    614587
    615588/**
    616  * Adds a 64-bit unsigned integer value to a 128-bit unsigned integer values,
    617  * storing the result in the 128-bit one.
    618  *
    619  * @returns pValue1Result.
    620  * @param   pValue1Result   The first value and result.
    621  * @param   uValue2         The second value, 64-bit.
    622  */
    623 DECLINLINE(PRTUINT128U) RTUInt128AssignAddU64(PRTUINT128U pValue1Result, uint64_t uValue2)
    624 {
    625     pValue1Result->s.Lo += uValue2;
    626     if (pValue1Result->s.Lo < uValue2)
    627         pValue1Result->s.Hi++;
    628     return pValue1Result;
    629 }
    630 
    631 
    632 /**
    633  * Subtracts two 128-bit unsigned integer values, storing the result in the
     589 * Subtracts two 64-bit unsigned integer values, storing the result in the
    634590 * first.
    635591 *
     
    638594 * @param   pValue2         The subtrahend value.
    639595 */
    640 DECLINLINE(PRTUINT128U) RTUInt128AssignSub(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)
    641 {
    642     uint64_t const uTmp = pValue1Result->s.Lo;
     596DECLINLINE(PRTUINT64U) RTUInt64AssignSub(PRTUINT64U pValue1Result, PCRTUINT64U pValue2)
     597{
     598    uint32_t const uTmp = pValue1Result->s.Lo;
    643599    pValue1Result->s.Lo -= pValue2->s.Lo;
    644600    if (pValue1Result->s.Lo > uTmp)
     
    650606
    651607/**
    652  * Multiplies two 128-bit unsigned integer values, storing the result in the
     608 * Multiplies two 64-bit unsigned integer values, storing the result in the
    653609 * first.
    654610 *
     
    657613 * @param   pValue2         The second value.
    658614 */
    659 DECLINLINE(PRTUINT128U) RTUInt128AssignMul(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)
    660 {
    661     RTUINT128U Result;
    662     RTUInt128Mul(&Result, pValue1Result, pValue2);
     615DECLINLINE(PRTUINT64U) RTUInt64AssignMul(PRTUINT64U pValue1Result, PCRTUINT64U pValue2)
     616{
     617    RTUINT64U Result;
     618    RTUInt64Mul(&Result, pValue1Result, pValue2);
    663619    *pValue1Result = Result;
    664620    return pValue1Result;
     
    667623
    668624/**
    669  * Divides a 128-bit unsigned integer value by another, storing the result in
     625 * Divides a 64-bit unsigned integer value by another, storing the result in
    670626 * the first.
    671627 *
     
    674630 * @param   pValue2         The divisor value.
    675631 */
    676 DECLINLINE(PRTUINT128U) RTUInt128AssignDiv(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)
    677 {
    678     RTUINT128U Result;
    679     RTUINT128U Ignored;
    680     RTUInt128DivRem(&Result, &Ignored, pValue1Result, pValue2);
     632DECLINLINE(PRTUINT64U) RTUInt64AssignDiv(PRTUINT64U pValue1Result, PCRTUINT64U pValue2)
     633{
     634    RTUINT64U Result;
     635    RTUINT64U Ignored;
     636    RTUInt64DivRem(&Result, &Ignored, pValue1Result, pValue2);
    681637    *pValue1Result = Result;
    682638    return pValue1Result;
     
    685641
    686642/**
    687  * Divides a 128-bit unsigned integer value by another, storing the remainder in
     643 * Divides a 64-bit unsigned integer value by another, storing the remainder in
    688644 * the first.
    689645 *
     
    692648 * @param   pValue2         The divisor value.
    693649 */
    694 DECLINLINE(PRTUINT128U) RTUInt128AssignMod(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)
    695 {
    696     RTUINT128U Ignored;
    697     RTUINT128U Result;
    698     RTUInt128DivRem(&Ignored, &Result, pValue1Result, pValue2);
     650DECLINLINE(PRTUINT64U) RTUInt64AssignMod(PRTUINT64U pValue1Result, PCRTUINT64U pValue2)
     651{
     652    RTUINT64U Ignored;
     653    RTUINT64U Result;
     654    RTUInt64DivRem(&Ignored, &Result, pValue1Result, pValue2);
    699655    *pValue1Result = Result;
    700656    return pValue1Result;
     
    703659
    704660/**
    705  * Performs a bitwise AND of two 128-bit unsigned integer values and assigned
     661 * Performs a bitwise AND of two 64-bit unsigned integer values and assigned
    706662 * the result to the first one.
    707663 *
     
    710666 * @param   pValue2         The second value.
    711667 */
    712 DECLINLINE(PRTUINT128U) RTUInt128AssignAnd(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)
    713 {
    714 #if ARCH_BITS >= 64
     668DECLINLINE(PRTUINT64U) RTUInt64AssignAnd(PRTUINT64U pValue1Result, PCRTUINT64U pValue2)
     669{
     670#if ARCH_BITS >= 32
    715671    pValue1Result->s.Hi &= pValue2->s.Hi;
    716672    pValue1Result->s.Lo &= pValue2->s.Lo;
    717673#else
    718     pValue1Result->DWords.dw0 &= pValue2->DWords.dw0;
    719     pValue1Result->DWords.dw1 &= pValue2->DWords.dw1;
    720     pValue1Result->DWords.dw2 &= pValue2->DWords.dw2;
    721     pValue1Result->DWords.dw3 &= pValue2->DWords.dw3;
     674    pValue1Result->Words.w0 &= pValue2->Words.w0;
     675    pValue1Result->Words.w1 &= pValue2->Words.w1;
     676    pValue1Result->Words.w2 &= pValue2->Words.w2;
     677    pValue1Result->Words.w3 &= pValue2->Words.w3;
    722678#endif
    723679    return pValue1Result;
     
    726682
    727683/**
    728  * Performs a bitwise AND of a 128-bit unsigned integer value and a mask made
    729  * up of the first N bits, assigning the result to the the 128-bit value.
     684 * Performs a bitwise AND of a 64-bit unsigned integer value and a mask made
     685 * up of the first N bits, assigning the result to the the 64-bit value.
    730686 *
    731687 * @returns pValueResult.
     
    734690 *                          bit).
    735691 */
    736 DECLINLINE(PRTUINT128U) RTUInt128AssignAndNFirstBits(PRTUINT128U pValueResult, unsigned cBits)
    737 {
    738     if (cBits <= 64)
    739     {
    740         if (cBits != 64)
    741             pValueResult->s.Lo &= (RT_BIT_64(cBits) - 1);
     692DECLINLINE(PRTUINT64U) RTUInt64AssignAndNFirstBits(PRTUINT64U pValueResult, unsigned cBits)
     693{
     694    if (cBits <= 32)
     695    {
     696        if (cBits != 32)
     697            pValueResult->s.Lo &= (RT_BIT_32(cBits) - 1);
    742698        pValueResult->s.Hi = 0;
    743699    }
    744     else if (cBits < 128)
    745         pValueResult->s.Hi &= (RT_BIT_64(cBits - 64) - 1);
    746 /** @todo \#if ARCH_BITS >= 64 */
     700    else if (cBits < 64)
     701        pValueResult->s.Hi &= (RT_BIT_32(cBits - 32) - 1);
    747702    return pValueResult;
    748703}
     
    750705
    751706/**
    752  * Performs a bitwise OR of two 128-bit unsigned integer values and assigned
     707 * Performs a bitwise OR of two 64-bit unsigned integer values and assigned
    753708 * the result to the first one.
    754709 *
     
    757712 * @param   pValue2         The second value.
    758713 */
    759 DECLINLINE(PRTUINT128U) RTUInt128AssignOr(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)
    760 {
    761 #if ARCH_BITS >= 64
     714DECLINLINE(PRTUINT64U) RTUInt64AssignOr(PRTUINT64U pValue1Result, PCRTUINT64U pValue2)
     715{
     716#if ARCH_BITS >= 32
    762717    pValue1Result->s.Hi |= pValue2->s.Hi;
    763718    pValue1Result->s.Lo |= pValue2->s.Lo;
    764719#else
    765     pValue1Result->DWords.dw0 |= pValue2->DWords.dw0;
    766     pValue1Result->DWords.dw1 |= pValue2->DWords.dw1;
    767     pValue1Result->DWords.dw2 |= pValue2->DWords.dw2;
    768     pValue1Result->DWords.dw3 |= pValue2->DWords.dw3;
     720    pValue1Result->Words.w0 |= pValue2->Words.w0;
     721    pValue1Result->Words.w1 |= pValue2->Words.w1;
     722    pValue1Result->Words.w2 |= pValue2->Words.w2;
     723    pValue1Result->Words.w3 |= pValue2->Words.w3;
    769724#endif
    770725    return pValue1Result;
     
    779734 * @param   iBit            The bit to set (0 based).
    780735 */
    781 DECLINLINE(PRTUINT128U) RTUInt128AssignOrBit(PRTUINT128U pValue1Result, uint32_t iBit)
    782 {
    783 #if ARCH_BITS >= 64
    784     if (iBit >= 64)
    785         pValue1Result->s.Hi |= RT_BIT_64(iBit - 64);
     736DECLINLINE(PRTUINT64U) RTUInt64AssignOrBit(PRTUINT64U pValue1Result, unsigned iBit)
     737{
     738#if ARCH_BITS >= 32
     739    if (iBit >= 32)
     740        pValue1Result->s.Hi |= RT_BIT_32(iBit - 32);
    786741    else
    787         pValue1Result->s.Lo |= RT_BIT_64(iBit);
    788 #else
    789     if (iBit >= 64)
    790     {
    791         if (iBit >= 96)
    792             pValue1Result->DWords.dw3 |= RT_BIT_32(iBit - 96);
    793         else
    794             pValue1Result->DWords.dw2 |= RT_BIT_32(iBit - 64);
     742        pValue1Result->s.Lo |= RT_BIT_32(iBit);
     743#else
     744    if (iBit >= 32)
     745    {
     746        if (iBit >= 48)
     747            pValue1Result->Words.w3 |= UINT16_C(1) << (iBit - 48);
     748        else
     749            pValue1Result->Words.w2 |= UINT16_C(1) << (iBit - 32);
    795750    }
    796751    else
    797752    {
    798         if (iBit >= 32)
    799             pValue1Result->DWords.dw1 |= RT_BIT_32(iBit - 32);
    800         else
    801             pValue1Result->DWords.dw0 |= RT_BIT_32(iBit);
     753        if (iBit >= 16)
     754            pValue1Result->Words.w1 |= UINT16_C(1) << (iBit - 16);
     755        else
     756            pValue1Result->Words.w0 |= UINT16_C(1) << (iBit);
    802757    }
    803758#endif
     
    808763
    809764/**
    810  * Performs a bitwise XOR of two 128-bit unsigned integer values and assigned
     765 * Performs a bitwise XOR of two 64-bit unsigned integer values and assigned
    811766 * the result to the first one.
    812767 *
     
    815770 * @param   pValue2         The second value.
    816771 */
    817 DECLINLINE(PRTUINT128U) RTUInt128AssignXor(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)
    818 {
    819 #if ARCH_BITS >= 64
     772DECLINLINE(PRTUINT64U) RTUInt64AssignXor(PRTUINT64U pValue1Result, PCRTUINT64U pValue2)
     773{
     774#if ARCH_BITS >= 32
    820775    pValue1Result->s.Hi ^= pValue2->s.Hi;
    821776    pValue1Result->s.Lo ^= pValue2->s.Lo;
    822777#else
    823     pValue1Result->DWords.dw0 ^= pValue2->DWords.dw0;
    824     pValue1Result->DWords.dw1 ^= pValue2->DWords.dw1;
    825     pValue1Result->DWords.dw2 ^= pValue2->DWords.dw2;
    826     pValue1Result->DWords.dw3 ^= pValue2->DWords.dw3;
     778    pValue1Result->Words.w0 ^= pValue2->Words.w0;
     779    pValue1Result->Words.w1 ^= pValue2->Words.w1;
     780    pValue1Result->Words.w2 ^= pValue2->Words.w2;
     781    pValue1Result->Words.w3 ^= pValue2->Words.w3;
    827782#endif
    828783    return pValue1Result;
     
    831786
    832787/**
    833  * Performs a bitwise left shift on a 128-bit unsigned integer value, assigning
     788 * Performs a bitwise left shift on a 64-bit unsigned integer value, assigning
    834789 * the result to it.
    835790 *
     
    838793 * @param   cBits           The number of bits to shift.
    839794 */
    840 DECLINLINE(PRTUINT128U) RTUInt128AssignShiftLeft(PRTUINT128U pValueResult, int cBits)
    841 {
    842     RTUINT128U const InVal = *pValueResult;
    843 /** @todo \#if ARCH_BITS >= 64 */
     795DECLINLINE(PRTUINT64U) RTUInt64AssignShiftLeft(PRTUINT64U pValueResult, int cBits)
     796{
     797    RTUINT64U const InVal = *pValueResult;
    844798    if (cBits > 0)
    845799    {
    846800        /* (left shift) */
    847         if (cBits >= 128)
    848             RTUInt128SetZero(pValueResult);
    849         else if (cBits >= 64)
     801        if (cBits >= 64)
     802            RTUInt64SetZero(pValueResult);
     803        else if (cBits >= 32)
    850804        {
    851805            pValueResult->s.Lo  = 0;
    852             pValueResult->s.Hi  = InVal.s.Lo << (cBits - 64);
     806            pValueResult->s.Hi  = InVal.s.Lo << (cBits - 32);
    853807        }
    854808        else
    855809        {
    856810            pValueResult->s.Hi  = InVal.s.Hi << cBits;
    857             pValueResult->s.Hi |= InVal.s.Lo >> (64 - cBits);
     811            pValueResult->s.Hi |= InVal.s.Lo >> (32 - cBits);
    858812            pValueResult->s.Lo  = InVal.s.Lo << cBits;
    859813        }
     
    863817        /* (right shift) */
    864818        cBits = -cBits;
    865         if (cBits >= 128)
    866             RTUInt128SetZero(pValueResult);
    867         else if (cBits >= 64)
     819        if (cBits >= 64)
     820            RTUInt64SetZero(pValueResult);
     821        else if (cBits >= 32)
    868822        {
    869823            pValueResult->s.Hi  = 0;
    870             pValueResult->s.Lo  = InVal.s.Hi >> (cBits - 64);
     824            pValueResult->s.Lo  = InVal.s.Hi >> (cBits - 32);
    871825        }
    872826        else
    873827        {
    874828            pValueResult->s.Lo  = InVal.s.Lo >> cBits;
    875             pValueResult->s.Lo |= InVal.s.Hi << (64 - cBits);
     829            pValueResult->s.Lo |= InVal.s.Hi << (32 - cBits);
    876830            pValueResult->s.Hi  = InVal.s.Hi >> cBits;
    877831        }
     
    882836
    883837/**
    884  * Performs a bitwise left shift on a 128-bit unsigned integer value, assigning
     838 * Performs a bitwise left shift on a 64-bit unsigned integer value, assigning
    885839 * the result to it.
    886840 *
     
    889843 * @param   cBits           The number of bits to shift.
    890844 */
    891 DECLINLINE(PRTUINT128U) RTUInt128AssignShiftRight(PRTUINT128U pValueResult, int cBits)
    892 {
    893     return RTUInt128AssignShiftLeft(pValueResult, -cBits);
    894 }
    895 
    896 
    897 /**
    898  * Performs a bitwise NOT on a 128-bit unsigned integer value, assigning the
     845DECLINLINE(PRTUINT64U) RTUInt64AssignShiftRight(PRTUINT64U pValueResult, int cBits)
     846{
     847    return RTUInt64AssignShiftLeft(pValueResult, -cBits);
     848}
     849
     850
     851/**
     852 * Performs a bitwise NOT on a 64-bit unsigned integer value, assigning the
    899853 * result to it.
    900854 *
     
    902856 * @param   pValueResult    The value and result.
    903857 */
    904 DECLINLINE(PRTUINT128U) RTUInt128AssignBitwiseNot(PRTUINT128U pValueResult)
    905 {
    906 #if ARCH_BITS >= 64
     858DECLINLINE(PRTUINT64U) RTUInt64AssignBitwiseNot(PRTUINT64U pValueResult)
     859{
     860#if ARCH_BITS >= 32
    907861    pValueResult->s.Hi = ~pValueResult->s.Hi;
    908862    pValueResult->s.Lo = ~pValueResult->s.Lo;
    909863#else
    910     pValueResult->DWords.dw0 = ~pValueResult->DWords.dw0;
    911     pValueResult->DWords.dw1 = ~pValueResult->DWords.dw1;
    912     pValueResult->DWords.dw2 = ~pValueResult->DWords.dw2;
    913     pValueResult->DWords.dw3 = ~pValueResult->DWords.dw3;
     864    pValueResult->Words.w0 = ~pValueResult->Words.w0;
     865    pValueResult->Words.w1 = ~pValueResult->Words.w1;
     866    pValueResult->Words.w2 = ~pValueResult->Words.w2;
     867    pValueResult->Words.w3 = ~pValueResult->Words.w3;
    914868#endif
    915869    return pValueResult;
     
    918872
    919873/**
    920  * Performs a boolean NOT on a 128-bit unsigned integer value, assigning the
     874 * Performs a boolean NOT on a 64-bit unsigned integer value, assigning the
    921875 * result to it.
    922876 *
     
    924878 * @param   pValueResult    The value and result.
    925879 */
    926 DECLINLINE(PRTUINT128U) RTUInt128AssignBooleanNot(PRTUINT128U pValueResult)
    927 {
    928     return RTUInt128AssignBoolean(pValueResult, RTUInt128IsZero(pValueResult));
    929 }
    930 
    931 
    932 /**
    933  * Compares two 128-bit unsigned integer values.
     880DECLINLINE(PRTUINT64U) RTUInt64AssignBooleanNot(PRTUINT64U pValueResult)
     881{
     882    return RTUInt64AssignBoolean(pValueResult, RTUInt64IsZero(pValueResult));
     883}
     884
     885
     886/**
     887 * Compares two 64-bit unsigned integer values.
    934888 *
    935889 * @retval  0 if equal.
     
    940894 * @param   pValue2             The second value.
    941895 */
    942 DECLINLINE(int) RTUInt128Compare(PCRTUINT128U pValue1, PCRTUINT128U pValue2)
    943 {
    944 #if ARCH_BITS >= 64
     896DECLINLINE(int) RTUInt64Compare(PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     897{
     898#if ARCH_BITS >= 32
    945899    if (pValue1->s.Hi != pValue2->s.Hi)
    946900        return pValue1->s.Hi > pValue2->s.Hi ? 1 : -1;
     
    949903    return 0;
    950904#else
    951     if (pValue1->DWords.dw3 != pValue2->DWords.dw3)
    952         return pValue1->DWords.dw3 > pValue2->DWords.dw3 ? 1 : -1;
    953     if (pValue1->DWords.dw2 != pValue2->DWords.dw2)
    954         return pValue1->DWords.dw2 > pValue2->DWords.dw2 ? 1 : -1;
    955     if (pValue1->DWords.dw1 != pValue2->DWords.dw1)
    956         return pValue1->DWords.dw1 > pValue2->DWords.dw1 ? 1 : -1;
    957     if (pValue1->DWords.dw0 != pValue2->DWords.dw0)
    958         return pValue1->DWords.dw0 > pValue2->DWords.dw0 ? 1 : -1;
     905    if (pValue1->Words.w3 != pValue2->Words.w3)
     906        return pValue1->Words.w3 > pValue2->Words.w3 ? 1 : -1;
     907    if (pValue1->Words.w2 != pValue2->Words.w2)
     908        return pValue1->Words.w2 > pValue2->Words.w2 ? 1 : -1;
     909    if (pValue1->Words.w1 != pValue2->Words.w1)
     910        return pValue1->Words.w1 > pValue2->Words.w1 ? 1 : -1;
     911    if (pValue1->Words.w0 != pValue2->Words.w0)
     912        return pValue1->Words.w0 > pValue2->Words.w0 ? 1 : -1;
    959913    return 0;
    960914#endif
     
    963917
    964918/**
    965  * Tests if a 128-bit unsigned integer value is smaller than another.
     919 * Tests if a 64-bit unsigned integer value is smaller than another.
    966920 *
    967921 * @returns true if the first value is smaller, false if not.
     
    969923 * @param   pValue2             The second value.
    970924 */
    971 DECLINLINE(bool) RTUInt128IsSmaller(PCRTUINT128U pValue1, PCRTUINT128U pValue2)
    972 {
    973 #if ARCH_BITS >= 64
     925DECLINLINE(bool) RTUInt64IsSmaller(PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     926{
     927#if ARCH_BITS >= 32
    974928    return pValue1->s.Hi < pValue2->s.Hi
    975929        || (   pValue1->s.Hi == pValue2->s.Hi
    976930            && pValue1->s.Lo  < pValue2->s.Lo);
    977931#else
    978     return pValue1->DWords.dw3 < pValue2->DWords.dw3
    979         || (   pValue1->DWords.dw3 == pValue2->DWords.dw3
    980             && (   pValue1->DWords.dw2  < pValue2->DWords.dw2
    981                 || (   pValue1->DWords.dw2 == pValue2->DWords.dw2
    982                     && (   pValue1->DWords.dw1  < pValue2->DWords.dw1
    983                         || (   pValue1->DWords.dw1 == pValue2->DWords.dw1
    984                             && pValue1->DWords.dw0  < pValue2->DWords.dw0)))));
    985 #endif
    986 }
    987 
    988 
    989 /**
    990  * Tests if a 128-bit unsigned integer value is larger than another.
     932    return pValue1->Words.w3 < pValue2->Words.w3
     933        || (   pValue1->Words.w3 == pValue2->Words.w3
     934            && (   pValue1->Words.w2  < pValue2->Words.w2
     935                || (   pValue1->Words.w2 == pValue2->Words.w2
     936                    && (   pValue1->Words.w1  < pValue2->Words.w1
     937                        || (   pValue1->Words.w1 == pValue2->Words.w1
     938                            && pValue1->Words.w0  < pValue2->Words.w0)))));
     939#endif
     940}
     941
     942
     943/**
     944 * Tests if a 32-bit unsigned integer value is larger than another.
    991945 *
    992946 * @returns true if the first value is larger, false if not.
     
    994948 * @param   pValue2             The second value.
    995949 */
    996 DECLINLINE(bool) RTUInt128IsLarger(PCRTUINT128U pValue1, PCRTUINT128U pValue2)
    997 {
    998 #if ARCH_BITS >= 64
     950DECLINLINE(bool) RTUInt64IsLarger(PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     951{
     952#if ARCH_BITS >= 32
    999953    return pValue1->s.Hi > pValue2->s.Hi
    1000954        || (   pValue1->s.Hi == pValue2->s.Hi
    1001955            && pValue1->s.Lo  > pValue2->s.Lo);
    1002956#else
    1003     return pValue1->DWords.dw3 > pValue2->DWords.dw3
    1004         || (   pValue1->DWords.dw3 == pValue2->DWords.dw3
    1005             && (   pValue1->DWords.dw2  > pValue2->DWords.dw2
    1006                 || (   pValue1->DWords.dw2 == pValue2->DWords.dw2
    1007                     && (   pValue1->DWords.dw1  > pValue2->DWords.dw1
    1008                         || (   pValue1->DWords.dw1 == pValue2->DWords.dw1
    1009                             && pValue1->DWords.dw0  > pValue2->DWords.dw0)))));
    1010 #endif
    1011 }
    1012 
    1013 
    1014 /**
    1015  * Tests if a 128-bit unsigned integer value is larger or equal than another.
     957    return pValue1->Words.w3 > pValue2->Words.w3
     958        || (   pValue1->Words.w3 == pValue2->Words.w3
     959            && (   pValue1->Words.w2  > pValue2->Words.w2
     960                || (   pValue1->Words.w2 == pValue2->Words.w2
     961                    && (   pValue1->Words.w1  > pValue2->Words.w1
     962                        || (   pValue1->Words.w1 == pValue2->Words.w1
     963                            && pValue1->Words.w0  > pValue2->Words.w0)))));
     964#endif
     965}
     966
     967
     968/**
     969 * Tests if a 64-bit unsigned integer value is larger or equal than another.
    1016970 *
    1017971 * @returns true if the first value is larger or equal, false if not.
     
    1019973 * @param   pValue2             The second value.
    1020974 */
    1021 DECLINLINE(bool) RTUInt128IsLargerOrEqual(PCRTUINT128U pValue1, PCRTUINT128U pValue2)
    1022 {
    1023 #if ARCH_BITS >= 64
     975DECLINLINE(bool) RTUInt64IsLargerOrEqual(PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     976{
     977#if ARCH_BITS >= 32
    1024978    return pValue1->s.Hi > pValue2->s.Hi
    1025979        || (   pValue1->s.Hi == pValue2->s.Hi
    1026980            && pValue1->s.Lo >= pValue2->s.Lo);
    1027981#else
    1028     return pValue1->DWords.dw3 > pValue2->DWords.dw3
    1029         || (   pValue1->DWords.dw3 == pValue2->DWords.dw3
    1030             && (   pValue1->DWords.dw2  > pValue2->DWords.dw2
    1031                 || (   pValue1->DWords.dw2 == pValue2->DWords.dw2
    1032                     && (   pValue1->DWords.dw1  > pValue2->DWords.dw1
    1033                         || (   pValue1->DWords.dw1 == pValue2->DWords.dw1
    1034                             && pValue1->DWords.dw0 >= pValue2->DWords.dw0)))));
    1035 #endif
    1036 }
    1037 
    1038 
    1039 /**
    1040  * Tests if two 128-bit unsigned integer values not equal.
     982    return pValue1->Words.w3 > pValue2->Words.w3
     983        || (   pValue1->Words.w3 == pValue2->Words.w3
     984            && (   pValue1->Words.w2  > pValue2->Words.w2
     985                || (   pValue1->Words.w2 == pValue2->Words.w2
     986                    && (   pValue1->Words.w1  > pValue2->Words.w1
     987                        || (   pValue1->Words.w1 == pValue2->Words.w1
     988                            && pValue1->Words.w0 >= pValue2->Words.w0)))));
     989#endif
     990}
     991
     992
     993/**
     994 * Tests if two 64-bit unsigned integer values not equal.
    1041995 *
    1042996 * @returns true if equal, false if not equal.
     
    1044998 * @param   pValue2             The second value.
    1045999 */
    1046 DECLINLINE(bool) RTUInt128IsEqual(PCRTUINT128U pValue1, PCRTUINT128U pValue2)
    1047 {
    1048 #if ARCH_BITS >= 64
     1000DECLINLINE(bool) RTUInt64IsEqual(PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     1001{
     1002#if ARCH_BITS >= 32
    10491003    return pValue1->s.Hi == pValue2->s.Hi
    10501004        && pValue1->s.Lo == pValue2->s.Lo;
    10511005#else
    1052     return pValue1->DWords.dw0 == pValue2->DWords.dw0
    1053         && pValue1->DWords.dw1 == pValue2->DWords.dw1
    1054         && pValue1->DWords.dw2 == pValue2->DWords.dw2
    1055         && pValue1->DWords.dw3 == pValue2->DWords.dw3;
    1056 #endif
    1057 }
    1058 
    1059 
    1060 /**
    1061  * Tests if two 128-bit unsigned integer values are not equal.
     1006    return pValue1->Words.w0 == pValue2->Words.w0
     1007        && pValue1->Words.w1 == pValue2->Words.w1
     1008        && pValue1->Words.w2 == pValue2->Words.w2
     1009        && pValue1->Words.w3 == pValue2->Words.w3;
     1010#endif
     1011}
     1012
     1013
     1014/**
     1015 * Tests if two 64-bit unsigned integer values are not equal.
    10621016 *
    10631017 * @returns true if not equal, false if equal.
     
    10651019 * @param   pValue2             The second value.
    10661020 */
    1067 DECLINLINE(bool) RTUInt128IsNotEqual(PCRTUINT128U pValue1, PCRTUINT128U pValue2)
    1068 {
    1069     return !RTUInt128IsEqual(pValue1, pValue2);
    1070 }
    1071 
    1072 
    1073 /**
    1074  * Sets a bit in a 128-bit unsigned integer type.
     1021DECLINLINE(bool) RTUInt64IsNotEqual(PCRTUINT64U pValue1, PCRTUINT64U pValue2)
     1022{
     1023    return !RTUInt64IsEqual(pValue1, pValue2);
     1024}
     1025
     1026
     1027/**
     1028 * Sets a bit in a 64-bit unsigned integer type.
    10751029 *
    10761030 * @returns pValueResult.
     
    10781032 * @param   iBit            The bit to set.
    10791033 */
    1080 DECLINLINE(PRTUINT128U) RTUInt128BitSet(PRTUINT128U pValueResult, unsigned iBit)
    1081 {
    1082     if (iBit < 64)
    1083     {
    1084 #if ARCH_BITS >= 64
    1085         pValueResult->s.Lo |= RT_BIT_64(iBit);
    1086 #else
    1087         if (iBit < 32)
    1088             pValueResult->DWords.dw0 |= RT_BIT_32(iBit);
    1089         else
    1090             pValueResult->DWords.dw1 |= RT_BIT_32(iBit - 32);
    1091 #endif
    1092     }
    1093     else if (iBit < 128)
    1094     {
    1095 #if ARCH_BITS >= 64
    1096         pValueResult->s.Hi |= RT_BIT_64(iBit - 64);
    1097 #else
    1098         if (iBit < 96)
    1099             pValueResult->DWords.dw2 |= RT_BIT_32(iBit - 64);
    1100         else
    1101             pValueResult->DWords.dw3 |= RT_BIT_32(iBit - 96);
     1034DECLINLINE(PRTUINT64U) RTUInt64BitSet(PRTUINT64U pValueResult, unsigned iBit)
     1035{
     1036    if (iBit < 32)
     1037    {
     1038#if ARCH_BITS >= 32
     1039        pValueResult->s.Lo |= RT_BIT_32(iBit);
     1040#else
     1041        if (iBit < 16)
     1042            pValueResult->Words.w0 |= UINT16_C(1) << iBit;
     1043        else
     1044            pValueResult->Words.w1 |= UINT16_C(1) << (iBit - 32);
     1045#endif
     1046    }
     1047    else if (iBit < 64)
     1048    {
     1049#if ARCH_BITS >= 32
     1050        pValueResult->s.Hi |= UINT16_C(1) << (iBit - 32);
     1051#else
     1052        if (iBit < 48)
     1053            pValueResult->Words.w2 |= UINT16_C(1) << (iBit - 64);
     1054        else
     1055            pValueResult->Words.w3 |= UINT16_C(1) << (iBit - 96);
    11021056#endif
    11031057    }
     
    11071061
    11081062/**
    1109  * Sets a bit in a 128-bit unsigned integer type.
     1063 * Sets a bit in a 64-bit unsigned integer type.
    11101064 *
    11111065 * @returns pValueResult.
     
    11131067 * @param   iBit            The bit to set.
    11141068 */
    1115 DECLINLINE(PRTUINT128U) RTUInt128BitClear(PRTUINT128U pValueResult, unsigned iBit)
    1116 {
    1117     if (iBit < 64)
    1118     {
    1119 #if ARCH_BITS >= 64
    1120         pValueResult->s.Lo &= ~RT_BIT_64(iBit);
    1121 #else
    1122         if (iBit < 32)
    1123             pValueResult->DWords.dw0 &= ~RT_BIT_32(iBit);
    1124         else
    1125             pValueResult->DWords.dw1 &= ~RT_BIT_32(iBit - 32);
    1126 #endif
    1127     }
    1128     else if (iBit < 128)
    1129     {
    1130 #if ARCH_BITS >= 64
    1131         pValueResult->s.Hi &= ~RT_BIT_64(iBit - 64);
    1132 #else
    1133         if (iBit < 96)
    1134             pValueResult->DWords.dw2 &= ~RT_BIT_32(iBit - 64);
    1135         else
    1136             pValueResult->DWords.dw3 &= ~RT_BIT_32(iBit - 96);
     1069DECLINLINE(PRTUINT64U) RTUInt64BitClear(PRTUINT64U pValueResult, unsigned iBit)
     1070{
     1071    if (iBit < 32)
     1072    {
     1073#if ARCH_BITS >= 32
     1074        pValueResult->s.Lo &= ~RT_BIT_32(iBit);
     1075#else
     1076        if (iBit < 48)
     1077            pValueResult->Words.w0 &= ~(UINT16_C(1) << (iBit));
     1078        else
     1079            pValueResult->Words.w1 &= ~(UINT16_C(1) << (iBit - 32));
     1080#endif
     1081    }
     1082    else if (iBit < 64)
     1083    {
     1084#if ARCH_BITS >= 32
     1085        pValueResult->s.Hi &= ~RT_BIT_32(iBit - 32);
     1086#else
     1087        if (iBit < 48)
     1088            pValueResult->Words.w2 &= ~(UINT16_C(1) << (iBit - 64));
     1089        else
     1090            pValueResult->Words.w3 &= ~(UINT16_C(1) << (iBit - 96));
    11371091#endif
    11381092    }
     
    11421096
    11431097/**
    1144  * Tests if a bit in a 128-bit unsigned integer value is set.
     1098 * Tests if a bit in a 64-bit unsigned integer value is set.
    11451099 *
    11461100 * @returns pValueResult.
     
    11481102 * @param   iBit            The bit to test.
    11491103 */
    1150 DECLINLINE(bool) RTUInt128BitTest(PRTUINT128U pValueResult, unsigned iBit)
     1104DECLINLINE(bool) RTUInt64BitTest(PRTUINT64U pValueResult, unsigned iBit)
    11511105{
    11521106    bool fRc;
    1153     if (iBit < 64)
    1154     {
    1155 #if ARCH_BITS >= 64
    1156         fRc = RT_BOOL(pValueResult->s.Lo & RT_BIT_64(iBit));
    1157 #else
    1158         if (iBit < 32)
    1159             fRc = RT_BOOL(pValueResult->DWords.dw0 & RT_BIT_32(iBit));
    1160         else
    1161             fRc = RT_BOOL(pValueResult->DWords.dw1 & RT_BIT_32(iBit - 32));
    1162 #endif
    1163     }
    1164     else if (iBit < 128)
    1165     {
    1166 #if ARCH_BITS >= 64
     1107    if (iBit < 32)
     1108    {
     1109#if ARCH_BITS >= 32
     1110        fRc = RT_BOOL(pValueResult->s.Lo & RT_BIT_32(iBit));
     1111#else
     1112        if (iBit < 16)
     1113            fRc = RT_BOOL(pValueResult->Words.w0 & (UINT16_C(1) << (iBit)));
     1114        else
     1115            fRc = RT_BOOL(pValueResult->Words.w1 & (UINT16_C(1) << (iBit - 16)));
     1116#endif
     1117    }
     1118    else if (iBit < 64)
     1119    {
     1120#if ARCH_BITS >= 32
    11671121        fRc = RT_BOOL(pValueResult->s.Hi & RT_BIT_64(iBit - 64));
    11681122#else
    1169         if (iBit < 96)
    1170             fRc = RT_BOOL(pValueResult->DWords.dw2 & RT_BIT_32(iBit - 64));
    1171         else
    1172             fRc = RT_BOOL(pValueResult->DWords.dw3 & RT_BIT_32(iBit - 96));
     1123        if (iBit < 48)
     1124            fRc = RT_BOOL(pValueResult->Words.w2 & (UINT16_C(1) << (iBit - 32)));
     1125        else
     1126            fRc = RT_BOOL(pValueResult->Words.w3 & (UINT16_C(1) << (iBit - 48)));
    11731127#endif
    11741128    }
     
    11801134
    11811135/**
    1182  * Set a range of bits a 128-bit unsigned integer value.
     1136 * Set a range of bits a 64-bit unsigned integer value.
    11831137 *
    11841138 * @returns pValueResult.
     
    11871141 * @param   cBits           The number of bits to set.
    11881142 */
    1189 DECLINLINE(PRTUINT128U) RTUInt128BitSetRange(PRTUINT128U pValueResult, unsigned iFirstBit, unsigned cBits)
     1143DECLINLINE(PRTUINT64U) RTUInt64BitSetRange(PRTUINT64U pValueResult, unsigned iFirstBit, unsigned cBits)
    11901144{
    11911145    /* bounds check & fix. */
    1192     if (iFirstBit < 128)
    1193     {
    1194         if (iFirstBit + cBits > 128)
    1195             cBits = 128 - iFirstBit;
    1196 
    1197 #if ARCH_BITS >= 64
    1198         if (iFirstBit + cBits < 64)
    1199             pValueResult->s.Lo |= (RT_BIT_64(cBits) - 1) << iFirstBit;
    1200         else if (iFirstBit + cBits < 128 && iFirstBit >= 64)
    1201             pValueResult->s.Hi |= (RT_BIT_64(cBits) - 1) << (iFirstBit - 64);
    1202         else
    1203 #else
     1146    if (iFirstBit < 64)
     1147    {
     1148        if (iFirstBit + cBits > 64)
     1149            cBits = 64 - iFirstBit;
     1150
     1151#if ARCH_BITS >= 32
    12041152        if (iFirstBit + cBits < 32)
    1205             pValueResult->DWords.dw0 |= (RT_BIT_32(cBits) - 1) << iFirstBit;
     1153            pValueResult->s.Lo |= (RT_BIT_32(cBits) - 1) << iFirstBit;
    12061154        else if (iFirstBit + cBits < 64 && iFirstBit >= 32)
    1207             pValueResult->DWords.dw1 |= (RT_BIT_32(cBits) - 1) << (iFirstBit - 32);
    1208         else if (iFirstBit + cBits < 96 && iFirstBit >= 64)
    1209             pValueResult->DWords.dw2 |= (RT_BIT_32(cBits) - 1) << (iFirstBit - 64);
    1210         else if (iFirstBit + cBits < 128 && iFirstBit >= 96)
    1211             pValueResult->DWords.dw3 |= (RT_BIT_32(cBits) - 1) << (iFirstBit - 96);
     1155            pValueResult->s.Hi |= (RT_BIT_32(cBits) - 1) << (iFirstBit - 32);
     1156        else
     1157#else
     1158        if (iFirstBit + cBits < 16)
     1159            pValueResult->Words.w0 |= ((UINT16_C(1) << cBits) - 1) << iFirstBit;
     1160        else if (iFirstBit + cBits < 32 && iFirstBit >= 16)
     1161            pValueResult->Words.w1 |= ((UINT16_C(1) << cBits) - 1) << (iFirstBit - 16);
     1162        else if (iFirstBit + cBits < 48 && iFirstBit >= 32)
     1163            pValueResult->Words.w2 |= ((UINT16_C(1) << cBits) - 1) << (iFirstBit - 32);
     1164        else if (iFirstBit + cBits < 64 && iFirstBit >= 48)
     1165            pValueResult->Words.w3 |= ((UINT16_C(1) << cBits) - 1) << (iFirstBit - 48);
    12121166        else
    12131167#endif
    12141168            while (cBits-- > 0)
    1215                 RTUInt128BitSet(pValueResult, iFirstBit++);
     1169                RTUInt64BitSet(pValueResult, iFirstBit++);
    12161170    }
    12171171    return pValueResult;
     
    12201174
    12211175/**
    1222  * Test if all the bits of a 128-bit unsigned integer value are set.
     1176 * Test if all the bits of a 64-bit unsigned integer value are set.
    12231177 *
    12241178 * @returns true if they are, false if they aren't.
    12251179 * @param   pValue          The input and output value.
    12261180 */
    1227 DECLINLINE(bool) RTUInt128BitAreAllSet(PRTUINT128U pValue)
    1228 {
    1229 #if ARCH_BITS >= 64
    1230     return pValue->s.Hi == UINT64_MAX
    1231         && pValue->s.Lo == UINT64_MAX;
    1232 #else
    1233     return pValue->DWords.dw0 == UINT32_MAX
    1234         && pValue->DWords.dw1 == UINT32_MAX
    1235         && pValue->DWords.dw2 == UINT32_MAX
    1236         && pValue->DWords.dw3 == UINT32_MAX;
    1237 #endif
    1238 }
    1239 
    1240 
    1241 /**
    1242  * Test if all the bits of a 128-bit unsigned integer value are clear.
     1181DECLINLINE(bool) RTUInt64BitAreAllSet(PRTUINT64U pValue)
     1182{
     1183#if ARCH_BITS >= 32
     1184    return pValue->s.Hi == UINT32_MAX
     1185        && pValue->s.Lo == UINT32_MAX;
     1186#else
     1187    return pValue->Words.w0 == UINT16_MAX
     1188        && pValue->Words.w1 == UINT16_MAX
     1189        && pValue->Words.w2 == UINT16_MAX
     1190        && pValue->Words.w3 == UINT16_MAX;
     1191#endif
     1192}
     1193
     1194
     1195/**
     1196 * Test if all the bits of a 64-bit unsigned integer value are clear.
    12431197 *
    12441198 * @returns true if they are, false if they aren't.
    12451199 * @param   pValue          The input and output value.
    12461200 */
    1247 DECLINLINE(bool) RTUInt128BitAreAllClear(PRTUINT128U pValue)
    1248 {
    1249 #if ARCH_BITS >= 64
    1250     return pValue->s.Hi == 0
    1251         && pValue->s.Lo == 0;
    1252 #else
    1253     return pValue->DWords.dw0 == 0
    1254         && pValue->DWords.dw1 == 0
    1255         && pValue->DWords.dw2 == 0
    1256         && pValue->DWords.dw3 == 0;
    1257 #endif
    1258 }
    1259 
    1260 
    1261 DECLINLINE(uint32_t) RTUInt128BitCount(PCRTUINT128U pValue)
    1262 {
    1263     uint32_t cBits;
     1201DECLINLINE(bool) RTUInt64BitAreAllClear(PRTUINT64U pValue)
     1202{
     1203    return RTUInt64IsZero(pValue);
     1204}
     1205
     1206
     1207DECLINLINE(unsigned) RTUInt64BitCount(PCRTUINT64U pValue)
     1208{
     1209    unsigned cBits;
    12641210    if (pValue->s.Hi != 0)
    12651211    {
    1266         if (pValue->DWords.dw3)
    1267             cBits = 96 + ASMBitLastSetU32(pValue->DWords.dw3);
    1268         else
    1269             cBits = 64 + ASMBitLastSetU32(pValue->DWords.dw2);
     1212#if ARCH_BITS >= 32
     1213        cBits = 32 + ASMBitLastSetU32(pValue->s.Hi);
     1214#else
     1215        if (pValue->Words.w3)
     1216            cBits = 48 + ASMBitLastSetU16(pValue->Words.w3);
     1217        else
     1218            cBits = 32 + ASMBitLastSetU16(pValue->Words.w2);
     1219#endif
    12701220    }
    12711221    else
    12721222    {
    1273         if (pValue->DWords.dw1)
    1274             cBits = 32 + ASMBitLastSetU32(pValue->DWords.dw1);
    1275         else
    1276             cBits =  0 + ASMBitLastSetU32(pValue->DWords.dw0);
     1223#if ARCH_BITS >= 32
     1224        cBits = ASMBitLastSetU32(pValue->s.Lo);
     1225#else
     1226        if (pValue->Words.w1)
     1227            cBits = 16 + ASMBitLastSetU16(pValue->Words.w1);
     1228        else
     1229            cBits =  0 + ASMBitLastSetU16(pValue->Words.w0);
     1230#endif
    12771231    }
    12781232    return cBits;
     
    12811235
    12821236/**
    1283  * Divides a 128-bit unsigned integer value by another, returning both quotient
     1237 * Divides a 64-bit unsigned integer value by another, returning both quotient
    12841238 * and remainder.
    12851239 *
     
    12901244 * @param   pValue2             The divisor value.
    12911245 */
    1292 DECLINLINE(PRTUINT128U) RTUInt128DivRem(PRTUINT128U pQuotient, PRTUINT128U pRemainder, PCRTUINT128U pValue1, PCRTUINT128U pValue2)
     1246DECLINLINE(PRTUINT64U) RTUInt64DivRem(PRTUINT64U pQuotient, PRTUINT64U pRemainder, PCRTUINT64U pValue1, PCRTUINT64U pValue2)
    12931247{
    12941248    int iDiff;
     
    13051259        if (pValue2->s.Lo == 1)
    13061260        {
    1307             RTUInt128SetZero(pRemainder);
     1261            RTUInt64SetZero(pRemainder);
    13081262            *pQuotient = *pValue1;
    13091263            return pQuotient;
    13101264        }
    1311         /** @todo RTUint128DivModBy64 */
     1265        /** @todo RTUInt64DivModByU32 */
    13121266    }
    13131267
    13141268    /* Dividend is smaller? */
    1315     iDiff = RTUInt128Compare(pValue1, pValue2);
     1269    iDiff = RTUInt64Compare(pValue1, pValue2);
    13161270    if (iDiff < 0)
    13171271    {
    13181272        *pRemainder = *pValue1;
    1319         RTUInt128SetZero(pQuotient);
     1273        RTUInt64SetZero(pQuotient);
    13201274    }
    13211275
     
    13231277    else if (iDiff == 0)
    13241278    {
    1325         RTUInt128SetZero(pRemainder);
    1326         RTUInt128AssignU64(pQuotient, 1);
     1279        RTUInt64SetZero(pRemainder);
     1280        RTUInt64AssignU8(pQuotient, 1);
    13271281    }
    13281282    else
     
    13311285         * Prepare.
    13321286         */
    1333         uint32_t   iBitAdder = RTUInt128BitCount(pValue1) - RTUInt128BitCount(pValue2);
    1334         RTUINT128U NormDivisor = *pValue2;
     1287        unsigned  iBitAdder = RTUInt64BitCount(pValue1) - RTUInt64BitCount(pValue2);
     1288        RTUINT64U NormDivisor = *pValue2;
    13351289        if (iBitAdder)
    13361290        {
    1337             RTUInt128ShiftLeft(&NormDivisor, pValue2, iBitAdder);
    1338             if (RTUInt128IsLarger(&NormDivisor, pValue1))
     1291            RTUInt64ShiftLeft(&NormDivisor, pValue2, iBitAdder);
     1292            if (RTUInt64IsLarger(&NormDivisor, pValue1))
    13391293            {
    1340                 RTUInt128AssignShiftRight(&NormDivisor, 1);
     1294                RTUInt64AssignShiftRight(&NormDivisor, 1);
    13411295                iBitAdder--;
    13421296            }
     
    13451299            NormDivisor = *pValue2;
    13461300
    1347         RTUInt128SetZero(pQuotient);
     1301        RTUInt64SetZero(pQuotient);
    13481302        *pRemainder = *pValue1;
    13491303
     
    13511305         * Do the division.
    13521306         */
    1353         if (RTUInt128IsLargerOrEqual(pRemainder, pValue2))
     1307        if (RTUInt64IsLargerOrEqual(pRemainder, pValue2))
    13541308        {
    13551309            for (;;)
    13561310            {
    1357                 if (RTUInt128IsLargerOrEqual(pRemainder, &NormDivisor))
     1311                if (RTUInt64IsLargerOrEqual(pRemainder, &NormDivisor))
    13581312                {
    1359                     RTUInt128AssignSub(pRemainder, &NormDivisor);
    1360                     RTUInt128AssignOrBit(pQuotient, iBitAdder);
     1313                    RTUInt64AssignSub(pRemainder, &NormDivisor);
     1314                    RTUInt64AssignOrBit(pQuotient, iBitAdder);
    13611315                }
    1362                 if (RTUInt128IsSmaller(pRemainder, pValue2))
     1316                if (RTUInt64IsSmaller(pRemainder, pValue2))
    13631317                    break;
    1364                 RTUInt128AssignShiftRight(&NormDivisor, 1);
     1318                RTUInt64AssignShiftRight(&NormDivisor, 1);
    13651319                iBitAdder--;
    13661320            }
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