31 Commits

Author SHA1 Message Date
Alex Rønne Petersen
9d534790eb 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 })
2025-06-05 06:12:00 +02:00
Kiëd Llaentenn
d31bda13cb std.atomic: make cache_line const a comptime_int
This fixes potential issues and unintended coercions in other areas,
such as std.ArrayList.
2025-02-22 03:48:09 +01:00
Ben Grant
15fe999572 std.atomic: fix cache line size for RISC-V 2025-01-12 04:51:00 +01:00
cancername
c271fe5092
std.atomic: add a function to get the cache line size for a particular cpu (#21956) 2024-11-13 05:35:05 +01:00
Alex Rønne Petersen
be5378b038
Merge pull request #21587 from alexrp/hexagon-porting
Some initial `hexagon-linux` port work
2024-10-06 13:35:56 +02:00
David Rubin
043b1adb8d
remove @fence (#21585)
closes #11650
2024-10-04 22:21:27 +00:00
Alex Rønne Petersen
6dd19961b3
std.atomic: Provide a more accurate cache_line value for hexagon v73+. 2024-10-03 09:12:35 +02:00
Andrew Kelley
8f7cbaa4c0
Merge pull request #20870 from alexrp/target-cleanup-3
`std.Target`: Remove more dead OS/architecture tags
2024-08-01 01:32:32 -07:00
Alex Rønne Petersen
f03d54f069 std.atomic: Don't lie to the compiler about memory clobbers in spinLoopHint(). 2024-08-01 01:07:56 -07:00
Alex Rønne Petersen
c8ca05e93a
std.Target: Remove sparcel architecture tag.
What is `sparcel`, you might ask? Good question!

If you take a peek in the SPARC v8 manual, §2.2, it is quite explicit that SPARC
v8 is a big-endian architecture. No little-endian or mixed-endian support to be
found here.

On the other hand, the SPARC v9 manual, in §3.2.1.2, states that it has support
for mixed-endian operation, with big-endian mode being the default.

Ok, so `sparcel` must just be referring to SPARC v9 running in little-endian
mode, surely?

Nope:

* 40b4fd7a3e/llvm/lib/Target/Sparc/SparcTargetMachine.cpp (L226)
* 40b4fd7a3e/llvm/lib/Target/Sparc/SparcTargetMachine.cpp (L104)

So, `sparcel` in LLVM is referring to some sort of fantastical little-endian
SPARC v8 architecture. I've scoured the internet and I can find absolutely no
evidence that such a thing exists or has ever existed. In fact, I can find no
evidence that a little-endian implementation of SPARC v9 ever existed, either.
Or any SPARC version, actually!

The support was added here: https://reviews.llvm.org/D8741

Notably, there is no mention whatsoever of what CPU this might be referring to,
and no justification given for the "but some are little" comment added in the
patch.

My best guess is that this might have been some private exercise in creating a
little-endian version of SPARC that never saw the light of day. Given that SPARC
v8 explicitly doesn't support little-endian operation (let alone little-endian
instruction encoding!), and no CPU is known to be implemented as such, I think
it's very reasonable for us to just remove this support.
2024-07-30 06:30:25 +02:00
Alex Rønne Petersen
9d23e711ef
std.atomic: Implement specialized spinLoopHint() for more architectures. 2024-07-29 09:41:47 +02:00
Alex Rønne Petersen
5b68595255
std.atomic: Define specialized cache_line values for more architectures. 2024-07-29 09:41:24 +02:00
Alex Rønne Petersen
d1d95294fd std.Target.Cpu.Arch: Remove the aarch64_32 tag.
This is a misfeature that we inherited from LLVM:

* https://reviews.llvm.org/D61259
* https://reviews.llvm.org/D61939

(`aarch64_32` and `arm64_32` are equivalent.)

I truly have no idea why this triple passed review in LLVM. It is, to date, the
*only* tag in the architecture component that is not, in fact, an architecture.
In reality, it is just an ILP32 ABI for AArch64 (*not* AArch32).

The triples that use `aarch64_32` look like `aarch64_32-apple-watchos`. Yes,
that triple is exactly what you think; it has no ABI component. They really,
seriously did this.

Since only Apple could come up with silliness like this, it should come as no
surprise that no one else uses `aarch64_32`. Later on, a GNU ILP32 ABI for
AArch64 was developed, and support was added to LLVM:

* https://reviews.llvm.org/D94143
* https://reviews.llvm.org/D104931

Here, sanity seems to have prevailed, and a triple using this ABI looks like
`aarch64-linux-gnu_ilp32` as you would expect.

As can be seen from the diffs in this commit, there was plenty of confusion
throughout the Zig codebase about what exactly `aarch64_32` was. So let's just
remove it. In its place, we'll use `aarch64-watchos-ilp32`,
`aarch64-linux-gnuilp32`, and so on. We'll then translate these appropriately
when talking to LLVM. Hence, this commit adds the `ilp32` ABI tag (we already
have `gnuilp32`).
2024-07-28 19:44:52 -07:00
Michael Dusan
5ce40e61c6
bsd: debitrot AtomicOrder renames
- complete std.builtin.AtomicOrder renames that were missed from 6067d39522f
2024-03-15 02:28:50 -04:00
Tristan Ross
6067d39522
std.builtin: make atomic order fields lowercase 2024-03-11 07:09:10 -07:00
Andrew Kelley
70931dbdea rework std.atomic
* move std.atomic.Atomic to std.atomic.Value
* fix incorrect argument order passed to testing.expectEqual
* make the functions be a thin wrapper over the atomic builtins and
  stick to the naming conventions.
* remove pointless functions loadUnchecked and storeUnchecked. Instead,
  name the field `raw` instead of `value` (which is redundant with the
  type name).
* simplify the tests by not passing every possible combination. Many
  cases were iterating over every possible combinations but then not
  even using the for loop element value!
* remove the redundant compile errors which are already implemented by
  the language itself.
* remove dead x86 inline assembly. this should be implemented in the
  language if at all.
2023-11-22 19:08:55 -07:00
Andrew Kelley
edb2f72988 std: remove atomic.Queue
This was originally supposed to be a lock-free queue, but I gave up on
that and made it be a thread-safe queue instead.

Putting the mutex directly inside the queue data structure makes it
non-composeable. Instead, the recommendation is to use a normal queue
protected by an external mutex.
2023-11-22 16:39:37 -07:00
Andrew Kelley
6bd97ab640 std: remove atomic.Stack
This was originally supposed to be a lock-free stack, but I gave up on
that and made it be a thread-safe stack which is implemented poorly
using spin locks. Nobody should use this data structure.

The alternative is a normal stack protected by a mutex.
2023-11-22 16:38:26 -07:00
Andrew Kelley
1fa2e911d9 std.atomic: remove some APIs
* remove `std.atomic.Ordering`
  - it is provided by the language with `std.builtin.AtomicOrder`.
* remove `std.atomic.fence`
  - it is provided by the language with `@fence`.
* remove `std.atomic.compilerFence`
  - if this is desired, it should be a language feature, not a standard
    library function with inline asm.
2023-11-22 14:27:49 -07:00
Jacob Young
3f1c51ca90 std: remove names from incorrectly named tests
Tests that only reference decls for the purpose of analyzing more tests
should be unnamed, otherwise trying to filter for just a referenced test
can become impossible depending on the names.
2023-04-21 23:08:48 -04:00
Ali Chraghi
f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
protty
e3cbea934e
std.Thread.Futex improvements (#11464)
* atomic: cache_line

* Thread: Futex rewrite + more native platform support

* Futex: tests compile

* Futex: compiles and runs test

* Futex: broadcast test

* Futex: fix PosixImpl for tests

* Futex: fix compile errors for bsd platforms

* Futex: review changes + fix timeout=0 + more comments
2022-04-19 19:42:15 -05:00
Andrew Kelley
6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Andrew Kelley
d17f492017 stage2: miscellaneous fixes for the branch
* Breaking language change: inline assembly must use string literal
   syntax. This is in preparation for inline assembly improvements that
   involve more integration with the Zig language. This means we cannot
   rely on text substitution.
 * Liveness: properly handle inline assembly and function calls with
   more than 3 operands.
   - More than 35 operands is not yet supported. This is a low priority
     to implement.
   - This required implementation in codegen.zig as well.
 * Liveness: fix bug causing incorrect tomb bits.
 * Sema: enable switch expressions that are evaluated at compile-time.
   - Runtime switch instructions still need to be reworked in this
     branch. There was a TODO left here (by me) with a suggestion to do
     some bigger changes as part of the AIR memory reworking. Now that
     time has come and I plan to honor the suggestion in a future commit
     before merging this branch.
 * AIR printing: fix missing ')' on alive instructions.

We're back to "hello world" working for the x86_64 backend.
2021-07-20 12:19:16 -07:00
Kenta Iwasaki
4909aa1da4 os/bits: remove duplicate sockaddr_storage for dragonfly 2021-06-01 18:35:13 +09:00
protty
eb6975f088
std.sync.atomic: extended atomic helper functions (#8866)
- deprecates `std.Thread.spinLoopHint` and moves it to `std.atomic.spinLoopHint`
- added an Atomic(T) generic wrapper type which replaces atomic.Bool and atomic.Int
- in Atomic(T), selectively expose member functions depending on T and include bitwise atomic methods when T is an Integer
- added fence() and compilerFence() to std.atomic
2021-05-31 11:11:30 -05:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
daurnimator
767dd772c0
std: add std.atomic.Bool 2020-11-19 00:58:13 +11:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Andrew Kelley
ed36dbbd9c
mv std/ lib/
that's all this commit does. further commits will fix cli flags and
such.

see #2221
2019-09-25 23:35:41 -04:00