1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615
|
/*--------------------------------------------------------------*/
/* maze.c -- general purpose maze router routines. */
/* */
/* This file contains the main cost evaluation routine, */
/* the route segment generator, and a routine to search */
/* the database for all parts of a routed network. */
/*--------------------------------------------------------------*/
/* Written by Tim Edwards, June 2011, based on code by Steve */
/* Beccue */
/*--------------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define MAZE
#include "qrouter.h"
#include "qconfig.h"
#include "point.h"
#include "node.h"
#include "maze.h"
#include "lef.h"
extern int TotalRoutes;
/*--------------------------------------------------------------*/
/* find_unrouted_node() -- */
/* */
/* On a power bus, the nodes are routed individually, using the */
/* entire power bus as the destination. So to find out if a */
/* node is already routed or not, the only way is to check the */
/* routes recorded for the net and determine if any net */
/* endpoint is on a node. */
/* */
/* Return the first node found that is not connected to any */
/* route endpoint. If all nodes are routed, then return NULL */
/*--------------------------------------------------------------*/
NODE find_unrouted_node(NET net)
{
int i, numroutes;
u_char *routednode;
NODE node;
ROUTE rt;
SEG seg1, seg2;
DPOINT tap;
// Quick check: If the number of routes == number of nodes,
// then return NULL and we're done.
numroutes = 0;
for (rt = net->routes; rt; rt = rt->next) numroutes++;
if (numroutes == net->numnodes) return NULL;
routednode = (u_char *)malloc(net->numnodes * sizeof(u_char));
for (i = 0; i < net->numnodes; i++) routednode[i] = 0;
// Otherwise, we don't know which nodes have been routed,
// so check each one individually.
for (rt = net->routes; rt; rt = rt->next) {
seg1 = rt->segments;
if (seg1 == NULL) continue;
seg2 = seg1;
while (seg2->next) seg2 = seg2->next;
for (node = net->netnodes; node; node = node->next) {
if (routednode[node->nodenum] == 1) continue;
for (tap = node->taps; tap; tap = tap->next) {
if (seg1->x1 == tap->gridx && seg1->y1 == tap->gridy
&& seg1->layer == tap->layer) {
routednode[node->nodenum] = 1;
break;
}
else if (seg1->x2 == tap->gridx && seg1->y2 == tap->gridy
&& seg1->layer == tap->layer) {
routednode[node->nodenum] = 1;
break;
}
else if (seg2->x1 == tap->gridx && seg2->y1 == tap->gridy
&& seg2->layer == tap->layer) {
routednode[node->nodenum] = 1;
break;
}
else if (seg2->x2 == tap->gridx && seg2->y2 == tap->gridy
&& seg2->layer == tap->layer) {
routednode[node->nodenum] = 1;
break;
}
}
if (tap == NULL) {
for (tap = node->extend; tap; tap = tap->next) {
seg1 = rt->segments;
seg2 = seg1;
while (seg2->next) seg2 = seg2->next;
if (seg1->x1 == tap->gridx && seg1->y1 == tap->gridy
&& seg1->layer == tap->layer) {
routednode[node->nodenum] = 1;
break;
}
else if (seg1->x2 == tap->gridx && seg1->y2 == tap->gridy
&& seg1->layer == tap->layer) {
routednode[node->nodenum] = 1;
break;
}
else if (seg2->x1 == tap->gridx && seg2->y1 == tap->gridy
&& seg2->layer == tap->layer) {
routednode[node->nodenum] = 1;
break;
}
else if (seg2->x2 == tap->gridx && seg2->y2 == tap->gridy
&& seg2->layer == tap->layer) {
routednode[node->nodenum] = 1;
break;
}
}
}
}
}
for (node = net->netnodes; node; node = node->next) {
if (routednode[node->nodenum] == 0) {
free(routednode);
return node;
}
}
free(routednode);
return NULL; /* Statement should never be reached */
}
/*--------------------------------------------------------------*/
/* set_powerbus_to_net() */
/* If we have a power or ground net, go through the entire Obs */
/* array and mark all points matching the net as TARGET in Obs2 */
/* */
/* We do this after the call to PR_SOURCE, before the calls */
/* to set PR_TARGET. */
/* */
/* If any grid position was marked as TARGET, return 1, else */
/* return 0 (meaning the net has been routed already). */
/*--------------------------------------------------------------*/
int set_powerbus_to_net(int netnum)
{
int x, y, lay, rval;
PROUTE *Pr;
rval = 0;
if ((netnum == VDD_NET) || (netnum == GND_NET)) {
for (lay = 0; lay < Num_layers; lay++)
for (x = 0; x < NumChannelsX[lay]; x++)
for (y = 0; y < NumChannelsY[lay]; y++)
if ((OBSVAL(x, y, lay) & NETNUM_MASK) == netnum) {
Pr = &OBS2VAL(x, y, lay);
// Skip locations that have been purposefully disabled
if (!(Pr->flags & PR_COST) && (Pr->prdata.net == MAXNETNUM))
continue;
else if (!(Pr->flags & PR_SOURCE)) {
Pr->flags |= (PR_TARGET | PR_COST);
Pr->prdata.cost = MAXRT;
rval = 1;
}
}
}
return rval;
}
/*--------------------------------------------------------------*/
/* clear_non_source_targets -- */
/* */
/* Look at all target nodes of a net. For any that are not */
/* marked as SOURCE, but have terminal points marked as */
/* PROCESSED, remove the PROCESSED flag and put the position */
/* back on the stack for visiting on the next round. */
/*--------------------------------------------------------------*/
void clear_non_source_targets(NET net, POINT *pushlist)
{
NODE node;
DPOINT ntap;
PROUTE *Pr;
POINT gpoint;
int lay, x, y;
for (node = net->netnodes; node; node = node->next) {
for (ntap = node->taps; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
Pr = &OBS2VAL(x, y, lay);
if (Pr->flags & PR_TARGET) {
if (Pr->flags & PR_PROCESSED) {
Pr->flags &= ~PR_PROCESSED;
if (~(Pr->flags & PR_ON_STACK)) {
Pr->flags |= PR_ON_STACK;
gpoint = allocPOINT();
gpoint->x1 = x;
gpoint->y1 = y;
gpoint->layer = lay;
gpoint->next = *pushlist;
*pushlist = gpoint;
}
}
}
}
if (ntap == NULL) {
// Try extended tap areas
for (ntap = node->extend; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
Pr = &OBS2VAL(x, y, lay);
if (Pr->flags & PR_TARGET) {
if (Pr->flags & PR_PROCESSED) {
Pr->flags &= ~PR_PROCESSED;
if (~(Pr->flags & PR_ON_STACK)) {
Pr->flags |= PR_ON_STACK;
gpoint = allocPOINT();
gpoint->x1 = x;
gpoint->y1 = y;
gpoint->layer = lay;
gpoint->next = pushlist[1];
pushlist[1] = gpoint;
}
}
}
}
}
}
}
/*--------------------------------------------------------------*/
/* clear_target_node -- */
/* */
/* Remove PR_TARGET flags from all points belonging to a node */
/*--------------------------------------------------------------*/
void clear_target_node(NODE node)
{
int x, y, lay;
NODEINFO lnode;
DPOINT ntap;
PROUTE *Pr;
/* Process tap points of the node */
for (ntap = node->taps; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
if ((lay < Pinlayers) && (((lnode = NODEIPTR(x, y, lay)) == NULL)
|| (lnode->nodesav == NULL)))
continue;
Pr = &OBS2VAL(x, y, lay);
Pr->flags = 0;
Pr->prdata.net = node->netnum;
}
for (ntap = node->extend; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
if (lay < Pinlayers) {
lnode = NODEIPTR(x, y, lay);
if (lnode == NULL) continue;
if (lnode->nodesav != node) continue;
}
Pr = &OBS2VAL(x, y, lay);
Pr->flags = 0;
Pr->prdata.net = node->netnum;
}
}
/*--------------------------------------------------------------*/
/* count_targets() --- */
/* */
/* Count the number of nodes of a net that are still marked as */
/* TARGET. */
/*--------------------------------------------------------------*/
int
count_targets(NET net)
{
NODE node;
PROUTE *Pr;
DPOINT ntap;
int lay, x, y;
int count = 0;
for (node = net->netnodes; node; node = node->next) {
for (ntap = node->taps; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
Pr = &OBS2VAL(x, y, lay);
if (Pr->flags & PR_TARGET) {
count++;
break;
}
}
if (ntap == NULL) {
// Try extended tap areas
for (ntap = node->extend; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
Pr = &OBS2VAL(x, y, lay);
if (Pr->flags & PR_TARGET) {
count++;
break;
}
}
}
}
return count;
}
/*--------------------------------------------------------------*/
/* set_node_to_net() --- */
/* */
/* Change the Obs2[][] flag values to "newflags" for all tap */
/* positions of route terminal "node". */
/* */
/* Return value is 1 if at least one terminal of the node */
/* is already marked as PR_SOURCE, indicating that the node */
/* has already been routed. Otherwise, the return value is */
/* zero if no error occured, and -1 if any point was found to */
/* be unoccupied by any net, which should not happen. */
/* */
/* If "bbox" is non-null, record the grid extents of the node */
/* in the x1, x2, y1, y2 values */
/* */
/* If "stage" is 1 (rip-up and reroute), then don't let an */
/* existing route prevent us from adding terminals. However, */
/* the area will be first checked for any part of the terminal */
/* that is routable, only resorting to overwriting colliding */
/* nets if there are no other available taps. Defcon stage 3 */
/* indicates desperation due to a complete lack of routable */
/* taps. This happens if, for example, a port is offset from */
/* the routing grid and tightly boxed in by obstructions. In */
/* such case, we allow routing on an obstruction, but flag the */
/* point. In the output stage, the stub route information will */
/* be used to reposition the contact on the port and away from */
/* the obstruction. */
/* */
/* If we completely fail to find a tap point under any */
/* condition, then return -2. This is a fatal error; there */
/* will be no way to route the net. */
/*--------------------------------------------------------------*/
int set_node_to_net(NODE node, int newflags, POINT *pushlist,
SEG bbox, u_char stage)
{
int x, y, lay, rank, base, obsnet = 0;
int result = 0;
u_char found_one = FALSE;
NODEINFO lnode;
POINT gpoint;
DPOINT ntap;
PROUTE *Pr;
/* If called from set_routes_to_net, the node has no taps, and the */
/* net is a power bus, just return. */
if ((node->taps == NULL) && (node->extend == NULL)) {
if ((node->netnum == VDD_NET) || (node->netnum == GND_NET))
return result;
}
/* Process tap points of the node */
for (ntap = node->taps; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
Pr = &OBS2VAL(x, y, lay);
if ((Pr->flags & (newflags | PR_COST)) == PR_COST) {
Fprintf(stderr, "Error: Tap position %d, %d layer %d not "
"marked as source!\n", x, y, lay);
return -1; // This should not happen.
}
if (Pr->flags & PR_SOURCE) {
if (!found_one)
return 1; // Node is already connected!
else
continue; // May be duplicate tap position
}
else if ((Pr->flags & PR_TARGET) && (newflags & PR_TARGET)) {
if (!found_one)
return 1;
else
continue;
}
else if (((Pr->prdata.net == node->netnum) || (stage == (u_char)2))
&& !(Pr->flags & newflags)) {
// If we got here, we're on the rip-up stage, and there
// is an existing route completely blocking the terminal.
// So we will route over it and flag it as a collision.
if (Pr->prdata.net != node->netnum) {
if ((Pr->prdata.net == (NO_NET | OBSTRUCT_MASK)) ||
(Pr->prdata.net == NO_NET))
continue;
else
Pr->flags |= PR_CONFLICT;
}
// Do the source and dest nodes need to be marked routable?
Pr->flags |= (newflags == PR_SOURCE) ? newflags : (newflags | PR_COST);
Pr->prdata.cost = (newflags == PR_SOURCE) ? 0 : MAXRT;
// Rank the position according to how difficult it is to route to:
//
// 0: no restrictions
// 1: requires a stub route
// 2: inside the halo
// 3: requires an offset
// 4: requires an offset and a stub route
rank = 0;
if (lay < Pinlayers) {
if (lnode = NODEIPTR(x, y, lay)) {
if (lnode->flags & NI_OFFSET_MASK) rank = 2;
if (lnode->flags & NI_STUB_MASK) rank++;
}
}
// push this point on the stack to process
if (pushlist != NULL) {
if (~(Pr->flags & PR_ON_STACK)) {
Pr->flags |= PR_ON_STACK;
gpoint = allocPOINT();
gpoint->x1 = x;
gpoint->y1 = y;
gpoint->layer = lay;
gpoint->next = pushlist[rank];
pushlist[rank] = gpoint;
}
}
found_one = TRUE;
// record extents
if (bbox) {
if (x < bbox->x1) bbox->x1 = x;
if (x > bbox->x2) bbox->x2 = x;
if (y < bbox->y1) bbox->y1 = y;
if (y > bbox->y2) bbox->y2 = y;
}
}
else if ((Pr->prdata.net < MAXNETNUM) && (Pr->prdata.net > 0)) obsnet++;
}
// Do the same for point in the halo around the tap, but only if
// they have been attached to the net during a past routing run.
for (ntap = node->extend; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
// Don't process extended areas if they coincide with other nodes,
// or those that are out-of-bounds
base = 0;
if (lay < Pinlayers) {
lnode = NODEIPTR(x, y, lay);
if (lnode == NULL) continue;
if (lnode->nodesav != node) continue;
// Otherwise, rank according to ease of reaching the tap.
if (lnode->flags & NI_OFFSET_MASK) base = 2;
if (lnode->flags & NI_STUB_MASK) base++;
}
Pr = &OBS2VAL(x, y, lay);
if (Pr->flags & PR_SOURCE) {
if (!found_one)
return 1; // Node is already connected!
else
continue; // May be duplicate tap record
}
else if ((Pr->flags & PR_TARGET) && (newflags & PR_TARGET)) {
if (!found_one)
return 1;
else
continue;
}
else if ( !(Pr->flags & newflags) &&
((Pr->prdata.net == node->netnum) ||
(stage == (u_char)2 && Pr->prdata.net < MAXNETNUM) ||
(stage == (u_char)3))) {
if (Pr->prdata.net != node->netnum) Pr->flags |= PR_CONFLICT;
Pr->flags |= (newflags == PR_SOURCE) ? newflags : (newflags | PR_COST);
Pr->prdata.cost = (newflags == PR_SOURCE) ? 0 : MAXRT;
// push this point on the stack to process
if (pushlist != NULL) {
if (~(Pr->flags & PR_ON_STACK)) {
Pr->flags |= PR_ON_STACK;
gpoint = allocPOINT();
gpoint->x1 = x;
gpoint->y1 = y;
gpoint->layer = lay;
rank = (found_one == TRUE) ? 2 + base : base;
gpoint->next = pushlist[rank];
pushlist[rank] = gpoint;
}
}
found_one = TRUE;
// record extents
if (bbox) {
if (x < bbox->x1) bbox->x1 = x;
if (x > bbox->x2) bbox->x2 = x;
if (y < bbox->y1) bbox->y1 = y;
if (y > bbox->y2) bbox->y2 = y;
}
}
else if ((Pr->prdata.net < MAXNETNUM) && (Pr->prdata.net > 0)) obsnet++;
}
// In the case that no valid tap points were found, if we're on the
// rip-up and reroute section, try again, ignoring existing routes that
// are in the way of the tap point. If that fails, then we will
// route over obstructions and shift the contact when committing the
// route solution. And if that fails, we're basically hosed.
//
// Make sure to check for the case that the tap point is simply not
// reachable from any grid point, in the first stage, so we don't
// wait until the rip-up and reroute stage to route them.
if ((result == 0) && (!found_one)) {
if (stage == (u_char)1)
return set_node_to_net(node, newflags, pushlist, bbox, (u_char)2);
else if (stage == (u_char)2)
return set_node_to_net(node, newflags, pushlist, bbox, (u_char)3);
else if ((stage == (u_char)0) && (obsnet == 0))
return set_node_to_net(node, newflags, pushlist, bbox, (u_char)3);
else
return -2;
}
return result;
}
/*--------------------------------------------------------------*/
/* Set all taps of node "node" to MAXNETNUM, so that it will */
/* not be routed to. */
/*--------------------------------------------------------------*/
int disable_node_nets(NODE node)
{
int x, y, lay;
int result = 0;
DPOINT ntap;
PROUTE *Pr;
/* Process tap points of the node */
for (ntap = node->taps; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
Pr = &OBS2VAL(x, y, lay);
if (Pr->flags & PR_SOURCE || Pr->flags & PR_TARGET || Pr->flags & PR_COST) {
result = 1;
}
else if (Pr->prdata.net == node->netnum) {
Pr->prdata.net = MAXNETNUM;
}
}
// Do the same for point in the halo around the tap, but only if
// they have been attached to the net during a past routing run.
for (ntap = node->extend; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
Pr = &OBS2VAL(x, y, lay);
if (Pr->flags & PR_SOURCE || Pr->flags & PR_TARGET || Pr->flags & PR_COST) {
result = 1;
}
else if (Pr->prdata.net == node->netnum) {
Pr->prdata.net = MAXNETNUM;
}
}
return result;
}
/*--------------------------------------------------------------*/
/* That which is already routed (routes should be attached to */
/* source nodes) is routable by definition. . . */
/*--------------------------------------------------------------*/
int set_route_to_net(NET net, ROUTE rt, int newflags, POINT *pushlist,
SEG bbox, u_char stage)
{
int x, y, lay;
int result = 0;
NODEINFO lnode;
POINT gpoint;
SEG seg;
NODE n2;
PROUTE *Pr;
if (rt && rt->segments) {
for (seg = rt->segments; seg; seg = seg->next) {
lay = seg->layer;
x = seg->x1;
y = seg->y1;
while (1) {
Pr = &OBS2VAL(x, y, lay);
Pr->flags = (newflags == PR_SOURCE) ? newflags : (newflags | PR_COST);
// Conflicts should not happen (check for this?)
// if (Pr->prdata.net != node->netnum) Pr->flags |= PR_CONFLICT;
Pr->prdata.cost = (newflags == PR_SOURCE) ? 0 : MAXRT;
// push this point on the stack to process
if (pushlist != NULL) {
if (~(Pr->flags & PR_ON_STACK)) {
Pr->flags |= PR_ON_STACK;
gpoint = allocPOINT();
gpoint->x1 = x;
gpoint->y1 = y;
gpoint->layer = lay;
gpoint->next = *pushlist;
*pushlist = gpoint;
}
}
// record extents
if (bbox) {
if (x < bbox->x1) bbox->x1 = x;
if (x > bbox->x2) bbox->x2 = x;
if (y < bbox->y1) bbox->y1 = y;
if (y > bbox->y2) bbox->y2 = y;
}
// If we found another node connected to the route,
// then process it, too.
lnode = (lay >= Pinlayers) ? NULL : NODEIPTR(x, y, lay);
n2 = (lnode) ? lnode->nodesav : NULL;
if ((n2 != (NODE)NULL) && (n2 != net->netnodes)) {
if (newflags == PR_SOURCE) clear_target_node(n2);
result = set_node_to_net(n2, newflags, pushlist, bbox, stage);
// On error, continue processing
}
// Process top part of via
if (seg->segtype & ST_VIA) {
if (lay != seg->layer) break;
lay++;
continue;
}
// Move to next grid position in segment
if (x == seg->x2 && y == seg->y2) break;
if (seg->x2 > seg->x1) x++;
else if (seg->x2 < seg->x1) x--;
if (seg->y2 > seg->y1) y++;
else if (seg->y2 < seg->y1) y--;
}
}
}
return result;
}
/*--------------------------------------------------------------*/
/* Process a route and all routes that connect to it. Works */
/* like the routine above, but searches the route endpoints for */
/* connecting nodes and routes, and then recursively calls */
/* itself on the connecting routes, and other routes that */
/* connect do the nodes. */
/*--------------------------------------------------------------*/
int set_route_to_net_recursive(NET net, ROUTE rt, int newflags,
POINT *pushlist, SEG bbox, u_char stage)
{
ROUTE route;
int result;
/* If route has been marked, return */
if (rt->flags & RT_VISITED) return 0;
rt->flags |= RT_VISITED;
/* First mark this route */
result = set_route_to_net(net, rt, newflags, pushlist, bbox, stage);
if (result < 0) return result;
/* Recursively mark the routes connected to the nodes of */
/* the endpoints or connected directly to the endpoints. */
if (rt->flags & RT_START_NODE) {
for (route = net->routes; route; route = route->next) {
if (!(route->flags & RT_START_NODE) && (route->start.route == rt)) {
result = set_route_to_net_recursive(net, route, newflags,
pushlist, bbox, stage);
if (result < 0) return result;
}
if (!(route->flags & RT_END_NODE) && (route->end.route == rt)) {
result = set_route_to_net_recursive(net, route, newflags,
pushlist, bbox, stage);
if (result < 0) return result;
}
}
}
else {
result = set_route_to_net_recursive(net, rt->start.route, newflags,
pushlist, bbox, stage);
if (result < 0) return result;
}
if (rt->flags & RT_END_NODE) {
for (route = net->routes; route; route = route->next) {
if (!(route->flags & RT_START_NODE) && (route->start.route == rt)) {
result = set_route_to_net_recursive(net, route, newflags,
pushlist, bbox, stage);
if (result < 0) return result;
}
if (!(route->flags & RT_END_NODE) && (route->end.route == rt)) {
result = set_route_to_net_recursive(net, route, newflags,
pushlist, bbox, stage);
if (result < 0) return result;
}
}
}
else {
result = set_route_to_net_recursive(net, rt->end.route, newflags,
pushlist, bbox, stage);
if (result < 0) return result;
}
return result;
}
/*--------------------------------------------------------------*/
/* Process all routes of a net that are connected in some way */
/* node "node", and set their routed positions to the value of */
/* "newflags" (PR_SOURCE or PR_DEST) in Obs2[]. */
/*--------------------------------------------------------------*/
int set_routes_to_net(NODE node, NET net, int newflags, POINT *pushlist,
SEG bbox, u_char stage)
{
ROUTE rt;
int result = 0;
/* Clear marks on all routes */
for (rt = net->routes; rt; rt = rt->next) rt->flags &= ~RT_VISITED;
/* Find any route that has node as an endpoint */
for (rt = net->routes; rt; rt = rt->next) {
if ((rt->flags & RT_START_NODE) && (rt->start.node == node))
result = set_route_to_net_recursive(net, rt, newflags,
pushlist, bbox, stage);
else if ((rt->flags & RT_END_NODE) && (rt->end.node == node))
result = set_route_to_net_recursive(net, rt, newflags,
pushlist, bbox, stage);
if (result < 0) return result;
}
return result;
}
/*--------------------------------------------------------------*/
/* Used by find_colliding() (see below). Save net "netnum" */
/* to the list of colliding nets if it is not already in the */
/* list. Return 1 if the list got longer, 0 otherwise. */
/* Find the route of the net that includes the point of */
/* collision, and mark it for rip-up. */
/*--------------------------------------------------------------*/
static int
addcollidingnet(NETLIST *nlptr, int netnum, int x, int y, int lay)
{
ROUTE rt;
NETLIST cnl;
NET fnet;
SEG seg;
int i;
int sx, sy;
u_char found;
for (cnl = *nlptr; cnl; cnl = cnl->next)
if (cnl->net->netnum == netnum)
return 0;
for (i = 0; i < Numnets; i++) {
fnet = Nlnets[i];
if (fnet->netnum == netnum) {
cnl = (NETLIST)malloc(sizeof(struct netlist_));
cnl->net = fnet;
cnl->next = *nlptr;
*nlptr = cnl;
/* If there are no routes then we're done. */
if (fnet->routes == NULL) return 0;
/* If there is only one route then there is no need */
/* to search or shuffle. */
if (fnet->routes->next == NULL) {
fnet->routes->flags |= RT_RIP;
return 1;
}
for (rt = fnet->routes; rt; rt = rt->next) {
found = 0;
for (seg = rt->segments; seg; seg = seg->next) {
if ((seg->layer == lay) || ((seg->segtype & ST_VIA) &&
((seg->layer + 1) == lay))) {
sx = seg->x1;
sy = seg->y1;
while (1) {
if ((sx == x) && (sy == y)) {
found = 1;
break;
}
if ((sx == seg->x2) && (sy == seg->y2)) break;
if (sx < seg->x2) sx++;
else if (sx > seg->x2) sx--;
if (sy < seg->y2) sy++;
else if (sy > seg->y2) sy--;
}
if (found) break;
}
}
if (found) rt->flags |= RT_RIP;
}
return 1;
}
}
return 0;
}
/*--------------------------------------------------------------*/
/* Find nets that are colliding with the given net "net", and */
/* create and return a list of them. */
/*--------------------------------------------------------------*/
NETLIST find_colliding(NET net, int *ripnum)
{
NETLIST nl = (NETLIST)NULL, cnl;
ROUTE rt;
SEG seg;
int lay, x, y, orignet, rnum;
/* Scan the routed points for recorded collisions. */
rnum = 0;
for (rt = net->routes; rt; rt = rt->next) {
if (rt->segments) {
for (seg = rt->segments; seg; seg = seg->next) {
lay = seg->layer;
x = seg->x1;
y = seg->y1;
// The following skips over vias, which is okay, since
// those positions are covered by segments on both layers
// or are terminal positions that by definition can't
// belong to a different net.
while (1) {
orignet = OBSVAL(x, y, lay) & ROUTED_NET_MASK;
if (orignet == DRC_BLOCKAGE) {
/* If original position was a DRC-related blockage, */
/* find out which net or nets would be in conflict. */
if (needblock[lay] & (ROUTEBLOCKX | VIABLOCKX)) {
if (x < NumChannelsX[lay] - 1) {
orignet = OBSVAL(x + 1, y, lay) & ROUTED_NET_MASK;
if (!(orignet & NO_NET)) {
orignet &= NETNUM_MASK;
if ((orignet != 0) && (orignet != net->netnum))
rnum += addcollidingnet(&nl, orignet, x, y, lay);
}
}
if (x > 0) {
orignet = OBSVAL(x - 1, y, lay) & ROUTED_NET_MASK;
if (!(orignet & NO_NET)) {
orignet &= NETNUM_MASK;
if ((orignet != 0) && (orignet != net->netnum))
rnum += addcollidingnet(&nl, orignet, x, y, lay);
}
}
}
if (needblock[lay] & (ROUTEBLOCKY | VIABLOCKY)) {
if (y < NumChannelsY[lay] - 1) {
orignet = OBSVAL(x, y + 1, lay) & ROUTED_NET_MASK;
if (!(orignet & NO_NET)) {
orignet &= NETNUM_MASK;
if ((orignet != 0) && (orignet != net->netnum))
rnum += addcollidingnet(&nl, orignet, x, y, lay);
}
}
if (y > 0) {
orignet = OBSVAL(x, y - 1, lay) & ROUTED_NET_MASK;
if (!(orignet & NO_NET)) {
orignet &= NETNUM_MASK;
if ((orignet != 0) && (orignet != net->netnum))
rnum += addcollidingnet(&nl, orignet, x, y, lay);
}
}
}
}
else {
orignet &= NETNUM_MASK;
if ((orignet != net->netnum) && (orignet != 0))
rnum += addcollidingnet(&nl, orignet, x, y, lay);
}
if ((x == seg->x2) && (y == seg->y2)) break;
if (x < seg->x2) x++;
else if (x > seg->x2) x--;
if (y < seg->y2) y++;
else if (y > seg->y2) y--;
}
}
}
}
/* Diagnostic */
if ((nl != NULL) && (Verbose > 0)) {
Fprintf(stdout, "Best route of %s collides with net%s: ",
net->netname, (rnum > 1) ? "s" : "");
for (cnl = nl; cnl; cnl = cnl->next) {
Fprintf(stdout, "%s ", cnl->net->netname);
}
Fprintf(stdout, "\n");
}
if (ripnum) *ripnum = rnum;
return nl;
}
/*--------------------------------------------------------------*/
/* ripup_dependent --- */
/* */
/* If a set of routes is being ripped out of a net (marked by */
/* RT_RIP in the flags), check if any routes below them have */
/* endpoints landing on a ripped-out net. If so, flag those */
/* nets for being ripped out as well. Repeat recursively. */
/*--------------------------------------------------------------*/
void ripup_dependent(NET net)
{
ROUTE rt, route;
u_char rerun = TRUE;
while (rerun) {
rerun = FALSE;
for (rt = net->routes; rt; rt = rt->next) {
if (rt->flags & RT_RIP) continue;
if (!(rt->flags & RT_START_NODE)) {
route = rt->start.route;
// route should not be NULL here. . .
if (route && (route->flags & RT_RIP)) {
rt->flags |= RT_RIP;
rerun = TRUE;
}
}
if (!(rt->flags & RT_END_NODE)) {
route = rt->end.route;
// route should not be NULL here. . .
if (route && (route->flags & RT_RIP)) {
rt->flags |= RT_RIP;
rerun = TRUE;
}
}
}
}
}
/*--------------------------------------------------------------*/
/* Failure analysis (debug procedure) */
/* Occasionally when ripping up a net or net route, the Obs */
/* array shows a different net in the position that is being */
/* ripped, which should not happen. This routine does a quick */
/* analysis to determine if the position is orphaned. If so, */
/* it just returns and ripup_net will overwrite the position. */
/* If it appears to be connected to a valid route, it will find */
/* the net and route segment and run rip-up on it. */
/*--------------------------------------------------------------*/
void analyze_route_overwrite(int x, int y, int lay, int netnum)
{
u_char is_valid = FALSE;
int i, sx, sy, l;
NET fnet;
ROUTE rt;
SEG seg;
/* Check on all sides to see if position is orphaned */
if ((x < NumChannelsX[0] - 1) && (OBSVAL(x + 1, y, lay) & NETNUM_MASK) == netnum)
is_valid = TRUE;
else if ((x > 0) && (OBSVAL(x - 1, y, lay) & NETNUM_MASK) == netnum)
is_valid = TRUE;
else if ((y < NumChannelsY[0] - 1) && (OBSVAL(x, y + 1, lay) & NETNUM_MASK) == netnum)
is_valid = TRUE;
else if ((y > 0) && (OBSVAL(x, y - 1, lay) & NETNUM_MASK) == netnum)
is_valid = TRUE;
else if ((lay < Num_layers - 1) && (OBSVAL(x, y, lay + 1) & NETNUM_MASK) == netnum)
is_valid = TRUE;
else if ((lay > 0) && (OBSVAL(x, y, lay - 1) & NETNUM_MASK) == netnum)
is_valid = TRUE;
if (is_valid == FALSE) {
Fprintf(stderr, "Net position %d %d %d appears to be orphaned.\n",
x, y, lay);
return; /* No action, just overwrite */
}
for (i = 0; i < Numnets; i++) {
fnet = Nlnets[i];
if (fnet->netnum == netnum) {
for (rt = fnet->routes; rt; rt = rt->next) {
for (seg = rt->segments; seg; seg = seg->next) {
sx = seg->x1;
sy = seg->y1;
l = seg->layer;
while (1) {
if ((sx == x) && (sy == y) && (l == lay)) {
Fprintf(stderr, "Net position %d %d %d appears to "
"belong to a valid network route.\n",
x, y, lay);
/* Found the route containing this position, */
/* so rip up the net now. */
Fprintf(stderr, "Taking evasive action against net "
"%d\n", netnum);
ripup_net(fnet, TRUE, FALSE, FALSE);
return;
}
if ((sx == seg->x2) && (sy == seg->y2)) {
if ((seg->segtype == ST_WIRE) || (l >= (lay + 1))) break;
else l++;
}
else {
if (seg->x2 > seg->x1) sx++;
else if (seg->x2 < seg->x1) sx--;
if (seg->y2 > seg->y1) sy++;
else if (seg->y2 < seg->y1) sy--;
}
}
}
}
break;
}
}
}
/*--------------------------------------------------------------*/
/* Remove all route records from a net. */
/*--------------------------------------------------------------*/
void remove_routes(ROUTE netroutes, u_char flagged)
{
ROUTE rt, rsave, rlast;
SEG seg;
/* Remove all flagged routing information from this net */
/* if "flagged" is true, otherwise remove all routing */
/* information. */
if (flagged && (netroutes != NULL)) {
rlast = NULL;
rsave = netroutes;
while (rsave) {
if (rsave->flags & RT_RIP) {
rt = rsave;
if (rlast == NULL)
netroutes = rsave->next;
else
rlast->next = rsave->next;
rsave = rsave->next;
while (rt->segments) {
seg = rt->segments->next;
free(rt->segments);
rt->segments = seg;
}
free(rt);
}
else {
rlast = rsave;
rsave = rsave->next;
}
}
}
else {
while (netroutes) {
rt = netroutes;
netroutes = rt->next;
while (rt->segments) {
seg = rt->segments->next;
free(rt->segments);
rt->segments = seg;
}
free(rt);
}
}
}
/*--------------------------------------------------------------*/
/* ripup_net --- */
/* */
/* Rip up the entire network located at position x, y, lay. */
/* */
/* If argument "restore" is TRUE, then at each node, restore */
/* the crossover cost by attaching the node back to the */
/* Nodeinfo array. */
/* */
/* If argument "flagged" is TRUE, then only remove routes */
/* that have been flagged with RT_RIP. */
/* */
/* If argument "retain" is TRUE, then do not remove the route */
/* records from the net. This assumes that the calling routine */
/* will retain them for possible replacement in case of route */
/* failure. */
/*--------------------------------------------------------------*/
u_char ripup_net(NET net, u_char restore, u_char flagged, u_char retain)
{
int thisnet, oldnet, x, y, lay, dir;
NODEINFO lnode;
NODE node;
ROUTE rt;
SEG seg;
DPOINT ntap;
if (flagged) ripup_dependent(net);
thisnet = net->netnum;
for (rt = net->routes; rt; rt = rt->next) {
if (flagged && !(rt->flags & RT_RIP)) continue;
if (rt->segments) {
for (seg = rt->segments; seg; seg = seg->next) {
lay = seg->layer;
x = seg->x1;
y = seg->y1;
while (1) {
oldnet = OBSVAL(x, y, lay) & NETNUM_MASK;
if ((oldnet > 0) && (oldnet < MAXNETNUM)) {
if (oldnet != thisnet) {
Fprintf(stderr, "Error: position %d %d layer %d has net "
"%d not %d!\n", x, y, lay, oldnet, thisnet);
// Stop-gap: Need to analyze the root of this problem.
// However, a reasonable action is to try to find the
// net and route associated with the incorrect net.
analyze_route_overwrite(x, y, lay, oldnet);
// return FALSE; // Something went wrong
}
// Reset the net number to zero along this route for
// every point that is not a node tap. Points that
// were routed over obstructions to reach off-grid
// taps are returned to obstructions.
if ((lay >= Pinlayers) || ((lnode = NODEIPTR(x, y, lay)) == NULL)
|| (lnode->nodesav == NULL)) {
dir = OBSVAL(x, y, lay) & PINOBSTRUCTMASK;
if (dir == 0)
OBSVAL(x, y, lay) = OBSVAL(x, y, lay) & BLOCKED_MASK;
else
OBSVAL(x, y, lay) = NO_NET | dir;
}
else {
// Clear routed mask bit
OBSVAL(x, y, lay) &= ~ROUTED_NET;
}
// Routes which had blockages added on the sides due
// to spacing constraints have DRC_BLOCKAGE set;
// these flags should be removed.
if (needblock[lay] & (ROUTEBLOCKX | VIABLOCKX)) {
if ((x > 0) && ((OBSVAL(x - 1, y, lay) &
DRC_BLOCKAGE) == DRC_BLOCKAGE))
OBSVAL(x - 1, y, lay) &= ~DRC_BLOCKAGE;
else if ((x < NumChannelsX[lay] - 1) &&
((OBSVAL(x + 1, y, lay) &
DRC_BLOCKAGE) == DRC_BLOCKAGE))
OBSVAL(x + 1, y, lay) &= ~DRC_BLOCKAGE;
}
if (needblock[lay] & (ROUTEBLOCKY | VIABLOCKY)) {
if ((y > 0) && ((OBSVAL(x, y - 1, lay) &
DRC_BLOCKAGE) == DRC_BLOCKAGE))
OBSVAL(x, y - 1, lay) &= ~DRC_BLOCKAGE;
else if ((y < NumChannelsY[lay] - 1) &&
((OBSVAL(x, y + 1, lay) &
DRC_BLOCKAGE) == DRC_BLOCKAGE))
OBSVAL(x, y + 1, lay) &= ~DRC_BLOCKAGE;
}
}
// Check for and handle via end on last route segment.
if ((x == seg->x2) && (y == seg->y2)) {
if (seg->segtype & ST_VIA) {
if (lay == seg->layer)
lay++;
else
break;
}
else
break;
}
if (x < seg->x2) x++;
else if (x > seg->x2) x--;
if (y < seg->y2) y++;
else if (y > seg->y2) y--;
}
}
}
}
// For each net node tap, restore the node pointer on Nodeinfo->nodeloc
// so that crossover costs are again applied to routes over this node
// tap.
if (restore != 0) {
if (flagged) {
for (rt = net->routes; rt; rt = rt->next) {
if (!(rt->flags & RT_RIP)) continue;
for (seg = rt->segments; seg; seg = seg->next) {
lay = seg->layer;
if (lay >= Pinlayers) continue;
x = seg->x1;
y = seg->y1;
lnode = NODEIPTR(x, y, lay);
if (lnode && lnode->nodesav)
lnode->nodeloc = lnode->nodesav;
}
}
}
else {
for (node = net->netnodes; node; node = node->next) {
for (ntap = node->taps; ntap; ntap = ntap->next) {
lay = ntap->layer;
x = ntap->gridx;
y = ntap->gridy;
if (lay < Pinlayers) {
lnode = NODEIPTR(x, y, lay);
if (lnode) lnode->nodeloc = lnode->nodesav;
}
}
}
}
}
if (retain == FALSE) {
remove_routes(net->routes, flagged);
net->routes = NULL;
// If we just ripped out a few of the routes, make sure all the
// other net routes have not been overwritten.
if (flagged) writeback_all_routes(net);
}
// If this was a specialnet (numnodes set to 0), then routes are
// considered fixed obstructions and cannot be removed.
return (net->numnodes == 0) ? FALSE : TRUE;
}
/*--------------------------------------------------------------*/
/* eval_pt - evaluate cost to get from given point to */
/* current point. Current point is passed in "ept", and */
/* the direction from the new point to the current point */
/* is indicated by "flags". */
/* */
/* ONLY consider the cost of the single step itself. */
/* */
/* If "stage" is nonzero, then this is a second stage */
/* routing, where we should consider other nets to be a */
/* high cost to short to, rather than a blockage. This */
/* will allow us to finish the route, but with a minimum */
/* number of collisions with other nets. Then, we rip up */
/* those nets, add them to the "failed" stack, and re- */
/* route this one. */
/* */
/* ARGS: none */
/* RETURNS: pointer to a new POINT record to put on the stack */
/* if the node needs to be (re)processed and isn't already */
/* on the stack, NULL otherwise. */
/* SIDE EFFECTS: none (get this right or else) */
/*--------------------------------------------------------------*/
POINT eval_pt(GRIDP *ept, u_char flags, u_char stage)
{
int thiscost = 0;
int netnum;
NODE node;
NODEINFO nodeptr, lnode;
NETLIST nl;
PROUTE *Pr, *Pt;
GRIDP newpt;
POINT ptret = NULL;
newpt = *ept;
// ConflictCost is passed in flags if "force" option is set
// and this route crosses a prohibited boundary. This allows
// the prohibited move but gives it a high cost.
if (flags & PR_CONFLICT) {
thiscost = ConflictCost * 10;
flags &= ~PR_CONFLICT;
}
switch (flags) {
case PR_PRED_N:
newpt.y--;
break;
case PR_PRED_S:
newpt.y++;
break;
case PR_PRED_E:
newpt.x--;
break;
case PR_PRED_W:
newpt.x++;
break;
case PR_PRED_U:
newpt.lay--;
break;
case PR_PRED_D:
newpt.lay++;
break;
}
Pr = &OBS2VAL(newpt.x, newpt.y, newpt.lay);
nodeptr = (newpt.lay < Pinlayers) ?
NODEIPTR(newpt.x, newpt.y, newpt.lay) : NULL;
if (!(Pr->flags & (PR_COST | PR_SOURCE))) {
// 2nd stage allows routes to cross existing routes
netnum = Pr->prdata.net;
if (stage && (netnum < MAXNETNUM)) {
if ((newpt.lay < Pinlayers) && nodeptr && (nodeptr->nodesav != NULL))
return NULL; // But cannot route over terminals!
// Is net k in the "noripup" list? If so, don't route it */
for (nl = CurNet->noripup; nl; nl = nl->next) {
if (nl->net->netnum == netnum)
return NULL;
}
// In case of a collision, we change the grid point to be routable
// but flag it as a point of collision so we can later see what
// were the net numbers of the interfering routes by cross-referencing
// the Obs[][] array.
Pr->flags |= (PR_CONFLICT | PR_COST);
Pr->prdata.cost = MAXRT;
thiscost += ConflictCost;
}
else if (stage && (netnum == DRC_BLOCKAGE)) {
if ((newpt.lay < Pinlayers) && nodeptr && (nodeptr->nodesav != NULL))
return NULL; // But cannot route over terminals!
// Position does not contain the net number, so we have to
// go looking for it. Fortunately this is a fairly rare
// occurrance. But it is necessary to find all neighboring
// nets that might have created the blockage, and refuse to
// route here if any of them are on the noripup list.
if (needblock[newpt.lay] & (ROUTEBLOCKX | VIABLOCKX)) {
if (newpt.x < NumChannelsX[newpt.lay] - 1) {
netnum = OBSVAL(newpt.x + 1, newpt.y, newpt.lay) & ROUTED_NET_MASK;
if (!(netnum & NO_NET)) {
netnum &= NETNUM_MASK;
if ((netnum != 0) && (netnum != CurNet->netnum))
// Is net k in the "noripup" list? If so, don't route it */
for (nl = CurNet->noripup; nl; nl = nl->next)
if (nl->net->netnum == netnum)
return NULL;
}
}
if (newpt.x > 0) {
netnum = OBSVAL(newpt.x - 1, newpt.y, newpt.lay) & ROUTED_NET_MASK;
if (!(netnum & NO_NET)) {
netnum &= NETNUM_MASK;
if ((netnum != 0) && (netnum != CurNet->netnum))
// Is net k in the "noripup" list? If so, don't route it */
for (nl = CurNet->noripup; nl; nl = nl->next)
if (nl->net->netnum == netnum)
return NULL;
}
}
}
if (needblock[newpt.lay] & (ROUTEBLOCKY | VIABLOCKY)) {
if (newpt.y < NumChannelsY[newpt.lay] - 1) {
netnum = OBSVAL(newpt.x, newpt.y + 1, newpt.lay) & ROUTED_NET_MASK;
if (!(netnum & NO_NET)) {
netnum &= NETNUM_MASK;
if ((netnum != 0) && (netnum != CurNet->netnum))
// Is net k in the "noripup" list? If so, don't route it */
for (nl = CurNet->noripup; nl; nl = nl->next)
if (nl->net->netnum == netnum)
return NULL;
}
}
if (newpt.y > 0) {
netnum = OBSVAL(newpt.x, newpt.y - 1, newpt.lay) & ROUTED_NET_MASK;
if (!(netnum & NO_NET)) {
netnum &= NETNUM_MASK;
if ((netnum != 0) && (netnum != CurNet->netnum))
// Is net k in the "noripup" list? If so, don't route it */
for (nl = CurNet->noripup; nl; nl = nl->next)
if (nl->net->netnum == netnum)
return NULL;
}
}
}
// In case of a collision, we change the grid point to be routable
// but flag it as a point of collision so we can later see what
// were the net numbers of the interfering routes by cross-referencing
// the Obs[][] array.
Pr->flags |= (PR_CONFLICT | PR_COST);
Pr->prdata.cost = MAXRT;
thiscost += ConflictCost;
}
else
return NULL; // Position is not routeable
}
// Compute the cost to step from the current point to the new point.
// "BlockCost" is used if the node has only one point to connect to,
// so that routing over it could block it entirely.
if ((newpt.lay > 0) && (newpt.lay < Pinlayers)) {
if (((lnode = NODEIPTR(newpt.x, newpt.y, newpt.lay - 1)) != (NODEINFO)NULL)
&& ((node = lnode->nodeloc) != NULL)) {
Pt = &OBS2VAL(newpt.x, newpt.y, newpt.lay - 1);
if (!(Pt->flags & PR_TARGET) && !(Pt->flags & PR_SOURCE)) {
if (node->taps && (node->taps->next == NULL))
thiscost += BlockCost; // Cost to block out a tap
else if (node->taps == NULL) {
if (node->extend != NULL) {
if (node->extend->next == NULL)
// Node has only one extended access point: Try
// very hard to avoid routing over it
thiscost += 10 * BlockCost;
else
thiscost += BlockCost;
}
// If both node->taps and node->extend are NULL, then
// the node has no access and will never be routed, so
// don't bother costing it.
}
else
thiscost += XverCost; // Cross-under cost
}
}
}
if (((newpt.lay + 1) < Pinlayers) && (newpt.lay < Num_layers - 1)) {
if (((lnode = NODEIPTR(newpt.x, newpt.y, newpt.lay + 1)) != (NODEINFO)NULL)
&& ((node = lnode->nodeloc) != NULL)) {
Pt = &OBS2VAL(newpt.x, newpt.y, newpt.lay + 1);
if (!(Pt->flags & PR_TARGET) && !(Pt->flags & PR_SOURCE)) {
if (node->taps && (node->taps->next == NULL))
thiscost += BlockCost; // Cost to block out a tap
else
thiscost += XverCost; // Cross-over cost
}
}
}
if (ept->lay != newpt.lay) thiscost += ViaCost;
if (ept->x != newpt.x) thiscost += (Vert[newpt.lay] * JogCost +
(1 - Vert[newpt.lay]) * SegCost);
if (ept->y != newpt.y) thiscost += (Vert[newpt.lay] * SegCost +
(1 - Vert[newpt.lay]) * JogCost);
// Add the cost to the cost of the original position
thiscost += ept->cost;
// Routes that reach nodes are given a cost based on the "quality"
// of the node location: higher cost given to stub routes and
// offset positions.
if (nodeptr != NULL) {
thiscost += (int)(fabsf(nodeptr->stub) * (float)OffsetCost);
}
// Replace node information if cost is minimum
if (Pr->flags & PR_CONFLICT)
thiscost += ConflictCost; // For 2nd stage routes
if (thiscost < Pr->prdata.cost) {
Pr->flags &= ~PR_PRED_DMASK;
Pr->flags |= flags;
Pr->prdata.cost = thiscost;
Pr->flags &= ~PR_PROCESSED; // Need to reprocess this node
if (Verbose > 3) {
Fprintf(stdout, "New cost %d at (%d %d %d)\n", thiscost,
newpt.x, newpt.y, newpt.lay);
}
if (~(Pr->flags & PR_ON_STACK)) {
Pr->flags |= PR_ON_STACK;
ptret = allocPOINT();
ptret->x1 = newpt.x;
ptret->y1 = newpt.y;
ptret->layer = newpt.lay;
ptret->next = NULL;
return ptret;
}
}
return NULL; // New position did not get a lower cost
} /* eval_pt() */
/*------------------------------------------------------*/
/* writeback_segment() --- */
/* */
/* Copy information from a single segment back */
/* the Obs[] array. */
/* */
/* NOTE: "needblock" is used to handle */
/* cases where the existence of a route prohibits any */
/* routing on adjacent tracks on the same plane due to */
/* DRC restrictions (i.e., metal is too wide for single */
/* track spacing). Be sure to check the value of */
/* adjacent positions in Obs against the mask */
/* NETNUM_MASK, because NETNUM_MASK includes NO_NET. */
/* By replacing only empty and routable positions with */
/* the unique flag combination DRC_BLOCKAGE, it */
/* is possible to detect and remove the same if that */
/* net is ripped up, without touching any position */
/* originally marked NO_NET. */
/* */
/* Another NOTE: Tap offsets can cause the position */
/* in front of the offset to be unroutable. So if the */
/* segment is on a tap offset, mark the position in */
/* front as unroutable. If the segment neighbors an */
/* offset tap, then mark the tap unroutable. */
/*------------------------------------------------------*/
void writeback_segment(SEG seg, int netnum)
{
double dist;
int i, layer, dir;
u_int sobs;
NODEINFO lnode;
if (seg->segtype & ST_VIA) {
/* Preserve blocking information */
dir = OBSVAL(seg->x1, seg->y1, seg->layer + 1) & (BLOCKED_MASK | PINOBSTRUCTMASK);
OBSVAL(seg->x1, seg->y1, seg->layer + 1) = netnum | dir;
if (needblock[seg->layer + 1] & VIABLOCKX) {
if ((seg->x1 < (NumChannelsX[seg->layer + 1] - 1)) &&
(OBSVAL(seg->x1 + 1, seg->y1, seg->layer + 1) & NETNUM_MASK) == 0)
OBSVAL(seg->x1 + 1, seg->y1, seg->layer + 1) = DRC_BLOCKAGE;
if ((seg->x1 > 0) &&
(OBSVAL(seg->x1 - 1, seg->y1, seg->layer + 1) & NETNUM_MASK) == 0)
OBSVAL(seg->x1 - 1, seg->y1, seg->layer + 1) = DRC_BLOCKAGE;
}
if (needblock[seg->layer + 1] & VIABLOCKY) {
if ((seg->y1 < (NumChannelsY[seg->layer + 1] - 1)) &&
(OBSVAL(seg->x1, seg->y1 + 1, seg->layer + 1) & NETNUM_MASK) == 0)
OBSVAL(seg->x1, seg->y1 + 1, seg->layer + 1) = DRC_BLOCKAGE;
if ((seg->y1 > 0) &&
(OBSVAL(seg->x1, seg->y1 - 1, seg->layer + 1) & NETNUM_MASK) == 0)
OBSVAL(seg->x1, seg->y1 - 1, seg->layer + 1) = DRC_BLOCKAGE;
}
// If position itself is an offset route, then make the route position
// on the forward side of the offset unroutable, on both via layers.
// (Like the above code, there is no check for whether the offset
// distance is enough to cause a DRC violation.)
layer = (seg->layer == 0) ? 0 : seg->layer - 1;
sobs = OBSVAL(seg->x1, seg->y1, seg->layer);
if (sobs & OFFSET_TAP) {
lnode = NODEIPTR(seg->x1, seg->y1, seg->layer);
dist = lnode->offset;
if (lnode->flags & NI_OFFSET_EW) {
if ((dist > 0) && (seg->x1 < (NumChannelsX[seg->layer] - 1))) {
OBSVAL(seg->x1 + 1, seg->y1, seg->layer) |= DRC_BLOCKAGE;
OBSVAL(seg->x1 + 1, seg->y1, seg->layer + 1) |= DRC_BLOCKAGE;
}
if ((dist < 0) && (seg->x1 > 0)) {
OBSVAL(seg->x1 - 1, seg->y1, seg->layer) |= DRC_BLOCKAGE;
OBSVAL(seg->x1 - 1, seg->y1, seg->layer + 1) |= DRC_BLOCKAGE;
}
}
else if (lnode->flags & NI_OFFSET_NS) {
if ((dist > 0) && (seg->y1 < (NumChannelsY[seg->layer] - 1))) {
OBSVAL(seg->x1, seg->y1 + 1, seg->layer) |= DRC_BLOCKAGE;
OBSVAL(seg->x1, seg->y1 + 1, seg->layer + 1) |= DRC_BLOCKAGE;
}
if ((dist < 0) && (seg->y1 > 0)) {
OBSVAL(seg->x1, seg->y1 - 1, seg->layer) |= DRC_BLOCKAGE;
OBSVAL(seg->x1, seg->y1 - 1, seg->layer + 1) |= DRC_BLOCKAGE;
}
}
}
}
for (i = seg->x1; ; i += (seg->x2 > seg->x1) ? 1 : -1) {
dir = OBSVAL(i, seg->y1, seg->layer) & (BLOCKED_MASK | PINOBSTRUCTMASK);
OBSVAL(i, seg->y1, seg->layer) = netnum | dir;
if (needblock[seg->layer] & ROUTEBLOCKY) {
if ((seg->y1 < (NumChannelsY[seg->layer] - 1)) &&
(OBSVAL(i, seg->y1 + 1, seg->layer) & NETNUM_MASK) == 0)
OBSVAL(i, seg->y1 + 1, seg->layer) = DRC_BLOCKAGE;
if ((seg->y1 > 0) &&
(OBSVAL(i, seg->y1 - 1, seg->layer) & NETNUM_MASK) == 0)
OBSVAL(i, seg->y1 - 1, seg->layer) = DRC_BLOCKAGE;
}
// Check position on each side for an offset tap on a different net, and
// mark the position unroutable.
//
// NOTE: This is a bit conservative, as it will block positions next to
// an offset tap without checking if the offset distance is enough to
// cause a DRC error. Could be refined. . .
layer = (seg->layer == 0) ? 0 : seg->layer - 1;
if (seg->y1 < (NumChannelsY[layer] - 1)) {
sobs = OBSVAL(i, seg->y1 + 1, layer);
if ((sobs & OFFSET_TAP) && !(sobs & ROUTED_NET)) {
lnode = NODEIPTR(i, seg->y1 + 1, layer);
if (lnode->flags & NI_OFFSET_NS) {
dist = lnode->offset;
if (dist < 0) {
OBSVAL(i, seg->y1 + 1, layer) |= DRC_BLOCKAGE;
}
}
}
}
if (seg->y1 > 0) {
sobs = OBSVAL(i, seg->y1 - 1, layer);
if ((sobs & OFFSET_TAP) && !(sobs & ROUTED_NET)) {
lnode = NODEIPTR(i, seg->y1 - 1, layer);
if (lnode->flags & NI_OFFSET_NS) {
dist = lnode->offset;
if (dist > 0) {
OBSVAL(i, seg->y1 - 1, layer) |= DRC_BLOCKAGE;
}
}
}
}
if (i == seg->x2) break;
}
for (i = seg->y1; ; i += (seg->y2 > seg->y1) ? 1 : -1) {
dir = OBSVAL(seg->x1, i, seg->layer) & (BLOCKED_MASK | PINOBSTRUCTMASK);
OBSVAL(seg->x1, i, seg->layer) = netnum | dir;
if (needblock[seg->layer] & ROUTEBLOCKX) {
if ((seg->x1 < (NumChannelsX[seg->layer] - 1)) &&
(OBSVAL(seg->x1 + 1, i, seg->layer) & NETNUM_MASK) == 0)
OBSVAL(seg->x1 + 1, i, seg->layer) = DRC_BLOCKAGE;
if ((seg->x1 > 0) &&
(OBSVAL(seg->x1 - 1, i, seg->layer) & NETNUM_MASK) == 0)
OBSVAL(seg->x1 - 1, i, seg->layer) = DRC_BLOCKAGE;
}
// Check position on each side for an offset tap on a different net, and
// mark the position unroutable (see above).
layer = (seg->layer == 0) ? 0 : seg->layer - 1;
if (seg->x1 < (NumChannelsX[layer] - 1)) {
sobs = OBSVAL(seg->x1 + 1, i, layer);
if ((sobs & OFFSET_TAP) && !(sobs & ROUTED_NET)) {
lnode = NODEIPTR(seg->x1 + 1, i, layer);
if (lnode->flags & NI_OFFSET_EW) {
dist = lnode->offset;
if (dist < 0) {
OBSVAL(seg->x1 + 1, i, layer) |= DRC_BLOCKAGE;
}
}
}
}
if (seg->x1 > 0) {
sobs = OBSVAL(seg->x1 - 1, i, layer);
if ((sobs & OFFSET_TAP) && !(sobs & ROUTED_NET)) {
lnode = NODEIPTR(seg->x1 - 1, i, layer);
if (lnode->flags & NI_OFFSET_EW) {
dist = lnode->offset;
if (dist > 0) {
OBSVAL(seg->x1 - 1, i, layer) |= DRC_BLOCKAGE;
}
}
}
}
if (i == seg->y2) break;
}
}
/*--------------------------------------------------------------*/
/* Set the endpoint information for the route. Look at the */
/* first and last points of the route, determine if they */
/* connect to a node or another route, and set the "start" and */
/* "end" records of the route, and the flags accordingly. */
/*--------------------------------------------------------------*/
void
route_set_connections(net, route)
NET net;
ROUTE route;
{
SEG seg, s;
ROUTE nr;
NODEINFO lnode;
u_char found, match;
int x, y;
/* Does first route segment connect to a node? */
seg = route->segments;
found = FALSE;
if (seg->layer < Pinlayers) {
lnode = NODEIPTR(seg->x1, seg->y1, seg->layer);
if (lnode != NULL) {
route->start.node = lnode->nodesav;
route->flags |= RT_START_NODE;
found = TRUE;
}
}
/* Does first route segment connect to a route? */
if (!found) {
for (nr = net->routes; nr; nr = nr->next) {
if (nr == route) continue;
for (s = nr->segments; s; s = s->next) {
match = FALSE;
if (seg->layer == s->layer) match = TRUE;
else if ((seg->segtype & ST_VIA) && ((seg->layer + 1) == s->layer))
match = TRUE;
else if ((s->segtype & ST_VIA) && ((s->layer + 1) == seg->layer))
match = TRUE;
if (!match) continue;
x = s->x1;
y = s->y1;
if (x == seg->x1 && y == seg->y1) {
found = TRUE;
route->start.route = nr;
break;
}
while (TRUE) {
if (s->x2 != s->x1) x += ((s->x2 > s->x1) ? 1 : -1);
if (s->y2 != s->y1) y += ((s->y2 > s->y1) ? 1 : -1);
if (x == seg->x1 && y == seg->y1) {
found = TRUE;
route->start.route = nr;
break;
}
if (x == s->x2 && y == s->y2) break;
}
if (found) break;
}
if (found) break;
}
}
if (!found) {
Fprintf(stderr, "Error: Failure to find route start node/route!\n");
}
/* Does last route segment connect to a node? */
/* NOTE: Avoid the case where the route is exactly one via connecting */
/* a node to a route directly above, in which case the following code */
/* would flag the node twice, incorrectly. */
found = FALSE;
if ((seg->next != NULL) || !(seg->segtype & ST_VIA)) {
for (; seg->next; seg = seg->next);
if (seg->layer < Pinlayers) {
lnode = NODEIPTR(seg->x2, seg->y2, seg->layer);
if (lnode != NULL) {
route->end.node = lnode->nodesav;
route->flags |= RT_END_NODE;
found = TRUE;
}
}
}
/* Does last route segment connect to a route? */
if (!found) {
for (nr = net->routes; nr; nr = nr->next) {
if (nr == route) continue;
for (s = nr->segments; s; s = s->next) {
match = FALSE;
if (seg->layer == s->layer) match = TRUE;
else if ((seg->segtype & ST_VIA) && ((seg->layer + 1) == s->layer))
match = TRUE;
else if ((s->segtype & ST_VIA) && ((s->layer + 1) == seg->layer))
match = TRUE;
if (!match) continue;
x = s->x1;
y = s->y1;
if (x == seg->x2 && y == seg->y2 && nr != route->start.route) {
found = TRUE;
route->end.route = nr;
break;
}
while (TRUE) {
if (s->x2 != s->x1) x += ((s->x2 > s->x1) ? 1 : -1);
if (s->y2 != s->y1) y += ((s->y2 > s->y1) ? 1 : -1);
if (x == seg->x2 && y == seg->y2 && nr != route->start.route) {
found = TRUE;
route->end.route = nr;
break;
}
if (x == s->x2 && y == s->y2) break;
}
if (found) break;
}
if (found) break;
}
}
if (!found) {
Fprintf(stderr, "Error: Failure to find route end node/route!\n");
}
}
/*--------------------------------------------------------------*/
/* commit_proute - turn the potential route into an actual */
/* route by generating the route segments */
/* */
/* ARGS: route structure to fill; "stage" is 1 if we're on */
/* second stage routing, in which case we fill the */
/* route structure but don't modify the Obs array. */
/* */
/* RETURNS: 1 on success, 0 on stacked via failure, and */
/* -1 on failure to find a terminal. On a stacked */
/* via failure, the route is committed anyway. */
/* */
/* SIDE EFFECTS: Obs update, RT llseg added */
/*--------------------------------------------------------------*/
int commit_proute(ROUTE rt, GRIDP *ept, u_char stage)
{
SEG seg, lseg;
NODEINFO lnode1, lnode2;
int lay2, rval;
int dx = -1, dy = -1, dl;
u_int netnum, netobs1, netobs2, dir1, dir2;
u_char first = (u_char)1;
u_char dmask;
u_char pflags, p2flags;
PROUTE *Pr;
POINT newlr, newlr2, lrtop, lrend, lrnext, lrcur, lrprev;
if (Verbose > 1) {
Flush(stdout);
Fprintf(stdout, "\nCommit: TotalRoutes = %d\n", TotalRoutes);
}
netnum = rt->netnum;
Pr = &OBS2VAL(ept->x, ept->y, ept->lay);
if (!(Pr->flags & PR_COST)) {
Fprintf(stderr, "commit_proute(): impossible - terminal is not routable!\n");
return -1;
}
// Generate an indexed route, recording the series of predecessors and their
// positions.
lrtop = (POINT)malloc(sizeof(struct point_));
lrtop->x1 = ept->x;
lrtop->y1 = ept->y;
lrtop->layer = ept->lay;
lrtop->next = NULL;
lrend = lrtop;
while (1) {
Pr = &OBS2VAL(lrend->x1, lrend->y1, lrend->layer);
dmask = Pr->flags & PR_PRED_DMASK;
if (dmask == PR_PRED_NONE) break;
newlr = (POINT)malloc(sizeof(struct point_));
newlr->x1 = lrend->x1;
newlr->y1 = lrend->y1;
newlr->layer = lrend->layer;
lrend->next = newlr;
newlr->next = NULL;
switch (dmask) {
case PR_PRED_N:
(newlr->y1)++;
break;
case PR_PRED_S:
(newlr->y1)--;
break;
case PR_PRED_E:
(newlr->x1)++;
break;
case PR_PRED_W:
(newlr->x1)--;
break;
case PR_PRED_U:
(newlr->layer)++;
break;
case PR_PRED_D:
(newlr->layer)--;
break;
}
lrend = newlr;
}
lrend = lrtop;
// TEST: Walk through the solution, and look for stacked vias. When
// found, look for an alternative path that avoids the stack.
rval = 1;
if (StackedContacts < (Num_layers - 1)) {
POINT lrppre;
POINT a, b;
PROUTE *pri, *pri2;
int stacks = 1, stackheight;
int cx, cy, cl;
int mincost, minx = -1, miny = -1, collide, cost;
while (stacks != 0) { // Keep doing until all illegal stacks are gone
stacks = 0;
lrcur = lrend;
lrprev = lrend->next;
while (lrprev != NULL) {
lrppre = lrprev->next;
if (lrppre == NULL) break;
stackheight = 0;
a = lrcur;
b = lrprev;
while (a->layer != b->layer) {
stackheight++;
a = b;
b = a->next;
if (b == NULL) break;
}
collide = FALSE;
while (stackheight > StackedContacts) { // Illegal stack found
stacks++;
// Try to move the second contact in the path
cx = lrprev->x1;
cy = lrprev->y1;
cl = lrprev->layer;
mincost = MAXRT;
dl = lrppre->layer;
// Check all four positions around the contact for the
// lowest cost, and make sure the position below that
// is available.
if (cx < NumChannelsX[cl] - 1) {
dx = cx + 1; // Check to the right
pri = &OBS2VAL(dx, cy, cl);
pflags = pri->flags;
cost = pri->prdata.cost;
if (collide && !(pflags & (PR_COST | PR_SOURCE)) &&
(pri->prdata.net < MAXNETNUM)) {
pflags = 0;
cost = ConflictCost;
}
if (pflags & PR_COST) {
pflags &= ~PR_COST;
if ((pflags & PR_PRED_DMASK) != PR_PRED_NONE && cost < mincost) {
pri2 = &OBS2VAL(dx, cy, dl);
p2flags = pri2->flags;
if (p2flags & PR_COST) {
p2flags &= ~PR_COST;
if ((p2flags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri2->prdata.cost < MAXRT) {
mincost = cost;
minx = dx;
miny = cy;
}
}
else if (collide && !(p2flags & (PR_COST | PR_SOURCE)) &&
(pri2->prdata.net < MAXNETNUM) &&
((cost + ConflictCost) < mincost)) {
mincost = cost + ConflictCost;
minx = dx;
miny = dy;
}
}
}
}
if (cx > 0) {
dx = cx - 1; // Check to the left
pri = &OBS2VAL(dx, cy, cl);
pflags = pri->flags;
cost = pri->prdata.cost;
if (collide && !(pflags & (PR_COST | PR_SOURCE)) &&
(pri->prdata.net < MAXNETNUM)) {
pflags = 0;
cost = ConflictCost;
}
if (pflags & PR_COST) {
pflags &= ~PR_COST;
if ((pflags & PR_PRED_DMASK) != PR_PRED_NONE && cost < mincost) {
pri2 = &OBS2VAL(dx, cy, dl);
p2flags = pri2->flags;
if (p2flags & PR_COST) {
p2flags &= ~PR_COST;
if ((p2flags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri2->prdata.cost < MAXRT) {
mincost = cost;
minx = dx;
miny = cy;
}
}
else if (collide && !(p2flags & (PR_COST | PR_SOURCE)) &&
(pri2->prdata.net < MAXNETNUM) &&
((cost + ConflictCost) < mincost)) {
mincost = cost + ConflictCost;
minx = dx;
miny = dy;
}
}
}
}
if (cy < NumChannelsY[cl] - 1) {
dy = cy + 1; // Check north
pri = &OBS2VAL(cx, dy, cl);
pflags = pri->flags;
cost = pri->prdata.cost;
if (collide && !(pflags & (PR_COST | PR_SOURCE)) &&
(pri->prdata.net < MAXNETNUM)) {
pflags = 0;
cost = ConflictCost;
}
if (pflags & PR_COST) {
pflags &= ~PR_COST;
if ((pflags & PR_PRED_DMASK) != PR_PRED_NONE && cost < mincost) {
pri2 = &OBS2VAL(cx, dy, dl);
p2flags = pri2->flags;
if (p2flags & PR_COST) {
p2flags &= ~PR_COST;
if ((p2flags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri2->prdata.cost < MAXRT) {
mincost = cost;
minx = cx;
miny = dy;
}
}
else if (collide && !(p2flags & (PR_COST | PR_SOURCE)) &&
(pri2->prdata.net < MAXNETNUM) &&
((cost + ConflictCost) < mincost)) {
mincost = cost + ConflictCost;
minx = dx;
miny = dy;
}
}
}
}
if (cy > 0) {
dy = cy - 1; // Check south
pri = &OBS2VAL(cx, dy, cl);
pflags = pri->flags;
cost = pri->prdata.cost;
if (collide && !(pflags & (PR_COST | PR_SOURCE)) &&
(pri->prdata.net < MAXNETNUM)) {
pflags = 0;
cost = ConflictCost;
}
if (pflags & PR_COST) {
pflags &= ~PR_COST;
if ((pflags & PR_PRED_DMASK) != PR_PRED_NONE && cost < mincost) {
pri2 = &OBS2VAL(cx, dy, dl);
p2flags = pri2->flags;
if (p2flags & PR_COST) {
p2flags &= ~PR_COST;
if ((p2flags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri2->prdata.cost < MAXRT) {
mincost = cost;
minx = cx;
miny = dy;
}
}
else if (collide && !(p2flags & (PR_COST | PR_SOURCE)) &&
(pri2->prdata.net < MAXNETNUM) &&
((cost + ConflictCost) < mincost)) {
mincost = cost + ConflictCost;
minx = dx;
miny = dy;
}
}
}
}
// Was there an available route? If so, modify
// records to route through this alternate path. If not,
// then try to move the first contact instead.
if (mincost < MAXRT) {
pri = &OBS2VAL(minx, miny, cl);
newlr = (POINT)malloc(sizeof(struct point_));
newlr->x1 = minx;
newlr->y1 = miny;
newlr->layer = cl;
pri2 = &OBS2VAL(minx, miny, dl);
newlr2 = (POINT)malloc(sizeof(struct point_));
newlr2->x1 = minx;
newlr2->y1 = miny;
newlr2->layer = dl;
lrprev->next = newlr;
newlr->next = newlr2;
// Check if point at pri2 is equal to position of
// lrppre->next. If so, bypass lrppre.
if ((lrnext = lrppre->next) != NULL) {
if (lrnext->x1 == minx && lrnext->y1 == miny &&
lrnext->layer == dl) {
newlr->next = lrnext;
free(lrppre);
free(newlr2);
lrppre = lrnext; // ?
}
else
newlr2->next = lrppre;
}
else
newlr2->next = lrppre;
break; // Found a solution; we're done.
}
else {
// If we couldn't offset lrprev position, then try
// offsetting lrcur.
cx = lrcur->x1;
cy = lrcur->y1;
cl = lrcur->layer;
mincost = MAXRT;
dl = lrprev->layer;
if (cx < NumChannelsX[cl] - 1) {
dx = cx + 1; // Check to the right
pri = &OBS2VAL(dx, cy, cl);
pflags = pri->flags;
if (pflags & PR_COST) {
pflags &= ~PR_COST;
if ((pflags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri->prdata.cost < mincost) {
pri2 = &OBS2VAL(dx, cy, dl);
p2flags = pri2->flags;
if (p2flags & PR_COST) {
p2flags &= ~PR_COST;
if ((p2flags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri2->prdata.cost < MAXRT) {
mincost = pri->prdata.cost;
minx = dx;
miny = cy;
}
}
}
}
}
if (cx > 0) {
dx = cx - 1; // Check to the left
pri = &OBS2VAL(dx, cy, cl);
pflags = pri->flags;
if (pflags & PR_COST) {
pflags &= ~PR_COST;
if ((pflags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri->prdata.cost < mincost) {
pri2 = &OBS2VAL(dx, cy, dl);
p2flags = pri2->flags;
if (p2flags & PR_COST) {
p2flags &= ~PR_COST;
if ((p2flags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri2->prdata.cost < MAXRT) {
mincost = pri->prdata.cost;
minx = dx;
miny = cy;
}
}
}
}
}
if (cy < NumChannelsY[cl] - 1) {
dy = cy + 1; // Check north
pri = &OBS2VAL(cx, dy, cl);
pflags = pri->flags;
if (pflags & PR_COST) {
pflags &= ~PR_COST;
if ((pflags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri->prdata.cost < mincost) {
pri2 = &OBS2VAL(cx, dy, dl);
p2flags = pri2->flags;
if (p2flags & PR_COST) {
p2flags &= ~PR_COST;
if ((p2flags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri2->prdata.cost < MAXRT) {
mincost = pri->prdata.cost;
minx = cx;
miny = dy;
}
}
}
}
}
if (cy > 0) {
dy = cy - 1; // Check south
pri = &OBS2VAL(cx, dy, cl);
pflags = pri->flags;
if (pflags & PR_COST) {
pflags &= ~PR_COST;
if ((pflags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri->prdata.cost < mincost) {
pri2 = &OBS2VAL(cx, dy, dl);
p2flags = pri2->flags;
if (p2flags & PR_COST) {
p2flags &= ~PR_COST;
if ((p2flags & PR_PRED_DMASK) != PR_PRED_NONE &&
pri2->prdata.cost < MAXRT) {
mincost = pri->prdata.cost;
minx = cx;
miny = dy;
}
}
}
}
}
if (mincost < MAXRT) {
newlr = (POINT)malloc(sizeof(struct point_));
newlr->x1 = minx;
newlr->y1 = miny;
newlr->layer = cl;
newlr2 = (POINT)malloc(sizeof(struct point_));
newlr2->x1 = minx;
newlr2->y1 = miny;
newlr2->layer = dl;
// If newlr is a source or target, then make it
// the endpoint, because we have just moved the
// endpoint along the source or target, and the
// original endpoint position is not needed.
pri = &OBS2VAL(minx, miny, cl);
pri2 = &OBS2VAL(lrcur->x1, lrcur->y1, lrcur->layer);
if ((((pri->flags & PR_SOURCE) && (pri2->flags & PR_SOURCE)) ||
((pri->flags & PR_TARGET) && (pri2->flags & PR_TARGET)))
&& (lrcur == lrtop)
) {
lrtop = newlr;
lrend = newlr;
free(lrcur);
lrcur = newlr;
}
else
lrcur->next = newlr;
newlr->next = newlr2;
// Check if point at pri2 is equal to position of
// lrprev->next. If so, bypass lrprev.
if (lrppre->x1 == minx && lrppre->y1 == miny &&
lrppre->layer == dl) {
newlr->next = lrppre;
free(lrprev);
free(newlr2);
lrprev = lrcur;
}
else
newlr2->next = lrprev;
break; // Found a solution; we're done.
}
else if (stage == 0) {
// On the first stage, we call it an error and move
// on to the next net. This is a bit conservative,
// but it works because failing to remove a stacked
// via is a rare occurrance.
if (Verbose > 0)
Fprintf(stderr, "Failed to remove stacked via "
"at grid point %d %d.\n",
lrcur->x1, lrcur->y1);
stacks = 0;
rval = 0;
goto cleanup;
}
else {
if (collide == TRUE) {
Fprintf(stderr, "Failed to remove stacked via "
"at grid point %d %d; position may "
"not be routable.\n",
lrcur->x1, lrcur->y1);
stacks = 0;
rval = 0;
goto cleanup;
}
// On the second stage, we will run through the
// search again, but allow overwriting other
// nets, which will be treated like other colliding
// nets in the regular route path search.
collide = TRUE;
}
}
}
lrcur = lrprev;
lrprev = lrppre;
}
}
}
lrend = lrtop;
lrcur = lrtop;
lrprev = lrcur->next;
lseg = (SEG)NULL;
while (1) {
seg = (SEG)malloc(sizeof(struct seg_));
seg->next = NULL;
seg->segtype = (lrcur->layer == lrprev->layer) ? ST_WIRE : ST_VIA;
seg->x1 = lrcur->x1;
seg->y1 = lrcur->y1;
seg->layer = MIN(lrcur->layer, lrprev->layer);
seg->x2 = lrprev->x1;
seg->y2 = lrprev->y1;
dx = seg->x2 - seg->x1;
dy = seg->y2 - seg->y1;
// segments are in order---place final segment at end of list
if (rt->segments == NULL)
rt->segments = seg;
else
lseg->next = seg;
// Continue processing predecessors as long as the direction is the same,
// so we get a single long wire segment. This minimizes the number of
// segments produced. Vias have to be handled one at a time, as we make
// no assumptions about stacked vias.
if (seg->segtype & ST_WIRE) {
while ((lrnext = lrprev->next) != NULL) {
lrnext = lrprev->next;
if (((lrnext->x1 - lrprev->x1) == dx) &&
((lrnext->y1 - lrprev->y1) == dy) &&
(lrnext->layer == lrprev->layer)) {
lrcur = lrprev;
lrprev = lrnext;
seg->x2 = lrprev->x1;
seg->y2 = lrprev->y1;
}
else
break;
}
}
if (Verbose > 3) {
Fprintf(stdout, "commit: index = %d, net = %d\n",
Pr->prdata.net, netnum);
if (seg->segtype & ST_WIRE) {
Fprintf(stdout, "commit: wire layer %d, (%d,%d) to (%d,%d)\n",
seg->layer, seg->x1, seg->y1, seg->x2, seg->y2);
}
else {
Fprintf(stdout, "commit: via %d to %d\n", seg->layer,
seg->layer + 1);
}
Flush(stdout);
}
// now fill in the Obs structure with this route....
lay2 = (seg->segtype & ST_VIA) ? seg->layer + 1 : seg->layer;
netobs1 = OBSVAL(seg->x1, seg->y1, seg->layer);
netobs2 = OBSVAL(seg->x2, seg->y2, lay2);
lnode1 = (seg->layer < Pinlayers) ? NODEIPTR(seg->x1, seg->y1, seg->layer) : NULL;
lnode2 = (lay2 < Pinlayers) ? NODEIPTR(seg->x2, seg->y2, lay2) : NULL;
dir1 = netobs1 & PINOBSTRUCTMASK;
dir2 = netobs2 & PINOBSTRUCTMASK;
netobs1 &= NETNUM_MASK;
netobs2 &= NETNUM_MASK;
netnum |= ROUTED_NET;
// Write back segment, but not on stage 2 or else the
// collision information will be lost. Stage 2 uses
// writeback_route to call writeback_segment after the
// colliding nets have been ripped up.
if (stage == (u_char)0)
writeback_segment(seg, netnum);
// If Obs shows this position as an obstruction, then this was a port with
// no taps in reach of a grid point. This will be dealt with by moving
// the via off-grid and onto the port position in emit_routes().
if (stage == (u_char)0) {
if (first && dir1) {
first = (u_char)0;
}
else if (first && dir2 && (seg->segtype & ST_VIA) && lrprev &&
(lrprev->layer != lay2)) {
// This also applies to vias at the beginning of a route
// if the path goes down instead of up (can happen on pins,
// in particular)
OBSVAL(seg->x1, seg->y1, lay2) |= dir2;
}
}
// Keep stub information on obstructions that have been routed
// over, so that in the rip-up stage, we can return them to obstructions.
OBSVAL(seg->x1, seg->y1, seg->layer) |= dir1;
OBSVAL(seg->x2, seg->y2, lay2) |= dir2;
// An offset route end on the previous segment, if it is a via, needs
// to carry over to this one, if it is a wire route.
if (lseg && ((lseg->segtype & (ST_VIA | ST_OFFSET_END)) ==
(ST_VIA | ST_OFFSET_END)))
if ((seg->segtype != ST_VIA) && (lnode1 != NULL))
if (((seg->x1 == seg->x2) && (lnode1->flags & NI_OFFSET_NS)) ||
((seg->y1 == seg->y2) && (lnode1->flags & NI_OFFSET_EW)))
seg->segtype |= ST_OFFSET_START;
// Check if the route ends are offset. If so, add flags. The segment
// entries are integer grid points, so offsets need to be made when
// the location is output. This is only for offsets that are in the
// same direction as the route, to make sure that the route reaches
// the offset via, and does not extend past it.
if (dir1 & OFFSET_TAP) {
if (lnode1 != NULL)
if (((seg->x1 == seg->x2) && (lnode1->flags & NI_OFFSET_NS)) ||
((seg->y1 == seg->y2) && (lnode1->flags & NI_OFFSET_EW)))
seg->segtype |= ST_OFFSET_START;
// An offset on a via needs to be applied to the previous route
// segment as well, if that route is a wire, and the offset is
// in the same direction as the wire.
if (lseg && (seg->segtype & ST_VIA) && !(lseg->segtype & ST_VIA) &&
(lnode2 != NULL))
if (((lseg->x1 == lseg->x2) && (lnode2->flags & NI_OFFSET_NS)) ||
((lseg->y1 == lseg->y2) && (lnode2->flags & NI_OFFSET_EW)))
lseg->segtype |= ST_OFFSET_END;
}
if (dir2 & OFFSET_TAP) seg->segtype |= ST_OFFSET_END;
lrend = lrcur; // Save the last route position
lrend->x1 = lrcur->x1;
lrend->y1 = lrcur->y1;
lrend->layer = lrcur->layer;
lrcur = lrprev; // Move to the next route position
lrcur->x1 = seg->x2;
lrcur->y1 = seg->y2;
lrprev = lrcur->next;
if (lrprev == NULL) {
if (dir2 && (stage == (u_char)0)) {
OBSVAL(seg->x2, seg->y2, lay2) |= dir2;
}
else if (dir1 && (seg->segtype & ST_VIA)) {
// This also applies to vias at the end of a route
OBSVAL(seg->x1, seg->y1, seg->layer) |= dir1;
}
// Before returning, set *ept to the endpoint
// position. This is for diagnostic purposes only.
ept->x = lrend->x1;
ept->y = lrend->y1;
ept->lay = lrend->layer;
// Clean up allocated memory for the route. . .
while (lrtop != NULL) {
lrnext = lrtop->next;
free(lrtop);
lrtop = lrnext;
}
return rval; // Success
}
lseg = seg; // Move to next segment position
}
cleanup:
while (lrtop != NULL) {
lrnext = lrtop->next;
free(lrtop);
lrtop = lrnext;
}
return 0;
} /* commit_proute() */
/*------------------------------------------------------*/
/* writeback_route() --- */
/* */
/* This routine is the last part of the routine */
/* above. It copies the net defined by the segments */
/* in the route structure "rt" into the Obs array. */
/* This is used only for stage 2, when the writeback */
/* is not done by commit_proute because we want to */
/* rip up nets first, and also done prior to routing */
/* for any pre-defined net routes. */
/*------------------------------------------------------*/
int writeback_route(ROUTE rt)
{
SEG seg;
int lay2;
u_int netnum, dir1, dir2;
u_char first = (u_char)1;
netnum = rt->netnum | ROUTED_NET;
for (seg = rt->segments; seg; seg = seg->next) {
/* Save stub route information at segment ends. */
/* NOTE: Where segment end is a via, make sure we are */
/* placing the segment end on the right metal layer! */
lay2 = (seg->segtype & ST_VIA) ? seg->layer + 1 : seg->layer;
dir1 = OBSVAL(seg->x1, seg->y1, seg->layer) & PINOBSTRUCTMASK;
dir2 = OBSVAL(seg->x2, seg->y2, lay2) & PINOBSTRUCTMASK;
writeback_segment(seg, netnum);
if (first) {
first = (u_char)0;
if (dir1)
OBSVAL(seg->x1, seg->y1, seg->layer) |= dir1;
else if (dir2)
OBSVAL(seg->x2, seg->y2, lay2) |= dir2;
}
else if (!seg->next) {
if (dir1)
OBSVAL(seg->x1, seg->y1, seg->layer) |= dir1;
else if (dir2)
OBSVAL(seg->x2, seg->y2, lay2) |= dir2;
}
}
return TRUE;
}
/*------------------------------------------------------*/
/* Writeback all routes belonging to a net */
/*------------------------------------------------------*/
int writeback_all_routes(NET net)
{
ROUTE rt;
int result = TRUE;
for (rt = net->routes; rt; rt = rt->next) {
if (writeback_route(rt) == FALSE)
result = FALSE;
}
return result;
}
/* end of maze.c */
|