Skip to content

Conversation

@alexrp
Copy link
Member

@alexrp alexrp commented May 13, 2025

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.

@alexrp alexrp marked this pull request as draft May 13, 2025 16:42
@alexrp alexrp force-pushed the target-features-api branch from 0a90f5d to df3391c Compare May 13, 2025 17:08
@alexrp alexrp force-pushed the target-features-api branch from df3391c to c0355e3 Compare May 13, 2025 17:35
@tensorush
Copy link
Contributor

tensorush commented May 14, 2025

Admittedly, this will sound a bit off-topic, but there's a trivial stylistic nitpick that I have in regards to std/Target.zig, namely, is... functions for determining arch aren't all correctly camelCased:

  • isBSD -> isBsd
  • isAARCH64 -> isAarch64
  • isRISCV -> isRiscV
  • isMIPS -> isMips
  • isMIPS32 -> isMips32
  • isMIPS64 -> isMips64
  • isPowerPC -> isPowerPc
  • isPowerPC32 -> isPowerPc32
  • isPowerPC64 -> isPowerPc64
  • isSPARC -> isSparc

There's also isMinGW, which I'd change to isMinGwLibC to match other abi-checking functions.

Although, I guess these're all breaking changes, technically.
Anyway, sorry if I'm polluting the discussion with an unrelated change.

@alexrp
Copy link
Member Author

alexrp commented May 14, 2025

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 powerpc, riscv, and spirv in snake_case, it should actually be isPowerpc, isRiscv, and isSpirv. I personally really don't like that. isAarch64 is also ugly IMO.

I'm hoping we can just neatly side-step most of this problem with #20690 and #23530.

@alexrp alexrp force-pushed the target-features-api branch 3 times, most recently from 8ed448b to e09de15 Compare May 20, 2025 16:50
@alexrp alexrp force-pushed the target-features-api branch 3 times, most recently from 1878367 to 64148cd Compare June 4, 2025 02:01
@alexrp alexrp marked this pull request as ready for review June 4, 2025 05:09
@alexrp
Copy link
Member Author

alexrp commented Jun 4, 2025

I might iterate on this further in the future, but I think this represents a pretty clear improvement on status quo, so will merge soon if no one has any objections.

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 })
@alexrp alexrp force-pushed the target-features-api branch from 64148cd to e4d043d Compare June 4, 2025 19:52
@alexrp alexrp enabled auto-merge (rebase) June 4, 2025 19:52
@alexrp alexrp merged commit 9d53479 into ziglang:master Jun 5, 2025
9 checks passed
@alexrp alexrp deleted the target-features-api branch June 5, 2025 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants