307 Commits

Author SHA1 Message Date
Alex Rønne Petersen 9e1e54d324 compiler-rt: additionally export __trunctfhf2 as __trunckfhf2 on powerpc
This is the name LLVM 22 expects.
2026-04-25 21:54:47 +02:00
Sertonix 084eab03d7 compiler_rt: Fix extern mem{set,cpy,move} type on arm
Otherwise gcc will refuse to compile the bootstrap compiler_rt.c.
Excerpt of the errors:

/builds/sertonix/aports/community/zig/src/zig-0.16.0/build/compiler_rt.c:1459:21: error: conflicting types for 'memcpy'; have 'uint8_t *(uint8_t *, const uint8_t *, uintptr_t)' {aka 'unsigned char *(unsigned char *, const unsigned char *, unsigned int)'}
 1459 | zig_extern uint8_t *memcpy(uint8_t *a0 zig_nonstring, uint8_t const *a1 zig_nonstring, uintptr_t a2);
      |                     ^~~~~~
/builds/sertonix/aports/community/zig/src/zig-0.16.0/stage1/zig.h:510:18: note: previous declaration of 'memcpy' with type 'void *(void *, const void *, unsigned int)'
  510 | zig_extern void *memcpy (void *zig_restrict, void const *zig_restrict, size_t);
      |                  ^~~~~~
/builds/sertonix/aports/community/zig/src/zig-0.16.0/build/compiler_rt.c: In function 'zig_e___negxf2':
/builds/sertonix/aports/community/zig/src/zig-0.16.0/build/compiler_rt.c:1758:9: error: passing argument 1 of 'memcpy' from incompatible pointer type [-Wincompatible-pointer-types]
 1758 |  memcpy(&t0, &a0, 16);
      |         ^~~
      |         |
      |         zig_u128 *
2026-04-23 08:42:53 +02:00
Pavel Verigo 2c5f2d67c1 Revert "compiler-rt: disable some limb64 tests on some big-endian targets"
This reverts commit 9125e24909.
2026-04-18 18:47:29 +02:00
Pavel Verigo 70c4b2424b limb64: make fixLastLimb endian aware 2026-04-18 18:47:17 +02:00
Alex Rønne Petersen adb1f3efc2 Merge pull request 'test: reinstate compiler-rt and zigc tests with different LLVM bug workarounds' (#31909) from alexrp/zig:reinstate-tests into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31909
2026-04-17 12:04:30 +02:00
Alex Rønne Petersen 9125e24909 compiler-rt: disable some limb64 tests on some big-endian targets
https://codeberg.org/ziglang/zig/issues/31905
2026-04-16 17:46:29 +02:00
rpkak f564a7733c remove code, which is only reached if c_longdouble is only 16 or 32 bits big 2026-04-16 07:05:31 +02:00
Christophe Delage a999fc9059 Add @exp(f128) and @exp2(f128) 2026-04-16 00:55:54 +02:00
Andrew Kelley e00b5daa1f Merge pull request 'stage2-wasm: finish bigint support' (#31784) from pavelverigo/zig:wasm-bigint-finish into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31784
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-15 23:07:40 +02:00
Alex Rønne Petersen 08850cfcb2 compiler-rt: export __stack_chk_guard as __guard_local on OpenBSD
closes https://codeberg.org/ziglang/zig/issues/31867
2026-04-15 16:22:54 +02:00
Pavel Verigo 773def30c2 stage2-wasm: fix bug in big endian limb64 + tiny fixes 2026-04-09 00:15:33 +02:00
Pavel Verigo ed9b0655f7 stage2-wasm: introduce __u?(div|mod)ei5, revert prev approach
Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
2026-04-09 00:14:09 +02:00
Pavel Verigo aa7874657b stage2-wasm: bigint div mod rem 2026-04-09 00:14:09 +02:00
Pavel Verigo df79ea941b stage2-wasm: bigint abs + test min/max 2026-04-09 00:14:09 +02:00
Pavel Verigo 0ebd270d90 stage2-wasm: bigint mulo 2026-04-09 00:14:08 +02:00
Pavel Verigo 58944586be stage2-wasm: bigint support bitops and intcast 2026-04-09 00:14:08 +02:00
mihael 4ccac1de41 compiler_rt: Make long double trig impls non-generic 2026-04-02 23:54:20 +02:00
mihael ad10c76007 compiler_rt: Stop using dunders for trig functions names
Additionally, use `std.math.pi / 4.0` for `pi/4` in `trig.zig`
instead of hardcoding the value.
2026-04-02 23:54:20 +02:00
mihael 61161132b6 compiler_rt: Dissolve math_utils.zig into long_double.zig & trig.zig
The closest namespace the pi/4 constant could belong to is `trig.zig` since
it's used across trig function implementations. On the other hand, chucking
`long double` bit slicing functions into `trig.zig` seems a little more
awkward, so they're put into their own namespace.
2026-04-02 23:54:20 +02:00
mihael f6ac1a6e05 compiler_rt: Symbolically link cosl & sinl impl to __cosl & __sinl
Some of the functions (e.g., `lgammal`) depended on the `__sinl` and
`__cosl`
functions being present.
2026-04-02 23:54:20 +02:00
mihael 9a53be5fb4 libzigc/math: Implement more precise sincosl in compiler_rt
The changes were tested by running:
```bash
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=sincosl -fqemu -fwasmtime --summary line
Build Summary: 369/369 steps succeeded
```

Additionally, I've added unit tests for `sincos`.
2026-04-02 23:54:20 +02:00
mihael a6d6af947d libzigc/math: Implement more precise cosl in compiler_rt
The implementation was ported from `musl`. Unit tests for `f80` and `f128` were also added.
`__cosl` was already implemented in `trig.zig` while working on `sinl`.

The changes were tested by running:
```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter='math.cosl' -fqemu -fwasmtime --summary line
Build Summary: 553/553 steps succeeded
```
2026-04-02 23:54:20 +02:00
mihael b5ec3e597e libzigc/math: Implement more precise sinl in compiler_rt
The implementation was ported from `musl`. Unit tests for `f80` and `f128` were also added.

The changes were tested by running:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=sinl -fqemu -fwasmtime --summary line
Build Summary: 553/553 steps succeeded
```
2026-04-02 23:54:20 +02:00
mihael ffd6f6cc6e libzigc/math: Implement more precise tanl in compiler_rt
The logic was more or less ported from `musl`, with small adjustments
where it was convenient. The 'internal' `__tanl` function was implemented
in the `trig.zig` module along with other 'internal' trigonometric functions.

Now, the `tanl` implementation is precise enough to pass all the relevant `libc-test` suite tests:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=tanl -fqemu -fwasmtime --summary line
Build Summary: 553/553 steps succeeded
```

The unit tests were also extended to include cases for `f80` and `f128`, and they're passing.
2026-04-02 23:54:20 +02:00
mihael c76644caf3 libzigc/math: Port rem_pio2l from musl to compiler_rt
Additionally, add helper functions for fetching the sign+exponent
and top 16 bits of a f80/f128's mantissa.

We'll need these functions to implement `cosl`, `sinl`, `tanl`, and,
transitively, `sincosl`.
2026-04-02 23:54:20 +02:00
Pavel Verigo 557caecaaa stage2-wasm: start big int support 2026-04-02 15:48:43 +02:00
Matthew Lugg b36cfc6352 compiler-rt: work around LLVM not respecting -fno-builtin 2026-03-28 19:25:01 +00:00
squidy239 4c3877069d remove various workarounds for issues that are now fixed (#31567)
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31567
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: squidy239 <sachabarsayuracko@gmail.com>
Co-committed-by: squidy239 <sachabarsayuracko@gmail.com>
2026-03-20 19:58:33 +01:00
Koko Bhadra 4fa465fc8f compiler_rt: optimize udivmod large-divisor case with trial quotient
Replace the O(n) shift-subtract loop with a constant-time trial
quotient approach (Knuth Algorithm D, TAOCP Vol 2 Section 4.3.1).

The old code iterates clz(b_hi)-clz(a_hi)+1 times (up to 64
iterations of 128-bit arithmetic). The new code uses a single
divwide call to get a trial quotient, then verifies with two
native-width widening multiplies.

Benchmark (Apple M1, ReleaseFast):
- Large divisor, large shift: 87ns -> 7.5ns (11.5x faster)
- Small divisor / uniform: unchanged
2026-03-05 20:22:19 +01:00
Chris Boesch 07b08b9638 compiler_rt: Implemented missing handling of denormal numbers when dividing f128 (#30198)
Replaces the "flush denormals to zero" placeholder in divtf3.zig with IEEE 754 denormal support including rounding.

fixes #30179

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30198
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Chris Boesch <chrboesch@noreply.codeberg.org>
Co-committed-by: Chris Boesch <chrboesch@noreply.codeberg.org>
2026-02-13 20:49:14 +01:00
Andrew Kelley 74608293af compiler_rt: common -> compiler_rt
use the "symbol" helper function in all exports

move all declarations from common.zig to compiler_rt.zig

flatten the tree structure somewhat (move contents of tiny files into
parent files)

No functional changes.
2026-02-09 20:03:15 -08:00
Andrew Kelley 04c180c8e5 compiler_rt: partial cleanup
introduce `symbol` helper function and partially migrate to using it
2026-02-09 20:04:17 +01:00
Andrew Kelley 550da1b676 std: migrate remaining sync primitives to Io
- delete std.Thread.Futex
- delete std.Thread.Mutex
- delete std.Thread.Semaphore
- delete std.Thread.Condition
- delete std.Thread.RwLock
- delete std.once

std.Thread.Mutex.Recursive remains... for now. it will be replaced with
a special purpose mechanism used only by panic logic.

std.Io.Threaded exposes mutexLock and mutexUnlock for the advanced case
when you need to call them directly.
2026-02-02 18:57:17 -08:00
rpkak 08d37d6e14 compiler_rt: fix sqrtf implementation; libc: remove sqrt implementations 2026-01-10 00:09:54 +01:00
David Rubin 938efe4aab compiler-rt: fix f80 ceil/floor optimization
Our implementation did the classic add-sub rounding trick `(y = x +/- C =+ C - x)`
with `C = 1 / eps(T) = 2^(mantissa - 1)`. This approach only works for values whose
magnitude is below the rounding capacity of the constant. For a 64-bit mantissa
(like f80 has), `C = 2^63` only rounds for `|x| < 2^63`. Before we allowed this to
be ran on `e < bias + 64` aka `|x| < 2^64`. And because it isn't large enough,
we lose a bit to rounding.

For reference, the musl implementation does the same thing, using `mantissa - 1`:
https://git.musl-libc.org/cgit/musl/tree/src/math/ceill.c#n18
where `LDBL_MANT_DIG` is 64 for `long double` on x86.

This commit also combines the floor and ceil implementations into one generic one.
2026-01-08 00:45:52 +01:00
Alex Rønne Petersen 50422d5c37 Merge pull request 'libc: remove most symbols already present in compiler_rt' (#30648) from mercenary/zig:2879-rt into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30648
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-01-05 15:49:55 +01:00
rpkak 8109766927 compiler_rt: fix exp, exp2, log, log10 and log2
the log update is a port of the current version from musl
2026-01-04 19:23:43 +01:00
Andrew Kelley b64491f2d6 compiler_rt: ensure no std.Io used when not testing 2026-01-04 00:27:08 -08:00
Michael Dusan 8fdfeb624d openbsd: fix OS version detection
- do not include resulting nullz from sysctl MIB fetch
- fixes bug: "7.8<NULL>" is a std.Target.Query.parseVersion error
2025-12-23 22:15:11 -08:00
Alex Rønne Petersen da9733d441 compiler-rt: implement __clear_cache() for arm/mips64-openbsd 2025-12-16 06:25:15 +01:00
Alex Rønne Petersen 672ce9e919 compiler-rt: export __stack_chk_fail as __stack_smash_handler on openbsd 2025-12-16 06:24:49 +01:00
Alex Rønne Petersen d5e3c8a2aa compiler-rt: disable extenddftf2 test on powerpc
This fails on a pwr10 machine.
2025-12-16 06:22:40 +01:00
Ali Cheraghi dec1163fbb all: replace all @Type usages
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-11-22 22:42:38 +00:00
Matthew Lugg 9c45a87490 compiler_rt: fix and simplify additional Windows exports
Simplifies the logic, clarifies the comment, and fixes a minor bug,
which is that we exported the Windows ABI name *instead* of the standard
compiler-rt name, but it's meant to be exported *in addition* to the
standard name (this is LLVM's behavior and it is more useful).
2025-11-15 09:49:01 +00:00
Alex Rønne Petersen 9ab7eec23e represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi
Apple's own headers and tbd files prefer to think of Mac Catalyst as a distinct
OS target. Earlier, when DriverKit support was added to LLVM, it was represented
a distinct OS. So why Apple decided to only represent Mac Catalyst as an ABI in
the target triple is beyond me. But this isn't the first time they've ignored
established target triple norms (see: armv7k and aarch64_32) and it probably
won't be the last.

While doing this, I also audited all Darwin OS prongs throughout the codebase
and made sure they cover all the tags.
2025-11-14 11:33:35 +01:00
Matthew Lugg 20bd5e8018 compiler-rt: remove dead code
`__addosi4`, `__addodi4`, `__addoti4`, `__subosi4`, `__subodi4`, and
`__suboti4` were all functions which we invented for no apparent reason.
Neither LLVM, nor GCC, nor the Zig compiler use these functions. It
appears the functions were created in a kind of misunderstanding of an
old language proposal; see https://github.com/ziglang/zig/pull/10824.

There is no benefit to these functions existing; if a Zig compiler
backend needs this operation, it is trivial to implement, and *far*
simpler than calling a compiler-rt routine. Therefore, this commit
deletes them. A small amount of that code was used by other parts of
compiler-rt; the logic is trivial so has just been inlined where needed.
I also chose to quickly implement `__addvdi3` (a standard function)
because it is trivial and we already implement the `sub` parallel.
2025-11-12 16:00:16 +00:00
GasInfinity 55c0693c4a fix: make compiler_rt and std.Io.Writer compile on 16-bit platforms. 2025-10-27 11:17:48 +01:00
mlugg 7a5d2a196f tweak tests to avoid timeouts 2025-10-18 09:28:42 +01:00
Zhenming Lin 9bfd4c3017 improve impl of __sqrth, sqrtf, sqrt, __sqrtx and sqrtq (#25416)
The previous version (ported from musl) used bit-by-bit calculations and was slow, but the current version (also ported from musl) uses lookup tables combined with Goldschmidt iterations to significantly improve the speed.
2025-10-06 11:45:51 -07:00
Zhenming-Lin 99323a4da1 improve impl of __floorh, __floorx, __ceilh and __ceilx 2025-09-24 20:57:25 -07:00