introduce bitloops
This commit is contained in:
@@ -22,6 +22,14 @@ public final class Masker {
|
||||
private final long[] adjHi = new long[SwedishGenerator.SIZE];
|
||||
private final int[] rCount = new int[8];
|
||||
private final int[] cCount = new int[9];
|
||||
private static final long[] NBR_LO = new long[SwedishGenerator.SIZE];
|
||||
private static final long[] NBR_HI = new long[SwedishGenerator.SIZE];
|
||||
static {
|
||||
for (int i = 0; i < SwedishGenerator.SIZE; i++) {
|
||||
NBR_LO[i] = IT[i].n1();
|
||||
NBR_HI[i] = IT[i].n2();
|
||||
}
|
||||
}
|
||||
public Masker(Rng rng, int[] stack, Clues cache) {
|
||||
this.rng = rng;
|
||||
this.stack = stack;
|
||||
@@ -387,16 +395,31 @@ public final class Masker {
|
||||
else penalty += 1000;
|
||||
}
|
||||
|
||||
//long nclLo = ~lo_cl & MASK_LO;
|
||||
//long nclHi = ~hi_cl & MASK_HI;
|
||||
//long hNbrLo = (nclLo >> 8) | (nclLo << 8) | (nclHi << 56);
|
||||
//long hNbrHi = (nclHi >> 8) | (nclLo >> 56);
|
||||
//long vNbrLo = ((nclLo & ~0x0101010101010101L) >> 1) | ((nclLo & ~0x8080808080808080L) << 1);
|
||||
//long vNbrHi = ((nclHi & ~0x01L) >> 1) | ((nclHi & ~0x80L) << 1);
|
||||
//penalty += bitCount(nclLo & ~cHLo & hNbrLo) * 800;
|
||||
//penalty += bitCount(nclLo & ~cVLo & vNbrLo) * 800;
|
||||
//penalty += bitCount(nclHi & ~cHHi & hNbrHi) * 800;
|
||||
//penalty += bitCount(nclHi & ~cVHi & vNbrHi) * 800;
|
||||
long remLo = lo_cl, remHi = hi_cl;
|
||||
while ((remLo | remHi) != X) {
|
||||
long compLo = 0, compHi = 0;
|
||||
if (remLo != X) compLo = lowestOneBit(remLo);
|
||||
else compHi = lowestOneBit(remHi);
|
||||
long lastLo, lastHi;
|
||||
do {
|
||||
lastLo = compLo; lastHi = compHi;
|
||||
long expandedLo = 0, expandedHi = 0;
|
||||
for (long bits = compLo; bits != X; bits &= bits - 1) {
|
||||
int idx = numberOfTrailingZeros(bits);
|
||||
expandedLo |= NBR_LO[idx]; expandedHi |= NBR_HI[idx];
|
||||
}
|
||||
for (long bits = compHi; bits != X; bits &= bits - 1) {
|
||||
int idx = 64 | numberOfTrailingZeros(bits);
|
||||
expandedLo |= NBR_LO[idx]; expandedHi |= NBR_HI[idx];
|
||||
}
|
||||
compLo |= expandedLo & lo_cl;
|
||||
compHi |= expandedHi & hi_cl;
|
||||
} while (compLo != lastLo || compHi != lastHi);
|
||||
int s = bitCount(compLo) + bitCount(compHi);
|
||||
if (s >= 2) penalty += (long) (s - 1) * 120;
|
||||
remLo &= ~compLo;
|
||||
remHi &= ~compHi;
|
||||
}
|
||||
|
||||
return penalty;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user