Skip to content

Fix incorrect IO tile corner detection in nextpnr-aegis#13

Open
hobostay wants to merge 1 commit intoMidstallSoftware:masterfrom
hobostay:fix/io-corner-detection
Open

Fix incorrect IO tile corner detection in nextpnr-aegis#13
hobostay wants to merge 1 commit intoMidstallSoftware:masterfrom
hobostay:fix/io-corner-detection

Conversation

@hobostay
Copy link
Copy Markdown

@hobostay hobostay commented Apr 9, 2026

Summary

The corner detection logic in nextpnr-aegis/aegis.cc used x != y / x == y to identify which IO tiles should have wires, BELs, and pips. This condition only excludes the diagonal corners (0,0) and (W-1,H-1), while incorrectly treating corners (W-1,0) and (0,H-1) as valid IO tiles.

Bug

For a grid of W×H (including IO ring), the four corners are:

  • (0, 0) — excluded by x == y
  • (W-1, 0)W-1 != 0, so incorrectly gets IO resources
  • (0, H-1)0 != H-1, so incorrectly gets IO resources
  • (W-1, H-1) — excluded by x == y

This causes the nextpnr model to create IO BELs at two corners that don't correspond to actual IO pads in the FPGA hardware (as modeled by the Rust simulator). The placer could then assign IO cells to these non-existent pad positions, producing a bitstream that doesn't work on the device.

Fix

Add an is_corner() helper that correctly checks all four grid corners:

bool is_corner(int x, int y) const {
    return (x == 0 || x == W - 1) && (y == 0 || y == H - 1);
}

Replace the three occurrences of the incorrect condition in init_wires, init_bels, and init_pips.

Test plan

  • Verify that for a 4×4 fabric (6×6 grid), only the 16 edge IO tiles (not corners) have IO BELs
  • Run existing nextpnr tests if available
  • Compare IO tile count against the Rust simulator's io_pad_pos construction

🤖 Generated with Claude Code

The previous corner detection used `x != y` / `x == y` which only
excluded the (0,0) and (W-1,H-1) diagonal corners. The corners
(W-1,0) and (0,H-1) were incorrectly treated as valid IO tiles,
causing IO BELs, wires, and pips to be created at positions that
don't correspond to actual IO pads in the FPGA hardware.

This mismatch between the nextpnr model and the simulator/hardware
could cause the placer to assign IO cells to non-existent pad
positions, producing a bitstream that doesn't work on the device.

Fix by adding an is_corner() helper that correctly identifies all
four grid corners, and use it in init_wires, init_bels, and init_pips.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant