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 long[] adjHi = new long[SwedishGenerator.SIZE];
|
||||||
private final int[] rCount = new int[8];
|
private final int[] rCount = new int[8];
|
||||||
private final int[] cCount = new int[9];
|
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) {
|
public Masker(Rng rng, int[] stack, Clues cache) {
|
||||||
this.rng = rng;
|
this.rng = rng;
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
@@ -387,16 +395,31 @@ public final class Masker {
|
|||||||
else penalty += 1000;
|
else penalty += 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
//long nclLo = ~lo_cl & MASK_LO;
|
long remLo = lo_cl, remHi = hi_cl;
|
||||||
//long nclHi = ~hi_cl & MASK_HI;
|
while ((remLo | remHi) != X) {
|
||||||
//long hNbrLo = (nclLo >> 8) | (nclLo << 8) | (nclHi << 56);
|
long compLo = 0, compHi = 0;
|
||||||
//long hNbrHi = (nclHi >> 8) | (nclLo >> 56);
|
if (remLo != X) compLo = lowestOneBit(remLo);
|
||||||
//long vNbrLo = ((nclLo & ~0x0101010101010101L) >> 1) | ((nclLo & ~0x8080808080808080L) << 1);
|
else compHi = lowestOneBit(remHi);
|
||||||
//long vNbrHi = ((nclHi & ~0x01L) >> 1) | ((nclHi & ~0x80L) << 1);
|
long lastLo, lastHi;
|
||||||
//penalty += bitCount(nclLo & ~cHLo & hNbrLo) * 800;
|
do {
|
||||||
//penalty += bitCount(nclLo & ~cVLo & vNbrLo) * 800;
|
lastLo = compLo; lastHi = compHi;
|
||||||
//penalty += bitCount(nclHi & ~cHHi & hNbrHi) * 800;
|
long expandedLo = 0, expandedHi = 0;
|
||||||
//penalty += bitCount(nclHi & ~cVHi & vNbrHi) * 800;
|
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;
|
return penalty;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user