[rom_ctrl,util] Use secded_gen's ecc_encode_some

Rather than doing things by hand (which is rather more error-prone).
Note that this actually changes the results (because there was a bug
in my add_ecc32 where we computed (word ^ bitmask) instead of (word &
bitmask)).

Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
diff --git a/hw/ip/rom_ctrl/util/mem.py b/hw/ip/rom_ctrl/util/mem.py
index 34f6839..0e16b3a 100644
--- a/hw/ip/rom_ctrl/util/mem.py
+++ b/hw/ip/rom_ctrl/util/mem.py
@@ -19,30 +19,14 @@
 old_sys_path = sys.path
 try:
     sys.path = sys.path + [_UTIL_DESIGN]
-    import secded_gen  # type: ignore
+    # This strange formulation explicitly re-exports ecc_encode_some from this
+    # module, allowing users of mem.py to call it directly without needing to
+    # do the sys.path dance.
+    from secded_gen import ecc_encode_some as ecc_encode_some  # type: ignore
 finally:
     sys.path = old_sys_path
 
 
-def red_xor32(word: int) -> int:
-    '''Reduction XOR for a uint32'''
-    word = (word & 0xffff) ^ (word >> 16)
-    word = (word & 0xff) ^ (word >> 8)
-    word = (word & 0xf) ^ (word >> 4)
-    word = (word & 0x3) ^ (word >> 2)
-    return (word & 0x1) ^ (word >> 1)
-
-
-def add_ecc32(word: int, bitmasks: List[int]) -> int:
-    '''Add Hsiao (39,32) ECC bits to a 32-bit unsigned word'''
-    assert 0 <= word < (1 << 32)
-    assert len(bitmasks) == 7
-    ret = word
-    for idx, bitmask in enumerate(bitmasks):
-        ret |= red_xor32(word ^ bitmask) << (32 + idx)
-    return ret
-
-
 class MemChunk:
     def __init__(self, base_addr: int, words: List[int]):
         '''A contiguous list of words starting at base_addr'''
@@ -85,9 +69,7 @@
         bits, to make 39-bit words.
 
         '''
-        codes = secded_gen.gen_code('hsiao', 32, 7)
-        bitmasks = secded_gen.calc_bitmasks(32, 7, codes, False)
-        self.words = [add_ecc32(w, bitmasks) for w in self.words]
+        self.words = ecc_encode_some('hsiao', 32, self.words)[0]
 
 
 class MemFile: