authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-27 15:57:01-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-27 15:57:01-07:00
loge02acc028825ec83951946e4947883c2c96211ce
tree9318e3538cb165e831d2a8518ffadab0eb7656ff
parent9082d761684b0717c45db93964bb7e569702af99

tools/update_cpu_features: better patching API

With this change, added & modified cpus & features participate in the same pruning system, and sorting takes into account the zig name, not the pre-modified llvm name. The modified target files in this commit are due to the improved sorting and pruning. The script now fully supports extra cpus & features.

5 files changed, 355 insertions(+), 288 deletions(-)

lib/std/target/amdgpu.zig+6-6
...@@ -41,8 +41,8 @@ pub const Feature = enum {...@@ -41,8 +41,8 @@ pub const Feature = enum {
41 get_wave_id_inst,41 get_wave_id_inst,
42 gfx10,42 gfx10,
43 gfx10_3_insts,43 gfx10_3_insts,
44 gfx10_insts,
45 gfx10_b_encoding,44 gfx10_b_encoding,
45 gfx10_insts,
46 gfx7_gfx8_gfx9_insts,46 gfx7_gfx8_gfx9_insts,
47 gfx8_insts,47 gfx8_insts,
48 gfx9,48 gfx9,
...@@ -347,16 +347,16 @@ pub const all_features = blk: {...@@ -347,16 +347,16 @@ pub const all_features = blk: {
347 .description = "Additional instructions for GFX10.3",347 .description = "Additional instructions for GFX10.3",
348 .dependencies = featureSet(&[_]Feature{}),348 .dependencies = featureSet(&[_]Feature{}),
349 };349 };
350 result[@enumToInt(Feature.gfx10_insts)] = .{
351 .llvm_name = "gfx10-insts",
352 .description = "Additional instructions for GFX10+",
353 .dependencies = featureSet(&[_]Feature{}),
354 };
355 result[@enumToInt(Feature.gfx10_b_encoding)] = .{350 result[@enumToInt(Feature.gfx10_b_encoding)] = .{
356 .llvm_name = "gfx10_b-encoding",351 .llvm_name = "gfx10_b-encoding",
357 .description = "Encoding format GFX10_B",352 .description = "Encoding format GFX10_B",
358 .dependencies = featureSet(&[_]Feature{}),353 .dependencies = featureSet(&[_]Feature{}),
359 };354 };
355 result[@enumToInt(Feature.gfx10_insts)] = .{
356 .llvm_name = "gfx10-insts",
357 .description = "Additional instructions for GFX10+",
358 .dependencies = featureSet(&[_]Feature{}),
359 };
360 result[@enumToInt(Feature.gfx7_gfx8_gfx9_insts)] = .{360 result[@enumToInt(Feature.gfx7_gfx8_gfx9_insts)] = .{
361 .llvm_name = "gfx7-gfx8-gfx9-insts",361 .llvm_name = "gfx7-gfx8-gfx9-insts",
362 .description = "Instructions shared in GFX7, GFX8, GFX9",362 .description = "Instructions shared in GFX7, GFX8, GFX9",
lib/std/target/powerpc.zig+12-12
...@@ -56,10 +56,10 @@ pub const Feature = enum {...@@ -56,10 +56,10 @@ pub const Feature = enum {
56 power8_vector,56 power8_vector,
57 power9_altivec,57 power9_altivec,
58 power9_vector,58 power9_vector,
59 ppc_postra_sched,
60 ppc_prera_sched,
61 ppc4xx,59 ppc4xx,
62 ppc6xx,60 ppc6xx,
61 ppc_postra_sched,
62 ppc_prera_sched,
63 predictable_select_expensive,63 predictable_select_expensive,
64 prefix_instrs,64 prefix_instrs,
65 recipprec,65 recipprec,
...@@ -397,16 +397,6 @@ pub const all_features = blk: {...@@ -397,16 +397,6 @@ pub const all_features = blk: {
397 .power9_altivec,397 .power9_altivec,
398 }),398 }),
399 };399 };
400 result[@enumToInt(Feature.ppc_postra_sched)] = .{
401 .llvm_name = "ppc-postra-sched",
402 .description = "Use PowerPC post-RA scheduling strategy",
403 .dependencies = featureSet(&[_]Feature{}),
404 };
405 result[@enumToInt(Feature.ppc_prera_sched)] = .{
406 .llvm_name = "ppc-prera-sched",
407 .description = "Use PowerPC pre-RA scheduling strategy",
408 .dependencies = featureSet(&[_]Feature{}),
409 };
410 result[@enumToInt(Feature.ppc4xx)] = .{400 result[@enumToInt(Feature.ppc4xx)] = .{
411 .llvm_name = "ppc4xx",401 .llvm_name = "ppc4xx",
412 .description = "Enable PPC 4xx instructions",402 .description = "Enable PPC 4xx instructions",
...@@ -417,6 +407,16 @@ pub const all_features = blk: {...@@ -417,6 +407,16 @@ pub const all_features = blk: {
417 .description = "Enable PPC 6xx instructions",407 .description = "Enable PPC 6xx instructions",
418 .dependencies = featureSet(&[_]Feature{}),408 .dependencies = featureSet(&[_]Feature{}),
419 };409 };
410 result[@enumToInt(Feature.ppc_postra_sched)] = .{
411 .llvm_name = "ppc-postra-sched",
412 .description = "Use PowerPC post-RA scheduling strategy",
413 .dependencies = featureSet(&[_]Feature{}),
414 };
415 result[@enumToInt(Feature.ppc_prera_sched)] = .{
416 .llvm_name = "ppc-prera-sched",
417 .description = "Use PowerPC pre-RA scheduling strategy",
418 .dependencies = featureSet(&[_]Feature{}),
419 };
420 result[@enumToInt(Feature.predictable_select_expensive)] = .{420 result[@enumToInt(Feature.predictable_select_expensive)] = .{
421 .llvm_name = "predictable-select-expensive",421 .llvm_name = "predictable-select-expensive",
422 .description = "Prefer likely predicted branches over selects",422 .description = "Prefer likely predicted branches over selects",
lib/std/target/riscv.zig-2
...@@ -390,7 +390,6 @@ pub const cpu = struct {...@@ -390,7 +390,6 @@ pub const cpu = struct {
390 .a,390 .a,
391 .c,391 .c,
392 .d,392 .d,
393 .f,
394 .m,393 .m,
395 }),394 }),
396 };395 };
...@@ -402,7 +401,6 @@ pub const cpu = struct {...@@ -402,7 +401,6 @@ pub const cpu = struct {
402 .a,401 .a,
403 .c,402 .c,
404 .d,403 .d,
405 .f,
406 .m,404 .m,
407 }),405 }),
408 };406 };
lib/std/target/x86.zig+132-132
...@@ -121,12 +121,12 @@ pub const Feature = enum {...@@ -121,12 +121,12 @@ pub const Feature = enum {
121 slow_unaligned_mem_32,121 slow_unaligned_mem_32,
122 soft_float,122 soft_float,
123 sse,123 sse,
124 sse_unaligned_mem,
125 sse2,124 sse2,
126 sse3,125 sse3,
127 sse4_1,126 sse4_1,
128 sse4_2,127 sse4_2,
129 sse4a,128 sse4a,
129 sse_unaligned_mem,
130 ssse3,130 ssse3,
131 tbm,131 tbm,
132 tsxldtrk,132 tsxldtrk,
...@@ -805,11 +805,6 @@ pub const all_features = blk: {...@@ -805,11 +805,6 @@ pub const all_features = blk: {
805 .description = "Enable SSE instructions",805 .description = "Enable SSE instructions",
806 .dependencies = featureSet(&[_]Feature{}),806 .dependencies = featureSet(&[_]Feature{}),
807 };807 };
808 result[@enumToInt(Feature.sse_unaligned_mem)] = .{
809 .llvm_name = "sse-unaligned-mem",
810 .description = "Allow unaligned memory operands with SSE instructions",
811 .dependencies = featureSet(&[_]Feature{}),
812 };
813 result[@enumToInt(Feature.sse2)] = .{808 result[@enumToInt(Feature.sse2)] = .{
814 .llvm_name = "sse2",809 .llvm_name = "sse2",
815 .description = "Enable SSE2 instructions",810 .description = "Enable SSE2 instructions",
...@@ -845,6 +840,11 @@ pub const all_features = blk: {...@@ -845,6 +840,11 @@ pub const all_features = blk: {
845 .sse3,840 .sse3,
846 }),841 }),
847 };842 };
843 result[@enumToInt(Feature.sse_unaligned_mem)] = .{
844 .llvm_name = "sse-unaligned-mem",
845 .description = "Allow unaligned memory operands with SSE instructions",
846 .dependencies = featureSet(&[_]Feature{}),
847 };
848 result[@enumToInt(Feature.ssse3)] = .{848 result[@enumToInt(Feature.ssse3)] = .{
849 .llvm_name = "ssse3",849 .llvm_name = "ssse3",
850 .description = "Enable SSSE3 instructions",850 .description = "Enable SSSE3 instructions",
...@@ -962,6 +962,45 @@ pub const all_features = blk: {...@@ -962,6 +962,45 @@ pub const all_features = blk: {
962};962};
963963
964pub const cpu = struct {964pub const cpu = struct {
965 pub const _i386 = CpuModel{
966 .name = "_i386",
967 .llvm_name = "i386",
968 .features = featureSet(&[_]Feature{
969 .slow_unaligned_mem_16,
970 .vzeroupper,
971 .x87,
972 }),
973 };
974 pub const _i486 = CpuModel{
975 .name = "_i486",
976 .llvm_name = "i486",
977 .features = featureSet(&[_]Feature{
978 .slow_unaligned_mem_16,
979 .vzeroupper,
980 .x87,
981 }),
982 };
983 pub const _i586 = CpuModel{
984 .name = "_i586",
985 .llvm_name = "i586",
986 .features = featureSet(&[_]Feature{
987 .cx8,
988 .slow_unaligned_mem_16,
989 .vzeroupper,
990 .x87,
991 }),
992 };
993 pub const _i686 = CpuModel{
994 .name = "_i686",
995 .llvm_name = "i686",
996 .features = featureSet(&[_]Feature{
997 .cmov,
998 .cx8,
999 .slow_unaligned_mem_16,
1000 .vzeroupper,
1001 .x87,
1002 }),
1003 };
965 pub const alderlake = CpuModel{1004 pub const alderlake = CpuModel{
966 .name = "alderlake",1005 .name = "alderlake",
967 .llvm_name = "alderlake",1006 .llvm_name = "alderlake",
...@@ -1049,43 +1088,45 @@ pub const cpu = struct {...@@ -1049,43 +1088,45 @@ pub const cpu = struct {
1049 .x87,1088 .x87,
1050 }),1089 }),
1051 };1090 };
1052 pub const athlon_4 = CpuModel{1091 pub const athlon64 = CpuModel{
1053 .name = "athlon_4",1092 .name = "athlon64",
1054 .llvm_name = "athlon-4",1093 .llvm_name = "athlon64",
1055 .features = featureSet(&[_]Feature{1094 .features = featureSet(&[_]Feature{
1056 .@"3dnowa",1095 .@"3dnowa",
1096 .@"64bit",
1057 .cmov,1097 .cmov,
1058 .cx8,1098 .cx8,
1099 .fast_scalar_shift_masks,
1059 .fxsr,1100 .fxsr,
1060 .nopl,1101 .nopl,
1061 .slow_shld,1102 .slow_shld,
1062 .slow_unaligned_mem_16,1103 .slow_unaligned_mem_16,
1063 .sse,1104 .sse2,
1064 .vzeroupper,1105 .vzeroupper,
1065 .x87,1106 .x87,
1066 }),1107 }),
1067 };1108 };
1068 pub const athlon_fx = CpuModel{1109 pub const athlon64_sse3 = CpuModel{
1069 .name = "athlon_fx",1110 .name = "athlon64_sse3",
1070 .llvm_name = "athlon-fx",1111 .llvm_name = "athlon64-sse3",
1071 .features = featureSet(&[_]Feature{1112 .features = featureSet(&[_]Feature{
1072 .@"3dnowa",1113 .@"3dnowa",
1073 .@"64bit",1114 .@"64bit",
1074 .cmov,1115 .cmov,
1075 .cx8,1116 .cx16,
1076 .fast_scalar_shift_masks,1117 .fast_scalar_shift_masks,
1077 .fxsr,1118 .fxsr,
1078 .nopl,1119 .nopl,
1079 .slow_shld,1120 .slow_shld,
1080 .slow_unaligned_mem_16,1121 .slow_unaligned_mem_16,
1081 .sse2,1122 .sse3,
1082 .vzeroupper,1123 .vzeroupper,
1083 .x87,1124 .x87,
1084 }),1125 }),
1085 };1126 };
1086 pub const athlon_mp = CpuModel{1127 pub const athlon_4 = CpuModel{
1087 .name = "athlon_mp",1128 .name = "athlon_4",
1088 .llvm_name = "athlon-mp",1129 .llvm_name = "athlon-4",
1089 .features = featureSet(&[_]Feature{1130 .features = featureSet(&[_]Feature{
1090 .@"3dnowa",1131 .@"3dnowa",
1091 .cmov,1132 .cmov,
...@@ -1099,23 +1140,27 @@ pub const cpu = struct {...@@ -1099,23 +1140,27 @@ pub const cpu = struct {
1099 .x87,1140 .x87,
1100 }),1141 }),
1101 };1142 };
1102 pub const athlon_tbird = CpuModel{1143 pub const athlon_fx = CpuModel{
1103 .name = "athlon_tbird",1144 .name = "athlon_fx",
1104 .llvm_name = "athlon-tbird",1145 .llvm_name = "athlon-fx",
1105 .features = featureSet(&[_]Feature{1146 .features = featureSet(&[_]Feature{
1106 .@"3dnowa",1147 .@"3dnowa",
1148 .@"64bit",
1107 .cmov,1149 .cmov,
1108 .cx8,1150 .cx8,
1151 .fast_scalar_shift_masks,
1152 .fxsr,
1109 .nopl,1153 .nopl,
1110 .slow_shld,1154 .slow_shld,
1111 .slow_unaligned_mem_16,1155 .slow_unaligned_mem_16,
1156 .sse2,
1112 .vzeroupper,1157 .vzeroupper,
1113 .x87,1158 .x87,
1114 }),1159 }),
1115 };1160 };
1116 pub const athlon_xp = CpuModel{1161 pub const athlon_mp = CpuModel{
1117 .name = "athlon_xp",1162 .name = "athlon_mp",
1118 .llvm_name = "athlon-xp",1163 .llvm_name = "athlon-mp",
1119 .features = featureSet(&[_]Feature{1164 .features = featureSet(&[_]Feature{
1120 .@"3dnowa",1165 .@"3dnowa",
1121 .cmov,1166 .cmov,
...@@ -1129,38 +1174,32 @@ pub const cpu = struct {...@@ -1129,38 +1174,32 @@ pub const cpu = struct {
1129 .x87,1174 .x87,
1130 }),1175 }),
1131 };1176 };
1132 pub const athlon64 = CpuModel{1177 pub const athlon_tbird = CpuModel{
1133 .name = "athlon64",1178 .name = "athlon_tbird",
1134 .llvm_name = "athlon64",1179 .llvm_name = "athlon-tbird",
1135 .features = featureSet(&[_]Feature{1180 .features = featureSet(&[_]Feature{
1136 .@"3dnowa",1181 .@"3dnowa",
1137 .@"64bit",
1138 .cmov,1182 .cmov,
1139 .cx8,1183 .cx8,
1140 .fast_scalar_shift_masks,
1141 .fxsr,
1142 .nopl,1184 .nopl,
1143 .slow_shld,1185 .slow_shld,
1144 .slow_unaligned_mem_16,1186 .slow_unaligned_mem_16,
1145 .sse2,
1146 .vzeroupper,1187 .vzeroupper,
1147 .x87,1188 .x87,
1148 }),1189 }),
1149 };1190 };
1150 pub const athlon64_sse3 = CpuModel{1191 pub const athlon_xp = CpuModel{
1151 .name = "athlon64_sse3",1192 .name = "athlon_xp",
1152 .llvm_name = "athlon64-sse3",1193 .llvm_name = "athlon-xp",
1153 .features = featureSet(&[_]Feature{1194 .features = featureSet(&[_]Feature{
1154 .@"3dnowa",1195 .@"3dnowa",
1155 .@"64bit",
1156 .cmov,1196 .cmov,
1157 .cx16,1197 .cx8,
1158 .fast_scalar_shift_masks,
1159 .fxsr,1198 .fxsr,
1160 .nopl,1199 .nopl,
1161 .slow_shld,1200 .slow_shld,
1162 .slow_unaligned_mem_16,1201 .slow_unaligned_mem_16,
1163 .sse3,1202 .sse,
1164 .vzeroupper,1203 .vzeroupper,
1165 .x87,1204 .x87,
1166 }),1205 }),
...@@ -1637,33 +1676,22 @@ pub const cpu = struct {...@@ -1637,33 +1676,22 @@ pub const cpu = struct {
1637 .xsaves,1676 .xsaves,
1638 }),1677 }),
1639 };1678 };
1640 pub const core_avx_i = CpuModel{1679 pub const core2 = CpuModel{
1641 .name = "core_avx_i",1680 .name = "core2",
1642 .llvm_name = "core-avx-i",1681 .llvm_name = "core2",
1643 .features = featureSet(&[_]Feature{1682 .features = featureSet(&[_]Feature{
1644 .@"64bit",1683 .@"64bit",
1645 .cmov,1684 .cmov,
1646 .cx16,1685 .cx16,
1647 .f16c,
1648 .false_deps_popcnt,
1649 .fast_15bytenop,
1650 .fast_scalar_fsqrt,
1651 .fast_shld_rotate,
1652 .fsgsbase,
1653 .fxsr,1686 .fxsr,
1654 .idivq_to_divl,
1655 .macrofusion,1687 .macrofusion,
1656 .mmx,1688 .mmx,
1657 .nopl,1689 .nopl,
1658 .pclmul,
1659 .popcnt,
1660 .rdrnd,
1661 .sahf,1690 .sahf,
1662 .slow_3ops_lea,1691 .slow_unaligned_mem_16,
1663 .slow_unaligned_mem_32,1692 .ssse3,
1664 .vzeroupper,1693 .vzeroupper,
1665 .x87,1694 .x87,
1666 .xsaveopt,
1667 }),1695 }),
1668 };1696 };
1669 pub const core_avx2 = CpuModel{1697 pub const core_avx2 = CpuModel{
...@@ -1704,22 +1732,33 @@ pub const cpu = struct {...@@ -1704,22 +1732,33 @@ pub const cpu = struct {
1704 .xsaveopt,1732 .xsaveopt,
1705 }),1733 }),
1706 };1734 };
1707 pub const core2 = CpuModel{1735 pub const core_avx_i = CpuModel{
1708 .name = "core2",1736 .name = "core_avx_i",
1709 .llvm_name = "core2",1737 .llvm_name = "core-avx-i",
1710 .features = featureSet(&[_]Feature{1738 .features = featureSet(&[_]Feature{
1711 .@"64bit",1739 .@"64bit",
1712 .cmov,1740 .cmov,
1713 .cx16,1741 .cx16,
1742 .f16c,
1743 .false_deps_popcnt,
1744 .fast_15bytenop,
1745 .fast_scalar_fsqrt,
1746 .fast_shld_rotate,
1747 .fsgsbase,
1714 .fxsr,1748 .fxsr,
1749 .idivq_to_divl,
1715 .macrofusion,1750 .macrofusion,
1716 .mmx,1751 .mmx,
1717 .nopl,1752 .nopl,
1753 .pclmul,
1754 .popcnt,
1755 .rdrnd,
1718 .sahf,1756 .sahf,
1719 .slow_unaligned_mem_16,1757 .slow_3ops_lea,
1720 .ssse3,1758 .slow_unaligned_mem_32,
1721 .vzeroupper,1759 .vzeroupper,
1722 .x87,1760 .x87,
1761 .xsaveopt,
1723 }),1762 }),
1724 };1763 };
1725 pub const corei7 = CpuModel{1764 pub const corei7 = CpuModel{
...@@ -1900,45 +1939,6 @@ pub const cpu = struct {...@@ -1900,45 +1939,6 @@ pub const cpu = struct {
1900 .xsaveopt,1939 .xsaveopt,
1901 }),1940 }),
1902 };1941 };
1903 pub const _i386 = CpuModel{
1904 .name = "_i386",
1905 .llvm_name = "i386",
1906 .features = featureSet(&[_]Feature{
1907 .slow_unaligned_mem_16,
1908 .vzeroupper,
1909 .x87,
1910 }),
1911 };
1912 pub const _i486 = CpuModel{
1913 .name = "_i486",
1914 .llvm_name = "i486",
1915 .features = featureSet(&[_]Feature{
1916 .slow_unaligned_mem_16,
1917 .vzeroupper,
1918 .x87,
1919 }),
1920 };
1921 pub const _i586 = CpuModel{
1922 .name = "_i586",
1923 .llvm_name = "i586",
1924 .features = featureSet(&[_]Feature{
1925 .cx8,
1926 .slow_unaligned_mem_16,
1927 .vzeroupper,
1928 .x87,
1929 }),
1930 };
1931 pub const _i686 = CpuModel{
1932 .name = "_i686",
1933 .llvm_name = "i686",
1934 .features = featureSet(&[_]Feature{
1935 .cmov,
1936 .cx8,
1937 .slow_unaligned_mem_16,
1938 .vzeroupper,
1939 .x87,
1940 }),
1941 };
1942 pub const icelake_client = CpuModel{1942 pub const icelake_client = CpuModel{
1943 .name = "icelake_client",1943 .name = "icelake_client",
1944 .llvm_name = "icelake-client",1944 .llvm_name = "icelake-client",
...@@ -2341,32 +2341,6 @@ pub const cpu = struct {...@@ -2341,32 +2341,6 @@ pub const cpu = struct {
2341 .x87,2341 .x87,
2342 }),2342 }),
2343 };2343 };
2344 pub const pentium_m = CpuModel{
2345 .name = "pentium_m",
2346 .llvm_name = "pentium-m",
2347 .features = featureSet(&[_]Feature{
2348 .cmov,
2349 .cx8,
2350 .fxsr,
2351 .mmx,
2352 .nopl,
2353 .slow_unaligned_mem_16,
2354 .sse2,
2355 .vzeroupper,
2356 .x87,
2357 }),
2358 };
2359 pub const pentium_mmx = CpuModel{
2360 .name = "pentium_mmx",
2361 .llvm_name = "pentium-mmx",
2362 .features = featureSet(&[_]Feature{
2363 .cx8,
2364 .mmx,
2365 .slow_unaligned_mem_16,
2366 .vzeroupper,
2367 .x87,
2368 }),
2369 };
2370 pub const pentium2 = CpuModel{2344 pub const pentium2 = CpuModel{
2371 .name = "pentium2",2345 .name = "pentium2",
2372 .llvm_name = "pentium2",2346 .llvm_name = "pentium2",
...@@ -2441,6 +2415,32 @@ pub const cpu = struct {...@@ -2441,6 +2415,32 @@ pub const cpu = struct {
2441 .x87,2415 .x87,
2442 }),2416 }),
2443 };2417 };
2418 pub const pentium_m = CpuModel{
2419 .name = "pentium_m",
2420 .llvm_name = "pentium-m",
2421 .features = featureSet(&[_]Feature{
2422 .cmov,
2423 .cx8,
2424 .fxsr,
2425 .mmx,
2426 .nopl,
2427 .slow_unaligned_mem_16,
2428 .sse2,
2429 .vzeroupper,
2430 .x87,
2431 }),
2432 };
2433 pub const pentium_mmx = CpuModel{
2434 .name = "pentium_mmx",
2435 .llvm_name = "pentium-mmx",
2436 .features = featureSet(&[_]Feature{
2437 .cx8,
2438 .mmx,
2439 .slow_unaligned_mem_16,
2440 .vzeroupper,
2441 .x87,
2442 }),
2443 };
2444 pub const pentiumpro = CpuModel{2444 pub const pentiumpro = CpuModel{
2445 .name = "pentiumpro",2445 .name = "pentiumpro",
2446 .llvm_name = "pentiumpro",2446 .llvm_name = "pentiumpro",
...@@ -2894,21 +2894,21 @@ pub const cpu = struct {...@@ -2894,21 +2894,21 @@ pub const cpu = struct {
2894 .x87,2894 .x87,
2895 }),2895 }),
2896 };2896 };
2897 pub const winchip_c6 = CpuModel{2897 pub const winchip2 = CpuModel{
2898 .name = "winchip_c6",2898 .name = "winchip2",
2899 .llvm_name = "winchip-c6",2899 .llvm_name = "winchip2",
2900 .features = featureSet(&[_]Feature{2900 .features = featureSet(&[_]Feature{
2901 .mmx,2901 .@"3dnow",
2902 .slow_unaligned_mem_16,2902 .slow_unaligned_mem_16,
2903 .vzeroupper,2903 .vzeroupper,
2904 .x87,2904 .x87,
2905 }),2905 }),
2906 };2906 };
2907 pub const winchip2 = CpuModel{2907 pub const winchip_c6 = CpuModel{
2908 .name = "winchip2",2908 .name = "winchip_c6",
2909 .llvm_name = "winchip2",2909 .llvm_name = "winchip-c6",
2910 .features = featureSet(&[_]Feature{2910 .features = featureSet(&[_]Feature{
2911 .@"3dnow",2911 .mmx,
2912 .slow_unaligned_mem_16,2912 .slow_unaligned_mem_16,
2913 .vzeroupper,2913 .vzeroupper,
2914 .x87,2914 .x87,
tools/update_cpu_features.zig+205-136
...@@ -4,25 +4,36 @@ const mem = std.mem;...@@ -4,25 +4,36 @@ const mem = std.mem;
4const json = std.json;4const json = std.json;
5const assert = std.debug.assert;5const assert = std.debug.assert;
66
7// All references to other features are based on "zig name" as the key.
8
7const FeatureOverride = struct {9const FeatureOverride = struct {
8 llvm_name: []const u8,10 llvm_name: []const u8,
9 omit: bool = false,11 omit: bool = false,
10 zig_name: ?[]const u8 = null,12 zig_name: ?[]const u8 = null,
11 desc: ?[]const u8 = null,13 desc: ?[]const u8 = null,
14 extra_deps: []const []const u8 = &.{},
12};15};
1316
14const ExtraCpu = struct {17const Cpu = struct {
15 llvm_name: ?[]const u8,18 llvm_name: ?[]const u8,
16 zig_name: []const u8,19 zig_name: []const u8,
17 features: []const []const u8,20 features: []const []const u8,
18};21};
1922
23const Feature = struct {
24 llvm_name: ?[]const u8 = null,
25 zig_name: []const u8,
26 desc: []const u8,
27 deps: []const []const u8,
28};
29
20const LlvmTarget = struct {30const LlvmTarget = struct {
21 zig_name: []const u8,31 zig_name: []const u8,
22 llvm_name: []const u8,32 llvm_name: []const u8,
23 td_name: []const u8,33 td_name: []const u8,
24 feature_overrides: []const FeatureOverride = &.{},34 feature_overrides: []const FeatureOverride = &.{},
25 extra_cpus: []const ExtraCpu = &.{},35 extra_cpus: []const Cpu = &.{},
36 extra_features: []const Feature = &.{},
26 branch_quota: ?usize = null,37 branch_quota: ?usize = null,
27};38};
2839
...@@ -54,6 +65,25 @@ const llvm_targets = [_]LlvmTarget{...@@ -54,6 +65,25 @@ const llvm_targets = [_]LlvmTarget{
54 .llvm_name = "neoversev1",65 .llvm_name = "neoversev1",
55 .zig_name = "neoverse_v1",66 .zig_name = "neoverse_v1",
56 },67 },
68 .{
69 .llvm_name = "exynosm3",
70 .zig_name = "exynos_m3",
71 },
72 .{
73 .llvm_name = "exynosm4",
74 .zig_name = "exynos_m4",
75 },
76 .{
77 .llvm_name = "v8.1a",
78 .extra_deps = &.{"v8a"},
79 },
80 },
81 .extra_features = &.{
82 .{
83 .zig_name = "v8a",
84 .desc = "Support ARM v8a instructions",
85 .deps = &.{ "fp_armv8", "neon" },
86 },
57 },87 },
58 },88 },
59 .{89 .{
...@@ -331,8 +361,9 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -331,8 +361,9 @@ fn processOneTarget(job: Job) anyerror!void {
331 render_progress.activate();361 render_progress.activate();
332362
333 const root_map = &tree.root.Object;363 const root_map = &tree.root.Object;
334 var all_features = std.ArrayList(*json.ObjectMap).init(arena);364 var features_table = std.StringHashMap(Feature).init(arena);
335 var all_cpus = std.ArrayList(*json.ObjectMap).init(arena);365 var all_features = std.ArrayList(Feature).init(arena);
366 var all_cpus = std.ArrayList(Cpu).init(arena);
336 {367 {
337 var it = root_map.iterator();368 var it = root_map.iterator();
338 root_it: while (it.next()) |kv| {369 root_it: while (it.next()) |kv| {
...@@ -342,23 +373,101 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -342,23 +373,101 @@ fn processOneTarget(job: Job) anyerror!void {
342 if (hasSuperclass(&kv.value.Object, "SubtargetFeature")) {373 if (hasSuperclass(&kv.value.Object, "SubtargetFeature")) {
343 const llvm_name = kv.value.Object.get("Name").?.String;374 const llvm_name = kv.value.Object.get("Name").?.String;
344 if (llvm_name.len == 0) continue;375 if (llvm_name.len == 0) continue;
376
377 var zig_name = (try llvmNameToZigName(arena, llvm_target, llvm_name)) orelse
378 continue :root_it;
379 var desc = kv.value.Object.get("Desc").?.String;
380 var deps = std.ArrayList([]const u8).init(arena);
381 const implies = kv.value.Object.get("Implies").?.Array;
382 for (implies.items) |imply| {
383 const other_key = imply.Object.get("def").?.String;
384 const other_obj = &root_map.getEntry(other_key).?.value.Object;
385 const other_llvm_name = other_obj.get("Name").?.String;
386 const other_zig_name = (try llvmNameToZigName(arena, llvm_target, other_llvm_name)) orelse continue;
387 try deps.append(other_zig_name);
388 }
345 for (llvm_target.feature_overrides) |feature_override| {389 for (llvm_target.feature_overrides) |feature_override| {
346 if (mem.eql(u8, llvm_name, feature_override.llvm_name)) {390 if (mem.eql(u8, llvm_name, feature_override.llvm_name)) {
347 if (feature_override.omit) {391 if (feature_override.omit) {
348 continue :root_it;392 continue :root_it;
349 }393 }
394 if (feature_override.zig_name) |override_name| {
395 zig_name = override_name;
396 }
397 if (feature_override.desc) |override_desc| {
398 desc = override_desc;
399 }
400 for (feature_override.extra_deps) |extra_dep| {
401 try deps.append(extra_dep);
402 }
403 break;
350 }404 }
351 }405 }
352406 const feature: Feature = .{
353 try all_features.append(&kv.value.Object);407 .llvm_name = llvm_name,
408 .zig_name = zig_name,
409 .desc = desc,
410 .deps = deps.items,
411 };
412 try features_table.put(zig_name, feature);
413 try all_features.append(feature);
354 }414 }
355 if (hasSuperclass(&kv.value.Object, "Processor")) {415 if (hasSuperclass(&kv.value.Object, "Processor")) {
356 try all_cpus.append(&kv.value.Object);416 const llvm_name = kv.value.Object.get("Name").?.String;
417 if (llvm_name.len == 0) continue;
418
419 var zig_name = (try llvmNameToZigName(arena, llvm_target, llvm_name)) orelse
420 continue :root_it;
421 var deps = std.ArrayList([]const u8).init(arena);
422 const features = kv.value.Object.get("Features").?.Array;
423 for (features.items) |feature| {
424 const feature_key = feature.Object.get("def").?.String;
425 const feature_obj = &root_map.getEntry(feature_key).?.value.Object;
426 const feature_llvm_name = feature_obj.get("Name").?.String;
427 if (feature_llvm_name.len == 0) continue;
428 const feature_zig_name = (try llvmNameToZigName(arena, llvm_target, feature_llvm_name)) orelse continue;
429 try deps.append(feature_zig_name);
430 }
431 const tune_features = kv.value.Object.get("TuneFeatures").?.Array;
432 for (tune_features.items) |feature| {
433 const feature_key = feature.Object.get("def").?.String;
434 const feature_obj = &root_map.getEntry(feature_key).?.value.Object;
435 const feature_llvm_name = feature_obj.get("Name").?.String;
436 if (feature_llvm_name.len == 0) continue;
437 const feature_zig_name = (try llvmNameToZigName(arena, llvm_target, feature_llvm_name)) orelse continue;
438 try deps.append(feature_zig_name);
439 }
440 for (llvm_target.feature_overrides) |feature_override| {
441 if (mem.eql(u8, llvm_name, feature_override.llvm_name)) {
442 if (feature_override.omit) {
443 continue :root_it;
444 }
445 if (feature_override.zig_name) |override_name| {
446 zig_name = override_name;
447 }
448 for (feature_override.extra_deps) |extra_dep| {
449 try deps.append(extra_dep);
450 }
451 break;
452 }
453 }
454 try all_cpus.append(.{
455 .llvm_name = llvm_name,
456 .zig_name = zig_name,
457 .features = deps.items,
458 });
357 }459 }
358 }460 }
359 }461 }
360 std.sort.sort(*json.ObjectMap, all_features.items, {}, objectLessThan);462 for (llvm_target.extra_features) |extra_feature| {
361 std.sort.sort(*json.ObjectMap, all_cpus.items, {}, objectLessThan);463 try features_table.put(extra_feature.zig_name, extra_feature);
464 try all_features.append(extra_feature);
465 }
466 for (llvm_target.extra_cpus) |extra_cpu| {
467 try all_cpus.append(extra_cpu);
468 }
469 std.sort.sort(Feature, all_features.items, {}, featureLessThan);
470 std.sort.sort(Cpu, all_cpus.items, {}, cpuLessThan);
362471
363 const target_sub_path = try fs.path.join(arena, &.{ "lib", "std", "target" });472 const target_sub_path = try fs.path.join(arena, &.{ "lib", "std", "target" });
364 var target_dir = try job.zig_src_dir.makeOpenPath(target_sub_path, .{});473 var target_dir = try job.zig_src_dir.makeOpenPath(target_sub_path, .{});
...@@ -389,10 +498,8 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -389,10 +498,8 @@ fn processOneTarget(job: Job) anyerror!void {
389 \\498 \\
390 );499 );
391500
392 for (all_features.items) |obj| {501 for (all_features.items) |feature| {
393 const llvm_name = obj.get("Name").?.String;502 try w.print(" {},\n", .{std.zig.fmtId(feature.zig_name)});
394 const zig_name = try llvmNameToZigName(arena, llvm_target, llvm_name);
395 try w.print(" {},\n", .{std.zig.fmtId(zig_name)});
396 }503 }
397504
398 try w.writeAll(505 try w.writeAll(
...@@ -413,45 +520,46 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -413,45 +520,46 @@ fn processOneTarget(job: Job) anyerror!void {
413 \\520 \\
414 );521 );
415522
416 for (all_features.items) |obj| {523 for (all_features.items) |feature| {
417 const llvm_name = obj.get("Name").?.String;524 if (feature.llvm_name) |llvm_name| {
418 const llvm_description = obj.get("Desc").?.String;525 try w.print(
419 const description = for (llvm_target.feature_overrides) |feature_override| {526 \\ result[@enumToInt(Feature.{})] = .{{
420 if (mem.eql(u8, llvm_name, feature_override.llvm_name)) {527 \\ .llvm_name = "{}",
421 if (feature_override.desc) |desc| {528 \\ .description = "{}",
422 break desc;529 \\ .dependencies = featureSet(&[_]Feature{{
423 }530 ,
424 }531 .{
425 } else llvm_description;532 std.zig.fmtId(feature.zig_name),
426 const zig_name = try llvmNameToZigName(arena, llvm_target, llvm_name);533 std.zig.fmtEscapes(llvm_name),
427 try w.print(534 std.zig.fmtEscapes(feature.desc),
428 \\ result[@enumToInt(Feature.{})] = .{{535 },
429 \\ .llvm_name = "{}",536 );
430 \\ .description = "{}",537 } else {
431 \\ .dependencies = featureSet(&[_]Feature{{538 try w.print(
432 ,539 \\ result[@enumToInt(Feature.{})] = .{{
433 .{540 \\ .llvm_name = null,
434 std.zig.fmtId(zig_name),541 \\ .description = "{}",
435 std.zig.fmtEscapes(llvm_name),542 \\ .dependencies = featureSet(&[_]Feature{{
436 std.zig.fmtEscapes(description),543 ,
437 },544 .{
438 );545 std.zig.fmtId(feature.zig_name),
439 const implies = obj.get("Implies").?.Array;546 std.zig.fmtEscapes(feature.desc),
547 },
548 );
549 }
440 var deps_set = std.StringHashMap(void).init(arena);550 var deps_set = std.StringHashMap(void).init(arena);
441 for (implies.items) |imply| {551 for (feature.deps) |dep| {
442 const other_key = imply.Object.get("def").?.String;552 try deps_set.put(dep, {});
443 try deps_set.put(other_key, {});
444 }553 }
445 try pruneFeatures(arena, root_map, &deps_set);554 try pruneFeatures(arena, features_table, &deps_set);
446 var dependencies = std.ArrayList(*json.ObjectMap).init(arena);555 var dependencies = std.ArrayList([]const u8).init(arena);
447 {556 {
448 var it = deps_set.iterator();557 var it = deps_set.iterator();
449 while (it.next()) |entry| {558 while (it.next()) |entry| {
450 const other_obj = &root_map.getEntry(entry.key).?.value.Object;559 try dependencies.append(entry.key);
451 try dependencies.append(other_obj);
452 }560 }
453 }561 }
454 std.sort.sort(*json.ObjectMap, dependencies.items, {}, objectLessThan);562 std.sort.sort([]const u8, dependencies.items, {}, asciiLessThan);
455563
456 if (dependencies.items.len == 0) {564 if (dependencies.items.len == 0) {
457 try w.writeAll(565 try w.writeAll(
...@@ -462,9 +570,7 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -462,9 +570,7 @@ fn processOneTarget(job: Job) anyerror!void {
462 } else {570 } else {
463 try w.writeAll("\n");571 try w.writeAll("\n");
464 for (dependencies.items) |dep| {572 for (dependencies.items) |dep| {
465 const other_llvm_name = dep.get("Name").?.String;573 try w.print(" .{},\n", .{std.zig.fmtId(dep)});
466 const other_zig_name = try llvmNameToZigName(arena, llvm_target, other_llvm_name);
467 try w.print(" .{},\n", .{std.zig.fmtId(other_zig_name)});
468 }574 }
469 try w.writeAll(575 try w.writeAll(
470 \\ }),576 \\ }),
...@@ -485,81 +591,42 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -485,81 +591,42 @@ fn processOneTarget(job: Job) anyerror!void {
485 \\pub const cpu = struct {591 \\pub const cpu = struct {
486 \\592 \\
487 );593 );
488 for (llvm_target.extra_cpus) |extra_cpu| {594 for (all_cpus.items) |cpu| {
489 try w.print(
490 \\ pub const {} = CpuModel{{
491 \\ .name = "{}",
492 \\
493 , .{
494 std.zig.fmtId(extra_cpu.zig_name),
495 std.zig.fmtEscapes(extra_cpu.zig_name),
496 });
497 if (extra_cpu.llvm_name) |llvm_name| {
498 try w.print(
499 \\ .llvm_name = "{}",
500 \\ .features = featureSet(&[_]Feature{{
501 , .{std.zig.fmtEscapes(llvm_name)});
502 } else {
503 try w.writeAll(
504 \\ .llvm_name = null,
505 \\ .features = featureSet(&[_]Feature{
506 );
507 }
508 if (extra_cpu.features.len == 0) {
509 try w.writeAll(
510 \\}),
511 \\ };
512 \\
513 );
514 } else {
515 try w.writeAll("\n");
516 for (extra_cpu.features) |feature_zig_name| {
517 try w.print(" .{},\n", .{std.zig.fmtId(feature_zig_name)});
518 }
519 try w.writeAll(
520 \\ }),
521 \\ };
522 \\
523 );
524 }
525 }
526 for (all_cpus.items) |obj| {
527 const llvm_name = obj.get("Name").?.String;
528 var deps_set = std.StringHashMap(void).init(arena);595 var deps_set = std.StringHashMap(void).init(arena);
529596 for (cpu.features) |feature_zig_name| {
530 const features = obj.get("Features").?.Array;597 try deps_set.put(feature_zig_name, {});
531 for (features.items) |feature| {
532 const feature_key = feature.Object.get("def").?.String;
533 try deps_set.put(feature_key, {});
534 }598 }
535 const tune_features = obj.get("TuneFeatures").?.Array;599 try pruneFeatures(arena, features_table, &deps_set);
536 for (tune_features.items) |feature| {600 var cpu_features = std.ArrayList([]const u8).init(arena);
537 const feature_key = feature.Object.get("def").?.String;
538 try deps_set.put(feature_key, {});
539 }
540 try pruneFeatures(arena, root_map, &deps_set);
541 var cpu_features = std.ArrayList(*json.ObjectMap).init(arena);
542 {601 {
543 var it = deps_set.iterator();602 var it = deps_set.iterator();
544 while (it.next()) |entry| {603 while (it.next()) |entry| {
545 const feature_obj = &root_map.getEntry(entry.key).?.value.Object;604 try cpu_features.append(entry.key);
546 const feature_llvm_name = feature_obj.get("Name").?.String;
547 if (feature_llvm_name.len == 0) continue;
548 try cpu_features.append(feature_obj);
549 }605 }
550 }606 }
551 std.sort.sort(*json.ObjectMap, cpu_features.items, {}, objectLessThan);607 std.sort.sort([]const u8, cpu_features.items, {}, asciiLessThan);
552 const zig_cpu_name = try llvmNameToZigName(arena, llvm_target, llvm_name);608 if (cpu.llvm_name) |llvm_name| {
553 try w.print(609 try w.print(
554 \\ pub const {} = CpuModel{{610 \\ pub const {} = CpuModel{{
555 \\ .name = "{}",611 \\ .name = "{}",
556 \\ .llvm_name = "{}",612 \\ .llvm_name = "{}",
557 \\ .features = featureSet(&[_]Feature{{613 \\ .features = featureSet(&[_]Feature{{
558 , .{614 , .{
559 std.zig.fmtId(zig_cpu_name),615 std.zig.fmtId(cpu.zig_name),
560 std.zig.fmtEscapes(zig_cpu_name),616 std.zig.fmtEscapes(cpu.zig_name),
561 std.zig.fmtEscapes(llvm_name),617 std.zig.fmtEscapes(llvm_name),
562 });618 });
619 } else {
620 try w.print(
621 \\ pub const {} = CpuModel{{
622 \\ .name = "{}",
623 \\ .llvm_name = null,
624 \\ .features = featureSet(&[_]Feature{{
625 , .{
626 std.zig.fmtId(cpu.zig_name),
627 std.zig.fmtEscapes(cpu.zig_name),
628 });
629 }
563 if (cpu_features.items.len == 0) {630 if (cpu_features.items.len == 0) {
564 try w.writeAll(631 try w.writeAll(
565 \\}),632 \\}),
...@@ -568,9 +635,7 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -568,9 +635,7 @@ fn processOneTarget(job: Job) anyerror!void {
568 );635 );
569 } else {636 } else {
570 try w.writeAll("\n");637 try w.writeAll("\n");
571 for (cpu_features.items) |feature_obj| {638 for (cpu_features.items) |feature_zig_name| {
572 const feature_llvm_name = feature_obj.get("Name").?.String;
573 const feature_zig_name = try llvmNameToZigName(arena, llvm_target, feature_llvm_name);
574 try w.print(" .{},\n", .{std.zig.fmtId(feature_zig_name)});639 try w.print(" .{},\n", .{std.zig.fmtId(feature_zig_name)});
575 }640 }
576 try w.writeAll(641 try w.writeAll(
...@@ -602,20 +667,26 @@ fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {...@@ -602,20 +667,26 @@ fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {
602 std.process.exit(code);667 std.process.exit(code);
603}668}
604669
605fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {670fn featureLessThan(context: void, a: Feature, b: Feature) bool {
606 const a_key = a.get("Name").?.String;671 return std.ascii.lessThanIgnoreCase(a.zig_name, b.zig_name);
607 const b_key = b.get("Name").?.String;672}
608 return std.ascii.lessThanIgnoreCase(a_key, b_key);673
674fn cpuLessThan(context: void, a: Cpu, b: Cpu) bool {
675 return std.ascii.lessThanIgnoreCase(a.zig_name, b.zig_name);
676}
677
678fn asciiLessThan(context: void, a: []const u8, b: []const u8) bool {
679 return std.ascii.lessThanIgnoreCase(a, b);
609}680}
610681
611fn llvmNameToZigName(682fn llvmNameToZigName(
612 arena: *mem.Allocator,683 arena: *mem.Allocator,
613 llvm_target: LlvmTarget,684 llvm_target: LlvmTarget,
614 llvm_name: []const u8,685 llvm_name: []const u8,
615) ![]const u8 {686) !?[]const u8 {
616 for (llvm_target.feature_overrides) |feature_override| {687 for (llvm_target.feature_overrides) |feature_override| {
617 if (mem.eql(u8, feature_override.llvm_name, llvm_name)) {688 if (mem.eql(u8, feature_override.llvm_name, llvm_name)) {
618 assert(!feature_override.omit);689 if (feature_override.omit) return null;
619 return feature_override.zig_name orelse break;690 return feature_override.zig_name orelse break;
620 }691 }
621 }692 }
...@@ -640,7 +711,7 @@ fn hasSuperclass(obj: *json.ObjectMap, class_name: []const u8) bool {...@@ -640,7 +711,7 @@ fn hasSuperclass(obj: *json.ObjectMap, class_name: []const u8) bool {
640711
641fn pruneFeatures(712fn pruneFeatures(
642 arena: *mem.Allocator,713 arena: *mem.Allocator,
643 root_map: *const json.ObjectMap,714 features_table: std.StringHashMap(Feature),
644 deps_set: *std.StringHashMap(void),715 deps_set: *std.StringHashMap(void),
645) !void {716) !void {
646 // For each element, recursively iterate over the dependencies and add717 // For each element, recursively iterate over the dependencies and add
...@@ -650,8 +721,8 @@ fn pruneFeatures(...@@ -650,8 +721,8 @@ fn pruneFeatures(
650 {721 {
651 var it = deps_set.iterator();722 var it = deps_set.iterator();
652 while (it.next()) |entry| {723 while (it.next()) |entry| {
653 const other_obj = &root_map.getEntry(entry.key).?.value.Object;724 const feature = features_table.get(entry.key).?;
654 try walkFeatures(root_map, &deletion_set, other_obj);725 try walkFeatures(features_table, &deletion_set, feature);
655 }726 }
656 }727 }
657 {728 {
...@@ -663,15 +734,13 @@ fn pruneFeatures(...@@ -663,15 +734,13 @@ fn pruneFeatures(
663}734}
664735
665fn walkFeatures(736fn walkFeatures(
666 root_map: *const json.ObjectMap,737 features_table: std.StringHashMap(Feature),
667 deletion_set: *std.StringHashMap(void),738 deletion_set: *std.StringHashMap(void),
668 feature: *json.ObjectMap,739 feature: Feature,
669) error{OutOfMemory}!void {740) error{OutOfMemory}!void {
670 const implies = feature.get("Implies").?.Array;741 for (feature.deps) |dep| {
671 for (implies.items) |imply| {742 try deletion_set.put(dep, {});
672 const other_key = imply.Object.get("def").?.String;743 const other_feature = features_table.get(dep).?;
673 try deletion_set.put(other_key, {});744 try walkFeatures(features_table, deletion_set, other_feature);
674 const other_obj = &root_map.getEntry(other_key).?.value.Object;
675 try walkFeatures(root_map, deletion_set, other_obj);
676 }745 }
677}746}