@@ -137,11 +137,13 @@ def transform_fragment(self, i, f):
137
137
log2_int (old .depth , need_pow2 = True )
138
138
f .specials .add (old )
139
139
except ValueError :
140
- new , glue = self ._split_mem (old )
140
+ new , comb , sync = self ._split_mem (old )
141
141
old_ports |= set (old .ports )
142
142
f .specials .update (new )
143
- f .comb += glue
144
-
143
+ f .comb += comb
144
+ for cd , sy in sync .items ():
145
+ s = f .sync .setdefault (cd , [])
146
+ s += sy
145
147
f .specials -= old_ports
146
148
147
149
def _split_mem (self , mem ):
@@ -162,11 +164,14 @@ def _split_mem(self, mem):
162
164
init = init , name = name ))
163
165
ports = []
164
166
comb = []
167
+ sync = {}
165
168
for port in mem .ports :
166
- p , c = self ._split_port (port , mems )
169
+ p , c , s = self ._split_port (port , mems )
167
170
ports += p
168
171
comb += c
169
- return mems + ports , comb
172
+ sy = sync .setdefault (port .clock .cd , [])
173
+ sy += s
174
+ return mems + ports , comb , sync
170
175
171
176
def _split_port (self , port , mems ):
172
177
ports = [mem .get_port (write_capable = port .we is not None ,
@@ -178,15 +183,22 @@ def _split_port(self, port, mems):
178
183
for mem in mems ]
179
184
180
185
sel = Signal (max = len (ports ), reset = len (ports ) - 1 )
181
- comb = []
186
+ sel_r = Signal .like (sel )
187
+ eq = sel_r .eq (sel )
188
+ if port .re is not None :
189
+ eq = If (port .re , eq )
190
+ comb , sync = [], []
191
+ if port .async_read :
192
+ comb += [eq ]
193
+ else :
194
+ sync += [eq ]
182
195
comb += reversed ([If (~ port .adr [len (p .adr )], sel .eq (i ))
183
196
for i , p in enumerate (ports )])
184
197
comb += [p .adr .eq (port .adr ) for p in ports ]
185
- comb .append (port .dat_r .eq (Array ([p .dat_r for p in ports ])[sel ]))
198
+ comb .append (port .dat_r .eq (Array ([p .dat_r for p in ports ])[sel_r ]))
186
199
if port .we is not None :
187
200
comb .append (Array ([p .we for p in ports ])[sel ].eq (port .we ))
188
201
comb += [p .dat_w .eq (port .dat_w ) for p in ports ]
189
202
if port .re is not None :
190
- raise NotImplementedError ("memory port with read-enable" )
191
203
comb += [p .re .eq (port .re ) for p in ports ]
192
- return ports , comb
204
+ return ports , comb , sync
0 commit comments