Skip to content

Commit e8cba85

Browse files
committed
std.Target: Introduce Cpu convenience functions for feature tests.
Before: * std.Target.arm.featureSetHas(target.cpu.features, .has_v7) * std.Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }) * std.Target.wasm.featureSetHasAll(target.cpu.features, .{ .atomics, .bulk_memory }) After: * target.cpu.has(.arm, .has_v7) * target.cpu.hasAny(.x86, &.{ .sse, .avx, .cmov }) * target.cpu.hasAll(.wasm, &.{ .atomics, .bulk_memory })
1 parent b77e601 commit e8cba85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+360
-384
lines changed

lib/compiler/aro/aro/target.zig

+8-8
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub fn ignoreNonZeroSizedBitfieldTypeAlignment(target: std.Target) bool {
162162
switch (target.cpu.arch) {
163163
.avr => return true,
164164
.arm => {
165-
if (std.Target.arm.featureSetHas(target.cpu.features, .has_v7)) {
165+
if (target.cpu.has(.arm, .has_v7)) {
166166
switch (target.os.tag) {
167167
.ios => return true,
168168
else => return false,
@@ -185,7 +185,7 @@ pub fn minZeroWidthBitfieldAlignment(target: std.Target) ?u29 {
185185
switch (target.cpu.arch) {
186186
.avr => return 8,
187187
.arm => {
188-
if (std.Target.arm.featureSetHas(target.cpu.features, .has_v7)) {
188+
if (target.cpu.has(.arm, .has_v7)) {
189189
switch (target.os.tag) {
190190
.ios => return 32,
191191
else => return null,
@@ -203,7 +203,7 @@ pub fn unnamedFieldAffectsAlignment(target: std.Target) bool {
203203
return true;
204204
},
205205
.armeb => {
206-
if (std.Target.arm.featureSetHas(target.cpu.features, .has_v7)) {
206+
if (target.cpu.has(.arm, .has_v7)) {
207207
if (std.Target.Abi.default(target.cpu.arch, target.os.tag) == .eabi) return true;
208208
}
209209
},
@@ -230,7 +230,7 @@ pub fn defaultAlignment(target: std.Target) u29 {
230230
switch (target.cpu.arch) {
231231
.avr => return 1,
232232
.arm => if (target.abi.isAndroid() or target.os.tag == .ios) return 16 else return 8,
233-
.sparc => if (std.Target.sparc.featureSetHas(target.cpu.features, .v9)) return 16 else return 8,
233+
.sparc => if (target.cpu.has(.sparc, .v9)) return 16 else return 8,
234234
.mips, .mipsel => switch (target.abi) {
235235
.none, .gnuabi64 => return 16,
236236
else => return 8,
@@ -268,7 +268,7 @@ pub fn systemCompiler(target: std.Target) LangOpts.Compiler {
268268
pub fn hasFloat128(target: std.Target) bool {
269269
if (target.cpu.arch.isWasm()) return true;
270270
if (target.os.tag.isDarwin()) return false;
271-
if (target.cpu.arch.isPowerPC()) return std.Target.powerpc.featureSetHas(target.cpu.features, .float128);
271+
if (target.cpu.arch.isPowerPC()) return target.cpu.has(.powerpc, .float128);
272272
return switch (target.os.tag) {
273273
.dragonfly,
274274
.haiku,
@@ -334,7 +334,7 @@ pub const FPSemantics = enum {
334334
.spirv32,
335335
.spirv64,
336336
=> return .IEEEHalf,
337-
.x86, .x86_64 => if (std.Target.x86.featureSetHas(target.cpu.features, .sse2)) return .IEEEHalf,
337+
.x86, .x86_64 => if (target.cpu.has(.x86, .sse2)) return .IEEEHalf,
338338
else => {},
339339
}
340340
return null;
@@ -399,7 +399,7 @@ pub fn defaultFpEvalMethod(target: std.Target) LangOpts.FPEvalMethod {
399399
return .double;
400400
}
401401
}
402-
if (std.Target.x86.featureSetHas(target.cpu.features, .sse)) {
402+
if (target.cpu.has(.x86, .sse)) {
403403
return .source;
404404
}
405405
return .extended;
@@ -765,7 +765,7 @@ test "target size/align tests" {
765765
.specifier = .char,
766766
};
767767

768-
try std.testing.expectEqual(true, std.Target.arm.featureSetHas(comp.target.cpu.features, .has_v7));
768+
try std.testing.expectEqual(true, comp.target.cpu.has(.arm, .has_v7));
769769
try std.testing.expectEqual(@as(u64, 1), ct.sizeof(&comp).?);
770770
try std.testing.expectEqual(@as(u64, 1), ct.alignof(&comp));
771771
try std.testing.expectEqual(true, ignoreNonZeroSizedBitfieldTypeAlignment(comp.target));

lib/compiler/aro/aro/toolchains/Linux.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub fn buildLinkerArgs(self: *const Linux, tc: *const Toolchain, argv: *std.Arra
318318

319319
fn getMultiarchTriple(target: std.Target) ?[]const u8 {
320320
const is_android = target.abi.isAndroid();
321-
const is_mips_r6 = std.Target.mips.featureSetHas(target.cpu.features, .mips32r6);
321+
const is_mips_r6 = target.cpu.has(.mips, .mips32r6);
322322
return switch (target.cpu.arch) {
323323
.arm, .thumb => if (is_android) "arm-linux-androideabi" else if (target.abi == .gnueabihf) "arm-linux-gnueabihf" else "arm-linux-gnueabi",
324324
.armeb, .thumbeb => if (target.abi == .gnueabihf) "armeb-linux-gnueabihf" else "armeb-linux-gnueabi",

lib/compiler_rt/aarch64_outline_atomics.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const builtin = @import("builtin");
33
const std = @import("std");
44
const linkage = @import("./common.zig").linkage;
5-
const always_has_lse = std.Target.aarch64.featureSetHas(builtin.cpu.features, .lse);
5+
const always_has_lse = builtin.cpu.has(.aarch64, .lse);
66

77
/// This default is overridden at runtime after inspecting CPU properties.
88
/// It is intentionally not exported in order to make the machine code that

lib/compiler_rt/atomics.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const supports_atomic_ops = switch (arch) {
1919
// operations (unless we're targeting Linux, the kernel provides a way to
2020
// perform CAS operations).
2121
// XXX: The Linux code path is not implemented yet.
22-
!std.Target.arm.featureSetHas(builtin.cpu.features, .has_v6m),
22+
!builtin.cpu.has(.arm, .has_v6m),
2323
else => true,
2424
};
2525

@@ -30,7 +30,7 @@ const largest_atomic_size = switch (arch) {
3030
// On SPARC systems that lacks CAS and/or swap instructions, the only
3131
// available atomic operation is a test-and-set (`ldstub`), so we force
3232
// every atomic memory access to go through the lock.
33-
.sparc => if (std.Target.sparc.featureSetHas(builtin.cpu.features, .hasleoncasa)) @sizeOf(usize) else 0,
33+
.sparc => if (builtin.cpu.has(.sparc, .hasleoncasa)) @sizeOf(usize) else 0,
3434

3535
// XXX: On x86/x86_64 we could check the presence of cmpxchg8b/cmpxchg16b
3636
// and set this parameter accordingly.

lib/compiler_rt/common.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub fn F16T(comptime OtherType: type) type {
114114
.spirv32,
115115
.spirv64,
116116
=> f16,
117-
.hexagon => if (std.Target.hexagon.featureSetHas(builtin.target.cpu.features, .v68)) f16 else u16,
117+
.hexagon => if (builtin.target.cpu.has(.hexagon, .v68)) f16 else u16,
118118
.x86, .x86_64 => if (builtin.target.os.tag.isDarwin()) switch (OtherType) {
119119
// Starting with LLVM 16, Darwin uses different abi for f16
120120
// depending on the type of the other return/argument..???

lib/compiler_rt/count0bits.zig

+1-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ fn clzsi2_generic(a: i32) callconv(.c) i32 {
142142
pub const __clzsi2 = switch (builtin.cpu.arch) {
143143
.arm, .armeb, .thumb, .thumbeb => impl: {
144144
const use_thumb1 =
145-
(builtin.cpu.arch.isThumb() or
146-
std.Target.arm.featureSetHas(builtin.cpu.features, .noarm)) and
147-
!std.Target.arm.featureSetHas(builtin.cpu.features, .thumb2);
145+
(builtin.cpu.arch.isThumb() or builtin.cpu.has(.arm, .noarm)) and !builtin.cpu.has(.arm, .thumb2);
148146

149147
if (use_thumb1) {
150148
break :impl __clzsi2_thumb1;

0 commit comments

Comments
 (0)