aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2005-07-04 17:51:36 +0000
committerH.J. Lu <hjl.tools@gmail.com>2005-07-04 17:51:36 +0000
commitb0eec63e04b6769048c6a4b14d180a7e09c7d104 (patch)
tree2d367bcd5a4f1b342123e225397f7399b37232de /contrib
parent9a5c4b9eb20e1c9a8f5a1843a77e16b484ae9126 (diff)
downloadgdb-b0eec63e04b6769048c6a4b14d180a7e09c7d104.zip
gdb-b0eec63e04b6769048c6a4b14d180a7e09c7d104.tar.gz
gdb-b0eec63e04b6769048c6a4b14d180a7e09c7d104.tar.bz2
2005-07-04 H.J. Lu <hongjiu.lu@intel.com>
* tic30-dis.c (cnvt_tmsfloat_ieee): Use HUGE_VALF if defined.
Diffstat (limited to 'contrib')
0 files changed, 0 insertions, 0 deletions
='n115' href='#n115'>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 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743
/* tc-nds32.c -- Assemble for the nds32
   Copyright (C) 2012-2017 Free Software Foundation, Inc.
   Contributed by Andes Technology Corporation.

   This file is part of GAS, the GNU Assembler.

   GAS is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GAS is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GAS; see the file COPYING.  If not, write to the Free
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.  */

#include "as.h"
#include "safe-ctype.h"
#include "subsegs.h"
#include "symcat.h"
#include "dwarf2dbg.h"
#include "dw2gencfi.h"
#include "opcodes/nds32-asm.h"
#include "elf/nds32.h"
#include "bfd/elf32-nds32.h"
#include "hash.h"
#include "sb.h"
#include "macro.h"
#include "struc-symbol.h"
#include "opcode/nds32.h"

#include <stdio.h>

/* GAS definitions.  */

/* Characters which start a comment.  */
const char comment_chars[] = "!";
/* Characters which start a comment when they appear at the start of a line.  */
const char line_comment_chars[] = "#!";
/* Characters which separate lines (null and newline are by default).  */
const char line_separator_chars[] = ";";
/* Characters which may be used as the exponent character
   in a floating point number.  */
const char EXP_CHARS[] = "eE";
/* Characters which may be used to indicate a floating point constant.  */
const char FLT_CHARS[] = "dDfF";

static int enable_16bit = 1;
/* Save for md_assemble to distinguish if this instruction is
   expanded from the pseudo instruction.  */
static bfd_boolean pseudo_opcode = FALSE;
static struct nds32_relocs_pattern *relocs_list = NULL;
/* Save instruction relation to inserting relaxation relocation.  */
struct nds32_relocs_pattern
{
  segT seg;
  fragS *frag;
  frchainS *frchain;
  symbolS *sym;
  fixS* fixP;
  struct nds32_opcode *opcode;
  char *where;
  struct nds32_relocs_pattern *next;
};

/* Suffix name and relocation.  */
struct suffix_name
{
  const char *suffix;
  short unsigned int reloc;
  int pic;
};
static int vec_size = 0;
/* If the assembly code is generated by compiler, it is supposed to have
   ".flag verbatim" at beginning of the content.  We have
   'nds32_flag' to parse it and set this field to be non-zero.  */
static int verbatim = 0;
static struct hash_control *nds32_gprs_hash;
static struct hash_control *nds32_hint_hash;
#define TLS_REG "$r27"
#define GOT_NAME "_GLOBAL_OFFSET_TABLE_"

/* Generate relocation for relax or not, and the default is true.  */
static int enable_relax_relocs = 1;
/* The value will be used in RELAX_ENTRY.  */
static int enable_relax_ex9 = 0;
/* The value will be used in RELAX_ENTRY.  */
static int enable_relax_ifc = 0;
/* Save option -O for performance.  */
static int optimize = 0;
/* Save option -Os for code size.  */
static int optimize_for_space = 0;
/* Flag to save label exist.  */
static int label_exist = 0;
/* Flag to save state in omit_fp region.  */
static int in_omit_fp = 0;
extern struct nds32_keyword keyword_gpr[];
/* Tag there is relax relocation having to link.  */
static bfd_boolean relaxing = FALSE;

static struct hash_control *nds32_relax_info_hash;
static relax_info_t relax_table[] =
{
  {
    "jal", 					/* opcode */
    BR_RANGE_S16M, 				/* br_range */
    {{0, 0, 0, FALSE}}, 			/* cond_field */
    {
      {
        INSN_JAL /* jal label */
      }, /* BR_RANGE_S256 */
      {
        INSN_JAL /* jal label */
      }, /* BR_RANGE_S16K */
      {
        INSN_JAL /* jal label */
      }, /* BR_RANGE_S64K */
      {
        INSN_JAL /* jal label */
      }, /* BR_RANGE_S16M */
      {
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JRAL_TA
      }, /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S256 */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S16K */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S64K */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S16M */
      {{0, 0, 0, FALSE}} /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 4, 4, 12},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, 0, BFD_RELOC_NDS32_HI20},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGCALL4},
	{4, 4, NDS32_HINT | NDS32_FIX, BFD_RELOC_NDS32_LO12S0_ORI},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{8, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{8, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bltzal",					/* opcode */
    BR_RANGE_S64K, 				/* br_range */
    {
      {0, 20, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BLTZAL /* bltzal $rt, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BLTZAL /* bltzal $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BLTZAL /* bltzal $rt, label */
      }, /* BR_RANGE_S64K */
      {
	INSN_BGEZ, /* bgez $rt, $1 */
        INSN_JAL /* jal label */
      }, /* BR_RANGE_S16M */
      {
	INSN_BGEZ, /* bgez $rt, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JRAL_TA /* jral $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 4, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGCALL5},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGCALL6},
        {4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bgezal",					/* opcode */
    BR_RANGE_S64K, 				/* br_range */
    {
      {0, 20, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BGEZAL /* bgezal $rt, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BGEZAL /* bgezal $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BGEZAL /* bgezal $rt, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BLTZ, /* bltz $rt, $1 */
        INSN_JAL /* jal label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BLTZ, /* bltz $rt, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JRAL_TA /* jral $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 4, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGCALL5},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGCALL6},
        {4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "j", 					/* opcode */
    BR_RANGE_S16M, 				/* br_range */
    {{0, 0, 0, FALSE}}, 			/* cond_field */
    {
      {
        (INSN_J8 << 16) /* j8 label */
      }, /* BR_RANGE_S256 */
      {
        INSN_J /* j label */
      }, /* BR_RANGE_S16K */
      {
        INSN_J /* j label */
      }, /* BR_RANGE_S64K */
      {
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      }, /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S256 */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S16K */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S64K */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S16M */
      {{0, 0, 0, FALSE}} /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {2, 4, 4, 4, 12},				/* relax_code_size */
    {2, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, 0, BFD_RELOC_NDS32_HI20},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP4},
	{4, 4, NDS32_HINT | NDS32_FIX, BFD_RELOC_NDS32_LO12S0_ORI},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{8, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{8, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "j8", 					/* opcode */
    BR_RANGE_S256, 				/* br_range */
    {{0, 0, 0, FALSE}}, 			/* cond_field */
    {
      {
        (INSN_J8 << 16) /* j8 label */
      }, /* BR_RANGE_S256 */
      {
        INSN_J /* j label */
      }, /* BR_RANGE_S16K */
      {
        INSN_J /* j label */
      }, /* BR_RANGE_S64K */
      {
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      }, /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S256 */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S16K */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S64K */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S16M */
      {{0, 0, 0, FALSE}} /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {2, 4, 4, 4, 12},				/* relax_code_size */
    {2, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, 0, BFD_RELOC_NDS32_HI20},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP4},
	{4, 4, NDS32_HINT | NDS32_FIX, BFD_RELOC_NDS32_LO12S0_ORI},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{8, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{8, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "beqz",					/* opcode */
    BR_RANGE_S64K, 				/* br_range */
    {
      {0, 20, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BEQZ /* beqz $rt, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BEQZ /* beqz $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BEQZ /* beqz $rt, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BNEZ, /* bnez $rt, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BNEZ, /* bnez $rt, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 4, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
	{0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
	{0, 4, NDS32_INSN16 , BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bgez",					/* opcode */
    BR_RANGE_S64K, 				/* br_range */
    {
      {0, 20, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BGEZ /* bgez $rt, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BGEZ /* bgez $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BGEZ /* bgez $rt, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BLTZ, /* bltz $rt, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BLTZ, /* bltz $rt, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 4, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bnez",					/* opcode */
    BR_RANGE_S64K, 				/* br_range */
    {
      {0, 20, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BNEZ /* bnez $rt, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BNEZ /* bnez $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BNEZ /* bnez $rt, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BEQZ, /* beqz $rt, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BEQZ, /* beqz $rt, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 4, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
	{0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
	{0, 4, NDS32_INSN16 , BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bgtz",					/* opcode */
    BR_RANGE_S64K, 				/* br_range */
    {
      {0, 20, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BGTZ /* bgtz $rt, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BGTZ /* bgtz $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BGTZ /* bgtz $rt, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BLEZ, /* blez $rt, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BLEZ, /* blez $rt, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 4, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "blez",					/* opcode */
    BR_RANGE_S64K, 				/* br_range */
    {
      {0, 20, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    },	 					/* cond_field */
    {
      {
        INSN_BLEZ /* blez $rt, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BLEZ /* blez $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BLEZ /* blez $rt, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BGTZ, /* bgtz $rt, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BGTZ, /* bgtz $rt, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 4, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bltz",					/* opcode */
    BR_RANGE_S64K, 				/* br_range */
    {
      {0, 20, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BLTZ /* bltz $rt, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BLTZ /* bltz $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BLTZ /* bltz $rt, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BGEZ, /* bgez $rt, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BGEZ, /* bgez $rt, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 4, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "beq",					/* opcode */
    BR_RANGE_S16K, 				/* br_range */
    {
      {0, 20, 0x1F, FALSE},
      {0, 15, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BEQ /* beq $rt, $ra, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BEQ /* beq $rt, $ra, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BNE, /* bne $rt, $ra, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BNE, /* bne $rt, $ra, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BNE, /* bne $rt, $ra, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 20, 0x1F, FALSE},
        {0, 15, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 15, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 15, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 15, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 15, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 8, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
        {0, 4, NDS32_INSN16, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_ABS, BFD_RELOC_NDS32_EMPTY},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bne",					/* opcode */
    BR_RANGE_S16K, 				/* br_range */
    {
      {0, 20, 0x1F, FALSE},
      {0, 15, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    },	 					/* cond_field */
    {
      {
        INSN_BNE /* bne $rt, $ra, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BNE /* bne $rt, $ra, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BEQ, /* beq $rt, $ra, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BEQ, /* beq $rt, $ra, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BEQ, /* beq $rt, $ra, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 20, 0x1F, FALSE},
        {0, 15, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 15, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 15, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 15, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 15, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 4, 8, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
        {0, 4, NDS32_INSN16, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "beqz38",					/* opcode */
    BR_RANGE_S256, 				/* br_range */
    {
      {0, 8, 0x7, FALSE},
      {0, 0, 0, FALSE}
    },	 					/* cond_field */
    {
      {
        INSN_BEQZ38 << 16 /* beqz $rt, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BEQZ /* beqz $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BEQZ /* beqz $rt, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BNEZ, /* bnez $rt, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BNEZ, /* bnez $rt, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 8, 0x7, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {2, 4, 4, 8, 16},				/* relax_code_size */
    {2, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
	{0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bnez38",					/* opcode */
    BR_RANGE_S256, 				/* br_range */
    {
      {0, 8, 0x7, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BNEZ38 << 16 /* bnez $rt, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BNEZ /* bnez $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BNEZ /* bnez $rt, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BEQZ, /* beqz $rt, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BEQZ, /* beqz $rt, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 8, 0x7, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {2, 4, 4, 8, 16},				/* relax_code_size */
    {2, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
	{0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "beqzs8",					/* opcode */
    BR_RANGE_S256, 				/* br_range */
    {{0, 0, 0, FALSE}}, 			/* cond_field */
    {
      {
        INSN_BEQZS8 << 16 /* beqz $r15, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BEQZ_TA /* bnez $rt, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BEQZ_TA /* bnez $rt, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BNEZ_TA, /* bnez $r15, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BNEZ_TA, /* bnez $r15, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S256 */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S16K */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S64K */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S16M */
      {{0, 0, 0, FALSE}} /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {2, 4, 4, 8, 16},				/* relax_code_size */
    {2, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
	{0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bnezs8",					/* opcode */
    BR_RANGE_S256, 				/* br_range */
    {{0, 0, 0, FALSE}}, 			/* cond_field */
    {
      {
        INSN_BNEZS8 << 16 /* bnez $r15, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BNEZ_TA /* bnez $r15, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BNEZ_TA /* bnez $r15, label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BEQZ_TA, /* beqz $r15, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BEQZ_TA, /* beqz $r15, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S256 */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S16K */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S64K */
      {{0, 0, 0, FALSE}}, /* BR_RANGE_S16M */
      {{0, 0, 0, FALSE}} /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {2, 4, 4, 8, 16},				/* relax_code_size */
    {2, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
	{0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bnes38",					/* opcode */
    BR_RANGE_S256, 				/* br_range */
    {
      {0, 8, 0x7, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BNES38 << 16 /* bne $rt, $R5, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BNE_R5 /* bne $rt, $R5, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BEQ_R5, /* beq $rt, $R5, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BEQ_R5, /* beq $rt, $R5, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BEQ_R5, /* beq $rt, $R5, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 8, 0x7, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {2, 4, 8, 8, 16},				/* relax_code_size */
    {2, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
	{0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "beqs38",					/* opcode */
    BR_RANGE_S256, 				/* br_range */
    {
      {0, 8, 0x7, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BEQS38 << 16 /* beq $rt, $R5, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_BEQ_R5 /* beq $rt, $R5, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BNE_R5, /* bne $rt, $R5, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BNE_R5, /* bne $rt, $R5, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BNE_R5, /* bne $rt, $R5, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 8, 0x7, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {2, 4, 8, 8, 16},				/* relax_code_size */
    {2, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
	{0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
	{0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
	{4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6},
	{4, 4, 0, BFD_RELOC_NDS32_HI20},
	{4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{8, 4, NDS32_FIX | NDS32_HINT, BFD_RELOC_NDS32_LO12S0_ORI},
	{8, 4, NDS32_PTR |NDS32_HINT, BFD_RELOC_NDS32_PTR},
	{12, 4, NDS32_ABS | NDS32_HINT, BFD_RELOC_NDS32_PTR_RESOLVED},
	{12, 4, NDS32_SYM | NDS32_HINT, BFD_RELOC_NDS32_EMPTY},
	{12, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "beqc",					/* opcode */
    BR_RANGE_S256, 				/* br_range */
    {
      {0, 8, 0x7FF, TRUE},
      {0, 20, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BEQC /* beqc $rt, imm11s, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_MOVI_TA, /* movi $ta, imm11s */
        INSN_BEQ_TA /* beq $rt, $ta, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BNEC, /* bnec $rt, imm11s, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BNEC, /* bnec $rt, imm11s, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BNEC, /* bnec $rt, imm11s, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 8, 0x7FF, TRUE},
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 0, 0xFFFFF, FALSE},
        {4, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 8, 0x7FF, FALSE},
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 8, 0x7FF, FALSE},
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 8, 0x7FF, FALSE},
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 8, 8, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP7},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL},
        {4, 4, 0, BFD_RELOC_NDS32_HI20},
	{8, 4, 0, BFD_RELOC_NDS32_LO12S0_ORI},
	{12, 4, NDS32_INSN16, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  },
  {
    "bnec",					/* opcode */
    BR_RANGE_S256, 				/* br_range */
    {
      {0, 8, 0x7FF, TRUE},
      {0, 20, 0x1F, FALSE},
      {0, 0, 0, FALSE}
    }, 						/* cond_field */
    {
      {
        INSN_BNEC /* bnec $rt, imm11s, label */
      }, /* BR_RANGE_S256 */
      {
        INSN_MOVI_TA, /* movi $ta, imm11s */
        INSN_BNE_TA /* bne $rt, $ta, label */
      }, /* BR_RANGE_S16K */
      {
        INSN_BEQC, /* beqc $rt, imm11s, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S64K */
      {
        INSN_BEQC, /* beqc $rt, imm11s, $1 */
        INSN_J /* j label */
      }, /* BR_RANGE_S16M */
      {
        INSN_BEQC, /* beqc $rt, imm11s, $1 */
        INSN_SETHI_TA, /* sethi $ta, label */
        INSN_ORI_TA, /* ori $ta, $ta, label */
        INSN_JR_TA /* jr $ta */
      } /* BR_RANGE_U4G */
    },						/* relax_code_seq */
    {
      {
        {0, 8, 0x7FF, TRUE},
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S256 */
      {
        {0, 0, 0xFFFFF, FALSE},
        {4, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16K */
      {
        {0, 8, 0x7FF, FALSE},
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S64K */
      {
        {0, 8, 0x7FF, FALSE},
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      }, /* BR_RANGE_S16M */
      {
        {0, 8, 0x7FF, FALSE},
        {0, 20, 0x1F, FALSE},
        {0, 0, 0, FALSE}
      } /* BR_RANGE_U4G */
    },						/* relax_code_condition */
    {4, 8, 8, 8, 16},				/* relax_code_size */
    {4, 4, 4, 4, 4},				/* relax_branch_isize */
    {
      {
        {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S256 */
      {
	{0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16},
	{0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP7},
	{4, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16K */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S64K */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL},
        {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL},
        {0, 0, 0, 0}
      }, /* BR_RANGE_S16M */
      {
        {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL},
        {4, 4, 0, BFD_RELOC_NDS32_HI20},
        {8, 4, 0, BFD_RELOC_NDS32_LO12S0_ORI},
	{12, 4, NDS32_INSN16, BFD_RELOC_NDS32_INSN16},
        {0, 0, 0, 0}
      } /* BR_RANGE_U4G */
    }						/* relax_fixup */
  }
};

/* GAS definitions for command-line options.  */
enum options
{
  OPTION_BIG = OPTION_MD_BASE,
  OPTION_LITTLE,
  OPTION_TURBO,
  OPTION_PIC,
  OPTION_RELAX_FP_AS_GP_OFF,
  OPTION_RELAX_B2BB_ON,
  OPTION_RELAX_ALL_OFF,
  OPTION_OPTIMIZE,
  OPTION_OPTIMIZE_SPACE
};

const char *md_shortopts = "m:O:";
struct option md_longopts[] =
{
  {"O1", no_argument, NULL, OPTION_OPTIMIZE},
  {"Os", no_argument, NULL, OPTION_OPTIMIZE_SPACE},
  {"big", no_argument, NULL, OPTION_BIG},
  {"little", no_argument, NULL, OPTION_LITTLE},
  {"EB", no_argument, NULL, OPTION_BIG},
  {"EL", no_argument, NULL, OPTION_LITTLE},
  {"meb", no_argument, NULL, OPTION_BIG},
  {"mel", no_argument, NULL, OPTION_LITTLE},
  {"mall-ext", no_argument, NULL, OPTION_TURBO},
  {"mext-all", no_argument, NULL, OPTION_TURBO},
  {"mpic", no_argument, NULL, OPTION_PIC},
  /* Relaxation related options.  */
  {"mno-fp-as-gp-relax", no_argument, NULL, OPTION_RELAX_FP_AS_GP_OFF},
  {"mb2bb", no_argument, NULL, OPTION_RELAX_B2BB_ON},
  {"mno-all-relax", no_argument, NULL, OPTION_RELAX_ALL_OFF},
  {NULL, no_argument, NULL, 0}
};

size_t md_longopts_size = sizeof (md_longopts);

struct nds32_parse_option_table
{
  const char *name;		/* Option string.  */
  const char *help;			/* Help description.  */
  int (*func) (const char *arg);	/* How to parse it.  */
};


/* The value `-1' represents this option has *NOT* been set.  */
#ifdef NDS32_DEFAULT_ARCH_NAME
static const char* nds32_arch_name = NDS32_DEFAULT_ARCH_NAME;
#else
static const char* nds32_arch_name = "v3";
#endif
static int nds32_baseline = -1;
static int nds32_gpr16 = -1;
static int nds32_fpu_sp_ext = -1;
static int nds32_fpu_dp_ext = -1;
static int nds32_freg = -1;
static int nds32_abi = -1;

/* Record ELF flags */
static int nds32_elf_flags = 0;
static int nds32_fpu_com = 0;

static int nds32_parse_arch (const char *str);
static int nds32_parse_baseline (const char *str);
static int nds32_parse_freg (const char *str);
static int nds32_parse_abi (const char *str);

static struct nds32_parse_option_table parse_opts [] =
{
  {"arch=", N_("<arch name>\t  Assemble for architecture <arch name>\n\
			  <arch name> could be\n\
			  v3, v3j, v3m, v3f, v3s, "\
			  "v2, v2j, v2f, v2s"), nds32_parse_arch},
  {"baseline=", N_("<baseline>\t  Assemble for baseline <baseline>\n\
			  <baseline> could be v2, v3, v3m"),
		  nds32_parse_baseline},
  {"fpu-freg=", N_("<freg>\t  Specify a FPU configuration\n\
			  <freg>\n\
			  0:     8 SP /  4 DP registers\n\
			  1:    16 SP /  8 DP registers\n\
			  2:    32 SP / 16 DP registers\n\
			  3:    32 SP / 32 DP registers"), nds32_parse_freg},
  {"abi=", N_("<abi>\t          Specify a abi version\n\
			  <abi> could be v1, v2, v2fp, v2fpp"), nds32_parse_abi},
  {NULL, NULL, NULL}
};

static int nds32_mac = 1;
static int nds32_div = 1;
static int nds32_16bit_ext = 1;
static int nds32_dx_regs = 1;
static int nds32_perf_ext = 1;
static int nds32_perf_ext2 = 1;
static int nds32_string_ext = 1;
static int nds32_audio_ext = 1;
static int nds32_fpu_fma = 0;
static int nds32_pic = 0;
static int nds32_relax_fp_as_gp = 1;
static int nds32_relax_b2bb = 0;
static int nds32_relax_all = 1;
struct nds32_set_option_table
{
  const char *name;		/* Option string.  */
  const char *help;			/* Help description.  */
  int *var;			/* Variable to be set.  */
  int value;			/* Value to set.  */
};

/* The option in this group has both Enable/Disable settings.
   Just list on here.  */

static struct nds32_set_option_table toggle_opts [] =
{
  {"mac", N_("Multiply instructions support"), &nds32_mac, 1},
  {"div", N_("Divide instructions support"), &nds32_div, 1},
  {"16bit-ext", N_("16-bit extension"), &nds32_16bit_ext, 1},
  {"dx-regs", N_("d0/d1 registers"), &nds32_dx_regs, 1},
  {"perf-ext", N_("Performance extension"), &nds32_perf_ext, 1},
  {"perf2-ext", N_("Performance extension 2"), &nds32_perf_ext2, 1},
  {"string-ext", N_("String extension"), &nds32_string_ext, 1},
  {"reduced-regs", N_("Reduced Register configuration (GPR16) option"), &nds32_gpr16, 1},
  {"audio-isa-ext", N_("AUDIO ISA extension"), &nds32_audio_ext, 1},
  {"fpu-sp-ext", N_("FPU SP extension"), &nds32_fpu_sp_ext, 1},
  {"fpu-dp-ext", N_("FPU DP extension"), &nds32_fpu_dp_ext, 1},
  {"fpu-fma", N_("FPU fused-multiply-add instructions"), &nds32_fpu_fma, 1},
  {NULL, NULL, NULL, 0}
};


/* GAS declarations.  */

/* This is the callback for nds32-asm.c to parse operands.  */
int
nds32_asm_parse_operand (struct nds32_asm_desc *pdesc,
			 struct nds32_asm_insn *pinsn,
			 char **pstr, int64_t *value);


struct nds32_asm_desc asm_desc;

/* md_after_parse_args ()

   GAS will call md_after_parse_args whenever it is defined.
   This function checks any conflicting options specified.  */

void
nds32_after_parse_args (void)
{
  /* If -march option is not used in command-line, set the value of option
     variable according to NDS32_DEFAULT_ARCH_NAME.  */
  nds32_parse_arch (nds32_arch_name);
}

/* This function is called when printing usage message (--help).  */

void
md_show_usage (FILE *stream)
{
  struct nds32_parse_option_table *coarse_tune;
  struct nds32_set_option_table *fine_tune;

  fprintf (stream, _("\n NDS32-specific assembler options:\n"));
  fprintf (stream, _("\
  -O1,			  Optimize for performance\n\
  -Os			  Optimize for space\n"));
  fprintf (stream, _("\
  -EL, -mel or -little    Produce little endian output\n\
  -EB, -meb or -big       Produce big endian output\n\
  -mpic			  Generate PIC\n\
  -mno-fp-as-gp-relax	  Suppress fp-as-gp relaxation for this file\n\
  -mb2bb-relax		  Back-to-back branch optimization\n\
  -mno-all-relax	  Suppress all relaxation for this file\n"));

  for (coarse_tune = parse_opts; coarse_tune->name != NULL; coarse_tune++)
    {
      if (coarse_tune->help != NULL)
	fprintf (stream, _("  -m%s%s\n"),
		 coarse_tune->name, _(coarse_tune->help));
    }

  for (fine_tune = toggle_opts; fine_tune->name != NULL; fine_tune++)
    {
      if (fine_tune->help != NULL)
	fprintf (stream, _("  -m[no-]%-17sEnable/Disable %s\n"),
		 fine_tune->name, _(fine_tune->help));
    }

  fprintf (stream, _("\
  -mall-ext		  Turn on all extensions and instructions support\n"));
}

void
nds32_frag_init (fragS *fragp)
{
  fragp->tc_frag_data.flag = 0;
  fragp->tc_frag_data.opcode = NULL;
  fragp->tc_frag_data.fixup = NULL;
}



/* This function reads an expression from a C string and returns a pointer past
   the end of the expression.  */

static char *
parse_expression (char *str, expressionS *exp)
{
  char *s;
  char *tmp;

  tmp = input_line_pointer;	/* Save line pointer.  */
  input_line_pointer = str;
  expression (exp);
  s = input_line_pointer;
  input_line_pointer = tmp;	/* Restore line pointer.  */

  return s;			/* Return pointer to where parsing stopped.  */
}

void
nds32_start_line_hook (void)
{
}

/*
 * Pseudo opcodes
 */

typedef void (*nds32_pseudo_opcode_func) (int argc, char *argv[], unsigned int pv);
struct nds32_pseudo_opcode
{
  const char *opcode;
  int argc;
  nds32_pseudo_opcode_func proc;
  unsigned int pseudo_val;

  /* Some instructions are not pseudo opcode, but they might still be
     expanded or changed with other instruction combination for some
     conditions.  We also apply this structure to assist such work.

     For example, if the distance of branch target '.L0' is larger than
     imm8s<<1 range,

     the instruction:

         beqzs8 .L0

     will be transformed into:

         bnezs8  .LCB0
         j  .L0
       .LCB0:

     However, sometimes we do not want assembler to do such changes
     because compiler knows how to generate corresponding instruction sequence.
     Use this field to indicate that this opcode is also a physical instruction.
     If the flag 'verbatim' is nozero and this opcode
     is a physical instruction, we should not expand it.  */
  int physical_op;
};
#define PV_DONT_CARE 0

static struct hash_control *nds32_pseudo_opcode_hash = NULL;

static int
builtin_isreg (const char *s, const char *x ATTRIBUTE_UNUSED)
{
  if (s [0] == '$' && hash_find (nds32_gprs_hash, (s + 1)))
    return 1;
  return 0;
}

static int
builtin_regnum (const char *s, const char *x ATTRIBUTE_UNUSED)
{
  struct nds32_keyword *k;
  if (*s != '$')
    return -1;
  s++;
  k = hash_find (nds32_gprs_hash, s);

  if (k == NULL)
    return -1;

  return k->value;
}

static int
builtin_addend (const char *s, char *x ATTRIBUTE_UNUSED)
{
  const char *ptr = s;

  while (*ptr != '+' && *ptr != '-' && *ptr)
    ++ptr;

  if (*ptr == 0)
    return 0;
  else
    return strtol (ptr, NULL, 0);
}

static void
md_assemblef (const char *format, ...)
{
  /* FIXME: hope this is long enough.  */
  char line[1024];
  va_list ap;
  unsigned int r;

  va_start (ap, format);
  r = vsnprintf (line, sizeof (line), format, ap);
  md_assemble (line);

  gas_assert (r < sizeof (line));
}

/* Some prototypes here, since some op may use another op.  */
static void do_pseudo_li_internal (const char *rt, int imm32s);
static void do_pseudo_move_reg_internal (char *dst, char *src);

static void
do_pseudo_b (int argc ATTRIBUTE_UNUSED, char *argv[], 
	     unsigned int pv ATTRIBUTE_UNUSED)
{
  char *arg_label = argv[0];
  relaxing = TRUE;
  /* b   label */
  if (nds32_pic && strstr (arg_label, "@PLT"))
    {
      md_assemblef ("sethi $ta,hi20(%s)", arg_label);
      md_assemblef ("ori $ta,$ta,lo12(%s)", arg_label);
      md_assemble  ((char *) "add $ta,$ta,$gp");
      md_assemble  ((char *) "jr $ta");
    }
  else
    {
      md_assemblef ("j %s", arg_label);
    }
  relaxing = FALSE;
}

static void
do_pseudo_bal (int argc ATTRIBUTE_UNUSED, char *argv[], 
	       unsigned int pv ATTRIBUTE_UNUSED)
{
  char *arg_label = argv[0];
  relaxing = TRUE;
  /* bal|call  label */
  if (nds32_pic
      && (strstr (arg_label, "@GOT") || strstr (arg_label, "@PLT")))
    {
      md_assemblef ("sethi $ta,hi20(%s)", arg_label);
      md_assemblef ("ori $ta,$ta,lo12(%s)", arg_label);
      md_assemble  ((char *) "add $ta,$ta,$gp");
      md_assemble ((char *) "jral $ta");
    }
  else
    {
      md_assemblef ("jal %s", arg_label);
    }
  relaxing = FALSE;
}

static void
do_pseudo_bge (int argc ATTRIBUTE_UNUSED, char *argv[], 
	       unsigned int pv ATTRIBUTE_UNUSED)
{
  /* rt5, ra5, label */
  md_assemblef ("slt $ta,%s,%s", argv[0], argv[1]);
  md_assemblef ("beqz $ta,%s", argv[2]);
}

static void
do_pseudo_bges (int argc ATTRIBUTE_UNUSED, char *argv[], 
		unsigned int pv ATTRIBUTE_UNUSED)
{
  /* rt5, ra5, label */
  md_assemblef ("slts $ta,%s,%s", argv[0], argv[1]);
  md_assemblef ("beqz $ta,%s", argv[2]);
}

static void
do_pseudo_bgt (int argc ATTRIBUTE_UNUSED, char *argv[], 
	       unsigned int pv ATTRIBUTE_UNUSED)
{
  /* bgt rt5, ra5, label */
  md_assemblef ("slt $ta,%s,%s", argv[1], argv[0]);
  md_assemblef ("bnez $ta,%s", argv[2]);
}

static void
do_pseudo_bgts (int argc ATTRIBUTE_UNUSED, char *argv[], 
		unsigned int pv ATTRIBUTE_UNUSED)
{
  /* bgt rt5, ra5, label */
  md_assemblef ("slts $ta,%s,%s", argv[1], argv[0]);
  md_assemblef ("bnez $ta,%s", argv[2]);
}

static void
do_pseudo_ble (int argc ATTRIBUTE_UNUSED, char *argv[], 
	       unsigned int pv ATTRIBUTE_UNUSED)
{
  /* bgt rt5, ra5, label */
  md_assemblef ("slt $ta,%s,%s", argv[1], argv[0]);
  md_assemblef ("beqz $ta,%s", argv[2]);
}

static void
do_pseudo_bles (int argc ATTRIBUTE_UNUSED, char *argv[], 
		unsigned int pv ATTRIBUTE_UNUSED)
{
  /* bgt rt5, ra5, label */
  md_assemblef ("slts $ta,%s,%s", argv[1], argv[0]);
  md_assemblef ("beqz $ta,%s", argv[2]);
}

static void
do_pseudo_blt (int argc ATTRIBUTE_UNUSED, char *argv[], 
	       unsigned int pv ATTRIBUTE_UNUSED)
{
  /* rt5, ra5, label */
  md_assemblef ("slt $ta,%s,%s", argv[0], argv[1]);
  md_assemblef ("bnez $ta,%s", argv[2]);
}

static void
do_pseudo_blts (int argc ATTRIBUTE_UNUSED, char *argv[], 
		unsigned int pv ATTRIBUTE_UNUSED)
{
  /* rt5, ra5, label */
  md_assemblef ("slts $ta,%s,%s", argv[0], argv[1]);
  md_assemblef ("bnez $ta,%s", argv[2]);
}

static void
do_pseudo_br (int argc ATTRIBUTE_UNUSED, char *argv[], 
	      unsigned int pv ATTRIBUTE_UNUSED)
{
  md_assemblef ("jr %s", argv[0]);
}

static void
do_pseudo_bral (int argc, char *argv[], 
		unsigned int pv ATTRIBUTE_UNUSED)
{
  if (argc == 1)
    md_assemblef ("jral $lp,%s", argv[0]);
  else
    md_assemblef ("jral %s,%s", argv[0], argv[1]);
}

static void
do_pseudo_la_internal (const char *arg_reg, char *arg_label,
		       const char *line)
{
  expressionS exp;

  parse_expression (arg_label, &exp);
  if (exp.X_op != O_symbol)
    {
      as_bad (_("la must use with symbol. '%s'"), line);
      return;
    }

  relaxing = TRUE;
  /* rt, label */
  if (!nds32_pic && !strstr(arg_label, "@"))
    {
      md_assemblef ("sethi %s,hi20(%s)", arg_reg, arg_label);
      md_assemblef ("ori %s,%s,lo12(%s)", arg_reg, arg_reg, arg_label);
    }
  else if (strstr (arg_label, "@TPOFF"))
    {
      /* la $rt, sym@TPOFF  */
      md_assemblef ("sethi $ta,hi20(%s)", arg_label);
      md_assemblef ("ori $ta,$ta,lo12(%s)", arg_label);
      md_assemblef ("add %s,$ta,%s", arg_reg, TLS_REG);
    }
  else if (strstr(arg_label, "@GOTTPOFF"))
    {
      /* la $rt, sym@GOTTPOFF*/
      md_assemblef ("sethi $ta,hi20(%s)", arg_label);
      md_assemblef ("lwi $ta,[$ta+lo12(%s)]", arg_label);
      md_assemblef ("add %s,$ta,%s", arg_reg, TLS_REG);
    }
  else if (nds32_pic && ((strstr (arg_label, "@PLT")
			  || strstr (arg_label, "@GOTOFF"))))
    {
      md_assemblef ("sethi $ta,hi20(%s)", arg_label);
      md_assemblef ("ori $ta,$ta,lo12(%s)", arg_label);
      md_assemblef ("add %s,$ta,$gp", arg_reg);
    }
  else if (nds32_pic && strstr (arg_label, "@GOT"))
    {
      long addend = builtin_addend (arg_label, NULL);

      md_assemblef ("sethi $ta,hi20(%s)", arg_label);
      md_assemblef ("ori $ta,$ta,lo12(%s)", arg_label);
      md_assemblef ("lw %s,[$gp+$ta]", arg_reg);
      if (addend != 0)
	{
	  if (addend < 0x4000 && addend >= -0x4000)
	    {
	      md_assemblef ("addi %s,%s,%d", arg_reg, arg_reg, addend);
	    }
	  else
	    {
	      do_pseudo_li_internal ("$ta", addend);
	      md_assemblef ("add %s,$ta,%s", arg_reg, arg_reg);
	    }
	}
    }
   else
      as_bad (_("need PIC qualifier with symbol. '%s'"), line);
  relaxing = FALSE;
}

static void
do_pseudo_la (int argc ATTRIBUTE_UNUSED, char *argv[], 
	      unsigned int pv ATTRIBUTE_UNUSED)
{
  do_pseudo_la_internal (argv[0], argv[1], argv[argc]);
}

static void
do_pseudo_li_internal (const char *rt, int imm32s)
{
  if (enable_16bit && imm32s <= 0xf && imm32s >= -0x10)
    md_assemblef ("movi55 %s,%d", rt, imm32s);
  else if (imm32s <= 0x7ffff && imm32s >= -0x80000)
    md_assemblef ("movi %s,%d", rt, imm32s);
  else if ((imm32s & 0xfff) == 0)
    md_assemblef ("sethi %s,hi20(%d)", rt, imm32s);
  else
    {
      md_assemblef ("sethi %s,hi20(%d)", rt, imm32s);
      md_assemblef ("ori %s,%s,lo12(%d)", rt, rt, imm32s);
    }
}

static void
do_pseudo_li (int argc ATTRIBUTE_UNUSED, char *argv[], 
	      unsigned int pv ATTRIBUTE_UNUSED)
{
  /* Validate argv[1] for constant expression.  */
  expressionS exp;

  parse_expression (argv[1], &exp);
  if (exp.X_op != O_constant)
    {
      as_bad (_("Operand is not a constant. `%s'"), argv[argc]);
      return;
    }

  do_pseudo_li_internal (argv[0], exp.X_add_number);
}

static void
do_pseudo_ls_bhw (int argc ATTRIBUTE_UNUSED, char *argv[], 
		  unsigned int pv)
{
  char ls = 'r';
  char size = 'x';
  const char *sign = "";

  /* Prepare arguments for various load/store.  */
  sign = (pv & 0x10) ? "s" : "";
  ls = (pv & 0x80000000) ? 's' : 'l';
  switch (pv & 0x3)
    {
    case 0: size = 'b'; break;
    case 1: size = 'h'; break;
    case 2: size = 'w'; break;
    }

  if (ls == 's' || size == 'w')
    sign = "";

  if (builtin_isreg (argv[1], NULL))
    {
      /* lwi */
      md_assemblef ("%c%ci %s,[%s]", ls, size, argv[0], argv[1]);
    }
  else if (!nds32_pic)
    {
      relaxing = TRUE;
      if (strstr (argv[1], "@TPOFF"))
	{
	  /* ls.w $rt, sym@TPOFF  */
	  md_assemblef ("sethi $ta,hi20(%s)", argv[1]);
	  md_assemblef ("ori $ta,$ta,lo12(%s)", argv[1]);
	  md_assemblef ("%c%c%s %s,[$ta+%s]", ls, size, sign, argv[0], TLS_REG);
	}
      else if (strstr (argv[1], "@GOTTPOFF"))
	{
	  /* ls.w $rt, sym@GOTTPOFF  */
	  md_assemblef ("sethi $ta,hi20(%s)", argv[1]);
	  md_assemblef ("lwi $ta,[$ta+lo12(%s)]", argv[1]);
	  md_assemblef ("%c%c%s %s,[$ta+%s]", ls, size, sign, argv[0], TLS_REG);
	}
      else
	{
	  /* lwi */
	  md_assemblef ("sethi $ta,hi20(%s)", argv[1]);
	  md_assemblef ("%c%c%si %s,[$ta+lo12(%s)]", ls, size, sign, argv[0], argv[1]);
	}
      relaxing = FALSE;
    }
  else
    {
      relaxing = TRUE;
      /* PIC code.  */
      if (strstr (argv[1], "@GOTOFF"))
	{
	  /* lw */
	  md_assemblef ("sethi $ta,hi20(%s)", argv[1]);
	  md_assemblef ("ori $ta,$ta,lo12(%s)", argv[1]);
	  md_assemblef ("%c%c%s %s,[$ta+$gp]", ls, size, sign, argv[0]);
	}
      else if (strstr (argv[1], "@GOT"))
	{
	  long addend = builtin_addend (argv[1], NULL);
	  /* lw */
	  md_assemblef ("sethi $ta,hi20(%s)", argv[1]);
	  md_assemblef ("ori $ta,$ta,lo12(%s)", argv[1]);
	  md_assemble ((char *) "lw $ta,[$gp+$ta]");	/* Load address word.  */
	  if (addend < 0x10000 && addend >= -0x10000)
	    {
	      md_assemblef ("%c%c%si %s,[$ta+(%d)]", ls, size, sign, argv[0], addend);
	    }
	  else
	    {
	      /* lw */
	      do_pseudo_li_internal (argv[0], addend);
	      md_assemblef ("%c%c%s %s,[$ta+%s]", ls, size, sign, argv[0], argv[0]);
	    }
	}
      else
	{
	  as_bad (_("needs @GOT or @GOTOFF. %s"), argv[argc]);
	}
      relaxing = FALSE;
    }
}

static void
do_pseudo_ls_bhwp (int argc ATTRIBUTE_UNUSED, char *argv[], 
		   unsigned int pv)
{
  char *arg_rt = argv[0];
  char *arg_label = argv[1];
  char *arg_inc = argv[2];
  char ls = 'r';
  char size = 'x';
  const char *sign = "";

  /* Prepare arguments for various load/store.  */
  sign = (pv & 0x10) ? "s" : "";
  ls = (pv & 0x80000000) ? 's' : 'l';
  switch (pv & 0x3)
    {
    case 0: size = 'b'; break;
    case 1: size = 'h'; break;
    case 2: size = 'w'; break;
    }

  if (ls == 's' || size == 'w')
    sign = "";

  do_pseudo_la_internal ("$ta", arg_label, argv[argc]);
  md_assemblef ("%c%c%si.bi %s,[$ta],%s", ls, size, sign, arg_rt, arg_inc);
}

static void
do_pseudo_ls_bhwpc (int argc ATTRIBUTE_UNUSED, char *argv[],
		    unsigned int pv)
{
  char *arg_rt = argv[0];
  char *arg_inc = argv[1];
  char ls = 'r';
  char size = 'x';
  const char *sign = "";

  /* Prepare arguments for various load/store.  */
  sign = (pv & 0x10) ? "s" : "";
  ls = (pv & 0x80000000) ? 's' : 'l';
  switch (pv & 0x3)
    {
    case 0: size = 'b'; break;
    case 1: size = 'h'; break;
    case 2: size = 'w'; break;
    }

  if (ls == 's' || size == 'w')
    sign = "";

  md_assemblef ("%c%c%si.bi %s,[$ta],%s", ls, size, sign, arg_rt, arg_inc);
}

static void
do_pseudo_ls_bhwi (int argc ATTRIBUTE_UNUSED, char *argv[], 
		   unsigned int pv)
{
  char ls = 'r';
  char size = 'x';
  const char *sign = "";

  /* Prepare arguments for various load/store.  */
  sign = (pv & 0x10) ? "s" : "";
  ls = (pv & 0x80000000) ? 's' : 'l';
  switch (pv & 0x3)
    {
    case 0: size = 'b'; break;
    case 1: size = 'h'; break;
    case 2: size = 'w'; break;
    }

  if (ls == 's' || size == 'w')
    sign = "";

  md_assemblef ("%c%c%si.bi %s,%s,%s",
		ls, size, sign, argv[0], argv[1], argv[2]);
}

static void
do_pseudo_move_reg_internal (char *dst, char *src)
{
  if (enable_16bit)
    md_assemblef ("mov55 %s,%s", dst, src);
  else
    md_assemblef ("ori %s,%s,0", dst, src);
}

static void
do_pseudo_move (int argc ATTRIBUTE_UNUSED, char *argv[], 
		unsigned int pv ATTRIBUTE_UNUSED)
{
  expressionS exp;

  if (builtin_isreg (argv[1], NULL))
    do_pseudo_move_reg_internal (argv[0], argv[1]);
  else
    {
      parse_expression (argv[1], &exp);
      if (exp.X_op == O_constant)
	/* move $rt, imm  -> li $rt, imm  */
	do_pseudo_li_internal (argv[0], exp.X_add_number);
      else
	/* l.w $rt, var  -> l.w $rt, var  */
	do_pseudo_ls_bhw (argc, argv, 2);
    }
}

static void
do_pseudo_neg (int argc ATTRIBUTE_UNUSED, char *argv[], 
	       unsigned int pv ATTRIBUTE_UNUSED)
{
  /* Instead of "subri".  */
  md_assemblef ("subri %s,%s,0", argv[0], argv[1]);
}

static void
do_pseudo_not (int argc ATTRIBUTE_UNUSED, char *argv[],
	       unsigned int pv ATTRIBUTE_UNUSED)
{
  md_assemblef ("nor %s,%s,%s", argv[0], argv[1], argv[1]);
}

static void
do_pseudo_pushpopm (int argc, char *argv[],
		    unsigned int pv ATTRIBUTE_UNUSED)
{
  /* posh/pop $ra, $rb */
  /* SMW.{b | a}{i | d}{m?} Rb, [Ra], Re, Enable4 */
  int rb, re, ra, en4;
  int i;
  const char *opc = "pushpopm";

  if (argc == 3)
    as_bad ("'pushm/popm $ra5, $rb5, $label' is deprecated.  "
	    "Only 'pushm/popm $ra5' is supported now. %s", argv[argc]);
  else if (argc == 1)
    as_bad ("'pushm/popm $ra5, $rb5'. %s\n", argv[argc]);

  if (strstr (argv[argc], "pop") == argv[argc])
    opc = "lmw.bim";
  else if (strstr (argv[argc], "push") == argv[argc])
    opc = "smw.adm";
  else
    as_fatal ("nds32-as internal error. %s", argv[argc]);

  rb = builtin_regnum (argv[0], NULL);
  re = builtin_regnum (argv[1], NULL);

  if (re < rb)
    {
      as_warn ("$rb should not be smaller than $ra. %s", argv[argc]);
      /* Swap to right order.  */
      ra = re;
      re = rb;
      rb = ra;
    }

  /* Build enable4 mask.  */
  en4 = 0;
  if (re >= 28 || rb >= 28)
    {
      for (i = (rb >= 28? rb: 28); i <= re; i++)
	en4 |= 1 << (3 - (i - 28));
    }

  /* Adjust $re, $rb.  */
  if (rb >= 28)
    rb = re = 31;
  else if (nds32_gpr16 != 1 && re >= 28)
    re = 27;

  /* Reduce register.  */
  if (nds32_gpr16 && re > 10 && !(rb == 31 && re == 31))
    {
      if (re >= 15 && strstr(opc, "smw") != NULL)
	md_assemblef ("%s $r15,[$sp],$r15,%d", opc, en4);
      if (rb <= 10)
	md_assemblef ("%s $r%d,[$sp],$r10, 0x0", opc, rb);
      if (re >= 15 && strstr(opc, "lmw") != NULL)
	md_assemblef ("%s $r15,[$sp],$r15,%d", opc, en4);
    }
  else
    md_assemblef ("%s $r%d,[$sp],$r%d,%d", opc, rb, re, en4);
}

static void
do_pseudo_pushpop (int argc, char *argv[],
		   unsigned int pv ATTRIBUTE_UNUSED)
{
  /* push/pop $ra5, $label=$sp */
  char *argvm[3];

  if (argc == 2)
    as_bad ("'push/pop $ra5, rb5' is deprecated.  "
	    "Only 'push/pop $ra5' is supported now. %s", argv[argc]);

  argvm[0] = argv[0];
  argvm[1] = argv[0];
  argvm[2] = argv[argc];
  do_pseudo_pushpopm (2, argvm, PV_DONT_CARE);
}

static void
do_pseudo_v3push (int argc ATTRIBUTE_UNUSED, char *argv[],
		  unsigned int pv ATTRIBUTE_UNUSED)
{
  md_assemblef ("push25 %s,%s", argv[0], argv[1]);
}

static void
do_pseudo_v3pop (int argc ATTRIBUTE_UNUSED, char *argv[], 
		 unsigned int pv ATTRIBUTE_UNUSED)
{
  md_assemblef ("pop25 %s,%s", argv[0], argv[1]);
}

/* pv == 0, parsing "push.s" pseudo instruction operands.
   pv != 0, parsing "pop.s" pseudo instruction operands.  */

static void
do_pseudo_pushpop_stack (int argc, char *argv[],
			 unsigned int pv)
{
  /* push.s Rb,Re,{$fp $gp $lp $sp}  ==>  smw.adm Rb,[$sp],Re,Eable4  */
  /* pop.s Rb,Re,{$fp $gp $lp $sp}   ==>  lmw.bim Rb,[$sp],Re,Eable4  */

  int rb, re;
  int en4;
  int last_arg_index;
  const char *opc = (pv == 0) ? "smw.adm" : "lmw.bim";

  rb = re = 0;

  if (argc == 1)
    {
      /* argc=1, operands pattern: { $fp $gp $lp $sp }  */

      /* Set register number Rb = Re = $sp = $r31.  */
      rb = re = 31;
    }
  else if (argc == 2 || argc == 3)
    {
      /* argc=2, operands pattern: Rb, Re  */
      /* argc=3, operands pattern: Rb, Re, { $fp $gp $lp $sp }  */

      /* Get register number in integer.  */
      rb = builtin_regnum (argv[0], NULL);
      re = builtin_regnum (argv[1], NULL);

      /* Rb should be equal/less than Re.  */
      if (rb > re)
	as_bad ("The first operand (%s) should be equal to or smaller than "
		"second operand (%s).", argv[0], argv[1]);

      /* forbid using $fp|$gp|$lp|$sp in Rb or Re
		      r28 r29 r30 r31  */
      if (rb >= 28)
	as_bad ("Cannot use $fp, $gp, $lp, or $sp at first operand !!");
      if (re >= 28)
	as_bad ("Cannot use $fp, $gp, $lp, or $sp at second operand !!");
    }
  else
    {
      as_bad ("Invalid operands pattern !!");
    }

  /* Build Enable4 mask.  */
  /* Using last_arg_index for argc=1|2|3 is safe, because $fp, $gp, $lp,
     and $sp only appear in argc=1 or argc=3 if argc=2, en4 remains 0,
     which is also valid for code generation.  */
  en4 = 0;
  last_arg_index = argc - 1;
  if (strstr (argv[last_arg_index], "$fp"))
    en4 |= 8;
  if (strstr (argv[last_arg_index], "$gp"))
    en4 |= 4;
  if (strstr (argv[last_arg_index], "$lp"))
    en4 |= 2;
  if (strstr (argv[last_arg_index], "$sp"))
    en4 |= 1;

  md_assemblef ("%s $r%d,[$sp],$r%d,%d", opc, rb, re, en4);
}

static void
do_pseudo_push_bhwd (int argc ATTRIBUTE_UNUSED, char *argv[],
		     unsigned int pv ATTRIBUTE_UNUSED)
{
  char size = 'x';
  /* If users omit push location, use $sp as default value.  */
  char location[8] = "$sp";  /* 8 is enough for register name.  */

  switch (pv & 0x3)
    {
    case 0: size = 'b'; break;
    case 1: size = 'h'; break;
    case 2: size = 'w'; break;
    case 3: size = 'w'; break;
    }

  if (argc == 2)
    {
      strncpy (location, argv[1], 8);
      location[7] = '\0';
    }

  md_assemblef ("l.%c $ta,%s", size, argv[0]);
  md_assemblef ("smw.adm $ta,[%s],$ta", location);

  if ((pv & 0x3) == 0x3) /* double-word */
    {
      md_assemblef ("l.w $ta,%s+4", argv[0]);
      md_assemblef ("smw.adm $ta,[%s],$ta", location);
    }
}

static void
do_pseudo_pop_bhwd (int argc ATTRIBUTE_UNUSED, char *argv[],
		    unsigned int pv ATTRIBUTE_UNUSED)
{
  char size = 'x';
  /* If users omit pop location, use $sp as default value.  */
  char location[8] = "$sp";  /* 8 is enough for register name.  */

  switch (pv & 0x3)
    {
    case 0: size = 'b'; break;
    case 1: size = 'h'; break;
    case 2: size = 'w'; break;
    case 3: size = 'w'; break;
    }

  if (argc == 3)
    {
      strncpy (location, argv[2], 8);
      location[7] = '\0';
    }

  if ((pv & 0x3) == 0x3) /* double-word */
    {
      md_assemblef ("lmw.bim %s,[%s],%s", argv[1], location, argv[1]);
      md_assemblef ("s.w %s,%s+4", argv[1], argv[0]);
    }

  md_assemblef ("lmw.bim %s,[%s],%s", argv[1], location, argv[1]);
  md_assemblef ("s.%c %s,%s", size, argv[1], argv[0]);
}

static void
do_pseudo_pusha (int argc ATTRIBUTE_UNUSED, char *argv[],
		 unsigned int pv ATTRIBUTE_UNUSED)
{
  /* If users omit push location, use $sp as default value.  */
  char location[8] = "$sp";  /* 8 is enough for register name.  */

  if (argc == 2)
    {
      strncpy (location, argv[1], 8);
      location[7] = '\0';
    }

  md_assemblef ("la $ta,%s", argv[0]);
  md_assemblef ("smw.adm $ta,[%s],$ta", location);
}

static void
do_pseudo_pushi (int argc ATTRIBUTE_UNUSED, char *argv[],
		 unsigned int pv ATTRIBUTE_UNUSED)
{
  /* If users omit push location, use $sp as default value.  */
  char location[8] = "$sp";  /* 8 is enough for register name.  */

  if (argc == 2)
    {
      strncpy (location, argv[1], 8);
      location[7] = '\0';
    }

  md_assemblef ("li $ta,%s", argv[0]);
  md_assemblef ("smw.adm $ta,[%s],$ta", location);
}

struct nds32_pseudo_opcode nds32_pseudo_opcode_table[] =
{
  {"b",      1, do_pseudo_b,      0, 0},
  {"bal",    1, do_pseudo_bal,    0, 0},

  {"bge",    3, do_pseudo_bge,    0, 0},
  {"bges",   3, do_pseudo_bges,   0, 0},

  {"bgt",    3, do_pseudo_bgt,    0, 0},
  {"bgts",   3, do_pseudo_bgts,   0, 0},

  {"ble",    3, do_pseudo_ble,    0, 0},
  {"bles",   3, do_pseudo_bles,   0, 0},

  {"blt",    3, do_pseudo_blt,    0, 0},
  {"blts",   3, do_pseudo_blts,   0, 0},

  {"br",     1, do_pseudo_br,     0, 0},
  {"bral",   1, do_pseudo_bral,   0, 0},

  {"call",   1, do_pseudo_bal,    0, 0},

  {"la",     2, do_pseudo_la, 0, 0},
  {"li",     2, do_pseudo_li, 0, 0},

  {"l.b",    2, do_pseudo_ls_bhw, 0, 0},
  {"l.h",    2, do_pseudo_ls_bhw, 1, 0},
  {"l.w",    2, do_pseudo_ls_bhw, 2, 0},
  {"l.bs",   2, do_pseudo_ls_bhw, 0 | 0x10, 0},
  {"l.hs",   2, do_pseudo_ls_bhw, 1 | 0x10, 0},
  {"s.b",    2, do_pseudo_ls_bhw, 0 | 0x80000000, 0},
  {"s.h",    2, do_pseudo_ls_bhw, 1 | 0x80000000, 0},
  {"s.w",    2, do_pseudo_ls_bhw, 2 | 0x80000000, 0},

  {"l.bp",   3, do_pseudo_ls_bhwp, 0, 0},
  {"l.bpc",  3, do_pseudo_ls_bhwpc, 0, 0},
  {"l.hp",   3, do_pseudo_ls_bhwp, 1, 0},
  {"l.hpc",  3, do_pseudo_ls_bhwpc, 1, 0},
  {"l.wp",   3, do_pseudo_ls_bhwp, 2, 0},
  {"l.wpc",  3, do_pseudo_ls_bhwpc, 2, 0},
  {"l.bsp",  3, do_pseudo_ls_bhwp, 0 | 0x10, 0},
  {"l.bspc", 3, do_pseudo_ls_bhwpc, 0 | 0x10, 0},
  {"l.hsp",  3, do_pseudo_ls_bhwp, 1 | 0x10, 0},
  {"l.hspc", 3, do_pseudo_ls_bhwpc, 1 | 0x10, 0},
  {"s.bp",   3, do_pseudo_ls_bhwp, 0 | 0x80000000, 0},
  {"s.bpc",   3, do_pseudo_ls_bhwpc, 0 | 0x80000000, 0},
  {"s.hp",   3, do_pseudo_ls_bhwp, 1 | 0x80000000, 0},
  {"s.hpc",   3, do_pseudo_ls_bhwpc, 1 | 0x80000000, 0},
  {"s.wp",   3, do_pseudo_ls_bhwp, 2 | 0x80000000, 0},
  {"s.wpc",   3, do_pseudo_ls_bhwpc, 2 | 0x80000000, 0},
  {"s.bsp",  3, do_pseudo_ls_bhwp, 0 | 0x80000000 | 0x10, 0},
  {"s.hsp",  3, do_pseudo_ls_bhwp, 1 | 0x80000000 | 0x10, 0},

  {"lbi.p",  3, do_pseudo_ls_bhwi, 0, 0},
  {"lhi.p",  3, do_pseudo_ls_bhwi, 1, 0},
  {"lwi.p",  3, do_pseudo_ls_bhwi, 2, 0},
  {"sbi.p",  3, do_pseudo_ls_bhwi, 0 | 0x80000000, 0},
  {"shi.p",  3, do_pseudo_ls_bhwi, 1 | 0x80000000, 0},
  {"swi.p",  3, do_pseudo_ls_bhwi, 2 | 0x80000000, 0},
  {"lbsi.p", 3, do_pseudo_ls_bhwi, 0 | 0x10, 0},
  {"lhsi.p", 3, do_pseudo_ls_bhwi, 1 | 0x10, 0},
  {"lwsi.p", 3, do_pseudo_ls_bhwi, 2 | 0x10, 0},

  {"move",   2, do_pseudo_move, 0, 0},
  {"neg",    2, do_pseudo_neg,  0, 0},
  {"not",    2, do_pseudo_not,  0, 0},

  {"pop",    2, do_pseudo_pushpop,   0, 0},
  {"push",   2, do_pseudo_pushpop,   0, 0},
  {"popm",   2, do_pseudo_pushpopm,  0, 0},
  {"pushm",   3, do_pseudo_pushpopm, 0, 0},

  {"v3push", 2, do_pseudo_v3push, 0, 0},
  {"v3pop",  2, do_pseudo_v3pop,  0, 0},

  /* Support pseudo instructions of pushing/poping registers into/from stack
       push.s  Rb, Re, { $fp $gp $lp $sp }  ==>  smw.adm  Rb,[$sp],Re,Enable4
       pop.s   Rb, Re, { $fp $gp $lp $sp }  ==>  lmw.bim  Rb,[$sp],Re,Enable4 */
  { "push.s", 3, do_pseudo_pushpop_stack, 0, 0 },
  { "pop.s", 3, do_pseudo_pushpop_stack, 1, 0 },
  { "push.b", 2, do_pseudo_push_bhwd, 0, 0 },
  { "push.h", 2, do_pseudo_push_bhwd, 1, 0 },
  { "push.w", 2, do_pseudo_push_bhwd, 2, 0 },
  { "push.d", 2, do_pseudo_push_bhwd, 3, 0 },
  { "pop.b", 3, do_pseudo_pop_bhwd, 0, 0 },
  { "pop.h", 3, do_pseudo_pop_bhwd, 1, 0 },
  { "pop.w", 3, do_pseudo_pop_bhwd, 2, 0 },
  { "pop.d", 3, do_pseudo_pop_bhwd, 3, 0 },
  { "pusha", 2, do_pseudo_pusha, 0, 0 },
  { "pushi", 2, do_pseudo_pushi, 0, 0 },

  {NULL, 0, NULL, 0, 0}
};

static void
nds32_init_nds32_pseudo_opcodes (void)
{
  struct nds32_pseudo_opcode *opcode = nds32_pseudo_opcode_table;

  nds32_pseudo_opcode_hash = hash_new ();
  for ( ; opcode->opcode; opcode++)
    {
      void *op;

      op = hash_find (nds32_pseudo_opcode_hash, opcode->opcode);
      if (op != NULL)
	{
	  as_warn (_("Duplicated pseudo-opcode %s."), opcode->opcode);
	  continue;
	}
      hash_insert (nds32_pseudo_opcode_hash, opcode->opcode, opcode);
    }
}

static struct nds32_pseudo_opcode *
nds32_lookup_pseudo_opcode (const char *str)
{
  int i = 0;
  /* Assume pseudo-opcode are less than 16-char in length.  */
  char op[16] = {0};

  for (i = 0; i < (int)ARRAY_SIZE (op); i++)
    {
      if (ISSPACE (op[i] = str[i]))
	break;
    }

  if (i >= (int)ARRAY_SIZE (op))
    return NULL;

  op[i] = '\0';

  return hash_find (nds32_pseudo_opcode_hash, op);
}

static void
nds32_pseudo_opcode_wrapper (char *line, struct nds32_pseudo_opcode *opcode)
{
  int argc = 0;
  char *argv[8] = {NULL};
  char *s;
  char *str = xstrdup (line);

  /* Parse arguments for opcode.  */
  s = str + strlen (opcode->opcode);

  if (!s[0])
    goto end;

  /* Dummy comma to ease separate arguments as below.  */
  s[0] = ',';
  do
    {
      if (s[0] == ',')
	{
	  if (argc >= opcode->argc
	      || (argc >= (int)ARRAY_SIZE (argv) - 1))
	    as_bad (_("Too many argument. `%s'"), line);

	  argv[argc] = s + 1;
	  argc ++;
	  s[0] = '\0';
	}
      ++s;
    } while (s[0] != '\0');
end:
  /* Put the origin line for debugging.  */
  argv[argc] = line;
  opcode->proc (argc, argv, opcode->pseudo_val);
  free (str);
}

/* This function will be invoked from function `nds32_after_parse_args'.
   Thus, if the value of option has been set, keep the value the way it is.  */

static int
nds32_parse_arch (const char *str)
{
  static const struct nds32_arch
  {
    const char *name;
    int baseline;
    int reduced_reg;
    int fpu_sp_ext;
    int fpu_dp_ext;
    int fpu_freg;
    int abi;
  } archs[] =
  {
    {"v3m", ISA_V3M, 1, 0, 0, E_NDS32_FPU_REG_32SP_16DP, E_NDS_ABI_AABI},
    {"v3j", ISA_V3,  1, 0, 0, E_NDS32_FPU_REG_32SP_16DP, E_NDS_ABI_AABI},
    {"v3s", ISA_V3,  0, 1, 0, E_NDS32_FPU_REG_32SP_16DP, E_NDS_ABI_V2FP_PLUS},
    {"v3f", ISA_V3,  0, 1, 1, E_NDS32_FPU_REG_32SP_16DP, E_NDS_ABI_V2FP_PLUS},
    {"v3",  ISA_V3,  0, 0, 0, E_NDS32_FPU_REG_32SP_16DP, E_NDS_ABI_AABI},
    {"v2j", ISA_V2,  1, 0, 0, E_NDS32_FPU_REG_32SP_16DP, E_NDS_ABI_AABI},
    {"v2s", ISA_V2,  0, 1, 0, E_NDS32_FPU_REG_32SP_16DP, E_NDS_ABI_V2FP_PLUS},
    {"v2f", ISA_V2,  0, 1, 1, E_NDS32_FPU_REG_32SP_16DP, E_NDS_ABI_V2FP_PLUS},
    {"v2",  ISA_V2,  0, 0, 0, E_NDS32_FPU_REG_32SP_16DP, E_NDS_ABI_AABI},
  };
  size_t i;

  for (i = 0; i < ARRAY_SIZE (archs); i++)
    {
      if (strcmp (str, archs[i].name) != 0)
	continue;

      /* The value `-1' represents this option has *NOT* been set.  */
      nds32_baseline = (-1 != nds32_baseline) ? nds32_baseline : archs[i].baseline;
      nds32_gpr16 = (-1 != nds32_gpr16) ? nds32_gpr16 : archs[i].reduced_reg;
      nds32_fpu_sp_ext = (-1 != nds32_fpu_sp_ext) ? nds32_fpu_sp_ext : archs[i].fpu_sp_ext;
      nds32_fpu_dp_ext = (-1 != nds32_fpu_dp_ext) ? nds32_fpu_dp_ext : archs[i].fpu_dp_ext;
      nds32_freg = (-1 != nds32_freg) ? nds32_freg : archs[i].fpu_freg;
      nds32_abi = (-1 != nds32_abi) ? nds32_abi : archs[i].abi;

      return 1;
    }

  /* Logic here rejects the input arch name.  */
  as_bad (_("unknown arch name `%s'\n"), str);

  return 1;
}

/* This function parses "baseline" specified.  */

static int
nds32_parse_baseline (const char *str)
{
  if (strcmp (str, "v3") == 0)
    nds32_baseline = ISA_V3;
  else if (strcmp (str, "v3m") == 0)
    nds32_baseline = ISA_V3M;
  else if (strcmp (str, "v2") == 0)
    nds32_baseline = ISA_V2;
  else
    {
      /* Logic here rejects the input baseline.  */
      as_bad (_("unknown baseline `%s'\n"), str);
      return 0;
    }

  return 1;
}

/* This function parses "fpu-freg" specified.  */

static int
nds32_parse_freg (const char *str)
{
  if (strcmp (str, "2") == 0)
    nds32_freg = E_NDS32_FPU_REG_32SP_16DP;
  else if (strcmp (str, "3") == 0)
    nds32_freg = E_NDS32_FPU_REG_32SP_32DP;
  else if (strcmp (str, "1") == 0)
    nds32_freg = E_NDS32_FPU_REG_16SP_8DP;
  else if (strcmp (str, "0") == 0)
    nds32_freg = E_NDS32_FPU_REG_8SP_4DP;
  else
    {
      /* Logic here rejects the input FPU configuration.  */
      as_bad (_("unknown FPU configuration `%s'\n"), str);
      return 0;
    }

  return 1;
}

/* This function parse "abi=" specified.  */

static int
nds32_parse_abi (const char *str)
{
  if (strcmp (str, "v2") == 0)
    nds32_abi = E_NDS_ABI_AABI;
  /* Obsolete.  */
  else if (strcmp (str, "v2fp") == 0)
    nds32_abi = E_NDS_ABI_V2FP;
  else if (strcmp (str, "v1") == 0)
    nds32_abi = E_NDS_ABI_V1;
  else if (strcmp (str,"v2fpp") == 0)
    nds32_abi = E_NDS_ABI_V2FP_PLUS;
  else
    {
      /* Logic here rejects the input abi version.  */
      as_bad (_("unknown ABI version`%s'\n"), str);
      return 0;
    }

  return 1;
}

/* This function turn on all extensions and instructions support.  */

static int
nds32_all_ext (void)
{
  nds32_mac = 1;
  nds32_div = 1;
  nds32_dx_regs = 1;
  nds32_16bit_ext = 1;
  nds32_perf_ext = 1;
  nds32_perf_ext2 = 1;
  nds32_string_ext = 1;
  nds32_audio_ext = 1;
  nds32_fpu_fma = 1;
  nds32_fpu_sp_ext = 1;
  nds32_fpu_dp_ext = 1;

  return 1;
}

/* GAS will call md_parse_option whenever getopt returns an unrecognized code,
   presumably indicating a special code value which appears in md_longopts.
   This function should return non-zero if it handled the option and zero
   otherwise.  There is no need to print a message about an option not being
   recognized.  This will be handled by the generic code.  */

int
nds32_parse_option (int c, const char *arg)
{
  struct nds32_parse_option_table *coarse_tune;
  struct nds32_set_option_table *fine_tune;
  const char *ptr_arg = NULL;

  switch (c)
    {
    case OPTION_OPTIMIZE:
      optimize = 1;
      optimize_for_space = 0;
      break;
    case OPTION_OPTIMIZE_SPACE:
      optimize = 0;
      optimize_for_space = 1;
      break;
    case OPTION_BIG:
      target_big_endian = 1;
      break;
    case OPTION_LITTLE:
      target_big_endian = 0;
      break;
    case OPTION_TURBO:
      nds32_all_ext ();
      break;
    case OPTION_PIC:
      nds32_pic = 1;
      break;
    case OPTION_RELAX_FP_AS_GP_OFF:
      nds32_relax_fp_as_gp = 0;
      break;
    case OPTION_RELAX_B2BB_ON:
      nds32_relax_b2bb = 1;
      break;
    case OPTION_RELAX_ALL_OFF:
      nds32_relax_all = 0;
      break;
    default:
      /* Determination of which option table to search for to save time.  */
      if (!arg)
	return 0;

      ptr_arg = strchr (arg, '=');

      if (ptr_arg)
	{
	  /* Find the value after '='.  */
	  if (ptr_arg != NULL)
	    ptr_arg++;
	  for (coarse_tune = parse_opts; coarse_tune->name != NULL; coarse_tune++)
	    {
	      if (strncmp (arg, coarse_tune->name, (ptr_arg - arg)) == 0)
		{
		  coarse_tune->func (ptr_arg);
		  return 1;
		}
	    }
	}
      else
	{
	  int disable = 0;

	  /* Filter out the Disable option first.  */
	  if (strncmp (arg, "no-", 3) == 0)
	    {
	      disable = 1;
	      arg += 3;
	    }

	  for (fine_tune = toggle_opts; fine_tune->name != NULL; fine_tune++)
	    {
	      if (strcmp (arg, fine_tune->name) == 0)
		{
		  if (fine_tune->var != NULL)
		    *fine_tune->var = (disable) ? 0 : 1;
		  return 1;
		}
	    }
	}
      /* Nothing match.  */
      return 0;
    }

  return 1;
}

/* tc_check_label  */

void
nds32_check_label (symbolS *label ATTRIBUTE_UNUSED)
{
  /* The code used to create BB is move to frob_label.
     They should go there.  */
}

static void
set_endian_little (int on)
{
  target_big_endian = !on;
}

/* These functions toggles the generation of 16-bit.  First encounter signals
   the beginning of not generating 16-bit instructions and next encounter
   signals the restoring back to default behavior.  */

static void
trigger_16bit (int trigger)
{
  enable_16bit = trigger;
}

static int backup_16bit_mode;
static void
restore_16bit (int no_use ATTRIBUTE_UNUSED)
{
  enable_16bit = backup_16bit_mode;
}

static void
off_16bit (int no_use ATTRIBUTE_UNUSED)
{
  backup_16bit_mode = enable_16bit;
  enable_16bit = 0;
}

/* Built-in segments for small object.  */
typedef struct nds32_seg_entryT
{
  segT s;
  const char *name;
  flagword flags;
} nds32_seg_entry;

nds32_seg_entry nds32_seg_table[] =
{
  {NULL, ".sdata_f", SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
		     | SEC_HAS_CONTENTS | SEC_SMALL_DATA},
  {NULL, ".sdata_b", SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
		     | SEC_HAS_CONTENTS | SEC_SMALL_DATA},
  {NULL, ".sdata_h", SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
		     | SEC_HAS_CONTENTS | SEC_SMALL_DATA},
  {NULL, ".sdata_w", SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
		     | SEC_HAS_CONTENTS | SEC_SMALL_DATA},
  {NULL, ".sdata_d", SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_DATA
		     | SEC_HAS_CONTENTS | SEC_SMALL_DATA},
  {NULL, ".sbss_f", SEC_ALLOC | SEC_SMALL_DATA},
  {NULL, ".sbss_b", SEC_ALLOC | SEC_SMALL_DATA},
  {NULL, ".sbss_h", SEC_ALLOC | SEC_SMALL_DATA},
  {NULL, ".sbss_w", SEC_ALLOC | SEC_SMALL_DATA},
  {NULL, ".sbss_d", SEC_ALLOC | SEC_SMALL_DATA}
};

/* Indexes to nds32_seg_table[].  */
enum NDS32_SECTIONS_ENUM
{
  SDATA_F_SECTION = 0,
  SDATA_B_SECTION = 1,
  SDATA_H_SECTION = 2,
  SDATA_W_SECTION = 3,
  SDATA_D_SECTION = 4,
  SBSS_F_SECTION = 5,
  SBSS_B_SECTION = 6,
  SBSS_H_SECTION = 7,
  SBSS_W_SECTION = 8,
  SBSS_D_SECTION = 9
};

/* The following code is borrowed from v850_seg.  Revise this is needed.  */

static void
do_nds32_seg (int i, subsegT sub)
{
  nds32_seg_entry *seg = nds32_seg_table + i;

  obj_elf_section_change_hook ();

  if (seg->s != NULL)
    subseg_set (seg->s, sub);
  else
    {
      seg->s = subseg_new (seg->name, sub);
      if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
	{
	  bfd_set_section_flags (stdoutput, seg->s, seg->flags);
	  if ((seg->flags & SEC_LOAD) == 0)
	    seg_info (seg->s)->bss = 1;
	}
    }
}

static void
nds32_seg (int i)
{
  subsegT sub = get_absolute_expression ();

  do_nds32_seg (i, sub);
  demand_empty_rest_of_line ();
}

/* Set if label adjustment is needed.  I should not adjust .xbyte in dwarf.  */
static symbolS *nds32_last_label;	/* Last label for alignment.  */

/* This code is referred from D30V for adjust label to be with pending
   alignment.  For example,
     LBYTE: .byte	0x12
     LHALF: .half	0x12
     LWORD: .word	0x12
   Without this, the above label will not attach to incoming data.  */

static void
nds32_adjust_label (int n)
{
  /* FIXME: I think adjust label and alignment is
     the programmer's obligation.  Sadly, VLSI team doesn't
     properly use .align for their test cases.
     So I re-implement cons_align and auto adjust labels, again.

     I think d30v's implementation is simple and good enough.  */

  symbolS *label = nds32_last_label;
  nds32_last_label = NULL;

  /* SEC_ALLOC is used to eliminate .debug_ sections.
     SEC_CODE is used to include section for ILM.  */
  if (((now_seg->flags & SEC_ALLOC) == 0 && (now_seg->flags & SEC_CODE) == 0)
      || strcmp (now_seg->name, ".eh_frame") == 0
      || strcmp (now_seg->name, ".gcc_except_table") == 0)
    return;

  /* Only frag by alignment when needed.
     Otherwise, it will fail to optimize labels on 4-byte boundary.  (bug8454)
     See md_convert_frag () and RELAX_SET_RELAXABLE (frag) for details.  */
  if (frag_now_fix () & ((1 << n) -1 ))
    {
      if (subseg_text_p (now_seg))
	frag_align_code (n, 0);
      else
	frag_align (n, 0, 0);

      /* Record the minimum alignment for this segment.  */
      record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
    }

  if (label != NULL)
    {
      symbolS *sym;
      int label_seen = FALSE;
      struct frag *old_frag;
      valueT old_value, new_value;

      gas_assert (S_GET_SEGMENT (label) == now_seg);

      old_frag  = symbol_get_frag (label);
      old_value = S_GET_VALUE (label);
      new_value = (valueT) frag_now_fix ();

      /* Multiple labels may be on the same address.  And the last symbol
	 may not be a label at all, e.g., register name, external function names,
	 so I have to track the last label in tc_frob_label instead of
	 just using symbol_lastP.  */
      for (sym = symbol_lastP; sym != NULL; sym = symbol_previous (sym))
	{
	  if (symbol_get_frag (sym) == old_frag
	      && S_GET_VALUE (sym) == old_value)
	    {
	      /* Warning HERE! */
	      label_seen = TRUE;
	      symbol_set_frag (sym, frag_now);
	      S_SET_VALUE (sym, new_value);
	    }
	  else if (label_seen && symbol_get_frag (sym) != old_frag)
	    break;
	}
    }
}

void
nds32_cons_align (int size ATTRIBUTE_UNUSED)
{
  /* Do nothing here.
     This is called before `md_flush_pending_output' is called by `cons'.

     There are two things should be done for auto-adjust-label.
     1. Align data/instructions and adjust label to be attached to them.
     2. Clear auto-adjust state, so incoming data/instructions will not
	adjust the label.

     For example,
	  .byte 0x1
	.L0:
	  .word 0x2
	  .word 0x3
     in this case, '.word 0x2' will adjust the label, .L0, but '.word 0x3' should not.

     I think `md_flush_pending_output' is a good place to clear the auto-adjust state,
     but it is also called by `cons' before this function.
     To simplify the code, instead of overriding .zero, .fill, .space, etc,
     I think we should just adjust label in `nds32_aligned_X_cons' instead of here.  */
}

static void
nds32_aligned_cons (int idx)
{
  nds32_adjust_label (idx);
  /* Call default handler.  */
  cons (1 << idx);
  if (now_seg->flags & SEC_CODE
      && now_seg->flags & SEC_ALLOC && now_seg->flags & SEC_RELOC)
    {
      /* Use BFD_RELOC_NDS32_DATA to avoid EX9 optimization replacing data.  */
      expressionS exp;

      exp.X_add_number = 0;
      exp.X_op = O_constant;
      fix_new_exp (frag_now, frag_now_fix () - (1 << idx), 1 << idx,
		   &exp, 0, BFD_RELOC_NDS32_DATA);
    }
}

/* `.double' directive.  */

static void
nds32_aligned_float_cons (int type)
{
  switch (type)
    {
    case 'f':
    case 'F':
    case 's':
    case 'S':
      nds32_adjust_label (2);
      break;
    case 'd':
    case 'D':
    case 'r':
    case 'R':
      nds32_adjust_label (4);
      break;
    default:
      as_bad ("Unrecognized float type, %c\n", (char)type);
    }
  /* Call default handler.  */
  float_cons (type);
}

static void
nds32_enable_pic (int ignore ATTRIBUTE_UNUSED)
{
  /* Another way to do -mpic.
     This is for GCC internal use and should always be first line
     of code, otherwise, the effect is not determined.  */
  nds32_pic = 1;
}

static void
nds32_set_abi (int ver)
{
  nds32_abi = ver;
}

/* Relax directive to set relocation R_NDS32_RELAX_ENTRY value.  */

static void
nds32_relax_relocs (int relax)
{
  char saved_char;
  char *name;
  int i;
  const char *subtype_relax[] =
    {"", "", "ex9", "ifc"};

  name = input_line_pointer;
  while (*input_line_pointer && !ISSPACE (*input_line_pointer))
    input_line_pointer++;
  saved_char = *input_line_pointer;
  *input_line_pointer = 0;

  for (i = 0; i < (int) ARRAY_SIZE (subtype_relax); i++)
    {
      if (strcmp (name, subtype_relax[i]) == 0)
	{
	  switch (i)
	    {
	    case 0:
	    case 1:
	      enable_relax_relocs = relax & enable_relax_relocs;
	      enable_relax_ex9 = relax & enable_relax_ex9;
	      enable_relax_ifc = relax & enable_relax_ifc;
	      break;
	    case 2:
	      enable_relax_ex9 = relax;
	      break;
	    case 3:
	      enable_relax_ifc = relax;
	      break;
	    default:
	      break;
	    }
	  break;
	}
    }
  *input_line_pointer = saved_char;
  ignore_rest_of_line ();
}

/* Record which arguments register($r0 ~ $r5) is not used in callee.
   bit[i] for $ri  */

static void
nds32_set_hint_func_args (int ignore ATTRIBUTE_UNUSED)
{
  ignore_rest_of_line ();
}

/* Insert relocations to mark the begin and end of a fp-omitted function,
   for further relaxation use.
   bit[i] for $ri  */

static void
nds32_omit_fp_begin (int mode)
{
  expressionS exp;

  if (nds32_relax_fp_as_gp == 0)
    return;
  exp.X_op = O_symbol;
  exp.X_add_symbol = abs_section_sym;
  if (mode == 1)
    {
      in_omit_fp = 1;
      exp.X_add_number = R_NDS32_RELAX_REGION_OMIT_FP_FLAG;
      fix_new_exp (frag_now, frag_now_fix (), 0, &exp, 0,
		   BFD_RELOC_NDS32_RELAX_REGION_BEGIN);
    }
  else
    {
      in_omit_fp = 0;
      exp.X_add_number = R_NDS32_RELAX_REGION_OMIT_FP_FLAG;
      fix_new_exp (frag_now, frag_now_fix (), 0, &exp, 0,
		   BFD_RELOC_NDS32_RELAX_REGION_END);
    }
}

/* Insert relocations to mark the begin and end of ex9 region,
   for further relaxation use.
   bit[i] for $ri */

static void
nds32_no_ex9_begin (int mode)
{
  expressionS exp;

  exp.X_op = O_symbol;
  exp.X_add_symbol = abs_section_sym;
  if (mode == 1)
    {
      exp.X_add_number = R_NDS32_RELAX_REGION_NO_EX9_FLAG;
      fix_new_exp (frag_now, frag_now_fix (), 0, &exp, 0,
		   BFD_RELOC_NDS32_RELAX_REGION_BEGIN);
    }
  else
    {
      exp.X_add_number = R_NDS32_RELAX_REGION_NO_EX9_FLAG;
      fix_new_exp (frag_now, frag_now_fix (), 0, &exp, 0,
		   BFD_RELOC_NDS32_RELAX_REGION_END);
    }
}

static void
nds32_loop_begin (int mode)
{
  /* Insert loop region relocation here.  */
  expressionS exp;

  exp.X_op = O_symbol;
  exp.X_add_symbol = abs_section_sym;
  if (mode == 1)
    {
      exp.X_add_number = R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG;
      fix_new_exp (frag_now, frag_now_fix (), 0, &exp, 0,
		   BFD_RELOC_NDS32_RELAX_REGION_BEGIN);
    }
  else
    {
      exp.X_add_number = R_NDS32_RELAX_REGION_INNERMOST_LOOP_FLAG;
      fix_new_exp (frag_now, frag_now_fix (), 0, &exp, 0,
		   BFD_RELOC_NDS32_RELAX_REGION_END);
    }
}

struct nds32_relocs_group
{
  struct nds32_relocs_pattern *pattern;
  struct nds32_relocs_group *next;
};

static struct nds32_relocs_group *nds32_relax_hint_current = NULL;

/* Insert a relax hint.  */

static void
nds32_relax_hint (int mode ATTRIBUTE_UNUSED)
{
  char *name;
  char saved_char;
  struct nds32_relocs_pattern *relocs = NULL;
  struct nds32_relocs_group *group, *new;

  name = input_line_pointer;
  while (*input_line_pointer && !ISSPACE (*input_line_pointer))
    input_line_pointer++;
  saved_char = *input_line_pointer;
  *input_line_pointer = 0;
  name = strdup (name);

  /* Find relax hint entry for next instruction, and all member will be
     initialized at that time.  */
  relocs = hash_find (nds32_hint_hash, name);
  if (relocs == NULL)
    {
      relocs = XNEW (struct nds32_relocs_pattern);
      hash_insert (nds32_hint_hash, name, relocs);
    }
  else
    {
      while (relocs->next)
	relocs=relocs->next;
      relocs->next = XNEW (struct nds32_relocs_pattern);
      relocs = relocs->next;
    }

  relocs->next = NULL;
  *input_line_pointer = saved_char;
  ignore_rest_of_line ();

  /* Get the final one of relax hint series.  */

  /* It has to build this list because there are maybe more than one
     instructions relative to the same instruction.  It to connect to
     next instruction after md_assemble.  */
  new = XNEW (struct nds32_relocs_group);
  new->pattern = relocs;
  new->next = NULL;
  group = nds32_relax_hint_current;
  if (!group)
    nds32_relax_hint_current = new;
  else
    {
      while (group->next != NULL)
	group = group->next;
      group->next = new;
    }
  relaxing = TRUE;
}

/* Decide the size of vector entries, only accepts 4 or 16 now.  */

static void
nds32_vec_size (int ignore ATTRIBUTE_UNUSED)
{
  expressionS exp;

  expression (&exp);

  if (exp.X_op == O_constant)
    {
      if (exp.X_add_number == 4 || exp.X_add_number == 16)
	{
	  if (vec_size == 0)
	    vec_size = exp.X_add_number;
	  else if (vec_size != exp.X_add_number)
	    as_warn (_("Different arguments of .vec_size are found, "
		       "previous %d, current %d"),
		     (int) vec_size, (int) exp.X_add_number);
	}
      else
	as_warn (_("Argument of .vec_size is expected 4 or 16, actual: %d."),
		 (int) exp.X_add_number);
    }
  else
    as_warn (_("Argument of .vec_size is not a constant."));
}

/* The behavior of ".flag" directive varies depending on the target.
   In nds32 target, we use it to recognize whether this assembly content is
   generated by compiler.  Other features can also be added in this function
   in the future.  */

static void
nds32_flag (int ignore ATTRIBUTE_UNUSED)
{
  char *name;
  char saved_char;
  int i;
  const char *possible_flags[] = { "verbatim" };

  /* Skip whitespaces.  */
  name = input_line_pointer;
  while (*input_line_pointer && !ISSPACE (*input_line_pointer))
    input_line_pointer++;
  saved_char = *input_line_pointer;
  *input_line_pointer = 0;

  for (i = 0; i < (int) ARRAY_SIZE (possible_flags); i++)
    {
      if (strcmp (name, possible_flags[i]) == 0)
	{
	  switch (i)
	    {
	    case 0:
	      /* flag: verbatim */
	      verbatim = 1;
	      break;
	    default:
	      break;
	    }
	  /* Already found the flag, no need to continue next loop.   */
	  break;
	}
    }

  *input_line_pointer = saved_char;
  ignore_rest_of_line ();
}

static void
nds32_n12hc (int ignore ATTRIBUTE_UNUSED)
{
  /* N1213HC core is used.  */
}


/* The target specific pseudo-ops which we support.  */
const pseudo_typeS md_pseudo_table[] =
{
  /* Forced alignment if declared these ways.  */
  {"ascii", stringer, 8 + 0},
  {"asciz", stringer, 8 + 1},
  {"double", nds32_aligned_float_cons, 'd'},
  {"dword", nds32_aligned_cons, 3},
  {"float", nds32_aligned_float_cons, 'f'},
  {"half", nds32_aligned_cons, 1},
  {"hword", nds32_aligned_cons, 1},
  {"int", nds32_aligned_cons, 2},
  {"long", nds32_aligned_cons, 2},
  {"octa", nds32_aligned_cons, 4},
  {"quad", nds32_aligned_cons, 3},
  {"qword", nds32_aligned_cons, 4},
  {"short", nds32_aligned_cons, 1},
  {"byte", nds32_aligned_cons, 0},
  {"single", nds32_aligned_float_cons, 'f'},
  {"string", stringer, 8 + 1},
  {"word", nds32_aligned_cons, 2},

  {"little", set_endian_little, 1},
  {"big", set_endian_little, 0},
  {"16bit_on", trigger_16bit, 1},
  {"16bit_off", trigger_16bit, 0},
  {"restore_16bit", restore_16bit, 0},
  {"off_16bit", off_16bit, 0},

  {"sdata_d", nds32_seg, SDATA_D_SECTION},
  {"sdata_w", nds32_seg, SDATA_W_SECTION},
  {"sdata_h", nds32_seg, SDATA_H_SECTION},
  {"sdata_b", nds32_seg, SDATA_B_SECTION},
  {"sdata_f", nds32_seg, SDATA_F_SECTION},

  {"sbss_d", nds32_seg, SBSS_D_SECTION},
  {"sbss_w", nds32_seg, SBSS_W_SECTION},
  {"sbss_h", nds32_seg, SBSS_H_SECTION},
  {"sbss_b", nds32_seg, SBSS_B_SECTION},
  {"sbss_f", nds32_seg, SBSS_F_SECTION},

  {"pic", nds32_enable_pic, 0},
  {"n12_hc", nds32_n12hc, 0},
  {"abi_1", nds32_set_abi, E_NDS_ABI_V1},
  {"abi_2", nds32_set_abi, E_NDS_ABI_AABI},
  /* Obsolete.  */
  {"abi_2fp", nds32_set_abi, E_NDS_ABI_V2FP},
  {"abi_2fp_plus", nds32_set_abi, E_NDS_ABI_V2FP_PLUS},
  {"relax", nds32_relax_relocs, 1},
  {"no_relax", nds32_relax_relocs, 0},
  {"hint_func_args", nds32_set_hint_func_args, 0}, /* Abandon??  */
  {"omit_fp_begin", nds32_omit_fp_begin, 1},
  {"omit_fp_end", nds32_omit_fp_begin, 0},
  {"no_ex9_begin", nds32_no_ex9_begin, 1},
  {"no_ex9_end", nds32_no_ex9_begin, 0},
  {"vec_size", nds32_vec_size, 0},
  {"flag", nds32_flag, 0},
  {"innermost_loop_begin", nds32_loop_begin, 1},
  {"innermost_loop_end", nds32_loop_begin, 0},
  {"relax_hint", nds32_relax_hint, 0},
  {NULL, NULL, 0}
};

void
nds32_pre_do_align (int n, char *fill, int len, int max)
{
  /* Only make a frag if we HAVE to...  */
  fragS *fragP;
  if (n != 0 && !need_pass_2)
    {
      if (fill == NULL)
	{
	  if (subseg_text_p (now_seg))
	    {
	      dwarf2_emit_insn (0);
	      fragP = frag_now;
	      frag_align_code (n, max);

	      /* Tag this alignment when there is a label before it.  */
	      if (label_exist)
		{
		  fragP->tc_frag_data.flag = NDS32_FRAG_LABEL;
		  label_exist = 0;
		}
	    }
	  else
	    frag_align (n, 0, max);
	}
      else if (len <= 1)
	frag_align (n, *fill, max);
      else
	frag_align_pattern (n, fill, len, max);
    }
}

void
nds32_do_align (int n)
{
  /* Optimize for space and label exists.  */
  expressionS exp;

  /* FIXME:I think this will break debug info sections and except_table.  */
  if (!enable_relax_relocs || !subseg_text_p (now_seg))
    return;

  /* Create and attach a BFD_RELOC_NDS32_LABEL fixup
     the size of instruction may not be correct because
     it could be relaxable.  */
  exp.X_op = O_symbol;
  exp.X_add_symbol = section_symbol (now_seg);
  exp.X_add_number = n;
  fix_new_exp (frag_now,
	       frag_now_fix (), 0, &exp, 0, BFD_RELOC_NDS32_LABEL);
}

/* Supported Andes machines.  */
struct nds32_machs
{
  enum bfd_architecture bfd_mach;
  int mach_flags;
};

/* This is the callback for nds32-asm.c to parse operands.  */

int
nds32_asm_parse_operand (struct nds32_asm_desc *pdesc ATTRIBUTE_UNUSED,
			 struct nds32_asm_insn *pinsn,
			 char **pstr, int64_t *value)
{
  char *hold;
  expressionS *pexp = pinsn->info;

  hold = input_line_pointer;
  input_line_pointer = *pstr;
  expression (pexp);
  *pstr = input_line_pointer;
  input_line_pointer = hold;

  switch (pexp->X_op)
    {
    case O_symbol:
      *value = 0;
      return NASM_R_SYMBOL;
    case O_constant:
      *value = pexp->X_add_number;
      return NASM_R_CONST;
    case O_illegal:
    case O_absent:
    case O_register:
    default:
      return NASM_R_ILLEGAL;
    }
}

/* GAS will call this function at the start of the assembly, after the command
   line arguments have been parsed and all the machine independent
   initializations have been completed.  */

void
md_begin (void)
{
  struct nds32_keyword *k;
  unsigned int i;

  bfd_set_arch_mach (stdoutput, TARGET_ARCH, nds32_baseline);

  nds32_init_nds32_pseudo_opcodes ();
  asm_desc.parse_operand = nds32_asm_parse_operand;
  nds32_asm_init (&asm_desc, 0);

  /* Initial general purpose registers hash table.  */
  nds32_gprs_hash = hash_new ();
  for (k = keyword_gpr; k->name; k++)
    hash_insert (nds32_gprs_hash, k->name, k);

  /* Initial branch hash table.  */
  nds32_relax_info_hash = hash_new ();
  for (i = 0; i < ARRAY_SIZE (relax_table); i++)
    hash_insert (nds32_relax_info_hash, relax_table[i].opcode,
		 &relax_table[i]);

  /* Initial relax hint hash table.  */
  nds32_hint_hash = hash_new ();
  enable_16bit = nds32_16bit_ext;
}

/* HANDLE_ALIGN in write.c.  */

void
nds32_handle_align (fragS *fragp)
{
  static const unsigned char nop16[] = { 0x92, 0x00 };
  static const unsigned char nop32[] = { 0x40, 0x00, 0x00, 0x09 };
  int bytes;
  char *p;

  if (fragp->fr_type != rs_align_code)
    return;

  bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
  p = fragp->fr_literal + fragp->fr_fix;

  if (bytes & 1)
    {
      *p++ = 0;
      bytes--;
    }

  if (bytes & 2)
    {
      expressionS exp_t;
      exp_t.X_op = O_symbol;
      exp_t.X_add_symbol = abs_section_sym;
      exp_t.X_add_number = R_NDS32_INSN16_CONVERT_FLAG;
      fix_new_exp (fragp, fragp->fr_fix, 2, &exp_t, 0,
		   BFD_RELOC_NDS32_INSN16);
      memcpy (p, nop16, 2);
      p += 2;
      bytes -= 2;
    }

  while (bytes >= 4)
    {
      memcpy (p, nop32, 4);
      p += 4;
      bytes -= 4;
    }

  bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
  fragp->fr_fix += bytes;
}

/* md_flush_pending_output  */

void
nds32_flush_pending_output (void)
{
  nds32_last_label = NULL;
}

void
nds32_frob_label (symbolS *label)
{
  dwarf2_emit_label (label);
}

/* TC_START_LABEL  */

int
nds32_start_label (int asmdone ATTRIBUTE_UNUSED, int secdone ATTRIBUTE_UNUSED)
{
  if (optimize && subseg_text_p (now_seg))
    label_exist = 1;
  return 1;
}

/* TARGET_FORMAT  */

const char *
nds32_target_format (void)
{
#ifdef TE_LINUX
  if (target_big_endian)
    return "elf32-nds32be-linux";
  else
    return "elf32-nds32le-linux";
#else
  if (target_big_endian)
    return "elf32-nds32be";
  else
    return "elf32-nds32le";
#endif
}

static enum nds32_br_range
get_range_type (const struct nds32_field *field)
{
  gas_assert (field != NULL);

  if (field->bitpos != 0)
    return BR_RANGE_U4G;

  if (field->bitsize == 24 && field->shift == 1)
    return BR_RANGE_S16M;
  else if (field->bitsize == 16 && field->shift == 1)
    return BR_RANGE_S64K;
  else if (field->bitsize == 14 && field->shift == 1)
    return BR_RANGE_S16K;
  else if (field->bitsize == 8 && field->shift == 1)
    return BR_RANGE_S256;
  else
    return BR_RANGE_U4G;
}

/* Save pseudo instruction relocation list.  */

static struct nds32_relocs_pattern*
nds32_elf_save_pseudo_pattern (fixS* fixP, struct nds32_opcode *opcode,
			       char *out, symbolS *sym,
			       struct nds32_relocs_pattern *reloc_ptr,
			       fragS *fragP)
{
  if (!reloc_ptr)
    reloc_ptr = XNEW (struct nds32_relocs_pattern);
  reloc_ptr->seg = now_seg;
  reloc_ptr->sym = sym;
  reloc_ptr->frag = fragP;
  reloc_ptr->frchain = frchain_now;
  reloc_ptr->fixP = fixP;
  reloc_ptr->opcode = opcode;
  reloc_ptr->where = out;
  reloc_ptr->next = NULL;
  return reloc_ptr;
}

/* Check X_md to transform relocation.  */

static fixS*
nds32_elf_record_fixup_exp (fragS *fragP, const char *str,
			    const struct nds32_field *fld,
			    expressionS *pexp, char* out,
			    struct nds32_asm_insn *insn)
{
  int reloc = -1;
  expressionS exp;
  fixS *fixP = NULL;

  /* Handle instruction relocation.  */
  if (fld && fld->bitpos == 0 && (insn->attr & NASM_ATTR_HI20))
    {
      /* Relocation for hi20 modifier.  */
      switch (pexp->X_md)
	{
	case BFD_RELOC_NDS32_GOTOFF:	/* @GOTOFF */
	  reloc = BFD_RELOC_NDS32_GOTOFF_HI20;
	  break;
	case BFD_RELOC_NDS32_GOT20:	/* @GOT */
	  reloc = BFD_RELOC_NDS32_GOT_HI20;
	  break;
	case BFD_RELOC_NDS32_25_PLTREL:	/* @PLT */
	  if (!nds32_pic)
	    as_bad (_("Invalid PIC expression."));
	  else
	    reloc = BFD_RELOC_NDS32_PLT_GOTREL_HI20;
	  break;
	case BFD_RELOC_NDS32_GOTPC20:	/* _GLOBAL_OFFSET_TABLE_ */
	  reloc = BFD_RELOC_NDS32_GOTPC_HI20;
	  break;
	case BFD_RELOC_NDS32_TPOFF:	/* @TPOFF */
	  reloc = BFD_RELOC_NDS32_TLS_LE_HI20;
	  break;
	case BFD_RELOC_NDS32_GOTTPOFF:	/* @GOTTPOFF */
	  reloc = BFD_RELOC_NDS32_TLS_IE_HI20;
	  break;
	default:	/* No suffix.  */
	  reloc = BFD_RELOC_NDS32_HI20;
	  break;
	}
      fixP = fix_new_exp (fragP, out - fragP->fr_literal, insn->opcode->isize,
			  insn->info, 0 /* pcrel */, reloc);
    }
  else if (fld && fld->bitpos == 0 && (insn->attr & NASM_ATTR_LO12))
    {
      /* Relocation for lo12 modifier.  */
      if (fld->bitsize == 15 && fld->shift == 0)
	{
	  /* [ls]bi || ori */
	  switch (pexp->X_md)
	    {
	    case BFD_RELOC_NDS32_GOTOFF:	/* @GOTOFF */
	      reloc = BFD_RELOC_NDS32_GOTOFF_LO12;
	      break;
	    case BFD_RELOC_NDS32_GOT20:		/* @GOT */
	      reloc = BFD_RELOC_NDS32_GOT_LO12;
	      break;
	    case BFD_RELOC_NDS32_25_PLTREL:	/* @PLT */
	      if (!nds32_pic)
		as_bad (_("Invalid PIC expression."));
	      else
		reloc = BFD_RELOC_NDS32_PLT_GOTREL_LO12;
	      break;
	    case BFD_RELOC_NDS32_GOTPC20:	/* _GLOBAL_OFFSET_TABLE_ */
	      reloc = BFD_RELOC_NDS32_GOTPC_LO12;
	      break;
	    case BFD_RELOC_NDS32_TPOFF:		/* @TPOFF */
	      reloc = BFD_RELOC_NDS32_TLS_LE_LO12;
	      break;
	    default:	/* No suffix.  */
	      reloc = BFD_RELOC_NDS32_LO12S0;
	      break;
	    }
	}
      else if (fld->bitsize == 15 && fld->shift == 1)
	reloc = BFD_RELOC_NDS32_LO12S1;		/* [ls]hi */
      else if (fld->bitsize == 15 && fld->shift == 2)
	{
	  /* [ls]wi */
	  switch (pexp->X_md)
	    {
	    case BFD_RELOC_NDS32_GOTTPOFF:	/* @GOTTPOFF */
	      reloc = BFD_RELOC_NDS32_TLS_IE_LO12S2;
	      break;
	    default:	/* No suffix.  */
	      reloc = BFD_RELOC_NDS32_LO12S2;
	      break;
	    }
	}
      else if (fld->bitsize == 15 && fld->shift == 3)
	reloc = BFD_RELOC_NDS32_LO12S3;		/* [ls]di */
      else if (fld->bitsize == 12 && fld->shift == 2)
	reloc = R_NDS32_LO12S2_SP_RELA;		/* f[ls][sd]i */

      fixP = fix_new_exp (fragP, out - fragP->fr_literal, insn->opcode->isize,
			  insn->info, 0 /* pcrel */, reloc);
    }
  else if (fld && fld->bitpos == 0 && insn->opcode->isize == 4
	   && (insn->attr & NASM_ATTR_PCREL))
    {
      /* Relocation for 32-bit branch instructions.  */
      if (fld->bitsize == 24 && fld->shift == 1)
	reloc = BFD_RELOC_NDS32_25_PCREL;
      else if (fld->bitsize == 16 && fld->shift == 1)
	reloc = BFD_RELOC_NDS32_17_PCREL;
      else if (fld->bitsize == 14 && fld->shift == 1)
	reloc = BFD_RELOC_NDS32_15_PCREL;
      else if (fld->bitsize == 8 && fld->shift == 1)
	reloc = BFD_RELOC_NDS32_WORD_9_PCREL;
      else
	abort ();

      fixP = fix_new_exp (fragP, out - fragP->fr_literal, insn->opcode->isize,
		   insn->info, 1 /* pcrel */, reloc);
    }
  else if (fld && fld->bitpos == 0 && insn->opcode->isize == 4
	   && (insn->attr & NASM_ATTR_GPREL))
    {
      /* Relocation for 32-bit gp-relative instructions.  */
      if (fld->bitsize == 19 && fld->shift == 0)
	reloc = BFD_RELOC_NDS32_SDA19S0;
      else if (fld->bitsize == 18 && fld->shift == 1)
	reloc = BFD_RELOC_NDS32_SDA18S1;
      else if (fld->bitsize == 17 && fld->shift == 2)
	reloc = BFD_RELOC_NDS32_SDA17S2;
      else
	abort ();

      fixP = fix_new_exp (fragP, out - fragP->fr_literal, insn->opcode->isize,
		   insn->info, 0 /* pcrel */, reloc);
      /* Insert INSN16 for converting fp_as_gp.  */
      exp.X_op = O_symbol;
      exp.X_add_symbol = abs_section_sym;
      exp.X_add_number = 0;
      if (in_omit_fp && reloc == BFD_RELOC_NDS32_SDA17S2)
	fix_new_exp (fragP, out - fragP->fr_literal,
		     insn->opcode->isize, &exp, 0 /* pcrel */,
		     BFD_RELOC_NDS32_INSN16);
    }
  else if (fld && fld->bitpos == 0 && insn->opcode->isize == 2
	   && (insn->attr & NASM_ATTR_PCREL))
    {
      /* Relocation for 16-bit branch instructions.  */
      if (fld->bitsize == 8 && fld->shift == 1)
	reloc = BFD_RELOC_NDS32_9_PCREL;
      else
	abort ();

      fixP = fix_new_exp (fragP, out - fragP->fr_literal, insn->opcode->isize,
		   insn->info, 1 /* pcrel */, reloc);
    }
  else if (fld && fld->bitpos == 0 && (insn->attr & NASM_ATTR_IFC_EXT))
    {
      /* Relocation for ifcall instruction.  */
      if (insn->opcode->isize == 2 && fld->bitsize == 9 && fld->shift == 1)
	reloc = BFD_RELOC_NDS32_10IFCU_PCREL;
      else if (insn->opcode->isize == 4 && fld->bitsize == 16
	       && fld->shift == 1)
	reloc = BFD_RELOC_NDS32_17IFC_PCREL;
      else
	abort ();

      fixP = fix_new_exp (fragP, out - fragP->fr_literal, insn->opcode->isize,
		   insn->info, 1 /* pcrel */, reloc);
    }
  else if (fld)
    as_bad (_("Don't know how to handle this field. %s"), str);

  return fixP;
}

/* Build instruction pattern to relax.  There are two type group pattern
   including pseudo instruction and relax hint.  */

static void
nds32_elf_build_relax_relation (fixS *fixP, expressionS *pexp, char* out,
				struct nds32_opcode *opcode, fragS *fragP,
				const struct nds32_field *fld)
{
  struct nds32_relocs_pattern *reloc_ptr;
  struct nds32_relocs_group *group;
  symbolS *sym = NULL;

  /* The expression may be used uninitialized.  */
  if (fld)
    sym = pexp->X_add_symbol;

  if (pseudo_opcode)
    {
      /* Save instruction relation for pseudo instruction expanding pattern.  */
      reloc_ptr = nds32_elf_save_pseudo_pattern (fixP, opcode, out, sym,
						 NULL, fragP);
      if (!relocs_list)
	relocs_list = reloc_ptr;
      else
	{
	  struct nds32_relocs_pattern *temp = relocs_list;
	  while (temp->next)
	    temp = temp->next;
	  temp->next = reloc_ptr;
	}
    }
  else if (nds32_relax_hint_current)
    {
      /* Save instruction relation by relax hint.  */
      group = nds32_relax_hint_current;
      while (group)
	{
	  nds32_elf_save_pseudo_pattern (fixP, opcode, out, sym,
					 group->pattern, fragP);
	  group = group->next;
	  free (nds32_relax_hint_current);
	  nds32_relax_hint_current = group;
	}
    }

  /* Set relaxing false only for relax_hint trigger it.  */
  if (!pseudo_opcode)
    relaxing = FALSE;
}

#define N32_MEM_EXT(insn) ((N32_OP6_MEM << 25) | insn)

/* Relax pattern for link time relaxation.  */

static struct nds32_relax_hint_table relax_ls_table[] =
{
  {
    /* Set address: la -> sethi ori.  */
    NDS32_RELAX_HINT_LA,	/* main_type */
    8,				/* relax_code_size */
    {
      OP6 (SETHI),
      OP6 (ORI),
    },				/* relax_code_seq */
    {
      {0, 4, NDS32_HINT | NDS32_ADDEND, BFD_RELOC_NDS32_LOADSTORE},
      {4, 4, NDS32_HINT | NDS32_ABS, BFD_RELOC_NDS32_INSN16}
    }				/* relax_fixup */
  },
  {
    /* Set address: l.w -> sethi ori.  */
    NDS32_RELAX_HINT_LS,	/* main_type */
    8,				/* relax_code_size */
    {
      OP6 (SETHI),
      OP6 (LBI),
    },				/* relax_code_seq */
    {
      {0, 4, NDS32_HINT | NDS32_ADDEND, BFD_RELOC_NDS32_LOADSTORE},
      {4, 4, NDS32_HINT | NDS32_ABS, BFD_RELOC_NDS32_INSN16}
    }				/* relax_fixup */
  },
  {
    0,
    0,
    {0},
    {{0, 0 , 0, 0}}
  }
};

/* Since sethi loadstore relocation has to using next instruction to determine
   elimination itself or not, we have to return the next instruction range.  */

static int
nds32_elf_sethi_range (struct nds32_relocs_pattern *pattern)
{
  int range = 0;
  while (pattern)
    {
      switch (pattern->opcode->value)
	{
	case INSN_LBI:
	case INSN_SBI:
	case INSN_LBSI:
	case N32_MEM_EXT (N32_MEM_LB):
	case N32_MEM_EXT (N32_MEM_LBS):
	case N32_MEM_EXT (N32_MEM_SB):
	  range = NDS32_LOADSTORE_BYTE;
	  break;
	case INSN_LHI:
	case INSN_SHI:
	case INSN_LHSI:
	case N32_MEM_EXT (N32_MEM_LH):
	case N32_MEM_EXT (N32_MEM_LHS):
	case N32_MEM_EXT (N32_MEM_SH):
	  range = NDS32_LOADSTORE_HALF;
	  break;
	case INSN_LWI:
	case INSN_SWI:
	case N32_MEM_EXT (N32_MEM_LW):
	case N32_MEM_EXT (N32_MEM_SW):
	  range = NDS32_LOADSTORE_WORD;
	  break;
	case INSN_FLSI:
	case INSN_FSSI:
	  range = NDS32_LOADSTORE_FLOAT_S;
	  break;
	case INSN_FLDI:
	case INSN_FSDI:
	  range = NDS32_LOADSTORE_FLOAT_D;
	  break;
	case INSN_ORI:
	  range = NDS32_LOADSTORE_IMM;
	  break;
	default:
	  range = NDS32_LOADSTORE_NONE;
	  break;
	}
      if (range != NDS32_LOADSTORE_NONE)
	break;
      pattern = pattern->next;
    }
  return range;
}

/* The args means: instruction size, the 1st instruction is converted to 16 or
   not, optimize option, 16 bit instruction is enable.  */
#define SET_ADDEND(size, convertible, optimize, insn16_on) \
  (((size) & 0xff) | ((convertible) ? 1 << 31 : 0) \
   | ((optimize) ? 1<< 30 : 0) | (insn16_on ? 1 << 29 : 0))

static void
nds32_set_elf_flags_by_insn (struct nds32_asm_insn * insn)
{
  /* Set E_NDS32_HAS_EXT_INST.  */
  if (insn->opcode->attr & NASM_ATTR_PERF_EXT)
    {
      if (nds32_perf_ext)
	nds32_elf_flags |= E_NDS32_HAS_EXT_INST;
      else
	as_bad (_("instruction %s requires enabling performance extension"),
		insn->opcode->opcode);
    }
  else if (insn->opcode->attr & NASM_ATTR_PERF2_EXT)
    {
      if (nds32_perf_ext2)
	nds32_elf_flags |= E_NDS32_HAS_EXT2_INST;
      else
	as_bad (_("instruction %s requires enabling performance extension II"),
		insn->opcode->opcode);
    }
  else if (insn->opcode->attr & NASM_ATTR_AUDIO_ISAEXT)
    {
      if (nds32_audio_ext)
	nds32_elf_flags |= E_NDS32_HAS_AUDIO_INST;
      else
	as_bad (_("instruction %s requires enabling AUDIO extension"),
		insn->opcode->opcode);
    }
  else if (insn->opcode->attr & NASM_ATTR_STR_EXT)
    {
      if (nds32_string_ext)
	nds32_elf_flags |= E_NDS32_HAS_STRING_INST;
      else
	as_bad (_("instruction %s requires enabling STRING extension"),
		insn->opcode->opcode);
    }
  else if ((insn->opcode->attr & NASM_ATTR_DIV)
	   && (insn->opcode->attr & NASM_ATTR_DXREG))
    {
      if (nds32_div && nds32_dx_regs)
	nds32_elf_flags |= E_NDS32_HAS_DIV_DX_INST;
      else
	as_bad (_("instruction %s requires enabling DIV & DX_REGS extension"),
		insn->opcode->opcode);
    }
  else if (insn->opcode->attr & NASM_ATTR_FPU)
    {
      if (nds32_fpu_sp_ext || nds32_fpu_dp_ext)
	{
	  if (!(nds32_elf_flags & (E_NDS32_HAS_FPU_INST | E_NDS32_HAS_FPU_DP_INST)))
	    nds32_fpu_com = 1;
	}
      else
	as_bad (_("instruction %s requires enabling FPU extension"),
		insn->opcode->opcode);
    }
  else if (insn->opcode->attr & NASM_ATTR_FPU_SP_EXT)
    {
      if (nds32_fpu_sp_ext)
	nds32_elf_flags |= E_NDS32_HAS_FPU_INST;
      else
	as_bad (_("instruction %s requires enabling FPU_SP extension"),
		insn->opcode->opcode);
    }
  else if ((insn->opcode->attr & NASM_ATTR_FPU_SP_EXT)
	   && (insn->opcode->attr & NASM_ATTR_MAC))
    {
      if (nds32_fpu_sp_ext && nds32_mac)
	{
	  nds32_elf_flags |= E_NDS32_HAS_FPU_MAC_INST;
	  nds32_elf_flags |= E_NDS32_HAS_FPU_INST;
	}
      else
	as_bad (_("instruction %s requires enabling FPU_MAC extension"),
		insn->opcode->opcode);
    }
  else if (insn->opcode->attr & NASM_ATTR_FPU_DP_EXT)
    {
      if (nds32_fpu_dp_ext)
	nds32_elf_flags |= E_NDS32_HAS_FPU_DP_INST;
      else
	as_bad (_("instruction %s requires enabling FPU_DP extension"),
		insn->opcode->opcode);
    }
  else if ((insn->opcode->attr & NASM_ATTR_FPU_DP_EXT)
	   && (insn->opcode->attr & NASM_ATTR_MAC))
    {
      if (nds32_fpu_dp_ext && nds32_mac)
	{
	  nds32_elf_flags |= E_NDS32_HAS_FPU_MAC_INST;
	  nds32_elf_flags |= E_NDS32_HAS_FPU_DP_INST;
	}
      else
	as_bad (_("instruction %s requires enabling FPU_MAC extension"),
		insn->opcode->opcode);
    }
  /* TODO: FPU_BOTH */
  else if ((insn->opcode->attr & NASM_ATTR_MAC)
	   && (insn->opcode->attr & NASM_ATTR_DXREG))
    {
      if (nds32_mac && nds32_dx_regs)
	nds32_elf_flags |= E_NDS32_HAS_MAC_DX_INST;
      else
	as_bad (_("instruction %s requires enabling DX_REGS extension"),
		insn->opcode->opcode);
    }
  /* TODO: for DX_REG set but not for MAC, DIV, AUDIO */
  else if (insn->opcode->attr & NASM_ATTR_IFC_EXT)
    {
      nds32_elf_flags |= E_NDS32_HAS_IFC_INST;
    }
  /* TODO: E_NDS32_HAS_SATURATION_INST */
}

/* Flag for analysis relaxation type.  */

enum nds32_insn_type
{
  N32_RELAX_SETHI = 1,
  N32_RELAX_BR = (1 << 1),
  N32_RELAX_LSI = (1 << 2),
  N32_RELAX_JUMP = (1 << 3),
  N32_RELAX_CALL = (1 << 4),
  N32_RELAX_ORI = (1 << 5),
  N32_RELAX_MEM = (1 << 6),
  N32_RELAX_MOVI = (1 << 7),
};

struct nds32_hint_map
{
  bfd_reloc_code_real_type hi_type;
  const char *opc;
  enum nds32_relax_hint_type hint_type;
  enum nds32_br_range range;
  enum nds32_insn_type insn_list;
};

/* Table to match instructions with hint and relax pattern.  */

static struct nds32_hint_map hint_map [] =
{
    {
      /* LONGCALL4.  */
      BFD_RELOC_NDS32_HI20,
      "jal",
      NDS32_RELAX_HINT_NONE,
      BR_RANGE_U4G,
      N32_RELAX_SETHI | N32_RELAX_ORI | N32_RELAX_CALL
    },
    {
      /* LONGCALL5.  */
      _dummy_first_bfd_reloc_code_real,
      "bgezal",
      NDS32_RELAX_HINT_NONE,
      BR_RANGE_S16M,
      N32_RELAX_BR | N32_RELAX_CALL
    },
    {
      /* LONGCALL6.  */
      BFD_RELOC_NDS32_HI20,
      "bgezal",
      NDS32_RELAX_HINT_NONE,
      BR_RANGE_U4G,
      N32_RELAX_BR | N32_RELAX_SETHI | N32_RELAX_ORI | N32_RELAX_CALL
    },
    {
      /* LONGJUMP4.  */
      BFD_RELOC_NDS32_HI20,
      "j",
      NDS32_RELAX_HINT_NONE,
      BR_RANGE_U4G,
      N32_RELAX_SETHI | N32_RELAX_ORI | N32_RELAX_JUMP
    },
    {
      /* LONGJUMP5.  */
      /* There is two kinds of variations of LONGJUMP5.  One of them
	 generate EMPTY relocation for converted INSN16 if needed.
	 But we don't distinguish them here.  */
      _dummy_first_bfd_reloc_code_real,
      "beq",
      NDS32_RELAX_HINT_NONE,
      BR_RANGE_S16M,
      N32_RELAX_BR | N32_RELAX_JUMP
    },
    {
      /* LONGJUMP6.  */
      BFD_RELOC_NDS32_HI20,
      "beq",
      NDS32_RELAX_HINT_NONE,
      BR_RANGE_U4G,
      N32_RELAX_SETHI | N32_RELAX_ORI | N32_RELAX_BR | N32_RELAX_JUMP
    },
    {
      /* LONGJUMP7.  */
      _dummy_first_bfd_reloc_code_real,
      "beqc",
      NDS32_RELAX_HINT_NONE,
      BR_RANGE_S16K,
      N32_RELAX_MOVI | N32_RELAX_BR
    },
    {
      /* LOADSTORE ADDRESS.  */
      BFD_RELOC_NDS32_HI20,
      NULL,
      NDS32_RELAX_HINT_LA,
      BR_RANGE_U4G,
      N32_RELAX_SETHI | N32_RELAX_ORI
    },
    {
      /* LOADSTORE ADDRESS.  */
      BFD_RELOC_NDS32_HI20,
      NULL,
      NDS32_RELAX_HINT_LS,
      BR_RANGE_U4G,
      N32_RELAX_SETHI | N32_RELAX_LSI
    },
    {0, NULL, 0, 0 ,0}
};

/* Find the relaxation pattern according to instructions.  */

static bfd_boolean
nds32_find_reloc_table (struct nds32_relocs_pattern *relocs_pattern,
			struct nds32_relax_hint_table *hint_info)
{
  unsigned int opcode, seq_size;
  enum nds32_br_range range;
  struct nds32_relocs_pattern *pattern, *hi_pattern = NULL;
  const char *opc = NULL;
  relax_info_t *relax_info = NULL;
  nds32_relax_fixup_info_t *fixup_info, *hint_fixup;
  enum nds32_relax_hint_type hint_type = NDS32_RELAX_HINT_NONE;
  struct nds32_relax_hint_table *table_ptr;
  uint32_t *code_seq, *hint_code;
  enum nds32_insn_type relax_type = 0;
  struct nds32_hint_map *map_ptr = hint_map;
  unsigned int i;
  const char *check_insn[] =
    { "bnes38", "beqs38", "bnez38", "bnezs8", "beqz38", "beqzs8" };

  /* TODO: PLT GOT.  */
  /* Traverse all pattern instruction and set flag.  */
  pattern = relocs_pattern;
  while (pattern)
    {
      if (pattern->opcode->isize == 4)
	{
	  /* 4 byte instruction.  */
	  opcode = N32_OP6 (pattern->opcode->value);
	  switch (opcode)
	    {
	    case N32_OP6_SETHI:
	      hi_pattern = pattern;
	      relax_type |= N32_RELAX_SETHI;
	      break;
	    case N32_OP6_MEM:
	      relax_type |= N32_RELAX_MEM;
	      break;
	    case N32_OP6_ORI:
	      relax_type |= N32_RELAX_ORI;
	      break;
	    case N32_OP6_BR1:
	    case N32_OP6_BR2:
	    case N32_OP6_BR3:
	      relax_type |= N32_RELAX_BR;
	      break;
	    case N32_OP6_MOVI:
	      relax_type |= N32_RELAX_MOVI;
	      break;
	    case N32_OP6_LBI:
	    case N32_OP6_SBI:
	    case N32_OP6_LBSI:
	    case N32_OP6_LHI:
	    case N32_OP6_SHI:
	    case N32_OP6_LHSI:
	    case N32_OP6_LWI:
	    case N32_OP6_SWI:
	    case N32_OP6_LWC:
	    case N32_OP6_SWC:
	      relax_type |= N32_RELAX_LSI;
	      break;
	    case N32_OP6_JREG:
	      if (__GF (pattern->opcode->value, 0, 1) == 1)
		relax_type |= N32_RELAX_CALL;
	      else
		relax_type |= N32_RELAX_JUMP;
	      break;
	    case N32_OP6_JI:
	      if (__GF (pattern->opcode->value, 24, 1) == 1)
		relax_type |= N32_RELAX_CALL;
	      else
		relax_type |= N32_RELAX_JUMP;
	      break;
	    default:
	      as_warn (_("relax hint unrecognized instruction: line %d."),
		       pattern->frag->fr_line);
	      return FALSE;
	    }
	}
      else
	{
	  /* 2 byte instruction.  Compare by opcode name because the opcode of
	     2byte instruction is not regular.  */
	  for (i = 0; i < sizeof (check_insn) / sizeof (check_insn[0]); i++)
	    {
	      if (strcmp (pattern->opcode->opcode, check_insn[i]) == 0)
		{
		  relax_type |= N32_RELAX_BR;
		  break;
		}
	    }
	  if (strcmp (pattern->opcode->opcode, "movi55") == 0)
	    relax_type |= N32_RELAX_MOVI;
	}
      pattern = pattern->next;
    }

  /* Analysis instruction flag to choose relaxation table.  */
  while (map_ptr->insn_list != 0)
    {
      if (map_ptr->insn_list == relax_type
	  && (!hi_pattern
	      || (hi_pattern->fixP
		  && hi_pattern->fixP->fx_r_type == map_ptr->hi_type)))
	{
	  opc = map_ptr->opc;
	  hint_type = map_ptr->hint_type;
	  range = map_ptr->range;
	  break;
	}
      map_ptr++;
    }

  if (map_ptr->insn_list == 0)
    {
      as_warn (_("Can not find match relax hint.  Line: %d"),
	       relocs_pattern->frag->fr_line);
      return FALSE;
    }

  /* Get the match table.  */
  if (opc)
    {
      /* Branch relax pattern.  */
      relax_info = hash_find (nds32_relax_info_hash, opc);
      if (!relax_info)
	return FALSE;
      fixup_info = relax_info->relax_fixup[range];
      code_seq = relax_info->relax_code_seq[range];
      seq_size = relax_info->relax_code_size[range];
    }
  else if (hint_type)
    {
      /* Load-store relax pattern.  */
      table_ptr = relax_ls_table;
      while (table_ptr->main_type != 0)
	{
	  if (table_ptr->main_type == hint_type)
	    {
	      fixup_info = table_ptr->relax_fixup;
	      code_seq = table_ptr->relax_code_seq;
	      seq_size = table_ptr->relax_code_size;
	      break;
	    }
	  table_ptr++;
	}
      if (table_ptr->main_type == 0)
	return FALSE;
    }
  else
    return FALSE;

  hint_fixup = hint_info->relax_fixup;
  hint_code = hint_info->relax_code_seq;
  hint_info->relax_code_size = seq_size;

  while (fixup_info->size != 0)
    {
      if (fixup_info->ramp & NDS32_HINT)
	{
	  memcpy (hint_fixup, fixup_info, sizeof (nds32_relax_fixup_info_t));
	  hint_fixup++;
	}
      fixup_info++;
    }
  /* Clear final relocation.  */
  memset (hint_fixup, 0, sizeof (nds32_relax_fixup_info_t));
  /* Copy code sequence.  */
  memcpy (hint_code, code_seq, seq_size);
  return TRUE;
}

/* Because there are a lot of variant of load-store, check
   all these type here.  */

#define CLEAN_REG(insn) ((insn) & 0xff0003ff)
static bfd_boolean
nds32_match_hint_insn (struct nds32_opcode *opcode, uint32_t seq)
{
  const char *check_insn[] =
    { "bnes38", "beqs38", "bnez38", "bnezs8", "beqz38", "beqzs8" };
  uint32_t insn = opcode->value;
  unsigned int i;

  insn = CLEAN_REG (opcode->value);
  if (insn == seq)
    return TRUE;

  switch (seq)
    {
    case OP6 (LBI):
      /* In relocation_table, it regards instruction LBI as representation
	 of all the NDS32_RELAX_HINT_LS pattern.  */
      if (insn == OP6 (LBI) || insn == OP6 (SBI) || insn == OP6 (LBSI)
	  || insn == OP6 (LHI) || insn == OP6 (SHI) || insn == OP6 (LHSI)
	  || insn == OP6 (LWI) || insn == OP6 (SWI)
	  || insn == OP6 (LWC) || insn == OP6 (SWC))
	 return TRUE;
      break;
    case OP6 (BR2):
      /* This is for LONGCALL5 and LONGCALL6.  */
      if (insn == OP6 (BR2))
        return TRUE;
      break;
    case OP6 (BR1):
      /* This is for LONGJUMP5 and LONGJUMP6.  */
      if (opcode->isize == 4
	  && (insn == OP6 (BR1) || insn == OP6 (BR2) || insn == OP6 (BR3)))
        return TRUE;
      else if (opcode->isize == 2)
	{
	  for (i = 0; i < sizeof (check_insn) / sizeof (check_insn[0]); i++)
	    if (strcmp (opcode->opcode, check_insn[i]) == 0)
	      return TRUE;
	}
      break;
    case OP6 (MOVI):
      /* This is for LONGJUMP7.  */
      if (opcode->isize == 2 && strcmp (opcode->opcode, "movi55") == 0)
        return TRUE;
      break;
    }
  return FALSE;
}

/* Append relax relocation for link time relaxing.  */

static void
nds32_elf_append_relax_relocs (const char *key ATTRIBUTE_UNUSED, void *value)
{
  struct nds32_relocs_pattern *relocs_pattern =
    (struct nds32_relocs_pattern *) value;
  struct nds32_relocs_pattern *pattern_temp, *pattern_now;
  symbolS *sym, *hi_sym = NULL;
  expressionS exp;
  fragS *fragP;
  segT seg_bak = now_seg;
  frchainS *frchain_bak = frchain_now;
  struct nds32_relax_hint_table hint_info;
  nds32_relax_fixup_info_t *hint_fixup, *fixup_now;
  size_t fixup_size;
  offsetT branch_offset;
  fixS *fixP;
  int range, offset;
  unsigned int ptr_offset, hint_count, relax_code_size, count = 0;
  uint32_t *code_seq, code_insn;
  char *where;
  int pcrel;

  if (!relocs_pattern)
    return;

  if (!nds32_find_reloc_table (relocs_pattern, &hint_info))
    return;

  /* Save symbol for some EMPTY relocation using.  */
  pattern_now = relocs_pattern;
  while (pattern_now)
    {
      if (pattern_now->opcode->value == OP6 (SETHI))
	{
	  hi_sym = pattern_now->sym;
	  break;
	}
      pattern_now = pattern_now->next;
    }

  /* Inserting fix up must specify now_seg or frchain_now.  */
  now_seg = relocs_pattern->seg;
  frchain_now = relocs_pattern->frchain;
  fragP = relocs_pattern->frag;
  branch_offset = fragP->fr_offset;

  hint_fixup = hint_info.relax_fixup;
  code_seq = hint_info.relax_code_seq;
  relax_code_size = hint_info.relax_code_size;
  pattern_now = relocs_pattern;

  /* Insert relaxation.  */
  exp.X_op = O_symbol;

  while (pattern_now)
    {
      /* Choose the match fixup by instruction.  */
      code_insn = CLEAN_REG (*(code_seq + count));
      if (!nds32_match_hint_insn (pattern_now->opcode, code_insn))
	{
	  count = 0;
	  code_insn = CLEAN_REG (*(code_seq + count));

	  while (!nds32_match_hint_insn (pattern_now->opcode, code_insn))
	    {
	      count++;
	      if (count >= relax_code_size / 4)
		{
		  as_bad (_("Internal error: Relax hint error. %s: %x"),
			  now_seg->name, pattern_now->opcode->value);
		  goto restore;
		}
	      code_insn = CLEAN_REG (*(code_seq + count));
	    }
	}
      fragP = pattern_now->frag;
      sym = pattern_now->sym;
      branch_offset = fragP->fr_offset;
      offset = count * 4;
      where = pattern_now->where;
      /* Find the instruction map fix.  */
      fixup_now = hint_fixup;
      while (fixup_now->offset != offset)
	{
	  fixup_now++;
	  if (fixup_now->size == 0)
	    break;
	}
      /* This element is without relaxation relocation.  */
      if (fixup_now->size == 0)
	{
	  pattern_now = pattern_now->next;
	  continue;
	}
      fixup_size = fixup_now->size;

      /* Insert all fixup.  */
      while (fixup_size != 0 && fixup_now->offset == offset)
	{
	  /* Set the real instruction size in element.  */
	  fixup_size = pattern_now->opcode->isize;
	  pcrel = ((fixup_now->ramp & NDS32_PCREL) != 0) ? 1 : 0;
	  if (fixup_now->ramp & NDS32_FIX)
	    {
	      /* Convert original relocation.  */
	      pattern_now->fixP->fx_r_type = fixup_now->r_type ;
	      fixup_size = 0;
	    }
	  else if ((fixup_now->ramp & NDS32_PTR) != 0)
	    {
	      /* This relocation has to point to another instruction.  Make
		 sure each resolved relocation has to be pointed.  */
	      pattern_temp = relocs_pattern;
	      /* All instruction in relax_table should be 32-bit.  */
	      hint_count = hint_info.relax_code_size / 4;
	      code_insn = CLEAN_REG (*(code_seq + hint_count - 1));
	      while (pattern_temp)
		{
		  /* Point to every resolved relocation.  */
		  if (nds32_match_hint_insn (pattern_temp->opcode, code_insn))
		    {
		      ptr_offset =
			pattern_temp->where - pattern_temp->frag->fr_literal;
		      exp.X_add_symbol = symbol_temp_new (now_seg, ptr_offset,
							  pattern_temp->frag);
		      exp.X_add_number = 0;
		      fixP =
			fix_new_exp (fragP, where - fragP->fr_literal,
				     fixup_size, &exp, 0, fixup_now->r_type);
		      fixP->fx_addnumber = fixP->fx_offset;
		    }
		  pattern_temp = pattern_temp->next;
		}
	      fixup_size = 0;
	    }
	  else if (fixup_now->ramp & NDS32_ADDEND)
	    {
	      range = nds32_elf_sethi_range (relocs_pattern);
	      if (range == NDS32_LOADSTORE_NONE)
		{
		  as_bad (_("Internal error: Range error. %s"), now_seg->name);
		  return;
		}
	      exp.X_add_symbol = abs_section_sym;
	      exp.X_add_number = SET_ADDEND (4, 0, optimize, enable_16bit);
	      exp.X_add_number |= ((range & 0x3f) << 8);
	    }
	  else if ((fixup_now->ramp & NDS32_ABS) != 0)
	    {
	      /* This is a tag relocation.  */
	      exp.X_add_symbol = abs_section_sym;
	      exp.X_add_number = 0;
	    }
	  else if ((fixup_now->ramp & NDS32_INSN16) != 0)
	    {
	      if (!enable_16bit)
		fixup_size = 0;
	      /* This is a tag relocation.  */
	      exp.X_add_symbol = abs_section_sym;
	      exp.X_add_number = 0;
	    }
	  else if ((fixup_now->ramp & NDS32_SYM) != 0)
	    {
	      /* For EMPTY relocation save the true symbol.  */
	      exp.X_add_symbol = hi_sym;
	      exp.X_add_number = branch_offset;
	    }
	  else
	    {
	      exp.X_add_symbol = sym;
	      exp.X_add_number = branch_offset;
	    }

	  if (fixup_size != 0)
	    {
	      fixP = fix_new_exp (fragP, where - fragP->fr_literal, fixup_size,
				  &exp, pcrel, fixup_now->r_type);
	      fixP->fx_addnumber = fixP->fx_offset;
	    }
	  fixup_now++;
	  fixup_size = fixup_now->size;
	}
      if (count < relax_code_size / 4)
	count++;
      pattern_now = pattern_now->next;
    }

restore:
  now_seg = seg_bak;
  frchain_now = frchain_bak;
}

/* Check instruction if it can be used for the baseline.  */

static bfd_boolean
nds32_check_insn_available (struct nds32_asm_insn insn, const char *str)
{
  int attr = insn.attr & ATTR_ALL;
  static int baseline_isa = 0;
  /* No isa setting or all isa can use.  */
  if (attr == 0 || attr == ATTR_ALL)
    return TRUE;

  if (baseline_isa == 0)
    {
      /* Map option baseline and instruction attribute.  */
      switch (nds32_baseline)
	{
	case ISA_V2:
	  baseline_isa = ATTR (ISA_V2);
	  break;
	case ISA_V3:
	  baseline_isa = ATTR (ISA_V3);
	  break;
	case ISA_V3M:
	  baseline_isa = ATTR (ISA_V3M);
	  break;
	}
    }

  if  ((baseline_isa & attr) == 0)
    {
      as_bad (_("Instruction %s not supported in the baseline."), str);
      return FALSE;
    }
  return TRUE;
}

/* Stub of machine dependent.  */

void
md_assemble (char *str)
{
  struct nds32_asm_insn insn;
  expressionS expr;
  char *out;
  struct nds32_pseudo_opcode *popcode;
  const struct nds32_field *fld = NULL;
  fixS *fixP;
  uint16_t insn_16;
  struct nds32_relocs_pattern *relocs_temp;
  expressionS *pexp;
  fragS *fragP;
  int label = label_exist;

  popcode = nds32_lookup_pseudo_opcode (str);
  /* Note that we need to check 'verbatim' and
     'opcode->physical_op'.  If the assembly content is generated by
     compiler and this opcode is a physical instruction, there is no
     need to perform pseudo instruction expansion/transformation.  */
  if (popcode && !(verbatim && popcode->physical_op))
    {
      pseudo_opcode = TRUE;
      nds32_pseudo_opcode_wrapper (str, popcode);
      pseudo_opcode = FALSE;
      nds32_elf_append_relax_relocs (NULL, relocs_list);

      /* Free pseudo list.  */
      relocs_temp = relocs_list;
      while (relocs_temp)
	{
	  relocs_list = relocs_list->next;
	  free (relocs_temp);
	  relocs_temp = relocs_list;
	}

      return;
    }

  label_exist = 0;
  insn.info = & expr;
  asm_desc.result = NASM_OK;
  nds32_assemble (&asm_desc, &insn, str);

  switch (asm_desc.result)
    {
    case NASM_ERR_UNKNOWN_OP:
      as_bad (_("Unrecognized opcode, %s."), str);
      return;
    case NASM_ERR_SYNTAX:
      as_bad (_("Incorrect syntax, %s."), str);
      return;
    case NASM_ERR_OPERAND:
      as_bad (_("Unrecognized operand/register, %s."), str);
      return;
    case NASM_ERR_OUT_OF_RANGE:
      as_bad (_("Operand out of range, %s."), str);
      return;
    case NASM_ERR_REG_REDUCED:
      as_bad (_("Prohibited register used for reduced-register, %s."), str);
      return;
    case NASM_ERR_JUNK_EOL:
      as_bad (_("Junk at end of line, %s."), str);
      return;
    }

  gas_assert (insn.opcode);

  nds32_set_elf_flags_by_insn (&insn);

  gas_assert (insn.opcode->isize == 4 || insn.opcode->isize == 2);

  if (!nds32_check_insn_available (insn, str))
    return;

  /* Make sure the beginning of text being 2-byte align.  */
  nds32_adjust_label (1);
  fld = insn.field;
  /* Try to allocate the max size to guarantee relaxable same branch
     instructions in the same fragment.  */
  frag_grow (NDS32_MAXCHAR);
  fragP = frag_now;
  if (fld && (insn.attr & NASM_ATTR_BRANCH)
      && (pseudo_opcode || (insn.opcode->value != INSN_JAL
			    && insn.opcode->value != INSN_J))
      && (!verbatim || pseudo_opcode))
    {
      /* User assembly code branch relax for it.  */
      /* If fld is not NULL, it is a symbol.  */
      /* Branch must relax to proper pattern in user assembly code exclude
	 J and JAL.  Keep these two in original type for users which wants
	 to keep their size be fixed.  In general, assembler does not convert
	 instruction generated by compiler.  But jump instruction may be
	 truncated in text virtual model.  For workaround, compiler generate
	 pseudo jump to fix this issue currently.  */

      /* Get branch range type.  */
      dwarf2_emit_insn (0);
      enum nds32_br_range range_type;

      pexp = insn.info;
      range_type = get_range_type (fld);

      out = frag_var (rs_machine_dependent, NDS32_MAXCHAR,
		      0, /* VAR is un-used.  */
		      range_type, /* SUBTYPE is used as range type.  */
		      pexp->X_add_symbol, pexp->X_add_number, 0);

      fragP->fr_fix += insn.opcode->isize;
      fragP->tc_frag_data.opcode = insn.opcode;
      fragP->tc_frag_data.insn = insn.insn;
      if (insn.opcode->isize == 4)
	bfd_putb32 (insn.insn, out);
      else if (insn.opcode->isize == 2)
	bfd_putb16 (insn.insn, out);
      fragP->tc_frag_data.flag |= NDS32_FRAG_BRANCH;
      return;
      /* md_convert_frag will insert relocations.  */
    }
  else if (!relaxing && enable_16bit && (optimize || optimize_for_space)
	   && ((!fld && !verbatim && insn.opcode->isize == 4
		&& nds32_convert_32_to_16 (stdoutput, insn.insn, &insn_16, NULL))
	       || (insn.opcode->isize == 2
		   && nds32_convert_16_to_32 (stdoutput, insn.insn, NULL))))
    {
      /* Record this one is relaxable.  */
      pexp = insn.info;
      dwarf2_emit_insn (0);
      if (fld)
	{
	  out = frag_var (rs_machine_dependent,
			  4, /* Max size is 32-bit instruction.  */
			  0, /* VAR is un-used.  */
			  0, pexp->X_add_symbol, pexp->X_add_number, 0);
	  fragP->tc_frag_data.flag |= NDS32_FRAG_RELAXABLE_BRANCH;
	}
      else
	out = frag_var (rs_machine_dependent,
			4, /* Max size is 32-bit instruction.  */
			0, /* VAR is un-used.  */
			0, NULL, 0, NULL);
      fragP->tc_frag_data.flag |= NDS32_FRAG_RELAXABLE;
      fragP->tc_frag_data.opcode = insn.opcode;
      fragP->tc_frag_data.insn = insn.insn;
      fragP->fr_fix += 2;

      /* In original, we don't relax the instruction with label on it,
	 but this may cause some redundant nop16.  Therefore, tag this
	 relaxable instruction and relax it carefully.  */
      if (label)
	fragP->tc_frag_data.flag |= NDS32_FRAG_LABEL;

      if (insn.opcode->isize == 4)
	bfd_putb16 (insn_16, out);
      else if (insn.opcode->isize == 2)
	bfd_putb16 (insn.insn, out);
      return;
    }
  else if ((verbatim || !relaxing) && optimize && label)
    {
      /* This instruction is with label.  */
      expressionS exp;
      out = frag_var (rs_machine_dependent, insn.opcode->isize,
		      0, 0, NULL, 0, NULL);
      /* If this instruction is branch target, it is not relaxable.  */
      fragP->tc_frag_data.flag = NDS32_FRAG_LABEL;
      fragP->tc_frag_data.opcode = insn.opcode;
      fragP->tc_frag_data.insn = insn.insn;
      fragP->fr_fix += insn.opcode->isize;
      if (insn.opcode->isize == 4)
	{
	  exp.X_op = O_symbol;
	  exp.X_add_symbol = abs_section_sym;
	  exp.X_add_number = 0;
	  fixP = fix_new_exp (fragP, fragP->fr_fix - 4, 0, &exp,
			      0, BFD_RELOC_NDS32_LABEL);
	  if (!verbatim)
	    fragP->tc_frag_data.flag = NDS32_FRAG_ALIGN;
	}
    }
  else
    out = frag_more (insn.opcode->isize);

  if (insn.opcode->isize == 4)
    bfd_putb32 (insn.insn, out);
  if (insn.opcode->isize == 2)
    bfd_putb16 (insn.insn, out);

  dwarf2_emit_insn (insn.opcode->isize);

  /* Compiler generating code and user assembly pseudo load-store, insert
     fixup here.  */
  pexp = insn.info;
  fixP = nds32_elf_record_fixup_exp (fragP, str, fld, pexp, out, &insn);
  /* Build relaxation pattern when relaxing is enable.  */
  if (relaxing)
    nds32_elf_build_relax_relation (fixP, pexp, out, insn.opcode, fragP, fld);
}

/* md_macro_start  */

void
nds32_macro_start (void)
{
}

/* md_macro_info  */

void
nds32_macro_info (void *info ATTRIBUTE_UNUSED)
{
}

/* md_macro_end  */

void
nds32_macro_end (void)
{
}

/* GAS will call this function with one argument, an expressionS pointer, for
   any expression that can not be recognized.  When the function is called,
   input_line_pointer will point to the start of the expression.  */

void
md_operand (expressionS *expressionP)
{
  if (*input_line_pointer == '#')
    {
      input_line_pointer++;
      expression (expressionP);
    }
}

/* GAS will call this function for each section at the end of the assembly, to
   permit the CPU back end to adjust the alignment of a section.  The function
   must take two arguments, a segT for the section and a valueT for the size of
   the section, and return a valueT for the rounded size.  */

valueT
md_section_align (segT segment, valueT size)
{
  int align = bfd_get_section_alignment (stdoutput, segment);

  return ((size + (1 << align) - 1) & -(1 << align));
}

/* GAS will call this function when a symbol table lookup fails, before it
   creates a new symbol.  Typically this would be used to supply symbols whose
   name or value changes dynamically, possibly in a context sensitive way.
   Predefined symbols with fixed values, such as register names or condition
   codes, are typically entered directly into the symbol table when md_begin
   is called.  One argument is passed, a char * for the symbol.  */

symbolS *
md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
{
  return NULL;
}

static long
nds32_calc_branch_offset (segT segment, fragS *fragP,
			  long stretch ATTRIBUTE_UNUSED,
			  relax_info_t *relax_info,
			  enum nds32_br_range branch_range_type)
{
  struct nds32_opcode *opcode = fragP->tc_frag_data.opcode;
  symbolS *branch_symbol = fragP->fr_symbol;
  offsetT branch_offset = fragP->fr_offset;
  offsetT branch_target_address;
  offsetT branch_insn_address;
  long offset = 0;

  if ((S_GET_SEGMENT (branch_symbol) != segment)
      || S_IS_WEAK (branch_symbol))
    {
      /* The symbol is not in the SEGMENT.  It could be far far away.  */
      offset = 0x80000000;
    }
  else
    {
      /* Calculate symbol-to-instruction offset.  */
      branch_target_address = S_GET_VALUE (branch_symbol) + branch_offset;
      /* If the destination symbol is beyond current frag address,
	 STRETCH will take effect to symbol's position.  */
      if (S_GET_VALUE (branch_symbol) > fragP->fr_address)
	branch_target_address += stretch;

      branch_insn_address = fragP->fr_address + fragP->fr_fix;
      branch_insn_address -= opcode->isize;

      /* Update BRANCH_INSN_ADDRESS to relaxed position.  */
      branch_insn_address += (relax_info->relax_code_size[branch_range_type]
			      - relax_info->relax_branch_isize[branch_range_type]);

      offset = branch_target_address - branch_insn_address;
    }

  return offset;
}

static enum nds32_br_range
nds32_convert_to_range_type (long offset)
{
  enum nds32_br_range range_type;

  if (-(0x100) <= offset && offset < 0x100) /* 256 bytes */
    range_type = BR_RANGE_S256;
  else if (-(0x4000) <= offset && offset < 0x4000) /* 16K bytes */
    range_type = BR_RANGE_S16K;
  else if (-(0x10000) <= offset && offset < 0x10000) /* 64K bytes */
    range_type = BR_RANGE_S64K;
  else if (-(0x1000000) <= offset && offset < 0x1000000) /* 16M bytes */
    range_type = BR_RANGE_S16M;
  else /* 4G bytes */
    range_type = BR_RANGE_U4G;

  return range_type;
}

/* Set instruction register mask.  */

static void
nds32_elf_get_set_cond (relax_info_t *relax_info, int offset, uint32_t *insn,
			uint32_t ori_insn, int range)
{
  nds32_cond_field_t *cond_fields = relax_info->cond_field;
  nds32_cond_field_t *code_seq_cond = relax_info->relax_code_condition[range];
  uint32_t mask;
  int i = 0;

  /* The instruction has conditions.  Collect condition values.  */
  while (code_seq_cond[i].bitmask != 0)
    {
      if (offset == code_seq_cond[i].offset)
	{
	  mask = (ori_insn >> cond_fields[i].bitpos) & cond_fields[i].bitmask;
	  /* Sign extend.  */
	  if (cond_fields[i].signed_extend)
	    mask = (mask ^ ((cond_fields[i].bitmask + 1) >> 1)) -
	      ((cond_fields[i].bitmask + 1) >> 1);
	  *insn |= (mask & code_seq_cond[i].bitmask) << code_seq_cond[i].bitpos;
	}
      i++;
    }
}


static int
nds32_relax_branch_instructions (segT segment, fragS *fragP,
				 long stretch ATTRIBUTE_UNUSED,
				 int init)
{
  enum nds32_br_range branch_range_type;
  struct nds32_opcode *opcode = fragP->tc_frag_data.opcode;
  long offset = 0;
  enum nds32_br_range real_range_type;
  int adjust = 0;
  relax_info_t *relax_info;
  int diff = 0;
  int i, j, k;
  int code_seq_size;
  uint32_t *code_seq;
  uint32_t insn;
  int insn_size;
  int code_seq_offset;

  /* Replace with gas_assert (fragP->fr_symbol != NULL); */
  if (fragP->fr_symbol == NULL)
    return adjust;

  /* If frag_var is not enough room, the previous frag is fr_full and with
     opcode.  The new one is rs_dependent but without opcode.  */
  if (opcode == NULL)
    return adjust;

  relax_info = hash_find (nds32_relax_info_hash, opcode->opcode);

  if (relax_info == NULL)
    return adjust;

  if (init)
    branch_range_type = relax_info->br_range;
  else
    branch_range_type = fragP->fr_subtype;

  offset = nds32_calc_branch_offset (segment, fragP, stretch,
				     relax_info, branch_range_type);

  real_range_type = nds32_convert_to_range_type (offset);

  /* If actual range is equal to instruction jump range, do nothing.  */
  if (real_range_type == branch_range_type)
    return adjust;

  /* Find out proper relaxation code sequence.  */
  for (i = BR_RANGE_S256; i < BR_RANGE_NUM; i++)
    {
      if (real_range_type <= (unsigned int) i)
	{
	  if (init)
	    diff = relax_info->relax_code_size[i] - opcode->isize;
	  else
	    diff = relax_info->relax_code_size[i]
	      - relax_info->relax_code_size[branch_range_type];

	  /* If the instruction could be converted to 16-bits,
	     minus the difference.  */
	  code_seq_offset = 0;
	  j = 0;
	  k = 0;
	  code_seq_size = relax_info->relax_code_size[i];
	  code_seq = relax_info->relax_code_seq[i];
	  while (code_seq_offset < code_seq_size)
	    {
	      insn = code_seq[j];
	      if (insn & 0x80000000) /* 16-bits instruction.  */
		{
		  insn_size = 2;
		}
	      else /* 32-bits instruction.  */
		{
		  insn_size = 4;

		  while (relax_info->relax_fixup[i][k].size !=0
			 && relax_info->relax_fixup[i][k].offset < code_seq_offset)
		    k++;
		}

	      code_seq_offset += insn_size;
	      j++;
	    }

	  /* Update fr_subtype to new NDS32_BR_RANGE.  */
	  fragP->fr_subtype = i;
	  break;
	}
    }

  return diff + adjust;
}

/* Adjust relaxable frag till current frag.  */

static int
nds32_adjust_relaxable_frag (fragS *startP, fragS *fragP)
{
  int adj;
  if (startP->tc_frag_data.flag & NDS32_FRAG_RELAXED)
    adj = -2;
  else
    adj = 2;

  startP->tc_frag_data.flag ^= NDS32_FRAG_RELAXED;

  while (startP)
    {
      startP = startP->fr_next;
      if (startP)
	{
	  startP->fr_address += adj;
	  if (startP == fragP)
	    break;
	}
    }
  return adj;
}

static addressT
nds32_get_align (addressT address, int align)
{
  addressT mask, new_address;

  mask = ~((~0U) << align);
  new_address = (address + mask) & (~mask);
  return (new_address - address);
}

/* Check the prev_frag is legal.  */
static void
invalid_prev_frag (fragS * fragP, fragS **prev_frag)
{
  addressT address;
  fragS *frag_start = *prev_frag;

  if (!frag_start)
    return;

  if (frag_start->last_fr_address >= fragP->last_fr_address)
    {
      *prev_frag = NULL;
      return;
    }

  fragS *frag_t = *prev_frag;
  while (frag_t != fragP)
    {
      if (frag_t->fr_type == rs_align
	  || frag_t->fr_type == rs_align_code
	  || frag_t->fr_type == rs_align_test)
	{
	  /* Relax instruction can not walk across label.  */
	  if (frag_t->tc_frag_data.flag & NDS32_FRAG_LABEL)
	    {
	      prev_frag = NULL;
	      return;
	    }
	  /* Relax previous relaxable to align rs_align frag.  */
	  address = frag_t->fr_address + frag_t->fr_fix;
	  addressT offset = nds32_get_align (address, (int) frag_t->fr_offset);
	  if (offset & 0x2)
	    {
	      /* If there is label on the prev_frag, check if it is aligned.  */
	      if (!((*prev_frag)->tc_frag_data.flag & NDS32_FRAG_LABEL)
		  || (((*prev_frag)->fr_address + (*prev_frag)->fr_fix  - 2 )
		      & 0x2) == 0)
		nds32_adjust_relaxable_frag (*prev_frag, frag_t);
	    }
	  *prev_frag = NULL;
	  return;
	}
      frag_t = frag_t->fr_next;
    }

  if (fragP->tc_frag_data.flag & NDS32_FRAG_ALIGN)
    {
      address = fragP->fr_address;
      addressT offset = nds32_get_align (address, 2);
      if (offset & 0x2)
	{
	  /* If there is label on the prev_frag, check if it is aligned.  */
	  if (!((*prev_frag)->tc_frag_data.flag & NDS32_FRAG_LABEL)
	      || (((*prev_frag)->fr_address + (*prev_frag)->fr_fix  - 2 )
		  & 0x2) == 0)
	    nds32_adjust_relaxable_frag (*prev_frag, fragP);
	}
      *prev_frag = NULL;
      return;
    }
}

/* md_relax_frag  */

int
nds32_relax_frag (segT segment, fragS *fragP, long stretch ATTRIBUTE_UNUSED)
{
  /* Currently, there are two kinds of relaxation in nds32 assembler.
     1. relax for branch
     2. relax for 32-bits to 16-bits  */

  static fragS *prev_frag = NULL;
  int adjust = 0;

  invalid_prev_frag (fragP, &prev_frag);

  if (fragP->tc_frag_data.flag & NDS32_FRAG_BRANCH)
    adjust = nds32_relax_branch_instructions (segment, fragP, stretch, 0);
  if (fragP->tc_frag_data.flag & NDS32_FRAG_LABEL)
    prev_frag = NULL;
  if (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXABLE
      && (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXED) == 0)
    /* Here is considered relaxed case originally.  But it may cause
       an endless loop when relaxing.  Once the instruction is relaxed,
       it can not be undone.  */
    prev_frag = fragP;

  return adjust;
}

/* This function returns an initial guess of the length by which a fragment
   must grow to hold a branch to reach its destination.  Also updates
   fr_type/fr_subtype as necessary.

   It is called just before doing relaxation.  Any symbol that is now undefined
   will not become defined.  The guess for fr_var is ACTUALLY the growth beyond
   fr_fix.  Whatever we do to grow fr_fix or fr_var contributes to our returned
   value.  Although it may not be explicit in the frag, pretend fr_var starts
   with a 0 value.  */

int
md_estimate_size_before_relax (fragS *fragP, segT segment)
{
  /* Currently, there are two kinds of relaxation in nds32 assembler.
     1. relax for branch
     2. relax for 32-bits to 16-bits  */

  /* Save previous relaxable frag.  */
  static fragS *prev_frag = NULL;
  int adjust = 0;

  invalid_prev_frag (fragP, &prev_frag);

  if (fragP->tc_frag_data.flag & NDS32_FRAG_BRANCH)
    adjust = nds32_relax_branch_instructions (segment, fragP, 0, 1);
  if (fragP->tc_frag_data.flag & NDS32_FRAG_LABEL)
    prev_frag = NULL;
  if (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXED)
    adjust = 2;
  else if (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXABLE)
    prev_frag = fragP;

  return adjust;
}

/* GAS will call this for each rs_machine_dependent fragment.  The instruction
   is completed using the data from the relaxation pass.  It may also create any
   necessary relocations.

   *FRAGP has been relaxed to its final size, and now needs to have the bytes
   inside it modified to conform to the new size.  It is called after relaxation
   is finished.

   fragP->fr_type == rs_machine_dependent.
   fragP->fr_subtype is the subtype of what the address relaxed to.  */

void
md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec, fragS *fragP)
{
  /* Convert branch relaxation instructions.  */
  symbolS *branch_symbol = fragP->fr_symbol;
  offsetT branch_offset = fragP->fr_offset;
  enum nds32_br_range branch_range_type = fragP->fr_subtype;
  struct nds32_opcode *opcode = fragP->tc_frag_data.opcode;
  uint32_t origin_insn = fragP->tc_frag_data.insn;
  relax_info_t *relax_info;
  char *fr_buffer;
  int fr_where;
  int addend ATTRIBUTE_UNUSED;
  offsetT branch_target_address, branch_insn_address;
  expressionS exp;
  fixS *fixP;
  uint32_t *code_seq;
  uint32_t insn;
  int code_size, insn_size, offset, fixup_size;
  int buf_offset, pcrel;
  int i, k;
  uint16_t insn_16;
  nds32_relax_fixup_info_t fixup_info[MAX_RELAX_FIX];
  /* Save the 1st instruction is converted to 16 bit or not.  */
  unsigned int branch_size;

  /* Replace with gas_assert (branch_symbol != NULL); */
  if (branch_symbol == NULL && !(fragP->tc_frag_data.flag & NDS32_FRAG_RELAXED))
    return;

  /* If frag_var is not enough room, the previous frag is fr_full and with
     opcode.  The new one is rs_dependent but without opcode.  */
  if (opcode == NULL)
    return;

  if (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXABLE_BRANCH)
    {
      relax_info = hash_find (nds32_relax_info_hash, opcode->opcode);

      if (relax_info == NULL)
	return;

      i = BR_RANGE_S256;
      while (i < BR_RANGE_NUM
	     && relax_info->relax_code_size[i]
	     != (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXED ? 4 : 2))
	i++;

      if (i >= BR_RANGE_NUM)
	as_bad ("Internal error: Cannot find relocation of"
		"relaxable branch.");

      exp.X_op = O_symbol;
      exp.X_add_symbol = branch_symbol;
      exp.X_add_number = branch_offset;
      pcrel = ((relax_info->relax_fixup[i][0].ramp & NDS32_PCREL) != 0) ? 1 : 0;
      fr_where = fragP->fr_fix - 2;
      fixP = fix_new_exp (fragP, fr_where, relax_info->relax_fixup[i][0].size,
			  &exp, pcrel, relax_info->relax_fixup[i][0].r_type);
      fixP->fx_addnumber = fixP->fx_offset;

      if (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXED)
	{
	  insn_16 = fragP->tc_frag_data.insn;
	  nds32_convert_16_to_32 (stdoutput, insn_16, &insn);
	  fr_buffer = fragP->fr_literal + fr_where;
	  fragP->fr_fix += 2;
	  exp.X_op = O_symbol;
	  exp.X_add_symbol = abs_section_sym;
	  exp.X_add_number = 0;
	  fix_new_exp (fragP, fr_where, 4,
		       &exp, 0, BFD_RELOC_NDS32_INSN16);
	  number_to_chars_bigendian (fr_buffer, insn, 4);
	}
    }
  else if (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXED)
    {
      if (fragP->tc_frag_data.opcode->isize == 2)
	{
	  insn_16 = fragP->tc_frag_data.insn;
	  nds32_convert_16_to_32 (stdoutput, insn_16, &insn);
	}
      else
	insn = fragP->tc_frag_data.insn;
      fragP->fr_fix += 2;
      fr_where = fragP->fr_fix - 4;
      fr_buffer = fragP->fr_literal + fr_where;
      exp.X_op = O_symbol;
      exp.X_add_symbol = abs_section_sym;
      exp.X_add_number = 0;
      fix_new_exp (fragP, fr_where, 4, &exp, 0,
		   BFD_RELOC_NDS32_INSN16);
      number_to_chars_bigendian (fr_buffer, insn, 4);
    }
  else if (fragP->tc_frag_data.flag & NDS32_FRAG_BRANCH)
    {
      /* Branch instruction adjust and append relocations.  */
      relax_info = hash_find (nds32_relax_info_hash, opcode->opcode);

      if (relax_info == NULL)
	return;

      fr_where = fragP->fr_fix - opcode->isize;
      fr_buffer = fragP->fr_literal + fr_where;

      if ((S_GET_SEGMENT (branch_symbol) != sec)
	  || S_IS_WEAK (branch_symbol))
	{
	  if (fragP->fr_offset & 3)
	    as_warn (_("Addend to unresolved symbol is not on word boundary."));
	  addend = 0;
	}
      else
	{
	  /* Calculate symbol-to-instruction offset.  */
	  branch_target_address = S_GET_VALUE (branch_symbol) + branch_offset;
	  branch_insn_address = fragP->fr_address + fr_where;
	  addend = (branch_target_address - branch_insn_address) >> 1;
	}

      code_size = relax_info->relax_code_size[branch_range_type];
      code_seq = relax_info->relax_code_seq[branch_range_type];

      memcpy (fixup_info, relax_info->relax_fixup[branch_range_type],
	      sizeof (fixup_info));

      /* Fill in frag.  */
      i = 0;
      k = 0;
      offset = 0; /* code_seq offset */
      buf_offset = 0; /* fr_buffer offset */
      while (offset < code_size)
	{
	  insn = code_seq[i];
	  if (insn & 0x80000000) /* 16-bits instruction.  */
	    {
	      insn = (insn >> 16) & 0xFFFF;
	      insn_size = 2;
	    }
	  else /* 32-bits instruction.  */
	    {
	      insn_size = 4;
	    }

	  nds32_elf_get_set_cond (relax_info, offset, &insn,
				  origin_insn, branch_range_type);

	  /* Try to convert to 16-bits instruction.  Currently, only the first
	     instruction in pattern can be converted.  EX: bnez sethi ori jr,
	     only bnez can be converted to 16 bit and ori can't.  */

	  while (fixup_info[k].size != 0
		 && relax_info->relax_fixup[branch_range_type][k].offset < offset)
	    k++;

	  number_to_chars_bigendian (fr_buffer + buf_offset, insn, insn_size);
	  buf_offset += insn_size;

	  offset += insn_size;
	  i++;
	}

      /* Set up fixup.  */
      exp.X_op = O_symbol;

      for (i = 0; fixup_info[i].size != 0; i++)
	{
	  fixup_size = fixup_info[i].size;
	  pcrel = ((fixup_info[i].ramp & NDS32_PCREL) != 0) ? 1 : 0;

	  if ((fixup_info[i].ramp & NDS32_CREATE_LABEL) != 0)
	    {
	      /* This is a reverse branch.  */
	      exp.X_add_symbol = symbol_temp_new (sec, 0, fragP->fr_next);
	      exp.X_add_number = 0;
	    }
	  else if ((fixup_info[i].ramp & NDS32_PTR) != 0)
	    {
	      /* This relocation has to point to another instruction.  */
	      branch_size = fr_where + code_size - 4;
	      exp.X_add_symbol = symbol_temp_new (sec, branch_size, fragP);
	      exp.X_add_number = 0;
	    }
	  else if ((fixup_info[i].ramp & NDS32_ABS) != 0)
	    {
	      /* This is a tag relocation.  */
	      exp.X_add_symbol = abs_section_sym;
	      exp.X_add_number = 0;
	    }
	  else if ((fixup_info[i].ramp & NDS32_INSN16) != 0)
	    {
	      if (!enable_16bit)
		continue;
	      /* This is a tag relocation.  */
	      exp.X_add_symbol = abs_section_sym;
	      exp.X_add_number = 0;
	    }
	  else
	    {
	      exp.X_add_symbol = branch_symbol;
	      exp.X_add_number = branch_offset;
	    }

	  if (fixup_info[i].r_type != 0)
	    {
	      fixP = fix_new_exp (fragP, fr_where + fixup_info[i].offset,
				  fixup_size, &exp, pcrel,
				  fixup_info[i].r_type);
	      fixP->fx_addnumber = fixP->fx_offset;
	    }
	}

      fragP->fr_fix = fr_where + buf_offset;
    }
}

/* tc_frob_file_before_fix  */

void
nds32_frob_file_before_fix (void)
{
}

static bfd_boolean
nds32_relaxable_section (asection *sec)
{
  return ((sec->flags & SEC_DEBUGGING) == 0
	  && strcmp (sec->name, ".eh_frame") != 0);
}

/* TC_FORCE_RELOCATION */
int
nds32_force_relocation (fixS * fix)
{
  switch (fix->fx_r_type)
    {
    case BFD_RELOC_NDS32_INSN16:
    case BFD_RELOC_NDS32_LABEL:
    case BFD_RELOC_NDS32_LONGCALL1:
    case BFD_RELOC_NDS32_LONGCALL2:
    case BFD_RELOC_NDS32_LONGCALL3:
    case BFD_RELOC_NDS32_LONGJUMP1:
    case BFD_RELOC_NDS32_LONGJUMP2:
    case BFD_RELOC_NDS32_LONGJUMP3:
    case BFD_RELOC_NDS32_LOADSTORE:
    case BFD_RELOC_NDS32_9_FIXED:
    case BFD_RELOC_NDS32_15_FIXED:
    case BFD_RELOC_NDS32_17_FIXED:
    case BFD_RELOC_NDS32_25_FIXED:
    case BFD_RELOC_NDS32_9_PCREL:
    case BFD_RELOC_NDS32_15_PCREL:
    case BFD_RELOC_NDS32_17_PCREL:
    case BFD_RELOC_NDS32_WORD_9_PCREL:
    case BFD_RELOC_NDS32_10_UPCREL:
    case BFD_RELOC_NDS32_25_PCREL:
    case BFD_RELOC_NDS32_MINUEND:
    case BFD_RELOC_NDS32_SUBTRAHEND:
      return 1;

    case BFD_RELOC_8:
    case BFD_RELOC_16:
    case BFD_RELOC_32:
    case BFD_RELOC_NDS32_DIFF_ULEB128:
      /* Linker should handle difference between two symbol.  */
      return fix->fx_subsy != NULL
	&& nds32_relaxable_section (S_GET_SEGMENT (fix->fx_addsy));
    case BFD_RELOC_64:
      if (fix->fx_subsy)
	as_bad ("Double word for difference between two symbols "
		"is not supported across relaxation.");
    default:
      ;
    }

  if (generic_force_reloc (fix))
    return 1;

  return fix->fx_pcrel;
}

/* TC_VALIDATE_FIX_SUB  */

int
nds32_validate_fix_sub (fixS *fix, segT add_symbol_segment)
{
  segT sub_symbol_segment;

  /* This code is referred from Xtensa.  Check their implementation for
     details.  */

  /* Make sure both symbols are in the same segment, and that segment is
     "normal" and relaxable.  */
  sub_symbol_segment = S_GET_SEGMENT (fix->fx_subsy);
  return (sub_symbol_segment == add_symbol_segment
	  && add_symbol_segment != undefined_section);
}

void
md_number_to_chars (char *buf, valueT val, int n)
{
  if (target_big_endian)
    number_to_chars_bigendian (buf, val, n);
  else
    number_to_chars_littleendian (buf, val, n);
}

/* Equal to MAX_PRECISION in atof-ieee.c.  */
#define MAX_LITTLENUMS 6

/* This function is called to convert an ASCII string into a floating point
   value in format used by the CPU.  */

const char *
md_atof (int type, char *litP, int *sizeP)
{
  int i;
  int prec;
  LITTLENUM_TYPE words[MAX_LITTLENUMS];
  char *t;

  switch (type)
    {
    case 'f':
    case 'F':
    case 's':
    case 'S':
      prec = 2;
      break;
    case 'd':
    case 'D':
    case 'r':
    case 'R':
      prec = 4;
      break;
    default:
      *sizeP = 0;
      return _("Bad call to md_atof()");
    }

  t = atof_ieee (input_line_pointer, type, words);
  if (t)
    input_line_pointer = t;
  *sizeP = prec * sizeof (LITTLENUM_TYPE);

  if (target_big_endian)
    {
      for (i = 0; i < prec; i++)
	{
	  md_number_to_chars (litP, (valueT) words[i],
			      sizeof (LITTLENUM_TYPE));
	  litP += sizeof (LITTLENUM_TYPE);
	}
    }
  else
    {
      for (i = prec - 1; i >= 0; i--)
	{
	  md_number_to_chars (litP, (valueT) words[i],
			      sizeof (LITTLENUM_TYPE));
	  litP += sizeof (LITTLENUM_TYPE);
	}
    }

  return 0;
}

/* md_elf_section_change_hook  */

void
nds32_elf_section_change_hook (void)
{
}

/* md_cleanup  */

void
nds32_cleanup (void)
{
}

/* This function is used to scan leb128 subtraction expressions,
   and insert fixups for them.

      e.g., .leb128  .L1 - .L0

   These expressions are heavily used in debug information or
   exception tables.  Because relaxation will change code size,
   we must resolve them in link time.  */

static void
nds32_insert_leb128_fixes (bfd *abfd ATTRIBUTE_UNUSED,
			   asection *sec, void *xxx ATTRIBUTE_UNUSED)
{
  segment_info_type *seginfo = seg_info (sec);
  struct frag *fragP;

  subseg_set (sec, 0);

  for (fragP = seginfo->frchainP->frch_root;
       fragP; fragP = fragP->fr_next)
    {
      expressionS *exp;

      /* Only unsigned leb128 can be handle.  */
      if (fragP->fr_type != rs_leb128 || fragP->fr_subtype != 0
	  || fragP->fr_symbol == NULL)
	continue;

      exp = symbol_get_value_expression (fragP->fr_symbol);

      if (exp->X_op != O_subtract)
	continue;

      fix_new_exp (fragP, fragP->fr_fix, 0,
		   exp, 0, BFD_RELOC_NDS32_DIFF_ULEB128);
    }
}

static void
nds32_insert_relax_entry (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
			  void *xxx ATTRIBUTE_UNUSED)
{
  segment_info_type *seginfo;
  fragS *fragP;
  fixS *fixP;
  expressionS exp;
  fixS *fixp;

  seginfo = seg_info (sec);
  if (!seginfo || !symbol_rootP || !subseg_text_p (sec) || sec->size == 0)
    return;
  /* If there is no relocation and relax is disabled, it is not necessary to
     insert R_NDS32_RELAX_ENTRY for linker do EX9 or IFC optimization.  */
  for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
    if (!fixp->fx_done)
      break;
  if (!fixp && !enable_relax_ex9 && !verbatim)
    return;

  subseg_change (sec, 0);

  /* Set RELAX_ENTRY flags for linker.  */
  fragP = seginfo->frchainP->frch_root;
  exp.X_op = O_symbol;
  exp.X_add_symbol = section_symbol (sec);
  exp.X_add_number = 0;
  if (!enable_relax_relocs)
    exp.X_add_number |= R_NDS32_RELAX_ENTRY_DISABLE_RELAX_FLAG;
  else
    {
      /* These flags are only enabled when global relax is enabled.
	 Maybe we can check DISABLE_RELAX_FLAG at link-time,
	 so we set them anyway.  */
      if (enable_relax_ex9)
	exp.X_add_number |= R_NDS32_RELAX_ENTRY_EX9_FLAG;
      if (enable_relax_ifc)
	exp.X_add_number |= R_NDS32_RELAX_ENTRY_IFC_FLAG;
      if (verbatim)
	exp.X_add_number |= R_NDS32_RELAX_ENTRY_VERBATIM_FLAG;
    }
  if (optimize)
    exp.X_add_number |= R_NDS32_RELAX_ENTRY_OPTIMIZE_FLAG;
  if (optimize_for_space)
    exp.X_add_number |= R_NDS32_RELAX_ENTRY_OPTIMIZE_FOR_SPACE_FLAG;

  fixP = fix_new_exp (fragP, 0, 0, &exp, 0, BFD_RELOC_NDS32_RELAX_ENTRY);
  fixP->fx_no_overflow = 1;
}

/* Analysis relax hint and insert suitable relocation pattern.  */

static void
nds32_elf_analysis_relax_hint (void)
{
  hash_traverse (nds32_hint_hash, nds32_elf_append_relax_relocs);
}

static void
nds32_elf_insert_final_frag (void)
{
  struct frchain *frchainP;
  asection *s;
  fragS *fragP;

  if (!optimize)
    return;

  for (s = stdoutput->sections; s; s = s->next)
    {
      segment_info_type *seginfo = seg_info (s);
      if (!seginfo)
	continue;

      for (frchainP = seginfo->frchainP; frchainP != NULL;
	   frchainP = frchainP->frch_next)
	{
	  subseg_set (s, frchainP->frch_subseg);

	  if (subseg_text_p (now_seg))
	    {
	      fragP = frag_now;
	      frag_var (rs_machine_dependent, 2, /* Max size.  */
			0, /* VAR is un-used.  */ 0, NULL, 0, NULL);
	      fragP->tc_frag_data.flag |= NDS32_FRAG_FINAL;
	    }
	}
    }
}

void
md_end (void)
{
  nds32_elf_insert_final_frag ();
  nds32_elf_analysis_relax_hint ();
  bfd_map_over_sections (stdoutput, nds32_insert_leb128_fixes, NULL);
}

/* Implement md_allow_local_subtract.  */

bfd_boolean
nds32_allow_local_subtract (expressionS *expr_l ATTRIBUTE_UNUSED,
			    expressionS *expr_r ATTRIBUTE_UNUSED,
			    segT sec ATTRIBUTE_UNUSED)
{
  /* Don't allow any subtraction, because relax may change the code.  */
  return FALSE;
}

/* Sort relocation by address.

   We didn't use qsort () in stdlib, because quick-sort is not a stable
   sorting algorithm.  Relocations at the same address (r_offset) must keep
   their relative order.  For example, RELAX_ENTRY must be the very first
   relocation entry.

   Currently, this function implements insertion-sort.  */

static int
compar_relent (const void *lhs, const void *rhs)
{
  const arelent **l = (const arelent **) lhs;
  const arelent **r = (const arelent **) rhs;

  if ((*l)->address > (*r)->address)
    return 1;
  else if ((*l)->address == (*r)->address)
    return 0;
  else
    return -1;
}

/* SET_SECTION_RELOCS ()

   Although this macro is originally used to set a relocation for each section,
   we use it to sort relocations in the same section by the address of the
   relocation.  */

void
nds32_set_section_relocs (asection *sec, arelent ** relocs ATTRIBUTE_UNUSED,
			  unsigned int n ATTRIBUTE_UNUSED)
{
  bfd *abfd ATTRIBUTE_UNUSED = sec->owner;
  if (bfd_get_section_flags (abfd, sec) & (flagword) SEC_RELOC)
    nds32_insertion_sort (sec->orelocation, sec->reloc_count,
			  sizeof (arelent**), compar_relent);
}

long
nds32_pcrel_from_section (fixS *fixP, segT sec ATTRIBUTE_UNUSED)
{
  if (fixP->fx_addsy == NULL || !S_IS_DEFINED (fixP->fx_addsy)
      || S_IS_EXTERNAL (fixP->fx_addsy) || S_IS_WEAK (fixP->fx_addsy))
    {
      /* Let linker resolve undefined symbols.  */
      return 0;
    }

  return fixP->fx_frag->fr_address + fixP->fx_where;
}

/* md_post_relax_hook ()
   Insert relax entry relocation into sections.  */

void
nds32_post_relax_hook (void)
{
  bfd_map_over_sections (stdoutput, nds32_insert_relax_entry, NULL);
}

/* tc_fix_adjustable ()

   Return whether this symbol (fixup) can be replaced with
   section symbols.  */

bfd_boolean
nds32_fix_adjustable (fixS *fixP)
{
  switch (fixP->fx_r_type)
    {
    case BFD_RELOC_NDS32_WORD_9_PCREL:
    case BFD_RELOC_NDS32_9_PCREL:
    case BFD_RELOC_NDS32_15_PCREL:
    case BFD_RELOC_NDS32_17_PCREL:
    case BFD_RELOC_NDS32_25_PCREL:
    case BFD_RELOC_NDS32_HI20:
    case BFD_RELOC_NDS32_LO12S0:
    case BFD_RELOC_8:
    case BFD_RELOC_16:
    case BFD_RELOC_32:
    case BFD_RELOC_NDS32_PTR:
    case BFD_RELOC_NDS32_LONGCALL4:
    case BFD_RELOC_NDS32_LONGCALL5:
    case BFD_RELOC_NDS32_LONGCALL6:
    case BFD_RELOC_NDS32_LONGJUMP4:
    case BFD_RELOC_NDS32_LONGJUMP5:
    case BFD_RELOC_NDS32_LONGJUMP6:
    case BFD_RELOC_NDS32_LONGJUMP7:
      return 1;
    default:
      return 0;
    }
}

/* elf_tc_final_processing  */

void
elf_nds32_final_processing (void)
{
  /* An FPU_COM instruction is found without previous non-FPU_COM
     instruction.  */
  if (nds32_fpu_com
      && !(nds32_elf_flags & (E_NDS32_HAS_FPU_INST | E_NDS32_HAS_FPU_DP_INST)))
    {
      /* Since only FPU_COM instructions are used and no other FPU instructions
	 are used.  The nds32_elf_flags will be decided by the enabled options
	 by command line or default configuration.  */
      if (nds32_fpu_dp_ext || nds32_fpu_sp_ext)
	{
	  nds32_elf_flags |= nds32_fpu_dp_ext ? E_NDS32_HAS_FPU_DP_INST : 0;
	  nds32_elf_flags |= nds32_fpu_sp_ext ? E_NDS32_HAS_FPU_INST : 0;
	}
      else
	{
	  /* Should never here.  */
	  as_bad (_("Used FPU instructions requires enabling FPU extension"));
	}
    }

  if (nds32_elf_flags & (E_NDS32_HAS_FPU_INST | E_NDS32_HAS_FPU_DP_INST))
    {
      /* Single/double FPU has been used, set FPU register config.  */
      /* We did not check the actual number of register used.  We may
	 want to do it while assemble.  */
      nds32_elf_flags &= ~E_NDS32_FPU_REG_CONF;
      nds32_elf_flags |= (nds32_freg << E_NDS32_FPU_REG_CONF_SHIFT);
    }

  if (nds32_pic)
    nds32_elf_flags |= E_NDS32_HAS_PIC;

  if (nds32_gpr16)
    nds32_elf_flags |= E_NDS32_HAS_REDUCED_REGS;

  nds32_elf_flags |= (E_NDS32_ELF_VER_1_4 | nds32_abi);
  elf_elfheader (stdoutput)->e_flags |= nds32_elf_flags;
}

/* Implement md_apply_fix.  Apply the fix-up or transform the fix-up for
   later relocation generation.  */

void
nds32_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
{
  char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
  bfd_vma value = *valP;

  if (fixP->fx_r_type < BFD_RELOC_UNUSED
      && fixP->fx_r_type > BFD_RELOC_NONE
      && fixP->fx_r_type != BFD_RELOC_NDS32_DIFF_ULEB128)
    {
      /* In our old nds32 binutils, it must convert relocations which is
	 generated by CGEN.  However, it does not have to consider this anymore.
	 In current, it only deal with data relocations which enum
	 is smaller than BFD_RELOC_NONE and BFD_RELOC_NDS32_DIFF_ULEB128.
	 It is believed that we can construct a better mechanism to
	 deal with the whole relocation issue in nds32 target
	 without using CGEN.  */
      fixP->fx_addnumber = value;
      fixP->tc_fix_data = NULL;

      /* Transform specific relocations here for later relocation generation.
	 Tag data here for ex9 relaxation and tag tls data for linker.  */
      switch (fixP->fx_r_type)
	{
	case BFD_RELOC_NDS32_DATA:
	  if (!enable_relax_ex9)
	    fixP->fx_done = 1;
	  break;
	case BFD_RELOC_NDS32_TPOFF:
	case BFD_RELOC_NDS32_TLS_LE_HI20:
	case BFD_RELOC_NDS32_TLS_LE_LO12:
	case BFD_RELOC_NDS32_TLS_LE_ADD:
	case BFD_RELOC_NDS32_TLS_LE_LS:
	case BFD_RELOC_NDS32_GOTTPOFF:
	case BFD_RELOC_NDS32_TLS_IE_HI20:
	case BFD_RELOC_NDS32_TLS_IE_LO12S2:
	  S_SET_THREAD_LOCAL (fixP->fx_addsy);
	  break;
	default:
	  break;
	}
      return;
    }

  if (fixP->fx_addsy == (symbolS *) NULL)
    fixP->fx_done = 1;

  if (fixP->fx_subsy != (symbolS *) NULL)
    {
      /* HOW DIFF RELOCATION WORKS.

	 First of all, this relocation is used to calculate the distance
	 between two symbols in the SAME section.  It is used for  jump-
	 table, debug information, exception table, et al.    Therefore,
	 it is a unsigned positive value.   It is NOT used for  general-
	 purpose arithmetic.

	 Consider this example,  the distance between  .LEND and .LBEGIN
	 is stored at the address of foo.

	 ---- >8 ---- >8 ---- >8 ---- >8 ----
	  .data
	  foo:
	    .word	.LBEGIN - .LEND

	  .text
	     [before]
	  .LBEGIN
			 \
	     [between]    distance
			 /
	  .LEND
	     [after]
	 ---- 8< ---- 8< ---- 8< ---- 8< ----

	 We use a single relocation entry for this expression.
	 * The initial distance value is stored directly in that location
	   specified by r_offset (i.e., foo in this example.)
	 * The begin of the region, i.e., .LBEGIN, is specified by
	   r_info/R_SYM and r_addend, e.g., .text + 0x32.
	 * The end of region, i.e., .LEND, is represented by
	   .LBEGIN + distance instead of .LEND, so we only need
	   a single relocation entry instead of two.

	 When an instruction is relaxed, we adjust the relocation entry
	 depending on where the instruction locates.    There are three
	 cases, before, after and between the region.
	 * between: Distance value is read from r_offset,  adjusted and
	   written back into r_offset.
	 * before: Only r_addend is adjust.
	 * after: We don't care about it.

	 Hereby, there are some limitation.

	 `(.LEND - 1) - .LBEGIN' and `(.LEND - .LBEGIN) - 1'
	 are semantically different, and we cannot handle latter case
	 when relaxation.

	 The latter expression means subtracting 1 from the distance
	 between .LEND and .LBEGIN.  And the former expression means
	 the distance between (.LEND - 1) and .LBEGIN.

	 The nuance affects whether to adjust distance value when relax
	 an instruction.  In another words, whether the instruction
	 locates in the region.  Because we use a single relocation entry,
	 there is no field left for .LEND and the subtrahend.

	 Since GCC-4.5, GCC may produce debug information in such expression
	     .long  .L1-1-.L0
	 in order to describe register clobbering during an function-call.
	     .L0:
		call foo
	     .L1:

	 Check http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01317.html
	 for details.  */

      value -= S_GET_VALUE (fixP->fx_subsy);
      *valP = value;
      fixP->fx_subsy = NULL;
      fixP->fx_offset -= value;

      switch (fixP->fx_r_type)
	{
	case BFD_RELOC_8:
	  fixP->fx_r_type = BFD_RELOC_NDS32_DIFF8;
	  md_number_to_chars (where, value, 1);
	  break;
	case BFD_RELOC_16:
	  fixP->fx_r_type = BFD_RELOC_NDS32_DIFF16;
	  md_number_to_chars (where, value, 2);
	  break;
	case BFD_RELOC_32:
	  fixP->fx_r_type = BFD_RELOC_NDS32_DIFF32;
	  md_number_to_chars (where, value, 4);
	  break;
	case BFD_RELOC_NDS32_DIFF_ULEB128:
	  /* cvt_frag_to_fill () has called output_leb128 () for us.  */
	  break;
	default:
	  as_bad_where (fixP->fx_file, fixP->fx_line,
			_("expression too complex"));
	  return;
	}
    }
  else if (fixP->fx_done)
    {
      /* We're finished with this fixup.  Install it because
	 bfd_install_relocation won't be called to do it.  */
      switch (fixP->fx_r_type)
	{
	case BFD_RELOC_8:
	  md_number_to_chars (where, value, 1);
	  break;
	case BFD_RELOC_16:
	  md_number_to_chars (where, value, 2);
	  break;
	case BFD_RELOC_32:
	  md_number_to_chars (where, value, 4);
	  break;
	case BFD_RELOC_64:
	  md_number_to_chars (where, value, 8);
	  break;
	default:
	  as_bad_where (fixP->fx_file, fixP->fx_line,
			_("Internal error: Unknown fixup type %d (`%s')"),
			fixP->fx_r_type,
			bfd_get_reloc_code_name (fixP->fx_r_type));
	  break;
	}
    }
}

/* Implement tc_gen_reloc.  Generate ELF relocation for a fix-up.  */

arelent *
tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
{
  arelent *reloc;
  bfd_reloc_code_real_type code;

  reloc = XNEW (arelent);

  reloc->sym_ptr_ptr = XNEW (asymbol *);
  *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
  reloc->address = fixP->fx_frag->fr_address + fixP->fx_where;

  code = fixP->fx_r_type;

  reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  if (reloc->howto == (reloc_howto_type *) NULL)
    {
      as_bad_where (fixP->fx_file, fixP->fx_line,
		    _("internal error: can't export reloc type %d (`%s')"),
		    fixP->fx_r_type, bfd_get_reloc_code_name (code));
      return NULL;
    }

  /* Add relocation handling here.  */

  switch (fixP->fx_r_type)
    {
    default:
      /* In general, addend of a relocation is the offset to the
	 associated symbol.  */
      reloc->addend = fixP->fx_offset;
      break;

    case BFD_RELOC_NDS32_DATA:
      /* Prevent linker from optimizing data in text sections.
	 For example, jump table.  */
      reloc->addend = fixP->fx_size;
      break;
    }

  return reloc;
}

struct suffix_name suffix_table[] =
{
  {"GOTOFF",	BFD_RELOC_NDS32_GOTOFF,	1},
  {"GOT",	BFD_RELOC_NDS32_GOT20,	1},
  {"TPOFF",	BFD_RELOC_NDS32_TPOFF,	0},
  {"PLT",	BFD_RELOC_NDS32_25_PLTREL,	1},
  {"GOTTPOFF",	BFD_RELOC_NDS32_GOTTPOFF,	0}
};

/* Implement md_parse_name.  */

int
nds32_parse_name (char const *name, expressionS *exprP,
		  enum expr_mode mode ATTRIBUTE_UNUSED,
		  char *nextcharP ATTRIBUTE_UNUSED)
{
  segT segment;

  exprP->X_op_symbol = NULL;
  exprP->X_md = BFD_RELOC_UNUSED;

  exprP->X_add_symbol = symbol_find_or_make (name);
  exprP->X_op = O_symbol;
  exprP->X_add_number = 0;

  /* Check the special name if a symbol.  */
  segment = S_GET_SEGMENT (exprP->X_add_symbol);
  if (segment != undefined_section)
    return 0;

  if (strcmp (name, GOT_NAME) == 0 && *nextcharP != '@')
    {
      /* Set for _GOT_OFFSET_TABLE_.  */
      exprP->X_md = BFD_RELOC_NDS32_GOTPC20;
    }
  else if (*nextcharP == '@')
    {
      size_t i;
      char *next;
      for (i = 0; i < ARRAY_SIZE (suffix_table); i++)
	{
	  next = input_line_pointer + 1 + strlen(suffix_table[i].suffix);
	  if (strncasecmp (input_line_pointer + 1, suffix_table[i].suffix,
			   strlen (suffix_table[i].suffix)) == 0
	      && !is_part_of_name (*next))
	    {
	      if (!nds32_pic && suffix_table[i].pic)
		as_bad (_("need PIC qualifier with symbol."));
	      exprP->X_md = suffix_table[i].reloc;
	      *input_line_pointer = *nextcharP;
	      input_line_pointer = next;
	      *nextcharP = *input_line_pointer;
	      *input_line_pointer = '\0';
	      break;
	    }
	}
    }
  return 1;
}

/* Implement tc_regname_to_dw2regnum.  */

int
tc_nds32_regname_to_dw2regnum (char *regname)
{
  struct nds32_keyword *sym = hash_find (nds32_gprs_hash, regname);

  if (!sym)
    return -1;

  return sym->value;
}

void
tc_nds32_frame_initial_instructions (void)
{
  /* CIE */
  /* Default cfa is register-31/sp.  */
  cfi_add_CFA_def_cfa (31, 0);
}