-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
std.Target
: Introduce Cpu
convenience functions for feature tests
#23873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
0a90f5d
to
df3391c
Compare
pub fn has(cpu: Cpu, comptime family: Arch.Family, feature: @field(Target, @tagName(family)).Feature) bool { | ||
if (family != cpu.arch.family()) return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit torn between the current behavior here and assert(family == cpu.arch.family())
. I like that the current behavior lets you check the family and feature(s) at the same time, but I can also see an argument that asserting might help catch bugs. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick grep shows a bunch of if (is_xyz_cpu) std.Target.xyz.featureSetHas()
instances and honestly, I can't imagine a scenario where asserting could be helpful to catch a bug.
df3391c
to
c0355e3
Compare
Admittedly, this will sound a bit off-topic, but there's a trivial stylistic nitpick that I have in regards to
There's also Although, I guess these're all breaking changes, technically. |
The problem with those, in my view, is that it's a case where Zig's style clashes with good taste. For example, because we write it as I'm hoping we can just neatly side-step most of this problem with #20690 and #23530. |
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 })
c0355e3
to
e8cba85
Compare
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 })
This is not necessarily the final shape I'd like this API to have; just putting this option up for discussion.