- Timestamp:
- Apr 14, 2016 12:50:47 AM (9 years ago)
- Location:
- trunk/include/iprt
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/uint128.h
r57978 r60482 29 29 #include <iprt/cdefs.h> 30 30 #include <iprt/types.h> 31 #include <iprt/err.h>32 31 #include <iprt/asm.h> 33 32 #ifdef RT_ARCH_AMD64 … … 449 448 DECLINLINE(PRTUINT128U) RTUInt128BooleanNot(PRTUINT128U pResult, PCRTUINT128U pValue) 450 449 { 450 pResult->s.Lo = pValue->s.Lo || pValue->s.Hi ? 0 : 1; 451 451 pResult->s.Hi = 0; 452 pResult->s.Lo = pValue->s.Lo || pValue->s.Hi ? 0 : 1;453 452 return pResult; 454 453 } … … 559 558 560 559 /** 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. 562 561 * 563 562 * @returns pValueResult -
trunk/include/iprt/uint64.h
r60406 r60482 1 1 /** @file 2 * IPRT - RTUINT 128U & uint128_t methods.2 * IPRT - RTUINT64U methods for old 32-bit and 16-bit compilers. 3 3 */ 4 4 5 5 /* 6 * Copyright (C) 2011-201 5Oracle Corporation6 * Copyright (C) 2011-2016 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 24 24 */ 25 25 26 #ifndef ___iprt_uint 128_h27 #define ___iprt_uint 128_h26 #ifndef ___iprt_uint64_h 27 #define ___iprt_uint64_h 28 28 29 29 #include <iprt/cdefs.h> 30 30 #include <iprt/types.h> 31 #include <iprt/err.h>32 31 #include <iprt/asm.h> 33 #ifdef RT_ARCH_AMD6434 # include <iprt/asm-math.h>35 #endif36 32 37 33 RT_C_DECLS_BEGIN 38 34 39 /** @defgroup grp_rt_uint 128 RTUInt128 - 128-bit Unsigned Integer Methods35 /** @defgroup grp_rt_uint64 RTUInt64 - 64-bit Unsigned Integer Methods for ancient compilers 40 36 * @ingroup grp_rt 41 37 * @{ … … 49 45 * @param pValue The input and output value. 50 46 */ 51 DECLINLINE(bool) RTUInt 128IsZero(PRTUINT128U pValue)52 { 53 #if ARCH_BITS >= 6454 return pValue->s. Hi== 055 && pValue->s. Lo== 0;56 #else 57 return pValue-> DWords.dw0 == 058 && pValue-> DWords.dw1 == 059 && pValue-> DWords.dw2 == 060 && pValue-> DWords.dw3 == 0;47 DECLINLINE(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; 61 57 #endif 62 58 } … … 69 65 * @param pResult The result variable. 70 66 */ 71 DECLINLINE(PRTUINT 128U) RTUInt128SetZero(PRTUINT128U pResult)72 { 73 #if ARCH_BITS >= 6467 DECLINLINE(PRTUINT64U) RTUInt64SetZero(PRTUINT64U pResult) 68 { 69 #if ARCH_BITS >= 32 74 70 pResult->s.Hi = 0; 75 71 pResult->s.Lo = 0; 76 72 #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(PRTUINT 128U) RTUInt128SetMax(PRTUINT128U pResult)93 { 94 #if ARCH_BITS >= 6495 pResult->s.Hi = UINT 64_MAX;96 pResult->s.Lo = UINT 64_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 */ 88 DECLINLINE(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. 111 107 * 112 108 * @returns pResult … … 115 111 * @param pValue2 The second value. 116 112 */ 117 DECLINLINE(PRTUINT 128U) RTUInt128Add(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)113 DECLINLINE(PRTUINT64U) RTUInt64Add(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2) 118 114 { 119 115 pResult->s.Hi = pValue1->s.Hi + pValue2->s.Hi; … … 126 122 127 123 /** 128 * Adds a 128-bit and a 64-bit unsigned integer values.124 * Adds a 64-bit and a 32-bit unsigned integer values. 129 125 * 130 126 * @returns pResult 131 127 * @param pResult The result variable. 132 128 * @param pValue1 The first value. 133 * @param uValue2 The second value, 64-bit.134 */ 135 DECLINLINE(PRTUINT 128U) RTUInt128AddU64(PRTUINT128U pResult, PCRTUINT128U pValue1, uint64_t uValue2)129 * @param uValue2 The second value, 32-bit. 130 */ 131 DECLINLINE(PRTUINT64U) RTUInt64AddU32(PRTUINT64U pResult, PCRTUINT64U pValue1, uint32_t uValue2) 136 132 { 137 133 pResult->s.Hi = pValue1->s.Hi; … … 144 140 145 141 /** 146 * Subtracts a 128-bit unsigned integer value from another.142 * Subtracts a 64-bit unsigned integer value from another. 147 143 * 148 144 * @returns pResult … … 151 147 * @param pValue2 The subtrahend value. 152 148 */ 153 DECLINLINE(PRTUINT 128U) RTUInt128Sub(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)149 DECLINLINE(PRTUINT64U) RTUInt64Sub(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2) 154 150 { 155 151 pResult->s.Lo = pValue1->s.Lo - pValue2->s.Lo; … … 162 158 163 159 /** 164 * Multiplies two 128-bit unsigned integer values.160 * Multiplies two 64-bit unsigned integer values. 165 161 * 166 162 * @returns pResult … … 169 165 * @param pValue2 The second value. 170 166 */ 171 DECLINLINE(PRTUINT 128U) RTUInt128Mul(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)172 { 173 RTUINT 64U uTmp;174 175 /* multiply all dwords in v1 by v2.dw0. */176 pResult->s.Lo = (uint 64_t)pValue1->DWords.dw0 * pValue2->DWords.dw0;177 178 uTmp.u = (uint 64_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 += (uint 64_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 = (uint 64_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 += (uint 64_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 += (uint 64_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.167 DECLINLINE(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. 216 212 * 217 213 * @returns pResult 218 214 * @param pResult The result variable. 219 215 * @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 */ 218 DECLINLINE(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 */ 264 DECLINLINE(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; 282 271 283 272 /* Multiply uLoValue1 and uHiValue1 by uLoValue1. */ 284 pResult->s.Lo = (uint 64_t)uLoValue1 * uLoValue2;285 286 uTmp.u = (uint 64_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++; 293 282 294 283 /* 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 299 DECLINLINE(PRTUINT64U) RTUInt64DivRem(PRTUINT64U pQuotient, PRTUINT64U pRemainder, PCRTUINT64U pValue1, PCRTUINT64U pValue2); 300 301 /** 302 * Divides a 64-bit unsigned integer value by another. 315 303 * 316 304 * @returns pResult … … 319 307 * @param pValue2 The divisor value. 320 308 */ 321 DECLINLINE(PRTUINT 128U) RTUInt128Div(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)322 { 323 RTUINT 128U Ignored;324 return RTUInt 128DivRem(pResult, &Ignored, pValue1, pValue2);325 } 326 327 328 /** 329 * Divides a 128-bit unsigned integer value by another, returning the remainder.309 DECLINLINE(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. 330 318 * 331 319 * @returns pResult … … 334 322 * @param pValue2 The divisor value. 335 323 */ 336 DECLINLINE(PRTUINT 128U) RTUInt128Mod(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)337 { 338 RTUINT 128U Ignored;339 RTUInt 128DivRem(&Ignored, pResult, pValue1, pValue2);340 return pResult; 341 } 342 343 344 /** 345 * Bitwise AND of two 128-bit unsigned integer values.324 DECLINLINE(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. 346 334 * 347 335 * @returns pResult … … 350 338 * @param pValue2 The second value. 351 339 */ 352 DECLINLINE(PRTUINT 128U) RTUInt128And(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)340 DECLINLINE(PRTUINT64U) RTUInt64And(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2) 353 341 { 354 342 pResult->s.Hi = pValue1->s.Hi & pValue2->s.Hi; … … 359 347 360 348 /** 361 * Bitwise OR of two 128-bit unsigned integer values.349 * Bitwise OR of two 64-bit unsigned integer values. 362 350 * 363 351 * @returns pResult … … 366 354 * @param pValue2 The second value. 367 355 */ 368 DECLINLINE(PRTUINT 128U) RTUInt128Or( PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)356 DECLINLINE(PRTUINT64U) RTUInt64Or( PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2) 369 357 { 370 358 pResult->s.Hi = pValue1->s.Hi | pValue2->s.Hi; … … 375 363 376 364 /** 377 * Bitwise XOR of two 128-bit unsigned integer values.365 * Bitwise XOR of two 64-bit unsigned integer values. 378 366 * 379 367 * @returns pResult … … 382 370 * @param pValue2 The second value. 383 371 */ 384 DECLINLINE(PRTUINT 128U) RTUInt128Xor(PRTUINT128U pResult, PCRTUINT128U pValue1, PCRTUINT128U pValue2)372 DECLINLINE(PRTUINT64U) RTUInt64Xor(PRTUINT64U pResult, PCRTUINT64U pValue1, PCRTUINT64U pValue2) 385 373 { 386 374 pResult->s.Hi = pValue1->s.Hi ^ pValue2->s.Hi; … … 391 379 392 380 /** 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. 394 382 * 395 383 * @returns pResult … … 398 386 * @param cBits The number of bits to shift it. 399 387 */ 400 DECLINLINE(PRTUINT 128U) RTUInt128ShiftLeft(PRTUINT128U pResult, PCRTUINT128U pValue, int cBits)401 { 402 cBits &= 127;403 if (cBits < 64)388 DECLINLINE(PRTUINT64U) RTUInt64ShiftLeft(PRTUINT64U pResult, PCRTUINT64U pValue, int cBits) 389 { 390 cBits &= 63; 391 if (cBits < 32) 404 392 { 405 393 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)); 407 395 } 408 396 else 409 397 { 410 398 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. 419 407 * 420 408 * @returns pResult … … 423 411 * @param cBits The number of bits to shift it. 424 412 */ 425 DECLINLINE(PRTUINT 128U) RTUInt128ShiftRight(PRTUINT128U pResult, PCRTUINT128U pValue, int cBits)426 { 427 cBits &= 127;428 if (cBits < 64)413 DECLINLINE(PRTUINT64U) RTUInt64ShiftRight(PRTUINT64U pResult, PCRTUINT64U pValue, int cBits) 414 { 415 cBits &= 63; 416 if (cBits < 32) 429 417 { 430 418 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)); 432 420 } 433 421 else 434 422 { 435 423 pResult->s.Hi = 0; 436 pResult->s.Lo = pValue->s.Hi >> (cBits - 64);424 pResult->s.Lo = pValue->s.Hi >> (cBits - 32); 437 425 } 438 426 return pResult; … … 447 435 * @param pValue The value. 448 436 */ 449 DECLINLINE(PRTUINT128U) RTUInt128BooleanNot(PRTUINT128U pResult, PCRTUINT128U pValue) 450 { 437 DECLINLINE(PRTUINT64U) RTUInt64BooleanNot(PRTUINT64U pResult, PCRTUINT64U pValue) 438 { 439 pResult->s.Lo = pValue->s.Lo || pValue->s.Hi ? 0 : 1; 451 440 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). 459 447 * 460 448 * @returns pResult. … … 462 450 * @param pValue The value. 463 451 */ 464 DECLINLINE(PRTUINT 128U) RTUInt128BitwiseNot(PRTUINT128U pResult, PCRTUINT128U pValue)452 DECLINLINE(PRTUINT64U) RTUInt64BitwiseNot(PRTUINT64U pResult, PCRTUINT64U pValue) 465 453 { 466 454 pResult->s.Hi = ~pValue->s.Hi; … … 471 459 472 460 /** 473 * Assigns one 128-bit unsigned integer value to another.461 * Assigns one 64-bit unsigned integer value to another. 474 462 * 475 463 * @returns pResult … … 477 465 * @param pValue The value to assign. 478 466 */ 479 DECLINLINE(PRTUINT 128U) RTUInt128Assign(PRTUINT128U pResult, PCRTUINT128U pValue)480 { 481 #if ARCH_BITS >= 64467 DECLINLINE(PRTUINT64U) RTUInt64Assign(PRTUINT64U pResult, PCRTUINT64U pValue) 468 { 469 #if ARCH_BITS >= 32 482 470 pResult->s.Hi = pValue->s.Hi; 483 471 pResult->s.Lo = pValue->s.Lo; 484 472 #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. 496 484 * 497 485 * @returns pValueResult … … 499 487 * @param fValue The boolean value. 500 488 */ 501 DECLINLINE(PRTUINT 128U) RTUInt128AssignBoolean(PRTUINT128U pValueResult, bool fValue)502 { 503 #if ARCH_BITS >= 64489 DECLINLINE(PRTUINT64U) RTUInt64AssignBoolean(PRTUINT64U pValueResult, bool fValue) 490 { 491 #if ARCH_BITS >= 32 504 492 pValueResult->s.Lo = fValue; 505 493 pValueResult->s.Hi = 0; 506 494 #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; 511 499 #endif 512 500 return pValueResult; … … 515 503 516 504 /** 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. 518 506 * 519 507 * @returns pValueResult … … 521 509 * @param u8Value The 8-bit unsigned integer value. 522 510 */ 523 DECLINLINE(PRTUINT 128U) RTUInt128AssignU8(PRTUINT128U pValueResult, uint8_t u8Value)524 { 525 #if ARCH_BITS >= 64511 DECLINLINE(PRTUINT64U) RTUInt64AssignU8(PRTUINT64U pValueResult, uint8_t u8Value) 512 { 513 #if ARCH_BITS >= 32 526 514 pValueResult->s.Lo = u8Value; 527 515 pValueResult->s.Hi = 0; 528 516 #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; 533 521 #endif 534 522 return pValueResult; … … 537 525 538 526 /** 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. 540 528 * 541 529 * @returns pValueResult … … 543 531 * @param u16Value The 16-bit unsigned integer value. 544 532 */ 545 DECLINLINE(PRTUINT 128U) RTUInt128AssignU16(PRTUINT128U pValueResult, uint16_t u16Value)546 { 547 #if ARCH_BITS >= 64533 DECLINLINE(PRTUINT64U) RTUInt64AssignU16(PRTUINT64U pValueResult, uint16_t u16Value) 534 { 535 #if ARCH_BITS >= 32 548 536 pValueResult->s.Lo = u16Value; 549 537 pValueResult->s.Hi = 0; 550 538 #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; 555 543 #endif 556 544 return pValueResult; … … 559 547 560 548 /** 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. 562 550 * 563 551 * @returns pValueResult … … 565 553 * @param u32Value The 32-bit unsigned integer value. 566 554 */ 567 DECLINLINE(PRTUINT 128U) RTUInt128AssignU32(PRTUINT128U pValueResult, uint32_t u32Value)568 { 569 #if ARCH_BITS >= 64555 DECLINLINE(PRTUINT64U) RTUInt64AssignU32(PRTUINT64U pValueResult, uint32_t u32Value) 556 { 557 #if ARCH_BITS >= 32 570 558 pValueResult->s.Lo = u32Value; 571 559 pValueResult->s.Hi = 0; 572 560 #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; 577 565 #endif 578 566 return pValueResult; … … 581 569 582 570 /** 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. 599 572 * 600 573 * @returns pValue1Result. … … 602 575 * @param pValue2 The second value. 603 576 */ 604 DECLINLINE(PRTUINT 128U) RTUInt128AssignAdd(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)605 { 606 uint 64_t const uTmp = pValue1Result->s.Lo;577 DECLINLINE(PRTUINT64U) RTUInt64AssignAdd(PRTUINT64U pValue1Result, PCRTUINT64U pValue2) 578 { 579 uint32_t const uTmp = pValue1Result->s.Lo; 607 580 pValue1Result->s.Lo += pValue2->s.Lo; 608 581 if (pValue1Result->s.Lo < uTmp) … … 614 587 615 588 /** 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 634 590 * first. 635 591 * … … 638 594 * @param pValue2 The subtrahend value. 639 595 */ 640 DECLINLINE(PRTUINT 128U) RTUInt128AssignSub(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)641 { 642 uint 64_t const uTmp = pValue1Result->s.Lo;596 DECLINLINE(PRTUINT64U) RTUInt64AssignSub(PRTUINT64U pValue1Result, PCRTUINT64U pValue2) 597 { 598 uint32_t const uTmp = pValue1Result->s.Lo; 643 599 pValue1Result->s.Lo -= pValue2->s.Lo; 644 600 if (pValue1Result->s.Lo > uTmp) … … 650 606 651 607 /** 652 * Multiplies two 128-bit unsigned integer values, storing the result in the608 * Multiplies two 64-bit unsigned integer values, storing the result in the 653 609 * first. 654 610 * … … 657 613 * @param pValue2 The second value. 658 614 */ 659 DECLINLINE(PRTUINT 128U) RTUInt128AssignMul(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)660 { 661 RTUINT 128U Result;662 RTUInt 128Mul(&Result, pValue1Result, pValue2);615 DECLINLINE(PRTUINT64U) RTUInt64AssignMul(PRTUINT64U pValue1Result, PCRTUINT64U pValue2) 616 { 617 RTUINT64U Result; 618 RTUInt64Mul(&Result, pValue1Result, pValue2); 663 619 *pValue1Result = Result; 664 620 return pValue1Result; … … 667 623 668 624 /** 669 * Divides a 128-bit unsigned integer value by another, storing the result in625 * Divides a 64-bit unsigned integer value by another, storing the result in 670 626 * the first. 671 627 * … … 674 630 * @param pValue2 The divisor value. 675 631 */ 676 DECLINLINE(PRTUINT 128U) RTUInt128AssignDiv(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)677 { 678 RTUINT 128U Result;679 RTUINT 128U Ignored;680 RTUInt 128DivRem(&Result, &Ignored, pValue1Result, pValue2);632 DECLINLINE(PRTUINT64U) RTUInt64AssignDiv(PRTUINT64U pValue1Result, PCRTUINT64U pValue2) 633 { 634 RTUINT64U Result; 635 RTUINT64U Ignored; 636 RTUInt64DivRem(&Result, &Ignored, pValue1Result, pValue2); 681 637 *pValue1Result = Result; 682 638 return pValue1Result; … … 685 641 686 642 /** 687 * Divides a 128-bit unsigned integer value by another, storing the remainder in643 * Divides a 64-bit unsigned integer value by another, storing the remainder in 688 644 * the first. 689 645 * … … 692 648 * @param pValue2 The divisor value. 693 649 */ 694 DECLINLINE(PRTUINT 128U) RTUInt128AssignMod(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)695 { 696 RTUINT 128U Ignored;697 RTUINT 128U Result;698 RTUInt 128DivRem(&Ignored, &Result, pValue1Result, pValue2);650 DECLINLINE(PRTUINT64U) RTUInt64AssignMod(PRTUINT64U pValue1Result, PCRTUINT64U pValue2) 651 { 652 RTUINT64U Ignored; 653 RTUINT64U Result; 654 RTUInt64DivRem(&Ignored, &Result, pValue1Result, pValue2); 699 655 *pValue1Result = Result; 700 656 return pValue1Result; … … 703 659 704 660 /** 705 * Performs a bitwise AND of two 128-bit unsigned integer values and assigned661 * Performs a bitwise AND of two 64-bit unsigned integer values and assigned 706 662 * the result to the first one. 707 663 * … … 710 666 * @param pValue2 The second value. 711 667 */ 712 DECLINLINE(PRTUINT 128U) RTUInt128AssignAnd(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)713 { 714 #if ARCH_BITS >= 64668 DECLINLINE(PRTUINT64U) RTUInt64AssignAnd(PRTUINT64U pValue1Result, PCRTUINT64U pValue2) 669 { 670 #if ARCH_BITS >= 32 715 671 pValue1Result->s.Hi &= pValue2->s.Hi; 716 672 pValue1Result->s.Lo &= pValue2->s.Lo; 717 673 #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; 722 678 #endif 723 679 return pValue1Result; … … 726 682 727 683 /** 728 * Performs a bitwise AND of a 128-bit unsigned integer value and a mask made729 * 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. 730 686 * 731 687 * @returns pValueResult. … … 734 690 * bit). 735 691 */ 736 DECLINLINE(PRTUINT 128U) RTUInt128AssignAndNFirstBits(PRTUINT128U pValueResult, unsigned cBits)737 { 738 if (cBits <= 64)739 { 740 if (cBits != 64)741 pValueResult->s.Lo &= (RT_BIT_ 64(cBits) - 1);692 DECLINLINE(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); 742 698 pValueResult->s.Hi = 0; 743 699 } 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); 747 702 return pValueResult; 748 703 } … … 750 705 751 706 /** 752 * Performs a bitwise OR of two 128-bit unsigned integer values and assigned707 * Performs a bitwise OR of two 64-bit unsigned integer values and assigned 753 708 * the result to the first one. 754 709 * … … 757 712 * @param pValue2 The second value. 758 713 */ 759 DECLINLINE(PRTUINT 128U) RTUInt128AssignOr(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)760 { 761 #if ARCH_BITS >= 64714 DECLINLINE(PRTUINT64U) RTUInt64AssignOr(PRTUINT64U pValue1Result, PCRTUINT64U pValue2) 715 { 716 #if ARCH_BITS >= 32 762 717 pValue1Result->s.Hi |= pValue2->s.Hi; 763 718 pValue1Result->s.Lo |= pValue2->s.Lo; 764 719 #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; 769 724 #endif 770 725 return pValue1Result; … … 779 734 * @param iBit The bit to set (0 based). 780 735 */ 781 DECLINLINE(PRTUINT 128U) RTUInt128AssignOrBit(PRTUINT128U pValue1Result, uint32_tiBit)782 { 783 #if ARCH_BITS >= 64784 if (iBit >= 64)785 pValue1Result->s.Hi |= RT_BIT_ 64(iBit - 64);736 DECLINLINE(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); 786 741 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); 795 750 } 796 751 else 797 752 { 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); 802 757 } 803 758 #endif … … 808 763 809 764 /** 810 * Performs a bitwise XOR of two 128-bit unsigned integer values and assigned765 * Performs a bitwise XOR of two 64-bit unsigned integer values and assigned 811 766 * the result to the first one. 812 767 * … … 815 770 * @param pValue2 The second value. 816 771 */ 817 DECLINLINE(PRTUINT 128U) RTUInt128AssignXor(PRTUINT128U pValue1Result, PCRTUINT128U pValue2)818 { 819 #if ARCH_BITS >= 64772 DECLINLINE(PRTUINT64U) RTUInt64AssignXor(PRTUINT64U pValue1Result, PCRTUINT64U pValue2) 773 { 774 #if ARCH_BITS >= 32 820 775 pValue1Result->s.Hi ^= pValue2->s.Hi; 821 776 pValue1Result->s.Lo ^= pValue2->s.Lo; 822 777 #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; 827 782 #endif 828 783 return pValue1Result; … … 831 786 832 787 /** 833 * Performs a bitwise left shift on a 128-bit unsigned integer value, assigning788 * Performs a bitwise left shift on a 64-bit unsigned integer value, assigning 834 789 * the result to it. 835 790 * … … 838 793 * @param cBits The number of bits to shift. 839 794 */ 840 DECLINLINE(PRTUINT128U) RTUInt128AssignShiftLeft(PRTUINT128U pValueResult, int cBits) 841 { 842 RTUINT128U const InVal = *pValueResult; 843 /** @todo \#if ARCH_BITS >= 64 */ 795 DECLINLINE(PRTUINT64U) RTUInt64AssignShiftLeft(PRTUINT64U pValueResult, int cBits) 796 { 797 RTUINT64U const InVal = *pValueResult; 844 798 if (cBits > 0) 845 799 { 846 800 /* (left shift) */ 847 if (cBits >= 128)848 RTUInt 128SetZero(pValueResult);849 else if (cBits >= 64)801 if (cBits >= 64) 802 RTUInt64SetZero(pValueResult); 803 else if (cBits >= 32) 850 804 { 851 805 pValueResult->s.Lo = 0; 852 pValueResult->s.Hi = InVal.s.Lo << (cBits - 64);806 pValueResult->s.Hi = InVal.s.Lo << (cBits - 32); 853 807 } 854 808 else 855 809 { 856 810 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); 858 812 pValueResult->s.Lo = InVal.s.Lo << cBits; 859 813 } … … 863 817 /* (right shift) */ 864 818 cBits = -cBits; 865 if (cBits >= 128)866 RTUInt 128SetZero(pValueResult);867 else if (cBits >= 64)819 if (cBits >= 64) 820 RTUInt64SetZero(pValueResult); 821 else if (cBits >= 32) 868 822 { 869 823 pValueResult->s.Hi = 0; 870 pValueResult->s.Lo = InVal.s.Hi >> (cBits - 64);824 pValueResult->s.Lo = InVal.s.Hi >> (cBits - 32); 871 825 } 872 826 else 873 827 { 874 828 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); 876 830 pValueResult->s.Hi = InVal.s.Hi >> cBits; 877 831 } … … 882 836 883 837 /** 884 * Performs a bitwise left shift on a 128-bit unsigned integer value, assigning838 * Performs a bitwise left shift on a 64-bit unsigned integer value, assigning 885 839 * the result to it. 886 840 * … … 889 843 * @param cBits The number of bits to shift. 890 844 */ 891 DECLINLINE(PRTUINT 128U) RTUInt128AssignShiftRight(PRTUINT128U pValueResult, int cBits)892 { 893 return RTUInt 128AssignShiftLeft(pValueResult, -cBits);894 } 895 896 897 /** 898 * Performs a bitwise NOT on a 128-bit unsigned integer value, assigning the845 DECLINLINE(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 899 853 * result to it. 900 854 * … … 902 856 * @param pValueResult The value and result. 903 857 */ 904 DECLINLINE(PRTUINT 128U) RTUInt128AssignBitwiseNot(PRTUINT128U pValueResult)905 { 906 #if ARCH_BITS >= 64858 DECLINLINE(PRTUINT64U) RTUInt64AssignBitwiseNot(PRTUINT64U pValueResult) 859 { 860 #if ARCH_BITS >= 32 907 861 pValueResult->s.Hi = ~pValueResult->s.Hi; 908 862 pValueResult->s.Lo = ~pValueResult->s.Lo; 909 863 #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; 914 868 #endif 915 869 return pValueResult; … … 918 872 919 873 /** 920 * Performs a boolean NOT on a 128-bit unsigned integer value, assigning the874 * Performs a boolean NOT on a 64-bit unsigned integer value, assigning the 921 875 * result to it. 922 876 * … … 924 878 * @param pValueResult The value and result. 925 879 */ 926 DECLINLINE(PRTUINT 128U) RTUInt128AssignBooleanNot(PRTUINT128U pValueResult)927 { 928 return RTUInt 128AssignBoolean(pValueResult, RTUInt128IsZero(pValueResult));929 } 930 931 932 /** 933 * Compares two 128-bit unsigned integer values.880 DECLINLINE(PRTUINT64U) RTUInt64AssignBooleanNot(PRTUINT64U pValueResult) 881 { 882 return RTUInt64AssignBoolean(pValueResult, RTUInt64IsZero(pValueResult)); 883 } 884 885 886 /** 887 * Compares two 64-bit unsigned integer values. 934 888 * 935 889 * @retval 0 if equal. … … 940 894 * @param pValue2 The second value. 941 895 */ 942 DECLINLINE(int) RTUInt 128Compare(PCRTUINT128U pValue1, PCRTUINT128U pValue2)943 { 944 #if ARCH_BITS >= 64896 DECLINLINE(int) RTUInt64Compare(PCRTUINT64U pValue1, PCRTUINT64U pValue2) 897 { 898 #if ARCH_BITS >= 32 945 899 if (pValue1->s.Hi != pValue2->s.Hi) 946 900 return pValue1->s.Hi > pValue2->s.Hi ? 1 : -1; … … 949 903 return 0; 950 904 #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; 959 913 return 0; 960 914 #endif … … 963 917 964 918 /** 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. 966 920 * 967 921 * @returns true if the first value is smaller, false if not. … … 969 923 * @param pValue2 The second value. 970 924 */ 971 DECLINLINE(bool) RTUInt 128IsSmaller(PCRTUINT128U pValue1, PCRTUINT128U pValue2)972 { 973 #if ARCH_BITS >= 64925 DECLINLINE(bool) RTUInt64IsSmaller(PCRTUINT64U pValue1, PCRTUINT64U pValue2) 926 { 927 #if ARCH_BITS >= 32 974 928 return pValue1->s.Hi < pValue2->s.Hi 975 929 || ( pValue1->s.Hi == pValue2->s.Hi 976 930 && pValue1->s.Lo < pValue2->s.Lo); 977 931 #else 978 return pValue1-> DWords.dw3 < pValue2->DWords.dw3979 || ( pValue1-> DWords.dw3 == pValue2->DWords.dw3980 && ( pValue1-> DWords.dw2 < pValue2->DWords.dw2981 || ( pValue1-> DWords.dw2 == pValue2->DWords.dw2982 && ( pValue1-> DWords.dw1 < pValue2->DWords.dw1983 || ( pValue1-> DWords.dw1 == pValue2->DWords.dw1984 && 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. 991 945 * 992 946 * @returns true if the first value is larger, false if not. … … 994 948 * @param pValue2 The second value. 995 949 */ 996 DECLINLINE(bool) RTUInt 128IsLarger(PCRTUINT128U pValue1, PCRTUINT128U pValue2)997 { 998 #if ARCH_BITS >= 64950 DECLINLINE(bool) RTUInt64IsLarger(PCRTUINT64U pValue1, PCRTUINT64U pValue2) 951 { 952 #if ARCH_BITS >= 32 999 953 return pValue1->s.Hi > pValue2->s.Hi 1000 954 || ( pValue1->s.Hi == pValue2->s.Hi 1001 955 && pValue1->s.Lo > pValue2->s.Lo); 1002 956 #else 1003 return pValue1-> DWords.dw3 > pValue2->DWords.dw31004 || ( pValue1-> DWords.dw3 == pValue2->DWords.dw31005 && ( pValue1-> DWords.dw2 > pValue2->DWords.dw21006 || ( pValue1-> DWords.dw2 == pValue2->DWords.dw21007 && ( pValue1-> DWords.dw1 > pValue2->DWords.dw11008 || ( pValue1-> DWords.dw1 == pValue2->DWords.dw11009 && 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. 1016 970 * 1017 971 * @returns true if the first value is larger or equal, false if not. … … 1019 973 * @param pValue2 The second value. 1020 974 */ 1021 DECLINLINE(bool) RTUInt 128IsLargerOrEqual(PCRTUINT128U pValue1, PCRTUINT128U pValue2)1022 { 1023 #if ARCH_BITS >= 64975 DECLINLINE(bool) RTUInt64IsLargerOrEqual(PCRTUINT64U pValue1, PCRTUINT64U pValue2) 976 { 977 #if ARCH_BITS >= 32 1024 978 return pValue1->s.Hi > pValue2->s.Hi 1025 979 || ( pValue1->s.Hi == pValue2->s.Hi 1026 980 && pValue1->s.Lo >= pValue2->s.Lo); 1027 981 #else 1028 return pValue1-> DWords.dw3 > pValue2->DWords.dw31029 || ( pValue1-> DWords.dw3 == pValue2->DWords.dw31030 && ( pValue1-> DWords.dw2 > pValue2->DWords.dw21031 || ( pValue1-> DWords.dw2 == pValue2->DWords.dw21032 && ( pValue1-> DWords.dw1 > pValue2->DWords.dw11033 || ( pValue1-> DWords.dw1 == pValue2->DWords.dw11034 && 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. 1041 995 * 1042 996 * @returns true if equal, false if not equal. … … 1044 998 * @param pValue2 The second value. 1045 999 */ 1046 DECLINLINE(bool) RTUInt 128IsEqual(PCRTUINT128U pValue1, PCRTUINT128U pValue2)1047 { 1048 #if ARCH_BITS >= 641000 DECLINLINE(bool) RTUInt64IsEqual(PCRTUINT64U pValue1, PCRTUINT64U pValue2) 1001 { 1002 #if ARCH_BITS >= 32 1049 1003 return pValue1->s.Hi == pValue2->s.Hi 1050 1004 && pValue1->s.Lo == pValue2->s.Lo; 1051 1005 #else 1052 return pValue1-> DWords.dw0 == pValue2->DWords.dw01053 && pValue1-> DWords.dw1 == pValue2->DWords.dw11054 && pValue1-> DWords.dw2 == pValue2->DWords.dw21055 && 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. 1062 1016 * 1063 1017 * @returns true if not equal, false if equal. … … 1065 1019 * @param pValue2 The second value. 1066 1020 */ 1067 DECLINLINE(bool) RTUInt 128IsNotEqual(PCRTUINT128U pValue1, PCRTUINT128U pValue2)1068 { 1069 return !RTUInt 128IsEqual(pValue1, pValue2);1070 } 1071 1072 1073 /** 1074 * Sets a bit in a 128-bit unsigned integer type.1021 DECLINLINE(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. 1075 1029 * 1076 1030 * @returns pValueResult. … … 1078 1032 * @param iBit The bit to set. 1079 1033 */ 1080 DECLINLINE(PRTUINT 128U) RTUInt128BitSet(PRTUINT128U pValueResult, unsigned iBit)1081 { 1082 if (iBit < 64)1083 { 1084 #if ARCH_BITS >= 641085 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 >= 641096 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);1034 DECLINLINE(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); 1102 1056 #endif 1103 1057 } … … 1107 1061 1108 1062 /** 1109 * Sets a bit in a 128-bit unsigned integer type.1063 * Sets a bit in a 64-bit unsigned integer type. 1110 1064 * 1111 1065 * @returns pValueResult. … … 1113 1067 * @param iBit The bit to set. 1114 1068 */ 1115 DECLINLINE(PRTUINT 128U) RTUInt128BitClear(PRTUINT128U pValueResult, unsigned iBit)1116 { 1117 if (iBit < 64)1118 { 1119 #if ARCH_BITS >= 641120 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 >= 641131 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);1069 DECLINLINE(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)); 1137 1091 #endif 1138 1092 } … … 1142 1096 1143 1097 /** 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. 1145 1099 * 1146 1100 * @returns pValueResult. … … 1148 1102 * @param iBit The bit to test. 1149 1103 */ 1150 DECLINLINE(bool) RTUInt 128BitTest(PRTUINT128U pValueResult, unsigned iBit)1104 DECLINLINE(bool) RTUInt64BitTest(PRTUINT64U pValueResult, unsigned iBit) 1151 1105 { 1152 1106 bool fRc; 1153 if (iBit < 64)1154 { 1155 #if ARCH_BITS >= 641156 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 >= 641107 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 1167 1121 fRc = RT_BOOL(pValueResult->s.Hi & RT_BIT_64(iBit - 64)); 1168 1122 #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))); 1173 1127 #endif 1174 1128 } … … 1180 1134 1181 1135 /** 1182 * Set a range of bits a 128-bit unsigned integer value.1136 * Set a range of bits a 64-bit unsigned integer value. 1183 1137 * 1184 1138 * @returns pValueResult. … … 1187 1141 * @param cBits The number of bits to set. 1188 1142 */ 1189 DECLINLINE(PRTUINT 128U) RTUInt128BitSetRange(PRTUINT128U pValueResult, unsigned iFirstBit, unsigned cBits)1143 DECLINLINE(PRTUINT64U) RTUInt64BitSetRange(PRTUINT64U pValueResult, unsigned iFirstBit, unsigned cBits) 1190 1144 { 1191 1145 /* 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 1204 1152 if (iFirstBit + cBits < 32) 1205 pValueResult-> DWords.dw0|= (RT_BIT_32(cBits) - 1) << iFirstBit;1153 pValueResult->s.Lo |= (RT_BIT_32(cBits) - 1) << iFirstBit; 1206 1154 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); 1212 1166 else 1213 1167 #endif 1214 1168 while (cBits-- > 0) 1215 RTUInt 128BitSet(pValueResult, iFirstBit++);1169 RTUInt64BitSet(pValueResult, iFirstBit++); 1216 1170 } 1217 1171 return pValueResult; … … 1220 1174 1221 1175 /** 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. 1223 1177 * 1224 1178 * @returns true if they are, false if they aren't. 1225 1179 * @param pValue The input and output value. 1226 1180 */ 1227 DECLINLINE(bool) RTUInt 128BitAreAllSet(PRTUINT128U pValue)1228 { 1229 #if ARCH_BITS >= 641230 return pValue->s.Hi == UINT 64_MAX1231 && pValue->s.Lo == UINT 64_MAX;1232 #else 1233 return pValue-> DWords.dw0 == UINT32_MAX1234 && pValue-> DWords.dw1 == UINT32_MAX1235 && pValue-> DWords.dw2 == UINT32_MAX1236 && 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.1181 DECLINLINE(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. 1243 1197 * 1244 1198 * @returns true if they are, false if they aren't. 1245 1199 * @param pValue The input and output value. 1246 1200 */ 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; 1201 DECLINLINE(bool) RTUInt64BitAreAllClear(PRTUINT64U pValue) 1202 { 1203 return RTUInt64IsZero(pValue); 1204 } 1205 1206 1207 DECLINLINE(unsigned) RTUInt64BitCount(PCRTUINT64U pValue) 1208 { 1209 unsigned cBits; 1264 1210 if (pValue->s.Hi != 0) 1265 1211 { 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 1270 1220 } 1271 1221 else 1272 1222 { 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 1277 1231 } 1278 1232 return cBits; … … 1281 1235 1282 1236 /** 1283 * Divides a 128-bit unsigned integer value by another, returning both quotient1237 * Divides a 64-bit unsigned integer value by another, returning both quotient 1284 1238 * and remainder. 1285 1239 * … … 1290 1244 * @param pValue2 The divisor value. 1291 1245 */ 1292 DECLINLINE(PRTUINT 128U) RTUInt128DivRem(PRTUINT128U pQuotient, PRTUINT128U pRemainder, PCRTUINT128U pValue1, PCRTUINT128U pValue2)1246 DECLINLINE(PRTUINT64U) RTUInt64DivRem(PRTUINT64U pQuotient, PRTUINT64U pRemainder, PCRTUINT64U pValue1, PCRTUINT64U pValue2) 1293 1247 { 1294 1248 int iDiff; … … 1305 1259 if (pValue2->s.Lo == 1) 1306 1260 { 1307 RTUInt 128SetZero(pRemainder);1261 RTUInt64SetZero(pRemainder); 1308 1262 *pQuotient = *pValue1; 1309 1263 return pQuotient; 1310 1264 } 1311 /** @todo RTU int128DivModBy64*/1265 /** @todo RTUInt64DivModByU32 */ 1312 1266 } 1313 1267 1314 1268 /* Dividend is smaller? */ 1315 iDiff = RTUInt 128Compare(pValue1, pValue2);1269 iDiff = RTUInt64Compare(pValue1, pValue2); 1316 1270 if (iDiff < 0) 1317 1271 { 1318 1272 *pRemainder = *pValue1; 1319 RTUInt 128SetZero(pQuotient);1273 RTUInt64SetZero(pQuotient); 1320 1274 } 1321 1275 … … 1323 1277 else if (iDiff == 0) 1324 1278 { 1325 RTUInt 128SetZero(pRemainder);1326 RTUInt 128AssignU64(pQuotient, 1);1279 RTUInt64SetZero(pRemainder); 1280 RTUInt64AssignU8(pQuotient, 1); 1327 1281 } 1328 1282 else … … 1331 1285 * Prepare. 1332 1286 */ 1333 u int32_t iBitAdder = RTUInt128BitCount(pValue1) - RTUInt128BitCount(pValue2);1334 RTUINT 128U NormDivisor = *pValue2;1287 unsigned iBitAdder = RTUInt64BitCount(pValue1) - RTUInt64BitCount(pValue2); 1288 RTUINT64U NormDivisor = *pValue2; 1335 1289 if (iBitAdder) 1336 1290 { 1337 RTUInt 128ShiftLeft(&NormDivisor, pValue2, iBitAdder);1338 if (RTUInt 128IsLarger(&NormDivisor, pValue1))1291 RTUInt64ShiftLeft(&NormDivisor, pValue2, iBitAdder); 1292 if (RTUInt64IsLarger(&NormDivisor, pValue1)) 1339 1293 { 1340 RTUInt 128AssignShiftRight(&NormDivisor, 1);1294 RTUInt64AssignShiftRight(&NormDivisor, 1); 1341 1295 iBitAdder--; 1342 1296 } … … 1345 1299 NormDivisor = *pValue2; 1346 1300 1347 RTUInt 128SetZero(pQuotient);1301 RTUInt64SetZero(pQuotient); 1348 1302 *pRemainder = *pValue1; 1349 1303 … … 1351 1305 * Do the division. 1352 1306 */ 1353 if (RTUInt 128IsLargerOrEqual(pRemainder, pValue2))1307 if (RTUInt64IsLargerOrEqual(pRemainder, pValue2)) 1354 1308 { 1355 1309 for (;;) 1356 1310 { 1357 if (RTUInt 128IsLargerOrEqual(pRemainder, &NormDivisor))1311 if (RTUInt64IsLargerOrEqual(pRemainder, &NormDivisor)) 1358 1312 { 1359 RTUInt 128AssignSub(pRemainder, &NormDivisor);1360 RTUInt 128AssignOrBit(pQuotient, iBitAdder);1313 RTUInt64AssignSub(pRemainder, &NormDivisor); 1314 RTUInt64AssignOrBit(pQuotient, iBitAdder); 1361 1315 } 1362 if (RTUInt 128IsSmaller(pRemainder, pValue2))1316 if (RTUInt64IsSmaller(pRemainder, pValue2)) 1363 1317 break; 1364 RTUInt 128AssignShiftRight(&NormDivisor, 1);1318 RTUInt64AssignShiftRight(&NormDivisor, 1); 1365 1319 iBitAdder--; 1366 1320 }
Note:
See TracChangeset
for help on using the changeset viewer.