Skip to content

Commit f0a3afe

Browse files
committed
refiddle the bit ordering
1 parent e6ea642 commit f0a3afe

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

deploy/src/shift_driver.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,19 @@ end
124124

125125
# --- Flush ---
126126

127+
function _bitreverse(x::UInt32, nbits::Integer)
128+
r = UInt32(0)
129+
for i in 0:nbits-1
130+
r |= ((x >> i) & UInt32(1)) << (nbits - 1 - i)
131+
end
132+
r
133+
end
134+
127135
function flush!(chain::ShiftRegisterChain)
128-
# Left-align: OSR shifts left, so MSB goes out first
129-
shift_out!(chain.sm, (chain.state & 0x00FFFFFF) << (32 - NBITS))
136+
# OSR shifts left (MSB first). Bit-reverse so shadow bit 0 → Q0,
137+
# then left-align into the top of the 32-bit word.
138+
reversed = _bitreverse(chain.state & 0x00FFFFFF, NBITS)
139+
shift_out!(chain.sm, reversed << (32 - NBITS))
130140
end
131141

132142
# --- Bulk writes (update shadow + flush) ---

0 commit comments

Comments
 (0)