mirror of
https://github.com/SikongJueluo/Mini-Nav.git
synced 2026-07-12 20:15:31 +08:00
feat(cam): migrate noise generation from xorshift64 to xorshift128
- Replace NOISE_GEN_BITS/NOISE_SAMPLE_BITS parameters with unified NOISE_BITS
- Use xorshift128 (random128) instead of xorshift64 for PRNG
- Add flip_mask_next combinational helper for single-cycle mask computation
- Add random_enable signal to advance PRNG only on accepted noisy writes
- Simplify FSM by removing mask_group_idx counter
- Update parameter validation: GROUP_BITS (= HASH_BITS/NOISE_BITS) must equal 64
- Update ref_model.py and tests to match new seed convention: {seed, seed}
- Update Makefile and sweep_noise.py with renamed parameters
This commit is contained in:
@@ -22,17 +22,20 @@ def apply_write_noise(
|
||||
width: int,
|
||||
rate_num: int,
|
||||
rate_den: int,
|
||||
noise_gen_bits: int = 8,
|
||||
noise_sample_bits: int = 8,
|
||||
noise_bits: int = 8,
|
||||
seed: int = 0,
|
||||
) -> list[int]:
|
||||
"""Apply write-noise flip masks to every row, returning noisy copies."""
|
||||
"""Apply write-noise flip masks to every row, returning noisy copies.
|
||||
|
||||
*seed* is a 64-bit value (RTL NOISE_SEED). It is duplicated to form
|
||||
the 128-bit xorshift initial state: {seed, seed}.
|
||||
"""
|
||||
noisy: list[int] = []
|
||||
state = seed
|
||||
state = (seed << 64) | seed
|
||||
mask_w = (1 << width) - 1
|
||||
for row in rows:
|
||||
flip, state = generate_write_flip_mask(
|
||||
state, width, noise_gen_bits, noise_sample_bits, rate_num, rate_den
|
||||
state, width, noise_bits, rate_num, rate_den
|
||||
)
|
||||
noisy.append((row ^ flip) & mask_w)
|
||||
return noisy
|
||||
@@ -44,8 +47,7 @@ def main() -> None:
|
||||
parser.add_argument("--queries", type=int, default=128)
|
||||
parser.add_argument("--width", type=int, default=512)
|
||||
parser.add_argument("--seed", type=int, default=1234)
|
||||
parser.add_argument("--noise-gen-bits", type=int, default=8)
|
||||
parser.add_argument("--noise-sample-bits", type=int, default=8)
|
||||
parser.add_argument("--noise-bits", type=int, default=8)
|
||||
parser.add_argument(
|
||||
"--rates",
|
||||
type=float,
|
||||
@@ -80,8 +82,7 @@ def main() -> None:
|
||||
width=args.width,
|
||||
rate_num=rate_num,
|
||||
rate_den=rate_den,
|
||||
noise_gen_bits=args.noise_gen_bits,
|
||||
noise_sample_bits=args.noise_sample_bits,
|
||||
noise_bits=args.noise_bits,
|
||||
seed=args.seed,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user