129 Commits

Author SHA1 Message Date
Alex Rønne Petersen
ace8396076
zig.h: Move some macros and includes closer to where they're used. 2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
0e934c7df1
zig.h: Use C99/C11 headers if available regardless of language standard.
If present, these headers are usable even when compiling for older C language
versions.

Most notably, this enables zig.h atomics to work with slimcc and TinyCC in C99
mode (and earlier).
2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
1c43c2c209
zig.h: Remove duplicate and unguarded stdint.h include.
We already do this for C99 only later in the file.
2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
125bf05c27
zig.h: Implement zig_unreachable() with __assume(0) for MSVC. 2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
062feb6c82
zig.h: Implement zig_frame_address() with _AddressOfReturnAddress() for MSVC. 2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
37538f19cd
zig.h: Use zig_*_windows_teb() inline assembly with TinyCC and slimcc. 2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
204df19d79
zig.h: Avoid depending on cpuid.h for zig_x86_cpuid().
Just use inline assembly instead, which is what that header does. Also make sure
we have a dummy implementation when inline assembly is unavailable.
2024-12-03 12:07:32 +01:00
Alex Rønne Petersen
24b57f4d30
zig.h: Introduce architecture macros to simplify checks throughout. 2024-12-03 11:57:21 +01:00
Alex Rønne Petersen
ba66814185
zig.h: Don't use __debugbreak() for MinGW.
It seems like only Clang supports this in MinGW mode, and Clang will already
take the __builtin_debugtrap() path anyway.
2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
d19e1919da
zig.h: Define zig_gnuc for both GCC and Clang and stop using __GNUC__.
There's only one spot in the header where we want to handle GCC but not Clang,
so just add an extra check there.
2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
dd1d9cce3c
zig.h: Add a zig_msvc macro to be used instead of _MSC_VER. 2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
f29daebd90
zig.h: Use __thread for slimcc in pre-C11 mode. 2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
fa6946f645
zig.h: Add support for C23 keywords.
The old spellings from C11 are deprecated in C23.
2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
023a7fefb1
zig.h: Add TinyCC support where appropriate.
tcc doesn't have __has_attribute and __has_builtin, so we need to manually check
for tcc in these preprocessor paths.
2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
43a1b88bc8
zig.h: Use __BYTE_ORDER__ instead of __LITTLE_ENDIAN__ for endianness check.
The former is supported by most compilers while the latter is Clang-only.
2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
aa19e71a27
zig.h: Add zig_trap() and zig_breakpoint() implementations for Hexagon. 2024-11-24 08:19:15 +01:00
Alex Rønne Petersen
6b2c8fc688 zig.h: Improve portability of zig_*_windows_teb() helpers.
* Make it work for thumb and aarch64.
* Clean up std.os.windows.teb() a bit.

I also updated stage1/zig.h since the changes are backwards-compatible and are
necessary due to the std.os.windows changes that call the newly-added functions.
2024-11-04 11:59:38 +01:00
David Rubin
043b1adb8d
remove @fence (#21585)
closes #11650
2024-10-04 22:21:27 +00:00
Alex Rønne Petersen
5daf47a212 zig.h: Improve portability of zig_trap() and zig_breakpoint(). 2024-09-23 17:34:15 -07:00
kcbanner
2a0238e5e3 zig.h: fixup pointer atomic load definitions 2024-07-26 10:42:10 -04:00
kcbanner
c318710653 zig.h: expand zig_msvc_atomic_load_ into version for relaxed, acquire, and seq_cst 2024-07-13 19:45:45 -04:00
kcbanner
bc28454b43 zig.h: replace _InterlockedExchangeAdd with a plain volatile load
This was causing zig2.exe to crash during bootstrap, because there was an atomic
load of read-only memory, and the attempt to write to it as part of the (idempotent)
atomic exchange was invalid.

Aligned reads (of u32 / u64) are atomic on x86 / x64, so this is replaced with an
optimization-proof load (`__iso_volatile_load8*`) and a reordering barrier.
2024-07-13 17:46:24 -04:00
Jacob Young
00da182e68
cbe: fix for export changes 2024-07-04 21:01:42 +01:00
kcbanner
0d12caee29 - Fix ypedef -> typedef 2024-06-21 00:12:13 -04:00
Andrew Kelley
9be8a9000f Revert "implement @expect builtin (#19658)"
This reverts commit a7de02e05216db9a04e438703ddf1b6b12f3fbef.

This did not implement the accepted proposal, and I did not sign off
on the changes. I would like a chance to review this, please.
2024-05-22 09:57:43 -07:00
David Rubin
a7de02e052
implement @expect builtin (#19658)
* implement `@expect`

* add docs

* add a second arg for expected bool

* fix typo

* move `expect` to use BinOp

* update to newer langref format
2024-05-22 10:51:16 -05:00
Jacob Young
e8dd79ca67 cbe: fix ub with integer @abs 2024-04-30 22:09:54 -07:00
Jacob Young
fb192df4f2 cbe: fix uncovered bugs 2024-03-30 20:50:48 -04:00
Jacob Young
6f10b11658 cbe: fix bugs revealed by an upcoming commit
Closes #18023
2024-03-30 20:50:48 -04:00
Jacob Young
047d6d996e cbe: fix non-msvc externs and exports
Closes #17817
2024-01-03 02:52:25 -05:00
Jacob Young
98b633ff17 Reapply "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 2b589783602c5428ecde9dbb3f41a81f85eb0f25.
2024-01-03 02:41:21 -05:00
Andrew Kelley
2b58978360 Revert "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 7161ed79c4abcaccdd56fe0b4fbd3d93472d41b8, reversing
changes made to 3f2a65594e1d3c0a4f4943a4ea522e8405db81e0.

Unfortunately, this sat in the PR queue too long and the merge broke the
zig1.wasm bootstrap process.
2024-01-01 17:49:57 -07:00
Andrew Kelley
7161ed79c4
Merge pull request #17824 from kcbanner/fixup_msvc_fmax
cbe: add a system for avoiding collisions with C compiler intrinsics
2024-01-01 15:36:16 -08:00
Jacob Young
0dbaa8d3ae zig.h: workaround for gcc f128 miscompilations 2023-11-12 17:30:24 -07:00
kcbanner
50e2fb8fd0 cbe: fixup __asm style exports, re-enable 12680 on macos now that alias isn't used 2023-11-05 23:36:11 -05:00
kcbanner
a4526d260b cbe: fix builtins not being used by zig_import when they are available 2023-11-05 20:34:13 -05:00
kcbanner
26dabbf301 cbe: handle underscore prexfix on macos, don't mangle extern function names 2023-11-05 20:34:13 -05:00
kcbanner
192e9a315d cbe: add DeclVisibility and zig_extern_mangled to handle exporting mangled symbols under a different name 2023-11-05 20:34:13 -05:00
kcbanner
ce293c982e cbe: avoid collisions with builtins and intrinsics
Changes:
- Add `isMangledIdent` to determine if `fmtIdent` would make any edits to the identifier
- Any function that has a mangled identifier is referred to using the mangled identifer
  within the current file, but if it is exported the first export will be with the non-mangled name.
- Add `zig_import` to import a symbol under a different name
- Add a level of indirection to float function names. Now, they are referred to as
  `zig_float_fn_<float type>_<operation>`. The definitions in zig.h are wrapped
  with `zig_import` to import the symbol under the real name.

The specific problem that sparked this change was the combination of
`zig_libc_name_f80(name) __##name##x` with the input `fma`, resulting
in `__fmax`, which is a new intrinsic in recent versions of cl.exe.

With the above changes in place, compiler_rt can output the following:

```
static zig_weak_linkage_fn zig_f80 zig_e___fmax(zig_f80, zig_f80, zig_f80);
zig_export(zig_weak_linkage_fn zig_f80 zig_e___fmax(zig_f80, zig_f80, zig_f80), __fmax, "__fmax");
```

Within compiler_rt, `zig_e___fmax` is used to refer to the function, but consumers
will import `__fmax`, which maps to their `zig_float_fn_f80_fma` definition from zig.h.
2023-11-05 20:34:13 -05:00
antlilja
bcf4a13913 Remove @fabs, fabs and absCast/Int from std lib
Replaces occurences of @fabs absCast and absInt with new @abs builtin.
Also removes the std.math.fabs alias from math.zig.
2023-09-27 11:24:28 -07:00
Michael Dusan
127198e58c cbe: support more symbol attributes
implement codegen for:

- decl weak linkage
- decl aliases
- fn decl weak linkage

windows msvc:
- `__declspec(selectany)` is not supported for functions
- skip weak linkage for functions

closes #17050
2023-09-24 14:44:15 -07:00
Jacob Young
9831f27238 cbe: get behavior tests running on arm
Specifically without linking libc.
2023-07-31 01:58:10 -04:00
Jacob Young
78eb3c5617 bootstrap: support aarch64 in 32-bit mode
* `CMakeLists.txt`: support the weird `uname -m` output.
 * `CMakeLists.txt`: detect and use the C compiler's default arm mode.
 * cbe: support gcc with both `f128` and `u128` emulated.
 * std.os.linux.thumb: fix incorrectly passed asm inputs.
2023-07-04 15:47:07 -07:00
Jacob Young
2e6a6d7564 llvm/cbe: fix signed @mod/@divFloor computations
Closes #15636
2023-05-10 15:11:52 -04:00
Jacob Young
f1782c07a9 cbe: implement @extern 2023-04-25 13:42:10 -04:00
Jacob Young
f5cf732659 zig.h: add missing msvc atomics 2023-04-22 01:16:25 -04:00
Jacob Young
5feb27c126 zig.h: fix float negation 2023-04-21 23:08:48 -04:00
Jacob Young
d56c6c7791 cbe: implement 128-bit atomics support
* Disable 128-bit atomics for x86_64 generic (currently also baseline)
   because they require heavy abi agreement to correctly lower.
   ** This is a breaking change **
 * Enable 128-bit atomics for aarch64 in Sema since it just works.
2023-04-21 16:36:31 -04:00
Jacob Young
5afaaf865f zig.h: fix msvc abi for f128 with a gnu compiler 2023-04-21 16:36:31 -04:00
Jacob Young
e364627e3e cbe: fix float casts involving f16
Fixes bugs with a previous fix to the f16 abi on x86 darwin.
2023-04-21 16:36:31 -04:00