Debian Codegraph @

himbaechel/uarch/gatemate/delay.cc

raw
1 /*
2 * nextpnr -- Next Generation Place and Route
3 *
4 * Copyright (C) 2024 The Project Peppercorn Authors.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 */
19
20 #include <boost/algorithm/string.hpp>
21 #include <boost/range/adaptor/reversed.hpp>
22
23 #include "gatemate.h"
24
25 #define HIMBAECHEL_CONSTIDS "uarch/gatemate/constids.inc"
26 #include "himbaechel_constids.h"
27
28 NEXTPNR_NAMESPACE_BEGIN
29
30 delay_t GateMateImpl::estimateDelay(WireId src, WireId dst) const
31 {
32 int sx, sy, dx, dy;
33 int d2d = 0;
34 if (tile_extra_data(src.tile)->die != tile_extra_data(dst.tile)->die)
35 d2d += 2000;
36 tile_xy(ctx->chip_info, src.tile, sx, sy);
37 tile_xy(ctx->chip_info, dst.tile, dx, dy);
38
39 return 100 + 100 * (std::abs(dx - sx) + std::abs(dy - sy)) + d2d;
40 }
41
42 delay_t GateMateImpl::predictDelay(BelId src_bel, IdString src_pin, BelId dst_bel, IdString dst_pin) const
43 {
44 int d2d = 0;
45 if (tile_extra_data(src_bel.tile)->die != tile_extra_data(dst_bel.tile)->die)
46 d2d += 2000;
47
48 Loc src_loc = ctx->getBelLocation(src_bel), dst_loc = ctx->getBelLocation(dst_bel);
49 return 100 + 100 * (std::abs(dst_loc.x - src_loc.x) + std::abs(dst_loc.y - src_loc.y)) + d2d;
50 }
51
52 bool GateMateImpl::get_delay_from_tmg_db(IdString id, DelayQuad &delay) const
53 {
54 auto fnd = timing.find(id);
55 if (fnd != timing.end()) {
56 delay = DelayQuad(fnd->second->delay.fast_min, fnd->second->delay.fast_max, fnd->second->delay.slow_min,
57 fnd->second->delay.slow_max);
58 return true;
59 }
60 return false;
61 }
62
63 void GateMateImpl::get_setuphold_from_tmg_db(IdString id_setup, IdString id_hold, DelayPair &setup,
64 DelayPair &hold) const
65 {
66 auto fnd = timing.find(id_setup);
67 if (fnd != timing.end()) {
68 setup.min_delay = fnd->second->delay.fast_min;
69 setup.max_delay = fnd->second->delay.fast_max;
70 }
71 fnd = timing.find(id_hold);
72 if (fnd != timing.end()) {
73 hold.min_delay = fnd->second->delay.fast_min;
74 hold.max_delay = fnd->second->delay.fast_max;
75 }
76 }
77
78 void GateMateImpl::get_setuphold_from_tmg_db(IdString id_setuphold, DelayPair &setup, DelayPair &hold) const
79 {
80 auto fnd = timing.find(id_setuphold);
81 if (fnd != timing.end()) {
82 setup.min_delay = fnd->second->delay.fast_min;
83 setup.max_delay = fnd->second->delay.fast_max;
84 hold.min_delay = fnd->second->delay.slow_min;
85 hold.max_delay = fnd->second->delay.slow_max;
86 }
87 }
88
89 bool GateMateImpl::getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, DelayQuad &delay) const
90 {
91 delay = DelayQuad{0};
92 static dict<IdString, IdString> map_upper = {
93 {id_D0_00, id_IN1}, {id_D1_00, id_IN2}, {id_D0_01, id_IN3}, {id_D1_01, id_IN4}, {id_D0_10, id_IN1},
94 {id_D1_10, id_IN3}, {id_OUT, id_OUT2}, {id_RAM_O, id_RAM_O2}, {id_RAM_I, id_RAM_I2}, {id_CPOUT, id_CPOUT2},
95 };
96 static dict<IdString, IdString> map_lower = {
97 {id_D0_00, id_IN5}, {id_D1_00, id_IN6}, {id_D0_01, id_IN7}, {id_D1_01, id_IN8}, {id_D0_10, id_IN5},
98 {id_D1_10, id_IN7}, {id_D0_02, id_IN5}, {id_D1_02, id_IN6}, {id_D0_03, id_IN7}, {id_D1_03, id_IN8},
99 {id_D0_11, id_IN5}, {id_D1_11, id_IN7}, {id_OUT, id_OUT1}, {id_RAM_O, id_RAM_O1}, {id_RAM_I, id_RAM_I1},
100 {id_CPOUT, id_CPOUT1}, {id_IN1, id_IN5}, {id_IN2, id_IN6}, {id_IN3, id_IN7}, {id_IN4, id_IN8},
101 };
102
103 static dict<IdString, IdString> map_both = {
104 {id_D0_00, id_IN1}, {id_D1_00, id_IN2}, {id_D0_01, id_IN3}, {id_D1_01, id_IN4},
105 {id_D0_10, id_IN1}, {id_D1_10, id_IN3}, {id_D0_02, id_IN5}, {id_D1_02, id_IN6},
106 {id_D0_03, id_IN7}, {id_D1_03, id_IN8}, {id_D0_11, id_IN5}, {id_D1_11, id_IN7},
107 };
108
109 int z = (cell->bel != BelId()) ? (ctx->getBelLocation(cell->bel).z % 2) : 0;
110 if (cell->type.in(id_CPE_L2T4, id_CPE_LT_L, id_CPE_LT_U)) {
111 IdString fp = fromPort, tp = toPort;
112 if (z == 0) {
113 if (map_upper.count(fp))
114 fp = map_upper[fp];
115 if (map_upper.count(tp))
116 tp = map_upper[tp];
117 } else {
118 if (map_lower.count(fp))
119 fp = map_lower[fp];
120 if (map_lower.count(tp))
121 tp = map_lower[tp];
122 }
123 return get_delay_from_tmg_db(ctx->idf("timing__ARBLUT_%s_%s", fp.c_str(ctx), tp.c_str(ctx)), delay);
124 } else if (cell->type.in(id_CPE_ADDF, id_CPE_ADDF2)) {
125 IdString fp = fromPort, tp = toPort;
126 if (map_both.count(fp))
127 fp = map_both[fp];
128 if (map_both.count(tp))
129 tp = map_both[tp];
130 return get_delay_from_tmg_db(ctx->idf("timing__ADDF2Y1_%s_%s", fp.c_str(ctx), tp.c_str(ctx)), delay);
131 } else if (cell->type.in(id_CPE_MX4)) {
132 IdString fp = fromPort, tp = toPort;
133 if (map_both.count(fp))
134 fp = map_both[fp];
135 if (map_both.count(tp))
136 tp = map_both[tp];
137 return get_delay_from_tmg_db(ctx->idf("timing__MX4A_%s_%s", fp.c_str(ctx), tp.c_str(ctx)), delay);
138 } else if (cell->type.in(id_CPE_MULT)) {
139 if (toPort == id_CPOUT1)
140 return get_delay_from_tmg_db(ctx->id("timing_cpout_OUT1"), delay);
141 if (toPort == id_CPOUT2)
142 return get_delay_from_tmg_db(ctx->id("timing_cpout_OUT2"), delay);
143 return get_delay_from_tmg_db(ctx->idf("timing__MULT_%s_%s", fromPort.c_str(ctx), toPort.c_str(ctx)), delay);
144 } else if (cell->type.in(id_CPE_FF, id_CPE_LATCH, id_CPE_FF_L, id_CPE_FF_U)) {
145 return false;
146 } else if (cell->type.in(id_CPE_CPLINES)) {
147 return true;
148 } else if (cell->type.in(id_CPE_BRIDGE)) {
149 return true;
150 } else if (cell->type.in(id_CPE_COMP)) {
151 return get_delay_from_tmg_db(fromPort == id_COMB1 ? id_timing_comb1_compout : id_timing_comb2_compout, delay);
152 } else if (cell->type.in(id_CPE_RAMI, id_CPE_RAMO, id_CPE_RAMIO)) {
153 if (fromPort == id_I && toPort == id_RAM_O)
154 return get_delay_from_tmg_db(z ? id_timing_comb12_RAM_O1 : id_timing_comb12_RAM_O2, delay);
155 if (fromPort == id_RAM_I && toPort == id_OUT)
156 return true;
157 return false;
158 } else if (cell->type.in(id_CPE_IBUF, id_CPE_OBUF, id_CPE_TOBUF, id_CPE_IOBUF)) {
159 if (fromPort == id_A && toPort == id_O)
160 return get_delay_from_tmg_db(id_timing_del_OBF, delay);
161 if (fromPort == id_T && toPort == id_O)
162 return get_delay_from_tmg_db(id_timing_del_TOBF_ctrl, delay);
163 if (fromPort == id_I && toPort == id_Y)
164 return get_delay_from_tmg_db(id_timing_del_IBF, delay);
165 return true;
166 } else if (cell->type.in(id_CPE_LVDS_IBUF, id_CPE_LVDS_OBUF, id_CPE_LVDS_TOBUF, id_CPE_LVDS_IOBUF)) {
167 if (fromPort == id_A && toPort.in(id_O_P, id_O_N))
168 return get_delay_from_tmg_db(id_timing_del_LVDS_OBF, delay);
169 if (fromPort == id_T && toPort.in(id_O_P, id_O_N))
170 return get_delay_from_tmg_db(id_timing_del_LVDS_TOBF_ctrl, delay);
171 if (fromPort.in(id_I_P, id_I_N) && toPort == id_Y)
172 return get_delay_from_tmg_db(id_timing_del_LVDS_IBF, delay);
173 return true;
174 } else if (cell->type.in(id_IOSEL)) {
175 bool output = bool_or_default(cell->params, id_OUT_SIGNAL);
176 bool enable = bool_or_default(cell->params, id_OE_ENABLE);
177 IdString o_s = bool_or_default(cell->params, id_OUT23_14_SEL)
178 ? (bool_or_default(cell->params, id_OUT2_3) ? id_OUT3 : id_OUT2)
179 : (bool_or_default(cell->params, id_OUT1_4) ? id_OUT4 : id_OUT1);
180 int oe = int_or_default(cell->params, id_OE_SIGNAL);
181 IdString oe_s = (oe & 2) ? ((oe & 1) ? id_OUT4 : id_OUT3) : ((oe & 1) ? id_OUT2 : id_OUT1);
182 if (output && fromPort != o_s)
183 return false;
184 if (enable && fromPort != oe_s)
185 return false;
186 return get_delay_from_tmg_db(ctx->idf("timing_io_sel_%s_%s", fromPort.c_str(ctx), toPort.c_str(ctx)), delay);
187 } else if (cell->type.in(id_CLKIN)) {
188 return get_delay_from_tmg_db(ctx->idf("timing_clkin_%s_%s", fromPort.c_str(ctx), toPort.c_str(ctx)), delay);
189 } else if (cell->type.in(id_GLBOUT)) {
190 return get_delay_from_tmg_db(ctx->idf("timing_glbout_%s_%s", fromPort.c_str(ctx), toPort.c_str(ctx)), delay);
191 } else if (cell->type.in(id_RAM, id_RAM_HALF)) {
192 return false;
193 } else if (cell->type.in(id_PLL)) {
194 if (fromPort.in(id_CLK_REF, id_USR_CLK_REF) && toPort.in(id_CLK0, id_CLK90, id_CLK180, id_CLK270))
195 return get_delay_from_tmg_db(ctx->id("timing_pll_clk_ref_i_clk_core0_o"), delay);
196 return false;
197 }
198 return false;
199 }
200
201 TimingPortClass GateMateImpl::getPortTimingClass(const CellInfo *cell, IdString port, int &clockInfoCount) const
202 {
203 auto disconnected = [cell](IdString p) { return !cell->ports.count(p) || cell->ports.at(p).net == nullptr; };
204 clockInfoCount = 0;
205 if (cell->type.in(id_CPE_L2T4, id_CPE_LT_L, id_CPE_LT_U)) {
206 if (port.in(id_IN1, id_IN2, id_IN3, id_IN4, id_COMBIN, id_CINY1, id_CINY2, id_CINX, id_PINX, id_D0_00, id_D1_00,
207 id_D0_01, id_D1_01, id_D0_10, id_D1_10, id_D0_02, id_D1_02, id_D0_03, id_D1_03, id_D0_11, id_D1_11))
208 return TMG_COMB_INPUT;
209 if (port == id_OUT && disconnected(id_IN1) && disconnected(id_IN2) && disconnected(id_IN3) &&
210 disconnected(id_IN4) && disconnected(id_D0_00) && disconnected(id_D1_00) && disconnected(id_D0_01) &&
211 disconnected(id_D1_01) && disconnected(id_D0_10) && disconnected(id_D1_10) && disconnected(id_D0_02) &&
212 disconnected(id_D1_02) && disconnected(id_D0_03) && disconnected(id_D1_03) && disconnected(id_D0_11) &&
213 disconnected(id_D1_11))
214 return TMG_IGNORE; // LUT with no inputs is a constant
215 if (port.in(id_OUT))
216 return TMG_COMB_OUTPUT;
217 return TMG_IGNORE;
218 } else if (cell->type.in(id_CPE_ADDF, id_CPE_ADDF2)) {
219 if (port.in(id_IN1, id_IN2, id_IN3, id_IN4, id_IN5, id_IN6, id_IN7, id_IN8, id_CINX, id_CINY1, id_D0_00,
220 id_D1_00, id_D0_01, id_D1_01, id_D0_10, id_D1_10, id_D0_02, id_D1_02, id_D0_03, id_D1_03, id_D0_11,
221 id_D1_11))
222 return TMG_COMB_INPUT;
223 if (port.in(id_OUT1, id_OUT2, id_COUTY1))
224 return TMG_COMB_OUTPUT;
225 return TMG_IGNORE;
226 } else if (cell->type.in(id_CPE_MX4)) {
227 if (port.in(id_IN1, id_IN2, id_IN3, id_IN4, id_IN5, id_IN6, id_IN7, id_IN8, id_D0_00, id_D1_00, id_D0_01,
228 id_D1_01, id_D0_10, id_D1_10, id_D0_02, id_D1_02, id_D0_03, id_D1_03, id_D0_11, id_D1_11))
229 return TMG_COMB_INPUT;
230 if (port.in(id_OUT1))
231 return TMG_COMB_OUTPUT;
232 return TMG_IGNORE;
233 } else if (cell->type.in(id_CPE_MULT)) {
234 if (port.in(id_IN1, id_IN5, id_IN8, id_CINX, id_PINX, id_CINY1, id_CINY2, id_PINY1, id_PINY2))
235 return TMG_COMB_INPUT;
236 return TMG_COMB_OUTPUT;
237 } else if (cell->type.in(id_CPE_CPLINES)) {
238 if (port.in(id_OUT1, id_OUT2, id_COMPOUT, id_CINX, id_PINX, id_CINY1, id_PINY1, id_CINY2, id_PINY2))
239 return TMG_COMB_INPUT;
240 return TMG_COMB_OUTPUT;
241 } else if (cell->type.in(id_CPE_BRIDGE)) {
242 if (port.in(id_MUXOUT))
243 return TMG_COMB_OUTPUT;
244 return TMG_COMB_INPUT;
245 } else if (cell->type.in(id_CPE_FF, id_CPE_FF_L, id_CPE_FF_U, id_CPE_LATCH)) {
246 if (port.in(id_CLK_INT))
247 return TMG_CLOCK_INPUT;
248 clockInfoCount = 1;
249 if (port == id_DOUT)
250 return TMG_REGISTER_OUTPUT;
251 // DIN, EN and SR
252 return TMG_REGISTER_INPUT;
253 } else if (cell->type.in(id_CPE_RAMI, id_CPE_RAMO, id_CPE_RAMIO, id_CPE_RAMIO_U, id_CPE_RAMIO_L)) {
254 if (port.in(id_I, id_RAM_I))
255 return TMG_COMB_INPUT;
256 if (port.in(id_O, id_RAM_O))
257 return TMG_COMB_OUTPUT;
258 return TMG_IGNORE;
259 } else if (cell->type.in(id_CPE_COMP)) {
260 if (port.in(id_COMB1, id_COMB2))
261 return TMG_COMB_INPUT;
262 return TMG_COMB_OUTPUT;
263 } else if (cell->type.in(id_CPE_IBUF, id_CPE_OBUF, id_CPE_TOBUF, id_CPE_IOBUF)) {
264 if (port.in(id_O))
265 return TMG_ENDPOINT;
266 if (port.in(id_Y))
267 return TMG_STARTPOINT;
268 return TMG_IGNORE;
269 } else if (cell->type.in(id_CPE_LVDS_IBUF, id_CPE_LVDS_OBUF, id_CPE_LVDS_TOBUF, id_CPE_LVDS_IOBUF)) {
270 if (port.in(id_O_P, id_O_N))
271 return TMG_ENDPOINT;
272 if (port.in(id_Y))
273 return TMG_STARTPOINT;
274 return TMG_IGNORE;
275 } else if (cell->type.in(id_IOSEL)) {
276 if (port.in(id_IN1, id_IN2, id_GPIO_EN, id_GPIO_OUT))
277 return TMG_COMB_OUTPUT;
278 if (port.in(id_OUT1, id_OUT2, id_OUT3, id_OUT4, id_GPIO_IN))
279 return TMG_COMB_INPUT;
280 return TMG_IGNORE;
281 } else if (cell->type.in(id_PLL)) {
282 if (port.in(id_CLK_REF, id_USR_CLK_REF))
283 return TMG_CLOCK_INPUT;
284 if (port.in(id_CLK0, id_CLK90, id_CLK180, id_CLK270))
285 return TMG_GEN_CLOCK;
286 return TMG_IGNORE;
287 } else if (cell->type.in(id_CLKIN)) {
288 if (port.in(id_CLK0, id_CLK1, id_CLK2, id_CLK3, id_SER_CLK))
289 return TMG_CLOCK_INPUT;
290 if (port.in(id_CLK_REF0, id_CLK_REF1, id_CLK_REF2, id_CLK_REF3))
291 return TMG_GEN_CLOCK;
292 return TMG_IGNORE;
293 } else if (cell->type.in(id_GLBOUT)) {
294 if (port.in(id_CLK0_0, id_CLK90_0, id_CLK180_0, id_CLK270_0, id_CLK_REF_OUT0, id_CLK0_1, id_CLK90_1,
295 id_CLK180_1, id_CLK270_1, id_CLK_REF_OUT1, id_CLK0_2, id_CLK90_2, id_CLK180_2, id_CLK270_2,
296 id_CLK_REF_OUT2, id_CLK0_3, id_CLK90_3, id_CLK180_3, id_CLK270_3, id_CLK_REF_OUT3, id_USR_GLB0,
297 id_USR_GLB1, id_USR_GLB2, id_USR_GLB3))
298 return TMG_CLOCK_INPUT;
299 if (port.in(id_GLB0, id_GLB1, id_GLB2, id_GLB3))
300 return TMG_GEN_CLOCK;
301 return TMG_IGNORE;
302 } else if (cell->type.in(id_SERDES)) {
303 return TMG_IGNORE;
304 } else if (cell->type.in(id_USR_RSTN)) {
305 return TMG_IGNORE;
306 } else if (cell->type.in(id_CFG_CTRL)) {
307 if (port.in(id_CLK))
308 return TMG_CLOCK_INPUT;
309 return TMG_IGNORE;
310 } else if (cell->type.in(id_RAM, id_RAM_HALF)) {
311 std::string name = port.str(ctx);
312 if (boost::starts_with(name, "CLKA[") || boost::starts_with(name, "CLKB[") || boost::starts_with(name, "CLOCK"))
313 return TMG_CLOCK_INPUT;
314 if (boost::ends_with(name, "_CI") || boost::ends_with(name, "_CO"))
315 return TMG_IGNORE;
316 if (name[0] == 'F') // Ignore forward and FIFO pins
317 return TMG_IGNORE;
318 for (auto c : boost::adaptors::reverse(name)) {
319 if (std::isdigit(c) || c == 'X' || c == '[' || c == ']')
320 continue;
321 if (c == 'A' || c == 'B')
322 clockInfoCount = 1;
323 else
324 NPNR_ASSERT_FALSE_STR("bad ram port");
325 return (cell->ports.at(port).type == PORT_OUT) ? TMG_REGISTER_OUTPUT : TMG_REGISTER_INPUT;
326 }
327 NPNR_ASSERT_FALSE_STR("no timing type for RAM port '" + port.str(ctx) + "'");
328 } else {
329 log_error("Cell type '%s' is unsupported (instantiated as '%s').\n", cell->type.c_str(ctx),
330 cell->name.c_str(ctx));
331 }
332 }
333
334 IdString clock(uint8_t val, IdString clk1, IdString clk2, IdString clk3, IdString clk4)
335 {
336 switch (val) {
337 case 0b00000000:
338 return clk1;
339 case 0b00000100:
340 return clk2;
341 case 0b00001000:
342 return clk3;
343 case 0b00001100:
344 return clk4;
345 case 0b00100011:
346 return id_CLOCK1;
347 case 0b00110011:
348 return id_CLOCK2;
349 case 0b00000011:
350 return id_CLOCK3;
351 case 0b00010011:
352 return id_CLOCK4;
353 default:
354 return clk1;
355 }
356 }
357
358 TimingClockingInfo GateMateImpl::getPortClockingInfo(const CellInfo *cell, IdString port, int index) const
359 {
360 TimingClockingInfo info;
361 info.setup = DelayPair(0);
362 info.hold = DelayPair(0);
363 info.clockToQ = DelayQuad(0);
364 if (cell->type.in(id_CPE_FF, id_CPE_FF_L, id_CPE_FF_U, id_CPE_LATCH)) {
365 bool inverted = int_or_default(cell->params, id_C_CPE_CLK, 0) == 0b01;
366 info.edge = inverted ? FALLING_EDGE : RISING_EDGE;
367 info.clock_port = id_CLK_INT;
368 if (port.in(id_DIN, id_EN, id_SR))
369 get_setuphold_from_tmg_db(id_timing_del_Setup_D_L, id_timing_del_Hold_D_L, info.setup, info.hold);
370 if (port.in(id_DOUT)) {
371 bool is_upper = (cell->bel != BelId()) && (ctx->getBelLocation(cell->bel).z == CPE_LT_U_Z);
372 get_delay_from_tmg_db(id_timing__SEQ_CLK_FF1_Q, info.clockToQ);
373 DelayQuad delay = DelayQuad{0};
374 get_delay_from_tmg_db(is_upper ? id_timing_Q2_OUT2 : id_timing_Q1_OUT1, delay);
375 info.clockToQ += delay;
376 get_delay_from_tmg_db(id_timing_del_CPE_CP_Q, delay);
377 info.clockToQ += delay;
378 }
379 } else if (cell->type.in(id_RAM, id_RAM_HALF)) {
380 std::string name = port.str(ctx);
381 int is_ecc_a = int_or_default(cell->params, id_A_ECC_EN, 0);
382 int is_ecc_b = int_or_default(cell->params, id_B_ECC_EN, 0);
383 if (boost::starts_with(name, "CLOCK")) {
384 if (is_ecc_a || is_ecc_b)
385 get_delay_from_tmg_db(id_timing_RAM_ECC_IOPATH_1, info.clockToQ);
386 else
387 get_delay_from_tmg_db(id_timing_RAM_NOECC_IOPATH_1, info.clockToQ);
388 }
389 if (boost::starts_with(name, "DOA")) {
390 if (is_ecc_a)
391 get_delay_from_tmg_db(id_timing_RAM_ECC_IOPATH_2, info.clockToQ);
392 else
393 get_delay_from_tmg_db(id_timing_RAM_NOECC_IOPATH_2, info.clockToQ);
394 }
395 if (boost::starts_with(name, "DOB")) {
396 if (is_ecc_b)
397 get_delay_from_tmg_db(id_timing_RAM_ECC_IOPATH_3, info.clockToQ);
398 else
399 get_delay_from_tmg_db(id_timing_RAM_NOECC_IOPATH_3, info.clockToQ);
400 }
401 if (boost::starts_with(name, "ECC")) {
402 if (is_ecc_a || is_ecc_b)
403 get_delay_from_tmg_db(id_timing_RAM_ECC_IOPATH_4, info.clockToQ);
404 else
405 get_delay_from_tmg_db(id_timing_RAM_NOECC_IOPATH_4, info.clockToQ);
406 }
407 if (boost::starts_with(name, "ADDRA")) {
408 if (is_ecc_a)
409 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_1, info.setup, info.hold);
410 else
411 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_1, info.setup, info.hold);
412 }
413 if (boost::starts_with(name, "ADDRB")) {
414 if (is_ecc_b)
415 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_1, info.setup, info.hold);
416 else
417 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_1, info.setup, info.hold);
418 }
419 if (boost::starts_with(name, "CLOCK1")) { // TODO CLOCK1 || CLOCK2 || CLOCK3 || CLOCK4?
420 if (is_ecc_a || is_ecc_b)
421 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_2, info.setup, info.hold);
422 else
423 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_2, info.setup, info.hold);
424 }
425 if (boost::starts_with(name, "DIA")) {
426 if (is_ecc_a)
427 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_3, info.setup, info.hold);
428 else
429 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_3, info.setup, info.hold);
430 }
431 if (boost::starts_with(name, "DIB")) {
432 if (is_ecc_b)
433 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_4, info.setup, info.hold);
434 else
435 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_4, info.setup, info.hold);
436 }
437 if (boost::starts_with(name, "ENA")) {
438 if (is_ecc_a)
439 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_5, info.setup, info.hold);
440 else
441 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_5, info.setup, info.hold);
442 }
443 if (boost::starts_with(name, "ENB")) {
444 if (is_ecc_b)
445 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_6, info.setup, info.hold);
446 else
447 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_6, info.setup, info.hold);
448 }
449 if (boost::starts_with(name, "GLWEA")) {
450 if (is_ecc_a)
451 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_7, info.setup, info.hold);
452 else
453 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_7, info.setup, info.hold);
454 }
455 if (boost::starts_with(name, "GLWEB")) {
456 if (is_ecc_b)
457 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_8, info.setup, info.hold);
458 else
459 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_8, info.setup, info.hold);
460 }
461 if (boost::starts_with(name, "WEA")) {
462 if (is_ecc_a)
463 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_9, info.setup, info.hold);
464 else
465 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_9, info.setup, info.hold);
466 }
467 if (boost::starts_with(name, "WEB")) {
468 if (is_ecc_b)
469 get_setuphold_from_tmg_db(id_timing_RAM_ECC_SETUPHOLD_10, info.setup, info.hold);
470 else
471 get_setuphold_from_tmg_db(id_timing_RAM_NOECC_SETUPHOLD_10, info.setup, info.hold);
472 }
473 bool is_clk_b = false;
474 for (auto c : boost::adaptors::reverse(name)) {
475 if (std::isdigit(c) || c == 'X' || c == '[' || c == ']')
476 continue;
477 if (c == 'A')
478 is_clk_b = false;
479 else if (c == 'B')
480 is_clk_b = true;
481 else
482 NPNR_ASSERT_FALSE_STR("bad ram port");
483 break;
484 }
485
486 bool inverted = int_or_default(cell->params, id_A_CLK_INV, 0);
487 if (is_clk_b)
488 inverted = int_or_default(cell->params, id_B_CLK_INV, 0);
489
490 info.edge = inverted ? FALLING_EDGE : RISING_EDGE;
491 uint8_t a0_clk_val = int_or_default(cell->params, id_RAM_cfg_forward_a0_clk, 0);
492 uint8_t a1_clk_val = int_or_default(cell->params, id_RAM_cfg_forward_a1_clk, 0);
493 uint8_t b0_clk_val = int_or_default(cell->params, id_RAM_cfg_forward_b0_clk, 0);
494 uint8_t b1_clk_val = int_or_default(cell->params, id_RAM_cfg_forward_b1_clk, 0);
495 IdString a0_clk =
496 clock(a0_clk_val, ctx->id("CLKA[0]"), ctx->id("CLKA[1]"), ctx->id("CLKB[0]"), ctx->id("CLKB[1]"));
497 IdString a1_clk =
498 clock(a1_clk_val, ctx->id("CLKA[2]"), ctx->id("CLKA[3]"), ctx->id("CLKB[2]"), ctx->id("CLKB[3]"));
499 IdString b0_clk =
500 clock(b0_clk_val, ctx->id("CLKB[0]"), ctx->id("CLKB[1]"), ctx->id("CLKA[0]"), ctx->id("CLKA[1]"));
501 IdString b1_clk =
502 clock(b1_clk_val, ctx->id("CLKB[2]"), ctx->id("CLKB[3]"), ctx->id("CLKA[2]"), ctx->id("CLKA[3]"));
503 if (ram_signal_clk.count(port)) {
504 switch (ram_signal_clk.at(port)) {
505 case 0:
506 info.clock_port = a0_clk;
507 break;
508 case 1:
509 info.clock_port = a1_clk;
510 break;
511 case 2:
512 info.clock_port = b0_clk;
513 break;
514 case 3:
515 info.clock_port = b1_clk;
516 break;
517 }
518 } else {
519 log_error("Unknown clock signal for %s.\n", name.c_str());
520 }
521 }
522
523 return info;
524 }
525
526 NEXTPNR_NAMESPACE_END