Skip to content

Commit 664b7aa

Browse files
committed
Fixing logicalxorcount
1 parent 184814b commit 664b7aa

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

headers/ewah.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,11 +1805,15 @@ size_t EWAHBoolArray<uword>::logicalxorcount(const EWAHBoolArray &a) const {
18051805
const bool i_is_prey = rlwi.getRunningLength() < rlwj.getRunningLength();
18061806
BufferedRunningLengthWord<uword> &prey = i_is_prey ? rlwi : rlwj;
18071807
BufferedRunningLengthWord<uword> &predator = i_is_prey ? rlwj : rlwi;
1808+
size_t index;
1809+
18081810
if (predator.getRunningBit()) {
1809-
prey.dischargeCountNegated(predator.getRunningLength(), & answer);
1811+
index = prey.dischargeCountNegated(predator.getRunningLength(), & answer);
18101812
} else {
1811-
prey.dischargeCount(predator.getRunningLength(), & answer);
1813+
index = prey.dischargeCount(predator.getRunningLength(), & answer);
18121814
}
1815+
if(predator.getRunningBit()) answer += (predator.getRunningLength() - index) * wordinbits;
1816+
18131817
predator.discardRunningWordsWithReload();
18141818
}
18151819
const size_t nbre_literal = std::min(rlwi.getNumberOfLiteralWords(),

src/unit.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,7 @@ template <class uword> bool countstest2() {
13691369
assert(b1.logicalorcount(b2) == b1.logicalor(b2).numberOfOnes());
13701370
assert(b1.logicalxorcount(b2) == b1.logicalxor(b2).numberOfOnes());
13711371
assert(b1.logicalandnotcount(b2) == b1.logicalandnot(b2).numberOfOnes());
1372+
assert(b2.logicalandnotcount(b1) == b2.logicalandnot(b1).numberOfOnes());
13721373
return true;
13731374
}
13741375

@@ -1383,9 +1384,24 @@ template <class uword> bool countstest3() {
13831384
assert(b1.logicalorcount(b2) == b1.logicalor(b2).numberOfOnes());
13841385
assert(b1.logicalxorcount(b2) == b1.logicalxor(b2).numberOfOnes());
13851386
assert(b1.logicalandnotcount(b2) == b1.logicalandnot(b2).numberOfOnes());
1387+
assert(b2.logicalandnotcount(b1) == b2.logicalandnot(b1).numberOfOnes());
13861388
return true;
13871389
}
13881390

1391+
template <class uword> bool countstest4() {
1392+
size_t data1[]={941063,941064,941065,941066,941067,941068,941069,941070,941071,941072,941073,941074,941075,941076,941077,941078,941079,941080,941081,941082,941083,941084,941085,941086,941087,941088,941089,941090,941091,941092,941093,941094,941095,941096,941097,941098,941099,941100,941101,941102,941103,941104,941105,941106,941107,941108,941109,941110,941111,941112,941113,941114,941115,941116,941117,941118,941119,941120,941121,941122,941123,941124,941125,941126,941127,941128,941129,941130,941131,941132,941133,941134,941135,941136,941137,941138,941139,941140,941141,941142,941143,941144,941145,941146,941147,941148,941149,941150,941151,941152,941153,941154,941155,941156,941157,941158,941159,941160,941161,941162,941163,941164,941165,941166,941167,941168,941169,941170,941171,941172,941173,941174,941175,941176,941177,941178,941179,941180,941181,941182,941183,941184,941185,941186,941187,941188,941189,941190,941191,941192,941193,941194,941195,941196,941197,941198,941199,941200,941201,941202,941203,941204,941205,941206,941207,941208,941209,941210,941211,941212,941213,941214,941215,941216,941217,941218,941219,941220,941221,941222,941223,941224,941225,941226,941227,941228,941229,941230,941231,941232,941233,941234,941235,941236,941237,941238,941239,941240,941241,941242,941243,941244,941245,941246,941247,941248,941249,941250,941251,941252,941253,941254,941255,941256,941257,941258,941259,941260,941261,941262,941263,941264,941265,941266,941267,941268,941269,941270,941271,941272,941273,941274,941275,941276,941277,941278,941279,941280,941281,941282,941283,941284,941285,941286,941287,941288,941289,941290,941291,941292,941293,941294,941295,941296,941297,941298,941299,941300,941301,941302,941303,941304,941305,941306,941307,941308,941309,941310,941311,941312,941313,941314,941315,941316,941317,941318};
1393+
size_t data2[]={34850,43256,52417,61592,70411,78960,88376,216599,225662,234391,251420,258995,312661,374271,434864,444105,484562,506410,534808,540927,548993,626059,669574,695383,704422,711412,719407,759742,941141};
1394+
EWAHBoolArray<uword> b1;
1395+
for(size_t k = 0 ; k < sizeof(data1)/sizeof(size_t); ++k) b1.set(data1[k]);
1396+
EWAHBoolArray<uword> b2;
1397+
for(size_t k = 0 ; k < sizeof(data2)/sizeof(size_t); ++k) b2.set(data2[k]);
1398+
assert(b1.logicalandcount(b2) == b1.logicaland(b2).numberOfOnes());
1399+
assert(b1.logicalorcount(b2) == b1.logicalor(b2).numberOfOnes());
1400+
assert(b1.logicalxorcount(b2) == b1.logicalxor(b2).numberOfOnes());
1401+
assert(b1.logicalandnotcount(b2) == b1.logicalandnot(b2).numberOfOnes());
1402+
assert(b2.logicalandnotcount(b1) == b2.logicalandnot(b1).numberOfOnes());
1403+
return true;
1404+
}
13891405

13901406

13911407
template <class uword> bool arrayinit2d() {
@@ -1407,13 +1423,18 @@ int main(void) {
14071423
if (!funnytest()) {
14081424
++failures;
14091425
}
1426+
if (!countstest4<uint64_t>())
1427+
++failures;
1428+
if (!countstest4<uint16_t>())
1429+
++failures;
1430+
if (!countstest4<uint32_t>())
1431+
++failures;
14101432
if (!countstest3<uint16_t>())
14111433
++failures;
14121434
if (!countstest3<uint32_t>())
14131435
++failures;
14141436
if (!countstest3<uint64_t>())
14151437
++failures;
1416-
14171438
if (!countstest1<uint16_t>())
14181439
++failures;
14191440
if (!countstest1<uint32_t>())

0 commit comments

Comments
 (0)