@@ -40,21 +40,6 @@ struct BitstreamBackend
4040 BitstreamBackend (Context *ctx, GateMateImpl *uarch, const std::string &device, std::ostream &out)
4141 : ctx(ctx), uarch(uarch), device(device), out(out) {};
4242
43- void get_bitstream_tile (int x, int y, int &b_x, int &b_y)
44- {
45- // Edge blocks are bit bigger
46- if (x == -2 )
47- x++;
48- if (x == 163 )
49- x--;
50- if (y == -2 )
51- y++;
52- if (y == 131 )
53- y--;
54- b_x = (x + 1 ) / 2 ;
55- b_y = (y + 1 ) / 2 ;
56- }
57-
5843 std::vector<bool > int_to_bitvector (int val, int size)
5944 {
6045 std::vector<bool > bv;
@@ -76,28 +61,16 @@ struct BitstreamBackend
7661 return bv;
7762 }
7863
79- CfgLoc getConfigLoc (Context *ctx, int tile)
64+ CfgLoc getConfigLoc (int tile)
8065 {
81- int x0, y0;
82- int bx, by;
83- tile_xy (ctx->chip_info , tile, x0, y0);
84- get_bitstream_tile (x0 - 2 , y0 - 2 , bx, by);
66+ auto ti = *uarch->tile_extra_data (tile);
8567 CfgLoc loc;
86- loc.die = 0 ;
87- loc.x = bx ;
88- loc.y = by ;
68+ loc.die = ti. die ;
69+ loc.x = ti. bit_x ;
70+ loc.y = ti. bit_y ;
8971 return loc;
9072 }
9173
92- int getInTileIndex (Context *ctx, int tile)
93- {
94- int x0, y0;
95- tile_xy (ctx->chip_info , tile, x0, y0);
96- x0 -= 2 - 1 ;
97- y0 -= 2 - 1 ;
98- return (x0 % 2 ) * 2 + (y0 % 2 ) + 1 ;
99- }
100-
10174 void write_bitstream ()
10275 {
10376 ChipConfig cc;
@@ -111,7 +84,7 @@ struct BitstreamBackend
11184 cc.configs [0 ].add_word (" GPIO.BANK_W1" , int_to_bitvector (1 , 1 ));
11285 cc.configs [0 ].add_word (" GPIO.BANK_W2" , int_to_bitvector (1 , 1 ));
11386 for (auto &cell : ctx->cells ) {
114- CfgLoc loc = getConfigLoc (ctx, cell.second .get ()->bel .tile );
87+ CfgLoc loc = getConfigLoc (cell.second .get ()->bel .tile );
11588 auto ¶ms = cell.second .get ()->params ;
11689 switch (cell.second ->type .index ) {
11790 case id_CC_IBUF.index :
@@ -127,9 +100,9 @@ struct BitstreamBackend
127100 }
128101 break ;
129102 case id_CPE.index : {
130- int x = getInTileIndex (ctx, cell.second .get ()->bel .tile );
103+ int id = uarch-> tile_extra_data ( cell.second .get ()->bel .tile )-> prim_id ;
131104 for (auto &p : params) {
132- cc.tiles [loc].add_word (stringf (" CPE%d.%s" , x , p.first .c_str (ctx)), p.second .as_bits ());
105+ cc.tiles [loc].add_word (stringf (" CPE%d.%s" , id , p.first .c_str (ctx)), p.second .as_bits ());
133106 }
134107 } break ;
135108 case id_BUFG.index :
@@ -169,20 +142,28 @@ struct BitstreamBackend
169142 chip_pip_info (ctx->chip_info , pip).extra_data .get ());
170143 if (extra_data.type == PipExtra::PIP_EXTRA_MUX && (extra_data.flags & MUX_VISIBLE)) {
171144 IdString name = IdString (extra_data.name );
172- CfgLoc loc = getConfigLoc (ctx, pip.tile );
145+ CfgLoc loc = getConfigLoc (pip.tile );
173146 std::string word = name.c_str (ctx);
174147 if (extra_data.flags & MUX_CONFIG) {
175- cc.configs [loc.die ].add_word (word, int_to_bitvector (extra_data.value , extra_data.bits ));
148+ cc.configs [loc.die ].add_word (word, int_to_bitvector (extra_data.value , extra_data.bits ));
176149 } else {
177- int x = getInTileIndex (ctx, pip.tile );
150+ int id = uarch-> tile_extra_data ( pip.tile )-> prim_id ;
178151 if (boost::starts_with (word, " IM." ))
179- boost::replace_all (word, " IM." , stringf (" IM%d." , x));
180- if (boost::starts_with (word, " OM." ))
181- boost::replace_all (word, " OM." , stringf (" OM%d." , x));
182- if (boost::starts_with (word, " IOES." ))
183- boost::replace_all (word, " IOES." , " IOES1." );
184- if (boost::starts_with (word, " CPE." ))
185- boost::replace_all (word, " CPE." , stringf (" CPE%d." , x));
152+ boost::replace_all (word, " IM." , stringf (" IM%d." , id));
153+ else if (boost::starts_with (word, " OM." ))
154+ boost::replace_all (word, " OM." , stringf (" OM%d." , id));
155+ else if (boost::starts_with (word, " CPE." ))
156+ boost::replace_all (word, " CPE." , stringf (" CPE%d." , id));
157+ else if (boost::starts_with (word, " IOES." ))
158+ boost::replace_all (word, " IOES." , stringf (" IOES%d." , id));
159+ else if (boost::starts_with (word, " LES." ))
160+ boost::replace_all (word, " LES." , stringf (" LES%d." , id));
161+ else if (boost::starts_with (word, " BES." ))
162+ boost::replace_all (word, " BES." , stringf (" BES%d." , id));
163+ else if (boost::starts_with (word, " RES." ))
164+ boost::replace_all (word, " RES." , stringf (" RES%d." , id));
165+ else if (boost::starts_with (word, " TES." ))
166+ boost::replace_all (word, " TES." , stringf (" TES%d." , id));
186167 cc.tiles [loc].add_word (word, int_to_bitvector (extra_data.value , extra_data.bits ));
187168 }
188169 }
0 commit comments