Skip to content

Instantly share code, notes, and snippets.

@cfelton
Last active August 29, 2015 14:16
Show Gist options
  • Save cfelton/d52fc4abe8d50b73c13c to your computer and use it in GitHub Desktop.
Save cfelton/d52fc4abe8d50b73c13c to your computer and use it in GitHub Desktop.
Flatten a matrix of signals (list of lists) to a single intbv.
def m_flatten(matrix, flat):
_flat = ConcatSignal(*[col(4,0) for row in matrix for col in row])
@always_comb
def rtl():
flat.next = _flat
return rtl
def test_flatten():
matrix = [[Signal(intbv(0)[8:]) for col in range(5)] for row in range(8)]
flat = Signal(intbv(0)[160:])
tbdut = m_flatten(matrix, flat)
@instance
def tbstim():
yield delay(1)
print(bin(flat, 160))
assert flat == 0
matrix[0][0].next = 0x8
yield delay(1)
print(bin(flat, 160))
assert flat[160-1] == 1
return tbdut, tbstim
Simulation(test_flatten()).run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment