62 Commits

Author SHA1 Message Date
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
kcbanner
77084093d8 cbe: handle building for -msvc using clang and -gnu using msvc 2023-01-23 13:48:37 -05:00
kcbanner
0d249e558a cbe: fixup handling of c_longdouble for msvc abi 2023-01-23 13:48:36 -05:00
kcbanner
a7209e7d12 cbe: fixup zig_export for x86 2023-01-23 13:48:36 -05:00
kcbanner
b22b84de9d cbe: fixup x86 atomics
- add zig_msvc_atomic_barrier()
- fix zig_msvc_atomic_load_p32
2023-01-23 13:48:36 -05:00
kcbanner
1aa2c32055 cbe: fixes for x86
- Emit calling convention
- Fix .Naked handling for msvc
- Add teb helper for x86
- Fix 128-bit shl implementation when rhs is >= 64
- Add 128-bit shl tests
2023-01-23 13:48:36 -05:00
Michael Dusan
db7b36f3fc zig.h: do not assume __GNUC__ is not clang (#2)
I missed this edit in 176940b5045ff0c9b20f9951dca34b2a1bb7edc0 .
2023-01-06 01:32:13 -05:00
Michael Dusan
176940b504 zig.h: do not assume __GNUC__ is not clang
A followup to 5bd69c655d9e04102c8a64ced1215c9d69f4f03f .

For compatibility purposes clang defines __GNUC__. This broke logic
where clang14 __has_builtin returns false but `|| defined(__GNUC__)`
made it true.

CI did not catch this because it uses clang15. However, bootstrapping
with latest apple compiler is clang14. We also want to support older
clang.
2023-01-05 15:25:35 -07:00
kcbanner
ee9a793d83 zig.h: fixup for -Wexpansion-to-defined 2023-01-04 02:23:15 -05:00
kcbanner
6d0c921379 cbe: revert movement of zig_float_from_repr to before float typedefs 2023-01-04 01:26:02 -05:00
Andrew Kelley
5bd69c655d zig.h: support GCC compilers that lack __has_builtin 2023-01-03 03:21:53 -05:00
kcbanner
45a55df12c cbe: fixups for -Wstrict-prototypes 2023-01-02 13:56:32 -07:00
kcbanner
cac652f81b cbe: fixup cpuid on non-msvc 2023-01-02 13:56:17 -07:00
kcbanner
ccf0ab0ef6 cbe: use callconv(.C) for zig.g stub functions, use zig.h function for windows teb instead of syscall 2023-01-02 13:56:11 -07:00
kcbanner
6cab3c304e cbe: be more explicit about x86 special cases 2023-01-02 13:55:45 -07:00
kcbanner
676e4f3824 cbe: changes to get zig2.c compiling under msvc
- Add cpuid / getXCR0 functions for the cbe to use instead of asm blocks
- Don't cast between 128 bit types during truncation
- Fixup truncation to use functions for shifts / adds
- Fixup float casts for undefined values
- Add test for 128 bit integer truncation
2023-01-01 16:44:29 -05:00
kcbanner
f07d33f54b cbe: fixes for compiling zig2.c under msvc
- add zig_mul_i128
- render slice structs in static initializers without casts / c99 style init
- add negative numbers and u128 to 128-bit multiply test
2023-01-01 16:44:29 -05:00
kcbanner
55c3551bef cbe: fixup 64 bit float atomics 2023-01-01 16:44:29 -05:00
kcbanner
7a20e7589e stage1: update zig1.wasm 2023-01-01 16:44:29 -05:00
kcbanner
5d59799641 cbe: add msvc flt atomics, re-enable test 2023-01-01 16:44:29 -05:00
kcbanner
6ed049fe36 cbe: all behaviour tests now pass on msvc
- Fix zig_clz_u128 not respecting the bits argument. This was crashing the compile-rt addxf3 tests with the cbe
- Instead of redering a negation for negative 128 bit int literals, render the literal as twos complement. This allows
rendering int representations of floats correctly (specifically f80).
2023-01-01 16:44:29 -05:00
kcbanner
7b999dae73 cbe: special float macros passthrough to builtins if available, but fallback to conversion from repr if not 2023-01-01 16:44:29 -05:00
kcbanner
5470708a89 cbe: implement 128 bit atomic operations with cmpxchg loops
- Enable 128 bit atomic int tests for the cbe only
2023-01-01 16:44:29 -05:00
kcbanner
d63b8d21b3 cbe: implement missing atomic builtings using cmpxchg loops 2023-01-01 16:44:29 -05:00
kcbanner
047fe58a53 cbe: fix msvc cmpxchg implementations 2023-01-01 16:44:28 -05:00
kcbanner
4f8f7b749c cbe: fixup incorrect bits value in 128 bit add/sub 2023-01-01 16:44:28 -05:00
kcbanner
b6f0af57a2 cbe: fix shl/shr
- zig_shr_u128 was actually shifting left
- handle shifting by zero explicitly (shifting u64 by 64 is undefined behaviour)
2023-01-01 16:44:28 -05:00
kcbanner
2d34477dbb cbe: msvc atomics
- Implement most atomic operations for msvc
- Disable "atomicrmw with floats" test for cbe
2023-01-01 16:44:28 -05:00
kcbanner
f155ef2f4b cbe: implementing 128 bit math functions for !zig_has_int128
- Add addo_(i|u)128, subo_(i|u)128, mulo_(i|u)128,
- Move zig_shlo_(i|u)128 into common code
- Fixup zig_shls_i128 passing rhs as 128
2023-01-01 16:44:28 -05:00
kcbanner
fbd3459a52 compiler_rt: fixup divti3 and fixunshfti 2023-01-01 16:44:28 -05:00
kcbanner
7fb3683c32 cbe: more msvc compatibility work
- Add .StaticInitializer to ValueRenderLocation to indicate that the emitted values
must be constant expressions (no function calls, struct casting).
- Add new path for special float types (nan, inf) that works in constant expressions
- Implement windows.teb() using a syscall for .stage2_c because x64 MSVC
doesn't support any kind of inline asm
2023-01-01 16:44:28 -05:00
kcbanner
7f3bc45772 cbe: nan builtins on msvc, fixup C2099 errors in static initializers
- Map the __builtin_nan(f|l)? functions to nan(f|l)? on msvc
- MSVC throws C2099 when initializing a struct with cast syntax
in a global initializer.  Added zig_as_init_  to handle this case,
 and generate it only in static initializers for > 64 bit ints.
- Change float initialization to emit the integer representation
in global initializers to avoid C2099 caused by calling nan.
2023-01-01 16:44:28 -05:00
kcbanner
c675a8e35c cbe: handle msvc not supporting long double 2023-01-01 16:44:28 -05:00
kcbanner
e836477ccf cbe: fixup f80 casting on msvc 2023-01-01 16:44:27 -05:00
kcbanner
7225a0043e cbe: handle msvc struct casting quirk
MSVC can't explicitly cast a struct to a typedef of itself (ie. f128 to i128). Added a
set of macros to handle float casting, and to not produce a cast for this specific
case on MSVC. A better approach would probably be to know if the cast is redundant
and not do it.
2023-01-01 16:44:27 -05:00
kcbanner
a43fdc1620 cbe: first set of changes for msvc compatibility
- Forward declare int builtins, so the definitions aren't assumed incorrectly
- Add define to handle MSVC not support static const in function parameter array lengths
- Fixup several spots where int128 support was assumed.
- Support zig_align
- Support zig_export
- Stub out some missing non-builtin functions
- Added StringLiteral to automatically split string literals when they get to 16380 in size,
which is the maxmimum pre-concatenation string literal size on MSVC.
2023-01-01 16:44:27 -05:00
Jacob Young
a2854f71dc zig.h: fix and add builtin fallbacks 2022-12-09 13:40:55 -05:00
Andrew Kelley
ee2fb5b2ab zig.h: fix f16 has builtin check 2022-12-06 12:27:28 -07:00
Jacob Young
4a701490d4 zig.h: avoid using _Float16 when __builtin_inff16 isn't available 2022-12-06 12:15:05 -07:00