amaranth-lang / amaranth-soc

System on Chip toolkit for Amaranth HDL
BSD 2-Clause "Simplified" License
83 stars 31 forks source link

`MemoryMap` doesn't uphold promise to iterate "in ascending order of [...] address" #74

Closed tpwrules closed 8 months ago

tpwrules commented 8 months ago

Many methods on MemoryMap claim to iterate objects "in ascending order of their address" but this appears to not be the case in the current code. The code as it stands appears to iterate in order of object addition, as this is how Python dicts natively iterate.

This original documentation was written five years ago, so it's unclear something changed or this was never implemented. Iterating in address order is a useful property and will help determinism of downstream code, such as the SoC bus decoders, so the class should be modified to do this properly.

jfng commented 8 months ago

These MemoryMap methods iterate by insertion order despite claiming to iterate on ascending order of addresses:

I think that the behavior should be fixed to match the docstring, rather than the opposite. Iterating in ascending order of addresses makes sense when generating files such as SVD definitions, headers, etc.