MCPcopy Create free account
hub / github.com/ablab/spades / extractBits

Method extractBits

ext/src/llvm/APInt.cpp:431–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429}
430
431APInt APInt::extractBits(unsigned numBits, unsigned bitPosition) const {
432 assert(numBits > 0 && "Can't extract zero bits");
433 assert(bitPosition < BitWidth && (numBits + bitPosition) <= BitWidth &&
434 "Illegal bit extraction");
435
436 if (isSingleWord())
437 return APInt(numBits, U.VAL >> bitPosition);
438
439 unsigned loBit = whichBit(bitPosition);
440 unsigned loWord = whichWord(bitPosition);
441 unsigned hiWord = whichWord(bitPosition + numBits - 1);
442
443 // Single word result extracting bits from a single word source.
444 if (loWord == hiWord)
445 return APInt(numBits, U.pVal[loWord] >> loBit);
446
447 // Extracting bits that start on a source word boundary can be done
448 // as a fast memory copy.
449 if (loBit == 0)
450 return APInt(numBits, makeArrayRef(U.pVal + loWord, 1 + hiWord - loWord));
451
452 // General case - shift + copy source words directly into place.
453 APInt Result(numBits, 0);
454 unsigned NumSrcWords = getNumWords();
455 unsigned NumDstWords = Result.getNumWords();
456
457 uint64_t *DestPtr = Result.isSingleWord() ? &Result.U.VAL : Result.U.pVal;
458 for (unsigned word = 0; word < NumDstWords; ++word) {
459 uint64_t w0 = U.pVal[loWord + word];
460 uint64_t w1 =
461 (loWord + word + 1) < NumSrcWords ? U.pVal[loWord + word + 1] : 0;
462 DestPtr[word] = (w0 >> loBit) | (w1 << (APINT_BITS_PER_WORD - loBit));
463 }
464
465 return Result.clearUnusedBits();
466}
467
468uint64_t APInt::extractBitsAsZExtValue(unsigned numBits,
469 unsigned bitPosition) const {

Callers

nothing calls this directly

Calls 7

assertClass · 0.85
isSingleWordFunction · 0.85
whichBitFunction · 0.85
whichWordFunction · 0.85
makeArrayRefFunction · 0.85
getNumWordsFunction · 0.85
APIntFunction · 0.50

Tested by

no test coverage detected