memory_bram: Move init data swizzling before other swizzling.
authorMarcelina Kościelnicka <mwk@0x04.net>
Tue, 3 Aug 2021 12:28:10 +0000 (14:28 +0200)
committerMarcelina Kościelnicka <mwk@0x04.net>
Tue, 3 Aug 2021 13:04:10 +0000 (15:04 +0200)
Fixes #2907.

passes/memory/memory_bram.cc

index 31fd769b0f62d58ee9452b95bbd8e432dd643a38..af8137adac103c9751d39a55fee17b560b130948 100644 (file)
@@ -798,6 +798,24 @@ grow_read_ports:;
                for (int j = 0; j < i; j++)
                        mem.emulate_priority(j, i);
 
+       // Swizzle the init data.  Do this before changing mem.width, so that get_init_data works.
+       bool cell_init = !mem.inits.empty();
+       vector<Const> initdata;
+       if (cell_init) {
+               Const initparam = mem.get_init_data();
+               initdata.reserve(mem.size);
+               for (int i = 0; i < mem.size; i++) {
+                       std::vector<State> val;
+                       for (auto idx : shuffle_map) {
+                               if (idx == -1)
+                                       val.push_back(State::Sx);
+                               else
+                                       val.push_back(initparam[mem.width * i + idx]);
+                       }
+                       initdata.push_back(Const(val));
+               }
+       }
+
        // Now the big swizzle.
        mem.width = GetSize(shuffle_map);
 
@@ -837,24 +855,6 @@ grow_read_ports:;
                port.srst_value = new_srst_value;
        }
 
-       // Swizzle the init data.
-       bool cell_init = !mem.inits.empty();
-       vector<Const> initdata;
-       if (cell_init) {
-               Const initparam = mem.get_init_data();
-               initdata.reserve(mem.size);
-               for (int i = 0; i < mem.size; i++) {
-                       std::vector<State> val;
-                       for (auto idx : shuffle_map) {
-                               if (idx == -1)
-                                       val.push_back(State::Sx);
-                               else
-                                       val.push_back(initparam[mem.width * i + idx]);
-                       }
-                       initdata.push_back(Const(val));
-               }
-       }
-
        // prepare variant parameters
 
        dict<IdString, Const> variant_params;