Commit Graph

100 Commits

Author SHA1 Message Date
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 2b58978360.
2024-01-03 02:41:21 -05:00
Andrew Kelley
2b58978360 Revert "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 7161ed79c4, reversing
changes made to 3f2a65594e.

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
Jacob Young
b45bcd6420 cbe: fix f128 and c_longdouble abi
Fixes the abi of `f128` on darwin and/or aarch64.  Also, when `double`
and `long double` were the same size, we used to incorrectly define
`zig_c_longdouble` as `zig_f128`.
2023-04-21 16:36:31 -04:00
Jacob Young
d9596a128f zig.h: fix typos affecting msvc 2023-04-21 16:36:31 -04:00
Jacob Young
d98974e826 cbe: fix issues with atomic floats
Since the Zig language documentation claims support for `.Min` and
`.Max` in `@atomicRmw` with floats, allow in Sema and implement for both
the llvm and C backends.
2023-04-21 16:36:30 -04:00
Jacob Young
bf6fd9ae3f cbe: enable CI for std tests 2023-04-21 16:36:10 -04:00
Andrew Kelley
aa45854ec3 zig.h: fix typo for zig_trap definition 2023-04-08 09:54:32 -07:00
Andrew Kelley
ef5afbfcf4 zig.h: f16 fix for compiler_rt
See #15092
2023-04-06 08:40:02 -07:00
Andrew Kelley
f289277599 Merge remote-tracking branch 'origin/master' into llvm16 2023-04-05 22:05:31 -07:00
Jacob Young
5870ffeb82 compiler_rt: change the abi of f16 on mac to depend on the other type 2023-04-05 22:05:10 -07:00
Jacob Young
243848167b compiler_rt: attempt to fix f16 abi on mac with llvm 16 2023-04-05 22:05:06 -07:00
Jacob Young
9c3bea8482 zig.h: fix non-msvc warnings in msvc code 2023-03-30 12:07:12 +03:00
Jacob Young
e33dfc300e zig.h: implement zig_breakpoint and zig_trap for more targets 2023-03-07 12:46:35 -05:00
Jacob Young
77d06012c2 CBE: implement unsigned big int div and mod 2023-03-07 03:03:35 -05:00
Andrew Kelley
34a23db664 zig.h: lower trap to SIGTRAP instead of SIGILL 2023-03-05 17:11:46 -07:00
Jacob Young
c478c7609e CBE: implement vector operations
Also, bigint add and sub which is all I was actually trying to do.
2023-03-05 02:59:02 -05:00
Jacob Young
9e3a5ecd39 CBE: fix behavior test failures on msvc 2023-03-05 02:59:02 -05:00
Jacob Young
e96a0fd0a1 CBE: "compute" max int alignment the lazy way 2023-03-05 02:59:01 -05:00
Jacob Young
93d696e84e CBE: implement some big integer and vector unary operations 2023-03-05 02:59:01 -05:00
Jacob Young
a8f4ac2b94 CBE: implement big integer and vector comparisons 2023-03-05 02:59:01 -05:00
Jacob Young
874ae81f1b CBE: implement big integer literals 2023-03-05 02:59:01 -05:00
r00ster91
65368683ad add @trap builtin
This introduces a new builtin function that compiles down to something that results in an illegal instruction exception/interrupt.
It can be used to exit a program abnormally.

This implements the builtin for all backends.
2023-03-04 12:08:19 +01:00
Jacob Young
9d24d0354f CBE: fix MSVC diagnostics generated by the behavior tests
After this, the last MSVC warnings are in behavior/bugs/529.zig:
behavior.c(37971): warning C4133: 'function': incompatible types - from 'A__8479 *' to 'A__8474 *'
behavior.c(37974): warning C4133: 'function': incompatible types - from 'A__8480 *' to 'A__8474 *'
2023-02-23 20:30:59 -05:00
Jacob Young
a0d7fd162b CBE: support call attributes
* Support always_tail and never_tail/never_inline with a comptime callee using clang
 * Support never_inline using gcc
 * Support never_inline using msvc

Unfortunately, can't enable behavior tests because of the conditional support.
2023-02-23 10:54:26 -05:00
Jacob Young
57f6adf85d CBE: implement c varargs
Removed some backend test skip checks for things disabled in std.
2023-02-23 01:21:59 -05:00
Jacob Young
248fb40dcc CBE: fix windows test failures 2023-02-21 15:46:34 -05:00
Jacob Young
25a3c933b9 CBE: fix test failures 2023-02-21 02:32:49 -05:00
Jacob Young
b76fed8206 zig.h: get no int128 path working on non-msvc 2023-02-21 00:27:12 -05:00
Jacob Young
3eed197c95 CBE: use stdint.h types instead of zig_ prefixes
This requires manual defines before C99 which may not have stdint.h.

Also have update-zig1 leave a copy of lib/zig.h in stage1/zig.h, which
allows lib/zig.h to be updated without needing to update zig1.wasm.
Note that since the object already existed with the exact same contents,
this completely avoids repo bloat due to zig.h changes.
2023-02-20 23:59:48 -05:00
kcbanner
a9b68308b9 cbe: fixes for tls, support for not linking libc, and enabling tests
- cbe: Implement linksection support, to support TLS when not linking libc
- cbe: Support under-aligned variables / struct fields
- cbe: Support packed structs (in the C definition of packed)
- windows: Fix regression with x86 _tls_array
- compiler_rt: Add 128-bit atomics to compiler_rt
- tests: Re-enable threadlocal tests on cbe+windows, and llvm+x86
- tests: Re-enable f80 tests that now pass
- ci: change windows ci to run the CBE behaviour tests with -lc, to match how the compiler is bootstrapped
- update zig1.wasm
2023-01-29 15:04:13 -05:00
kcbanner
c7a9c28310 update zig1.wasm 2023-01-23 13:48:37 -05:00