@@ -3575,12 +3575,8 @@ namespace {
3575
3575
if (CommonSpareBits.empty ())
3576
3576
return APInt ();
3577
3577
3578
- APInt v = interleaveSpareBits (IGM, PayloadTagBits,
3579
- PayloadTagBits.size (),
3580
- tag, 0 );
3581
- v |= interleaveSpareBits (IGM, CommonSpareBits,
3582
- CommonSpareBits.size (),
3583
- 0 , tagIndex);
3578
+ APInt v = scatterBits (PayloadTagBits.asAPInt (), tag);
3579
+ v |= scatterBits (~CommonSpareBits.asAPInt (), tagIndex);
3584
3580
return v;
3585
3581
}
3586
3582
@@ -4125,9 +4121,7 @@ namespace {
4125
4121
// If we have spare bits, pack tag bits into them.
4126
4122
unsigned numSpareBits = PayloadTagBits.count ();
4127
4123
if (numSpareBits > 0 ) {
4128
- APInt tagMaskVal
4129
- = interleaveSpareBits (IGM, PayloadTagBits,
4130
- PayloadTagBits.size (), tag, 0 );
4124
+ APInt tagMaskVal = scatterBits (PayloadTagBits.asAPInt (), tag);
4131
4125
payload.emitApplyOrMask (IGF, tagMaskVal);
4132
4126
}
4133
4127
@@ -4801,9 +4795,7 @@ namespace {
4801
4795
// enum containing this enum as a payload. Single payload layout
4802
4796
// unfortunately assumes that tagging the payload case is a no-op.
4803
4797
auto spareBitMask = ~CommonSpareBits.asAPInt ();
4804
- APInt tagBitMask
4805
- = interleaveSpareBits (IGM, PayloadTagBits, PayloadTagBits.size (),
4806
- spareTagBits, 0 );
4798
+ APInt tagBitMask = scatterBits (PayloadTagBits.asAPInt (), spareTagBits);
4807
4799
4808
4800
payload.emitApplyAndMask (IGF, spareBitMask);
4809
4801
payload.emitApplyOrMask (IGF, tagBitMask);
@@ -5315,8 +5307,8 @@ namespace {
5315
5307
auto payloadTagMask = payloadBitCount >= 32
5316
5308
? ~0u : (1 << payloadBitCount) - 1 ;
5317
5309
auto payloadPart = mask & payloadTagMask;
5318
- auto payloadBits = interleaveSpareBits (IGM, CommonSpareBits,
5319
- bits, payloadPart, 0 );
5310
+ auto payloadBits = scatterBits ( CommonSpareBits. asAPInt (). zextOrTrunc (bits) ,
5311
+ payloadPart);
5320
5312
if (getExtraTagBitCountForExtraInhabitants () > 0 ) {
5321
5313
auto extraBits = APInt (bits,
5322
5314
(mask >> payloadBitCount) & extraTagMask)
@@ -6916,41 +6908,20 @@ llvm::Value *irgen::emitScatterBits(IRGenFunction &IGF,
6916
6908
return result;
6917
6909
}
6918
6910
6919
- // / Interleave the occupiedValue and spareValue bits, taking a bit from one
6920
- // / or the other at each position based on the spareBits mask.
6921
- APInt
6922
- irgen::interleaveSpareBits (IRGenModule &IGM, const SpareBitVector &spareBits,
6923
- unsigned bits,
6924
- unsigned spareValue, unsigned occupiedValue) {
6925
- // FIXME: endianness.
6926
- SmallVector<llvm::APInt::WordType, 2 > valueParts;
6927
- valueParts.push_back (0 );
6928
-
6929
- llvm::APInt::WordType valueBit = 1 ;
6930
- auto advanceValueBit = [&]{
6931
- valueBit <<= 1 ;
6932
- if (valueBit == 0 ) {
6933
- valueParts.push_back (0 );
6934
- valueBit = 1 ;
6911
+ // / Unpack bits from the low bits of an integer value and
6912
+ // / move them to the bit positions indicated by the mask.
6913
+ llvm::APInt irgen::scatterBits (const llvm::APInt &mask, unsigned value) {
6914
+ llvm::APInt result (mask.getBitWidth (), 0 );
6915
+ for (unsigned i = 0 ; i < mask.getBitWidth () && value != 0 ; ++i) {
6916
+ if (!mask[i]) {
6917
+ continue ;
6935
6918
}
6936
- };
6937
-
6938
- for (unsigned i = 0 , e = spareBits.size ();
6939
- (occupiedValue || spareValue) && i < e;
6940
- ++i, advanceValueBit ()) {
6941
- if (spareBits[i]) {
6942
- if (spareValue & 1 )
6943
- valueParts.back () |= valueBit;
6944
- spareValue >>= 1 ;
6945
- } else {
6946
- if (occupiedValue & 1 )
6947
- valueParts.back () |= valueBit;
6948
- occupiedValue >>= 1 ;
6919
+ if (value & 1 ) {
6920
+ result.setBit (i);
6949
6921
}
6922
+ value >>= 1 ;
6950
6923
}
6951
-
6952
- // Create the value.
6953
- return llvm::APInt (bits, valueParts);
6924
+ return result;
6954
6925
}
6955
6926
6956
6927
// / A version of the above where the tag value is dynamic.
0 commit comments