introduce bitloops

This commit is contained in:
mike
2026-01-13 00:03:39 +01:00
parent 61d246e551
commit 6119722867
5 changed files with 47 additions and 49 deletions

View File

@@ -68,8 +68,7 @@ public record SwedishGenerator(Rng rng) {
static final byte B0 = (byte) 0;
static final byte B64 = (byte) 64;
static final long[] OFFSETS_D_IDX = Neighbors9x8.OFFSET_D_IDX;
static final long[] OFFSET_D_IDX_0_BASE = Neighbors9x8.OFFSET_D_IDX_0_BASE;
static final long[] OFFSETS_D_IDX = Neighbors9x8.OFFSET_D_IDX_0_BASE;
static final rci[] IT = Neighbors9x8.IT;
static final int[][] MUTATE_RI = new int[SIZE][625];
static final long[] NBR8_PACKED_LO = Neighbors9x8.NBR8_PACKED_LO;
@@ -314,19 +313,18 @@ public record SwedishGenerator(Rng rng) {
static record Slot(int key, long lo, long hi) {
static final int BIT_FOR_DIR = 3;
static final int BIT_FOR_DIR = 2;
static Slot from(int key, long lo, long hi) { return new Slot(key, lo, hi); }
public int len() { return Long.bitCount(lo) + Long.bitCount(hi); }
public int clueIndex() { return clueIndex(key); }
public static int clueIndex(int key) { return key >>> BIT_FOR_DIR; }
public static int dir(int key) { return key & 7; }
public static int dir(int key) { return key & 3; }
public boolean horiz() { return horiz(key); }
public boolean increasing() { return (key & 2) != 0; }
public static boolean increasing(int dir) { return (dir & 2) != 0; }
public boolean increasing() { return (key & 2) == 0; }
public static boolean increasing(int dir) { return (dir & 2) == 0; }
public IntStream walk() { return Gridded.walk((byte) key, lo, hi); }
public static boolean horiz(int d) { return (d & 1) == 0; }
public static boolean horizv2(int d) { return (d & 1) == 1; }
public static boolean horiz(int d) { return (d & 1) != 0; }
public static int packSlotDir(int idx, int d) { return (idx << BIT_FOR_DIR) | d; }
}
@@ -343,7 +341,7 @@ public record SwedishGenerator(Rng rng) {
// slice ray to stop before first clue, depending on direction monotonicity
// right/down => increasing indices; up/left => decreasing indices
boolean increasing = Slot.increasing(d + 1);
boolean increasing = Slot.increasing(d);
if (increasing) {
// first clue is lowest index among hits (lo first, then hi)
@@ -371,7 +369,7 @@ public record SwedishGenerator(Rng rng) {
}
if ((rayLo | rayHi) != 0) {
visitor.visit(Slot.packSlotDir(idx, d + 1), rayLo, rayHi);
visitor.visit(Slot.packSlotDir(idx, d), rayLo, rayHi);
}
}
@@ -398,7 +396,7 @@ public record SwedishGenerator(Rng rng) {
int key = (clueIdx << 2) | d;
long rLo = PATH_LO[key], rHi = PATH_HI[key];
long hLo = rLo & lo_cl, hHi = rHi & hi_cl;
if (Slot.increasing(d + 1)) {
if (Slot.increasing(d)) {
if (hLo != 0) {
rLo &= ((1L << Long.numberOfTrailingZeros(hLo)) - 1);
rHi = 0;
@@ -415,7 +413,7 @@ public record SwedishGenerator(Rng rng) {
}
if ((rLo | rHi) != 0) {
hasSlots = true;
if (Slot.horizv2(d)) covH.or(rLo, rHi);
if (Slot.horiz(d)) covH.or(rLo, rHi);
else covV.or(rLo, rHi);
if ((Long.bitCount(rLo) + Long.bitCount(rHi)) < MIN_LEN) penalty += 8000;
} else {