authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-11 17:03:46-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-06-11 17:03:46-04:00
logf7361970b334faf4433b3bd1d5dd6d499860c288
tree7e1b177c8e28979af2ceb306c71e2337a67f5b8e
parent45212e3b33151b016ae4a597a898db0cc13d4e6b
parentda4081fe21f534157a7a88e2d6b2b6a80ee2f32d
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #8060 from DrDeano/feature/add-mcpu-to-target-options

Add CPU feature check to standardTargetOptions

2 files changed, 62 insertions(+), 11 deletions(-)

lib/std/build.zig+53-9
...@@ -637,7 +637,7 @@ pub const Builder = struct {...@@ -637,7 +637,7 @@ pub const Builder = struct {
637 "target",637 "target",
638 "The CPU architecture, OS, and ABI to build for",638 "The CPU architecture, OS, and ABI to build for",
639 );639 );
640 const mcpu = self.option([]const u8, "cpu", "Target CPU");640 const mcpu = self.option([]const u8, "cpu", "Target CPU features to add or subtract");
641641
642 const triple = maybe_triple orelse return args.default_target;642 const triple = maybe_triple orelse return args.default_target;
643643
...@@ -699,20 +699,64 @@ pub const Builder = struct {...@@ -699,20 +699,64 @@ pub const Builder = struct {
699699
700 if (args.whitelist) |list| whitelist_check: {700 if (args.whitelist) |list| whitelist_check: {
701 // Make sure it's a match of one of the list.701 // Make sure it's a match of one of the list.
702 var mismatch_triple = true;
703 var mismatch_cpu_features = true;
704 var whitelist_item = CrossTarget{};
702 for (list) |t| {705 for (list) |t| {
706 mismatch_cpu_features = true;
707 mismatch_triple = true;
708
703 const t_triple = t.zigTriple(self.allocator) catch unreachable;709 const t_triple = t.zigTriple(self.allocator) catch unreachable;
704 if (mem.eql(u8, t_triple, selected_canonicalized_triple)) {710 if (mem.eql(u8, t_triple, selected_canonicalized_triple)) {
705 break :whitelist_check;711 mismatch_triple = false;
712 whitelist_item = t;
713 if (t.getCpuFeatures().isSuperSetOf(selected_target.getCpuFeatures())) {
714 mismatch_cpu_features = false;
715 break :whitelist_check;
716 } else {
717 break;
718 }
706 }719 }
707 }720 }
708 warn("Chosen target '{s}' does not match one of the supported targets:\n", .{721 if (mismatch_triple) {
709 selected_canonicalized_triple,722 warn("Chosen target '{s}' does not match one of the supported targets:\n", .{
710 });723 selected_canonicalized_triple,
711 for (list) |t| {724 });
712 const t_triple = t.zigTriple(self.allocator) catch unreachable;725 for (list) |t| {
713 warn(" {s}\n", .{t_triple});726 const t_triple = t.zigTriple(self.allocator) catch unreachable;
727 warn(" {s}\n", .{t_triple});
728 }
729 warn("\n", .{});
730 } else {
731 assert(mismatch_cpu_features);
732 const whitelist_cpu = whitelist_item.getCpu();
733 const selected_cpu = selected_target.getCpu();
734 warn("Chosen CPU model '{s}' does not match one of the supported targets:\n", .{
735 selected_cpu.model.name,
736 });
737 warn(" Supported feature Set: ", .{});
738 const all_features = whitelist_cpu.arch.allFeaturesList();
739 var populated_cpu_features = whitelist_cpu.model.features;
740 populated_cpu_features.populateDependencies(all_features);
741 for (all_features) |feature, i_usize| {
742 const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);
743 const in_cpu_set = populated_cpu_features.isEnabled(i);
744 if (in_cpu_set) {
745 warn("{s} ", .{feature.name});
746 }
747 }
748 warn("\n", .{});
749 warn(" Remove: ", .{});
750 for (all_features) |feature, i_usize| {
751 const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);
752 const in_cpu_set = populated_cpu_features.isEnabled(i);
753 const in_actual_set = selected_cpu.features.isEnabled(i);
754 if (in_actual_set and !in_cpu_set) {
755 warn("{s} ", .{feature.name});
756 }
757 }
758 warn("\n", .{});
714 }759 }
715 warn("\n", .{});
716 self.markInvalidUserInput();760 self.markInvalidUserInput();
717 return args.default_target;761 return args.default_target;
718 }762 }
lib/std/target.zig+9-2
...@@ -664,8 +664,15 @@ pub const Target = struct {...@@ -664,8 +664,15 @@ pub const Target = struct {
664 return @ptrCast(*const [byte_count]u8, &set.ints);664 return @ptrCast(*const [byte_count]u8, &set.ints);
665 }665 }
666666
667 pub fn eql(set: Set, other: Set) bool {667 pub fn eql(set: Set, other_set: Set) bool {
668 return mem.eql(usize, &set.ints, &other.ints);668 return mem.eql(usize, &set.ints, &other_set.ints);
669 }
670
671 pub fn isSuperSetOf(set: Set, other_set: Set) bool {
672 const V = std.meta.Vector(usize_count, usize);
673 const set_v: V = set.ints;
674 const other_v: V = other_set.ints;
675 return @reduce(.And, (set_v & other_v) == other_v);
669 }676 }
670 };677 };
671678