116 Commits

Author SHA1 Message Date
Andrew Kelley
783cb980ab Release 0.7.1 2020-12-13 12:14:58 -07:00
Andrew Kelley
cf0e453cc9 Merge pull request #7406 from ifreund/dyn-musl2
stage2: support dynamically linking musl libc
2020-12-12 16:52:55 -07:00
Andrew Kelley
9d2e5bbcb4 glibc: do not provide -lcrypt
glibc is dropping this functionality moving forward.

This is a partial revert of commit
97c0e1cc41
2020-12-12 12:44:41 -07:00
Andrew Kelley
a42c712934 std.fs.path.extension: different behavior for ending dot
extension("a.") now returns "." instead of "".

This matches both Python and Node.js standard library behavior as well
as my personal opinion on how this function should be defined.

Apologies for missing this in the code review.
2020-12-11 18:23:57 -07:00
Andrew Kelley
1bbf731e7e stage2: proper file extension stripping
Previously it used mem.split on "." and took the first iterated item.
Now it uses fs.path.extension and strips off that number of bytes.

Closes #7404
2020-12-11 17:44:33 -07:00
Andrew Kelley
a6de0b4136 std.fs.path.extension: add additional API guarantee
Added:

The returned slice is guaranteed to have its pointer
within the start and end pointer address range of `path`,
even if it is length zero.
2020-12-11 17:44:27 -07:00
Andrew Kelley
5df9f15843 Merge pull request #7098 from MasterQ32/std.fs.path.extension
Implements std.fs.path.extension
2020-12-11 17:44:19 -07:00
Andrew Kelley
4797fdb3db fix deadlock with build-exe on an object for windows
The steps to repro this issue are:

zig build-obj hello.zig -target x86_64-windows-msvc
zig build-exe hello.obj -target x86_64-windows-msvc --subsystem console
-lkernel32 -lntdll

What was happening is that the main Compilation added a work item to
produce kernel32.lib. Then it added a sub-Compilation to build zig's
libc, which ended up calling a function with extern "kernel32", which
caused the sub-Compilation to also try to produce kernel32.lib. The main
Compilation and sub-Compilation do not coordinate about the set of
import libraries that they will be trying to build, so this caused a
deadlock.

This commit solves the problem by disabling the extern "foo" feature
from working when building compiler_rt or libc. Zig's linker code is now
responsible for putting the appropriate import libs on the linker line,
if any for compiler_rt and libc.

Related: #5825
2020-12-11 17:23:55 -07:00
Andrew Kelley
74c17aa8c5 mingw-w64: add .def files for xinput1_4
closes #7398
2020-12-11 17:23:50 -07:00
Andrew Kelley
465b90c1fa mingw-w64: add support for -lwldap32
closes #7395
2020-12-11 00:51:28 -07:00
LemonBoy
00664dbdce zig fmt: Fix alignment of initializer elements
Resetting `column_counter` is not needed as the effective column number
is calculated by taking that value modulo `row_size`.

Closes #7289
2020-12-11 00:40:05 -07:00
Vexu
c9bc8b9d0c zig fmt: improve var decl initializer formatting 2020-12-11 00:39:52 -07:00
Andrew Kelley
fd4c98cbb7 stage2: detect redundant C/C++ source files
Cache exposes BinDigest.

Compilation gains a set of a BinDigest for every C/C++ source file. We
detect when the same source/flags have already been added and emit a
compile error. This prevents a deadlock in the caching system.

Closes #7308
2020-12-11 00:33:59 -07:00
Andrew Kelley
21236c0151 CLI: improved local cache directory logic
Previously, when choosing the local cache directory, if there was no
root source file, an explicitly chosen path, or other clues, zig would
choose cwd + zig-cache/ as the local cache directory.

This can be problematic if Zig is invoked with the CWD set to a
read-only directory, or a directory unrelated to the actual source files
being compiled. In the real world, we see this when using `zig cc` with
CGo, which for some reason changes the current working directory to the
read-only go standard library path before running the C compiler.

This commit conservatively chooses to use the global cache directory
as the local cache directory when there is no other reasonable choice,
and no longer will rely on the cwd path to choose a local cache directory.

As a reminder, the --cache-dir CLI flag and ZIG_LOCAL_CACHE_DIR
environment variable are available for overriding the decision. For the
zig build system, it will always choose the directory that build.zig is
+ zig-cache/.

Closes #7342
2020-12-10 17:00:46 -07:00
antlilja
ea70a983ba Added global-cache argument to build system + removed extra args.
* Field global_cache_root was added to Builder struct along with
mandatory argument for build_runner.zig. Logic for using the custom
global cache was also added.

* The arguments --cache-dir and --global-cache-dir are no longer passed
directly through to build_runner.zig and are instead only passed through the
mandatory cache_root and global_cache_root arguments.
2020-12-10 17:00:38 -07:00
Vexu
235d56cb82 make std.json.unescapeString pub 2020-12-10 14:10:48 -07:00
Andrew Kelley
b4c0396d3c CLI: infer --name based on first C source file or object
Previously, --name would only be inferred if there was exactly 1 C
source file or exactly 1 object. Now it will be inferred if there is at
least one of either.
2020-12-09 21:21:27 -07:00
Timon Kruiper
97692cb4fe Do not keep the build.zig cache manifest file locked.
This allows to have multiple instances of `zig build` at the same
time. For example when you have a long running `zig build run` and
then want to run `zig build somethingelse`.
2020-12-09 20:16:26 -07:00
Andrew Kelley
d9c808e3ff mingw-w64: patch to silence implicit-function-declaration warnings
Closes #7356

I did this as a patch to the source rather than passing flags so that
it would intentionally be reverted when we update to the next release of
mingw-w64. At this time if any warnings are still emitted we should find
out why and make sure upstream is aware of the problem.
2020-12-09 17:32:32 -07:00
Andrew Kelley
1f09584d05 MoveFileEx can return ACCESS_DENIED
I observed this on Windows 10, trying to use MoveFileEx with
MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH
to overwrite a running executable.
2020-12-09 17:32:26 -07:00
Martin Wickham
cad2e8da9d Fix operator precedence documentation 2020-12-09 17:31:49 -07:00
Andrew Kelley
b124d04e6a Merge pull request #7366 from LemonBoy/fix-7346
Some compiler-rt fixes
2020-12-09 12:21:28 -07:00
Lee Cannon
a7eea0813f Fixes #7352 - ignore zig fmt ignore zig-cache 2020-12-09 11:44:40 -07:00
Andrew Kelley
85c1db9222 Merge pull request #7355 from ziglang/lld-child-process
invoke LLD as a child process rather than a library
2020-12-09 00:32:30 -07:00
antlilja
40e37d4324 Change tag returned by zigTagType for c_longdouble to Float.
Function was returning Int before.
2020-12-08 17:10:55 -07:00
Nathanaël Courant
1ec0261518 Fix general purpose allocator incorrectly modifying total_requested_bytes in some cases 2020-12-08 13:57:02 -07:00
Andrew Kelley
5c13a4e54a tests: run-translated-c now respects -Dtarget 2020-12-08 13:56:56 -07:00
Andrew Kelley
c2de3bdc12 always use codeview (pdb) when object_format is PE/COFF
Previously, when mixing Zig and C/C++ code for windows-gnu targets, zig
would get codeview format but the C/C++ code would not get any debug
info. Now, C/C++ code properly emits debug info in codeview format and
everything just works.
2020-12-08 13:56:50 -07:00
Andrew Kelley
ad95eecf37 glibc: additionally provide -lcrypt
also remove redundant "util" string matching.
2020-12-08 13:56:21 -07:00
Nathan Michaels
83b2785a43 Implement msp430 mapping for c_longdouble. (#7333) 2020-12-08 11:14:33 -07:00
LemonBoy
e2104ecc2d stage1: Fix type mapping for c_longdouble
A quick and dirty job to let the compiler use the correct size and
alignment.
2020-12-08 11:14:21 -07:00
xackus
05fefc0d3f std.c: freeing null is a no-op 2020-12-08 11:11:49 -07:00
Veikka Tuominen
01ff3684dc Merge pull request #7313 from LemonBoy/booo
Fix a few unsound optimizations on single-element union/enum
2020-12-06 12:37:18 -07:00
Andrew Kelley
48c8948f49 update to latest clang C headers 2020-12-04 17:25:55 -07:00
Jakub Konka
f385419259 macho: specify -install_name as full dylib's name
This then allows for proper resolution of names via runpath search
path list, i.e., `-rpath @loader_path` will correctly resolve
to `@rpath/libxxx.dylib (...)` in the linked binary.
2020-12-04 14:54:17 -07:00
Jakub Konka
96a703ee6d Version-gate appending -syslibroot flag to lld
This commit version-gates appending `-syslibroot` flag to lld. This
is predicated upon the fact that for versions of macOS lower than
11, lld would fail to find and link against frameworks with this
flag specified.

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-12-04 12:39:07 -07:00
Jakub Konka
32997a2fb0 Merge pull request #7293 from kubkon/fix-7030
stage1: allow idx 0 err to be put into error_name_table
2020-12-04 12:39:01 -07:00
Andrew Kelley
a1d0c77539 add more mingw-w64 .def files
closes #7268
2020-12-03 18:04:39 -07:00
Andrew Kelley
2ce5f84c2f stage1: compile error for pointer arithmetic on ptr-to-array
See #2018
2020-12-03 17:46:21 -07:00
Andrew Kelley
05265160ae add @cImport files to Compilation cache manifest
closes #7007
2020-12-03 16:08:55 -07:00
Koakuma
52de625df9 Fix floating point parsing on BE systems (#7256)
* Fix floating point parsing on BE systems

* Load the appropriate endian.h files for macOS and BSD

* Add endian definition for Windows and extra check for ldshape selection

* Fix endian macro definition for macOS

Apparently their macros are defined without a leading __.

* Define new macro for endian checking purposes

This is gross and I really do not like the lack of standardization
around this part, but what can I do?
2020-12-03 13:47:31 -07:00
Miles Alan
cdde9d8885 std/event: Fix import path for WaitGroup 2020-12-03 13:44:25 -07:00
Andrew Kelley
ff802cc996 stage2: don't pass -l arguments when building .a or .o files
See #7094
2020-12-02 20:25:03 -07:00
LemonBoy
0ac43154eb std: Add nosuspend around stderr.print calls 2020-12-02 17:54:34 -07:00
Vexu
401d091fb4 std.build: addBuildOption special handling for SemanticVersion 2020-12-02 17:54:29 -07:00
Andrew Kelley
b1f52ca7f2 stage2: linkAsArchive: respect disable_lld_caching
Closes #7274
Closes #6943
2020-12-02 16:40:00 -07:00
LemonBoy
02cb3841a6 ci: Retry apt-get install at most three times
Try harder instead of failing after the first invocation fails.
2020-12-02 16:16:36 -07:00
LemonBoy
7c13bec7cb std: make the use of pthread_join POSIX-compliant
Applications supplying their own custom stack to pthread_create are not
allowed to free the allocated memory after pthread_join returns as,
according to the specification, the thread is not guaranteed to be dead
after the join call returns.

Avoid this class of problems by avoiding the use of a custom stack
altogether, let pthread handle its own resources.

Allocations made on the child stack are now done on the C heap.

Thanks @semarie for noticing the problem on OpenBSD and suggesting a
fix.

Closes #7275
2020-12-02 16:16:31 -07:00
Mathieu Guay-Paquet
7add370371 fix the tinyest typo 2020-12-02 16:16:02 -07:00
daurnimator
d15a0ec7b2 Localhost is special (#6955)
* std: always return loopback address when looking up localhost

* std: also return Ipv6 loopback

* std: remove commented out obsolete code
2020-12-01 17:14:43 -07:00
LemonBoy
0858d7b0df stage2: Create cache manifest before calling final
If we enter the `if` because `comp.disable_c_depfile` is false the `man`
object has no manifest and calling .final on it will trip an assertion.

Closes #7096
2020-12-01 16:52:52 -07:00
Andrew Kelley
a4c8bd8fd4 stage2: add -femit-foo=bar args to the cache hash
Closes #6979
Closes #7036
2020-12-01 16:36:37 -07:00
Alexandros Naskos
7099dff7ea Add package names and paths to the zig root module cache hash.
Add package names to the stage1 cache hash and package files to the
stage1 manifest file.
2020-12-01 14:57:27 -07:00
Timon Kruiper
6bf19e32e7 Make sure to include the root_name in the cache.
This fixes a bug where the caching system did not notice when the
--name flag changed.
2020-12-01 11:39:15 -07:00
Andrew Kelley
c8b8f0ea13 COFF linking: fix incorrectly passing .dll instead of .lib
commit 9d1816111d used the "output path"
as the path for passing shared library artifact paths to the Zig CLI.
For Windows, this was incorrect because it would pass the .dll instead
of the .lib file. This commit passes the "output lib path" instead,
which makes it pass the .lib path in case of a .dll on Windows.

This way the linker does not complain and say, "bad file type. Did you
specify a DLL instead of an import library?"
2020-12-01 11:31:48 -07:00
Andrew Kelley
d2445764a9 restore -target wasm32-freestanding-musl for C headers
See #5854

Some tiny tweaks too:
 * Use `wasm-freestanding-musl` instead of `wasm32-freestanding-musl`,
   making it pointer-size-agnostic.
 * Fix trying to build non-existent wasm musl start files.
2020-11-30 20:58:31 -07:00
Andrew Kelley
a9b7d8fa07 stage2: fix not detecting all dynamic libraries
Positional shared library arguments were not being detected as causing
dynamic linking, resulting in invalid linker lines. LLD did not have an
error message for this when targeting x86_64-linux but it did emit an
error message when targeting aarch64-linux, which is how I noticed the
problem.

This surfaced an error having to do with fifo.pipe() in the cat example
which I did not diagnose but solved the issue by doing the revamp that
was already overdue for that example.

It appears that the zig-window project was exploiting the previous
behavior for it to function properly, so this prompts the question, is
there some kind of static/dynamic executable hybrid that the compiler
should recognize? Unclear - but we can discuss that in #7240.
2020-11-30 20:58:15 -07:00
Andrew Kelley
57ac835a03 Merge branch 'alexnask-fix_6868' into master
Closes #7139
Closes #6868
2020-11-30 18:13:06 -07:00
Andrew Kelley
3c907e51d1 fix regression on wasm targets
The previous commit broke wasm targets because the linking step would
look for the compiler-rt lib in the wrong place. Fixed in this commit.
2020-11-30 17:47:24 -07:00
Andrew Kelley
791e38da8c Merge branch 'alexnask-bundle_compiler_rt' into master
Closes #7013
Closes #6817
2020-11-30 16:50:56 -07:00
Michael Freundorfer
1a61a9d4bf Fix WindowsDynLib.openW trying to strip the \??\ prefix when it does not exist 2020-11-30 12:13:17 -07:00
Jonathan Marler
8f346d9a4b fix memory leak in BufMap 2020-11-30 11:40:44 -07:00
LemonBoy
a7c2cfe16d stage1: Fix typeInfo generation for arrays w/o sentinel
ZigTypeIdOptional types have a different way of specifying their payload
value depending on whether the child type is a pointer or not (plus some
other special cases).

Fixes #7251
2020-11-29 11:39:35 -07:00
LemonBoy
0a4a99ec87 stage1: Add missing bitcast when rendering var ptr
Some types require this extra bitcast, eg. structs or unions with extra
padding fields inserted by the compiler.

Fixes #7250
2020-11-29 11:37:44 -07:00
LemonBoy
be2adff087 std: Avoid deadlock in the signal handler
stderr_mutex may still be held when we reach the signal handler, grab
our own stderr handle to print the error messages and avoid deadlocking.

Closes #7247
2020-11-29 11:31:38 -07:00
christian-stephen
a6222d1d4b Add readAllArrayListAligned to Reader which can accept an arbitrary alignment 2020-11-27 18:01:49 -07:00
Andrew Kelley
f09f960ce4 Merge branch 'kubkon-elf-soname-opt-in' into master
closes #7162
2020-11-27 17:57:11 -07:00
LemonBoy
288b8b535f stage1: Fix crash in *[N]T to []T conversion with zst
Prevent the crash by not making the codegen try to access the
non-existing ptr field in the slice.

Closes #6951
2020-11-27 15:34:13 -07:00
LemonBoy
36b8f5d194 stage1: Force union member types to be resolved
No test case because I couldn't reduce the huuuge test case.
Fixes the problem discovered by @ifreund.
2020-11-26 11:50:38 -07:00
Isaac Freund
41d57b051f std/os: fix prctl constants 2020-11-25 16:47:44 -07:00
LemonBoy
24d4bfb666 stage1: Fix ICE when generating struct fields with padding
Make gen_const_ptr_struct_recursive aware of the possible presence of
some trailing padding by always bitcasting the pointer to its expected
type.

Not an elegant solution but makes LLVM happy and is consistent with how
the other callsites are handling this case.

Fixes #5398
2020-11-25 16:36:57 -07:00
Jonathan Marler
06a75c16ff fix for GCC 9.2: -Wno-maybe-uninitialized 2020-11-24 18:32:57 -07:00
Frank Denis
8af016c5be Update the minimum cmake version we require
Recent versions of cmake complain about it:

<<
  CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.
>>

We don't require anything from version 2.8.5, and version 2.8.12 was
released in 2011, so it is very unlikely that anyone still uses 2.8.5.
2020-11-24 18:32:51 -07:00
Isaac Freund
a05ae01b4f std/os: define and use dev_t for linux x86_64 2020-11-20 18:36:23 -07:00
Isaac Freund
1344706b47 std/os: add time_t definiton for x86_64 linux 2020-11-20 18:36:15 -07:00
LemonBoy
72980388ca stage1: Resolve usingnamespace decls when calling @typeInfo
Closes #7176
2020-11-20 18:02:20 -07:00
LemonBoy
c6c25a1c09 stage1: Fix undefined assignment for bitfields
Prevents silent memory corruption.

Closes #7055
2020-11-18 22:51:34 -07:00
Frank Denis
3f134cfe5e edwards25519 - skip useless operations and duplicate lookup table
Just some trivial changes; no functional changes.

Skip useless nul additions and multiplications and comptime the
basepoint multiples only once.
2020-11-18 21:45:42 -08:00
breakin
e814f71052 Change seed for Murmur2_64 from u32 to u64 2020-11-18 18:06:04 -07:00
Veikka Tuominen
50269f2315 Merge pull request #6649 from Rocknest/verparse
make Version.parse less strict
2020-11-18 17:47:43 -07:00
Vexu
8af0a1987b make help in commands more consistent
Closes #7101

Co-authored-by: pfg <pfg@pfg.pw>
2020-11-18 17:37:14 -07:00
Timon Kruiper
b498d26376 Allow Zig to be built with clang 11 and -Werror
This was brought to the horizon when using zig-bootstrap to cross compile
Zig for windows-gnu.
2020-11-18 17:32:48 -07:00
LemonBoy
d3f1a4edce stage1: Add architecture-specific clobbers to asm()
We're basically following Clang's lead, add the necessary clobbers to
minimize the risk of generating wrong code.
2020-11-18 17:32:41 -07:00
Veikka Tuominen
1add7c616f Merge pull request #7084 from xackus/mem-volatile
std.mem: make sliceAsBytes, etc. respect volatile
2020-11-18 17:31:11 -07:00
Frank Denis
5f9a664de9 STAGE1_SOURCES: In 0.7.x, leb128.zig is in std/debug (#7148)
* STAGE1_SOURCES: In 0.7.x, leb128.zig is in std/debug

* codegen/aarch64.zig doesn't exist in 0.7.x

Co-authored-by: Frank Denis <github@purftpd.org>
2020-11-18 14:53:47 -05:00
LemonBoy
1c8cd268be stage1: Fix asyncCall with non-abi-aligned arguments
Make the code used to calculate the variable slot index into the frame
match what's done during the structure layout calculation.

Prevents a few nasty LLVM errors when such types are passed around.
2020-11-17 16:55:44 -07:00
Andrew Kelley
eea4cd2924 cli: make -h, --help consistent in usage text and parsing
also trivial fixes in the general usage text
2020-11-17 16:54:15 -07:00
Guoxin Yin
4d44a813de Add -h alias for --help 2020-11-17 11:39:42 -07:00
johnLate
51ffb0548d CMake: properly detect when to rebuild zig1.o
This is andrewrk's patch from ziglang#6724 (rebased)

CMake: Fix dependency problem

I don't know whether the error was expected cmake behavior or a bug.
This change seems to fix the issue. See ziglang#6724 for details.

cmake: add the correct set of zig stage2 sources
2020-11-16 18:04:54 -07:00
Alex Cameron
5b42704ea7 Prevent double file close in MachO linking 2020-11-16 15:00:22 -07:00
Frank Denis
c8b6e407ba Enable loop interleaving when unrolling is enabled
This mimics clang's default behavior.
2020-11-16 15:00:16 -07:00
LemonBoy
9e1e91dafc std: Make windows.ReadFile allow short reads
Make it behave like the read() wrapper for unix systems.
Reading the whole buffer breaks some use-cases like buffered readers
over sockets.

Closes #7121
2020-11-16 14:35:28 -07:00
LemonBoy
6624f9cd5c stage1: Fix generation of pass-by-value args in async fns
The mismatch between the argument slot type in the frame structure and
the one used in the store operation made the generated code write
garbage over the nearby fields.

Fixes #7104
2020-11-16 11:37:49 -07:00
Andrew Kelley
7d0c461b77 std.fs.path.dirname: return null when input path is root
This intentionally diverges from the unix dirname command, as well as
Python and Node.js standard libraries, which all have this edge case
return the input path, unmodified. This is a footgun, and nobody should
have ever done it this way.

Even the man page contradicts the behavior. It says:
"strip last component from file name". Now consider, if you
remove the last item from an array of length 1, then you
have now an array of length 0. After you strip the last component, there
should be no components remaining. Clearly, returning the input parameter
unmodified in this case does not match the documented behavior. This is
my justification for taking a stand on this API design.

closes #6746
closes #6727
closes #6584
closes #6592
closes #6602
2020-11-15 10:53:06 -07:00
LemonBoy
2d280825cd stage1: Disambiguate Wasm imports with same name
Closes #7088
2020-11-13 14:33:20 -07:00
LemonBoy
10617593f8 stage1: Resolve ErrorUnion children types
Since the code is accessing the abi_size field compute the full type
size for both err_set_type and payload_type, not only for the latter.
2020-11-13 14:29:38 -07:00
LemonBoy
10b1001a12 stage1: Ask LLVM to produce compact code in ReleaseSize mode
Let's follow what Clang does for -Oz and apply the `minsize` and
`optsize` attributes by default.

Closes #7048
Supersedes #7077
2020-11-13 10:27:26 -07:00
Hubert Jasudowicz
eaa1db2002 std: Fix code model argument 2020-11-11 19:33:10 -07:00
Vexu
1aec406311 std: fix HashMap.clearRetainingCapacity 2020-11-11 19:33:03 -07:00
Vexu
b6350a2b3f std: fix HashMap.putAssumeCapacity 2020-11-11 19:32:58 -07:00
Vexu
8c62733927 ensure TypeInfo payload is not undefined 2020-11-11 19:32:30 -07:00
LemonBoy
aa6fc29744 stage1: Fix crash in comptime struct generation
Using the gen_index rather than the src_index is needed to handle
structures containing zero-sized or comptime only types.

Closes #7027
2020-11-11 19:14:03 -07:00
Jonas Carpay
01a927a0cb Fix backticked code in langref 2020-11-11 19:13:52 -07:00
LemonBoy
7d3c5f207a stage1: Avoid resolving type entry in [0]T
The logic was already there but this rule was only applied in some
places, apply it in the remaining code paths.

Closes #7058
2020-11-11 19:13:04 -07:00
Andrew Kelley
0405698696 add missing -m<os>-version-min CLI args to clang
This fixes some code generation issues when targeting macOS and
compiling C/C++ code.
2020-11-10 15:24:57 -07:00
Andrew Kelley
73455eaf42 std.Target: bump default version max for macos 2020-11-10 15:24:51 -07:00
LemonBoy
85665386c6 stage1: Fix comparison of unions containing zero-sized types
The code tried to be too smart and skipped the equality (returning true)
if the payload type was zero-sized.
This optimization is completely wrong when the union payload is a
metatype!

Fixes #7047
2020-11-10 15:24:41 -07:00
Andrew Kelley
2c0caa8533 main: updateModule returns an error when there are any compile errors
closes #6976
2020-11-09 20:52:08 -07:00
daurnimator
904c513a1e Fix json parser close tracking (#6865)
* std: fix json parsing with unmatched closing tokens

* std: fix swapped json parsing errors
2020-11-09 16:29:22 -07:00
LemonBoy
0e2eb6eb65 stage1: Print correct error message for vector @intCast 2020-11-09 16:25:47 -07:00
Frank Denis
c2c3177d82 Don't prevent compilation on platforms where debug info is unsupported
We don't support debug information on platforms that are not tier-1,
but it shouldn't be a hard error that completely prevents compilation.
2020-11-09 16:23:27 -07:00
Alexandros Naskos
a28c244afb Windows TLS startup symbols are already provided by libcrt when linking against libc 2020-11-09 15:47:37 -07:00
Andrew Kelley
97ec177953 std.ResetEvent: disable flaky test on Windows
See #7009
2020-11-09 15:36:51 -07:00
data-man
810c03f426 Fix reduce documentation 2020-11-09 15:36:46 -07:00
Andrew Kelley
0f4b893d6d langref: add 0.7.0 link 2020-11-09 15:36:36 -07:00
Frank Denis
61507d95d8 Bump Zig version to 0.7.0 2020-11-09 15:36:26 -07:00
11380 changed files with 448599 additions and 1391112 deletions

View File

@@ -1,7 +1,7 @@
image: freebsd/latest
secrets:
- 51bfddf5-86a6-4e01-8576-358c72a4a0a4
- be22288f-b1bc-4243-abe3-43d8f0e7079b
- 5cfede76-914e-4071-893e-e5e2e6ae3cea
sources:
- https://github.com/ziglang/zig
tasks:

13
.gitattributes vendored
View File

@@ -3,10 +3,9 @@
langref.html.in text eol=lf
deps/SoftFloat-3e/*.txt text eol=crlf
deps/** linguist-vendored
lib/include/** linguist-vendored
lib/libc/** linguist-vendored
lib/libcxx/** linguist-vendored
lib/libcxxabi/** linguist-vendored
lib/libunwind/** linguist-vendored
lib/tsan/** linguist-vendored
deps/* linguist-vendored
lib/include/* linguist-vendored
lib/libc/* linguist-vendored
lib/libcxx/* linguist-vendored
lib/libcxxabi/* linguist-vendored
lib/libunwind/* linguist-vendored

4
.github/CODEOWNERS vendored
View File

@@ -1,4 +0,0 @@
# Autodoc
/src/Autodoc.zig @kristoff-it
/src/autodoc/* @kristoff-it
/lib/docs/* @kristoff-it

View File

@@ -1,12 +0,0 @@
---
name: Autodoc Issue
about: Issues with automatically generated docs, including stdlib docs.
title: 'Autodoc: {your issue}'
labels: autodoc
assignees: kristoff-it
---
Autodoc is still work in progress and as such many bugs and missing features are already known.
# Please report only <ins>regressions</ins>, i.e. things that worked in a previous build of new Autodoc (orange banner) that now don't work any more.

View File

@@ -1,33 +0,0 @@
name: Bug Report
description: File a bug report
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
A bug is when something works differently than it is expected to.
## Remember to search before filing a new report
Please search for this bug in the issue tracker, and use a bug report title that
would have made your bug report turn up in the search results for your search query.
- type: input
id: version
attributes:
label: Zig Version
description: "The output of `zig version`"
placeholder: "0.10.0-dev.4583+875e98a57"
validations:
required: true
- type: textarea
id: repro
attributes:
label: Steps to Reproduce and Observed Behavior
description: What exactly can someone else do, in order to observe the problem that you observed? Include the output and all error messages.
validations:
required: true
- type: textarea
id: expected
attributes:
label: Expected Behavior
description: What did you expect to happen instead?
validations:
required: true

View File

@@ -1,7 +0,0 @@
contact_links:
- name: Language Proposal
about: Propose to improve the Zig language
url: https://github.com/ziglang/zig/wiki/Language-Proposals
- name: Question
about: Please use one of the community spaces for questions or general discussions.
url: https://github.com/ziglang/zig/wiki/Community

3
.gitignore vendored
View File

@@ -10,9 +10,6 @@
# -andrewrk
zig-cache/
zig-out/
/release/
/debug/
/build/
/build-*/
/docgen_tmp/

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,7 @@ a link. There is no concept of "official" or "unofficial", however, each
gathering place has its own moderators and rules.
This is Andrew Kelley speaking. At least for now, I'm the moderator of the
ziglang organization GitHub repositories and the #zig IRC channel on Libera.chat.
ziglang organization GitHub repositories and the #zig IRC channel on Freenode.
**This document contains the rules that govern these two spaces only**.
The rules here are strict. This space is for focused, on topic, technical work

View File

@@ -5,11 +5,9 @@
One of the best ways you can contribute to Zig is to start using it for a
personal project. Here are some great examples:
* [Oxid](https://github.com/dbandstra/oxid) - arcade style game
* [TM35-Metronome](https://github.com/TM35-Metronome) - tools for modifying and randomizing Pokémon games
* [River](https://github.com/ifreund/river/) - a dynamic tiling wayland compositor
More examples can be found on the
[Community Projects Wiki](https://github.com/ziglang/zig/wiki/Community-Projects).
* [trOS](https://github.com/sjdh02/trOS) - tiny aarch64 baremetal OS thingy
Without fail, these projects lead to discovering bugs and helping flesh out use
cases, which lead to further design iterations of Zig. Importantly, each issue
@@ -53,8 +51,7 @@ knowledge of Zig internals.**
### Editing Source Code
First, build the Stage 1 compiler as described in
[Building Zig From Source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source).
First, build the Stage 1 compiler as described in [Building from Source](README.md#Building-from-Source).
Zig locates lib files relative to executable path by searching up the
filesystem tree for a sub-path of `lib/zig/std/std.zig` or `lib/std/std.zig`.
@@ -68,7 +65,7 @@ test and debug from a git working tree.
- `make` is typically sufficient to build zig during development iterations.
- `make install` performs a build __and__ install.
- `msbuild -p:Configuration=Release INSTALL.vcxproj` on Windows performs a
build and install. To avoid install, pass cmake option `-DZIG_NO_LIB=ON`.
build and install. To avoid install, pass cmake option `-DZIG_SKIP_INSTALL_LIB_FILES=ON`.
To test changes, do the following from the build directory:
@@ -104,17 +101,9 @@ When making changes to the compiler source code, the most helpful test step to
run is `test-behavior`. When editing documentation it is `docs`. You can find
this information and more in the `--help` menu.
#### Testing Changes to std lib
To quickly test a change to a file in the standard library, you can run zig test and specify a custom lib directory with the follow command-line argument.
```bash
./build/zig test lib/std/fmt.zig --zig-lib-dir lib --main-pkg-path lib/std
```
#### Testing Non-Native Architectures with QEMU
The Linux CI server additionally has qemu installed and sets `-fqemu`.
The Linux CI server additionally has qemu installed and sets `-Denable-qemu`.
This provides test coverage for, e.g. aarch64 even on x86_64 machines. It's
recommended for Linux users to install qemu and enable this testing option
when editing the standard library or anything related to a non-native
@@ -123,7 +112,7 @@ architecture.
##### glibc
Testing foreign architectures with dynamically linked glibc is one step trickier.
This requires enabling `--glibc-runtimes /path/to/glibc/multi/install/glibcs`.
This requires enabling `-Denable-foreign-glibc=/path/to/glibc/multi/install/glibcs`.
This path is obtained by building glibc for multiple architectures. This
process for me took an entire day to complete and takes up 65 GiB on my hard
drive. The CI server does not provide this test coverage. Instructions for
@@ -135,19 +124,11 @@ It's understood that most contributors will not have these tests enabled.
#### Testing Windows from a Linux Machine with Wine
When developing on Linux, another option is available to you: `-fwine`.
When developing on Linux, another option is available to you: `-Denable-wine`.
This will enable running behavior tests and std lib tests with Wine. It's
recommended for Linux users to install Wine and enable this testing option
when editing the standard library or anything Windows-related.
#### Testing WebAssembly using wasmtime
If you have [wasmtime](https://wasmtime.dev/) installed, take advantage of the
`-fwasmtime` flag which will enable running WASI behavior tests and std
lib tests. It's recommended for all users to install wasmtime and enable this
testing option when editing the standard library and especially anything
WebAssembly-related.
#### Improving Translate-C
Please read the [Editing Source Code](#editing-source-code) section as a
@@ -171,7 +152,7 @@ The relevant tests for this feature are:
same, and that the program exits cleanly. This kind of test coverage is preferred, when
possible, because it makes sure that the resulting Zig code is actually viable.
* `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
* `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
which checks that the relevant macros in `test/stage1/behavior/translate_c_macros.h`.
have the correct values. Macros have to be tested separately since they are expanded by
Clang in `run_translated_c` tests.
@@ -192,21 +173,21 @@ repo, we maintain a C API on top of Clang's C++ API:
Clang's C++ API changes. This one file necessarily does include Clang's C++ headers, which
makes it the slowest-to-compile source file in all of Zig's codebase.
* `src/clang.zig` - the Zig equivalent of `src/zig_clang.h`. This is a manually
* `src-self-hosted/clang.zig` - the Zig equivalent of `src/zig_clang.h`. This is a manually
maintained list of types and functions that are ABI-compatible with the Clang C API we
maintain. In theory this could be generated by running translate-c on `src/zig_clang.h`,
but that would introduce a dependency cycle, since we are using this file to implement
translate-c.
Finally, the actual source code for the translate-c feature is
`src/translate_c.zig`. This code uses the Clang C API exposed by
`src/clang.zig`, and produces Zig AST.
`src-self-hosted/translate_c.zig`. This code uses the Clang C API exposed by
`src-self-hosted/clang.zig`, and produces Zig AST.
The steps for contributing to translate-c look like this:
1. Identify a test case you want to improve. Add it as a run-translated-c test
case (usually preferable), or as a translate-c test case.
2. Edit `src/translate_c.zig` to improve the behavior.
2. Edit `src-self-hosted/translate_c.zig` to improve the behavior.
3. Run the relevant tests: `./zig build test-run-translated-c test-translate-c`

View File

@@ -1,6 +1,6 @@
The MIT License (Expat)
Copyright (c) 2015-2022, Zig contributors
Copyright (c) 2015 Andrew Kelley
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

104
README.md
View File

@@ -1,25 +1,111 @@
![ZIG](https://ziglang.org/img/zig-logo-dynamic.svg)
![ZIG](https://ziglang.org/zig-logo.svg)
A general-purpose programming language and toolchain for maintaining
**robust**, **optimal**, and **reusable** software.
## Resources
* [Introduction](https://ziglang.org/learn/#introduction)
* [Introduction](https://ziglang.org/#Introduction)
* [Download & Documentation](https://ziglang.org/download)
* [Chapter 0 - Getting Started | ZigLearn.org](https://ziglearn.org/)
* [Community](https://github.com/ziglang/zig/wiki/Community)
* [Contributing](https://github.com/ziglang/zig/blob/master/.github/CONTRIBUTING.md)
* [Code of Conduct](https://github.com/ziglang/zig/blob/master/.github/CODE_OF_CONDUCT.md)
* [Contributing](https://github.com/ziglang/zig/blob/master/CONTRIBUTING.md)
* [Code of Conduct](https://github.com/ziglang/zig/blob/master/CODE_OF_CONDUCT.md)
* [Frequently Asked Questions](https://github.com/ziglang/zig/wiki/FAQ)
* [Community Projects](https://github.com/ziglang/zig/wiki/Community-Projects)
## Installation
## Building from Source
* [download a pre-built binary](https://ziglang.org/download/)
* [install from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
* [build from source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source)
* [bootstrap zig for any target](https://github.com/ziglang/zig-bootstrap)
[![Build Status](https://dev.azure.com/ziglang/zig/_apis/build/status/ziglang.zig?branchName=master)](https://dev.azure.com/ziglang/zig/_build/latest?definitionId=1&branchName=master)
Note that you can
[download a binary of the master branch](https://ziglang.org/download/#release-master) or
[install Zig from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager).
### Stage 1: Build Zig from C++ Source Code
This step must be repeated when you make changes to any of the C++ source code.
#### Dependencies
##### POSIX
* cmake >= 2.8.5
* gcc >= 5.0.0 or clang >= 3.6.0
* LLVM, Clang, LLD development libraries == 11.x, compiled with the same gcc or clang version above
- Use the system package manager, or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#posix).
##### Windows
* cmake >= 3.15.3
* Microsoft Visual Studio. Supported versions:
- 2017 (version 15.8)
- 2019 (version 16)
* LLVM, Clang, LLD development libraries == 11.x
- Use the [pre-built binaries](https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows) or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#windows).
#### Instructions
##### POSIX
```
mkdir build
cd build
cmake ..
make install
```
Need help? [Troubleshooting Build Issues](https://github.com/ziglang/zig/wiki/Troubleshooting-Build-Issues)
##### MacOS
```
brew install cmake llvm
brew outdated llvm || brew upgrade llvm
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix llvm)
make install
```
##### Windows
See https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows
### Stage 2: Build Self-Hosted Zig from Zig Source Code
Now we use the stage1 binary:
```
zig build --prefix $(pwd)/stage2 -Denable-llvm
```
This produces `stage2/bin/zig` which can be used for testing and development.
Once it is feature complete, it will be used to build stage 3 - the final compiler
binary.
### Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler
*Note: Stage 2 compiler is not yet able to build Stage 3. Building Stage 3 is
not yet supported.*
Once the self-hosted compiler can build itself, this will be the actual
compiler binary that we will install to the system. Until then, users should
use stage 1.
#### Debug / Development Build
```
stage2/bin/zig build
```
This produces `zig-cache/bin/zig`.
#### Release / Install Build
```
stage2/bin/zig build install -Drelease
```
## License

1327
build.zig

File diff suppressed because it is too large Load Diff

87
ci/azure/linux_script Executable file
View File

@@ -0,0 +1,87 @@
#!/bin/sh
set -x
set -e
BUILDDIR="$(pwd)"
sudo sh -c 'echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list'
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get remove -y llvm-*
sudo rm -rf /usr/local/*
# Some APT mirrors can be flaky, retry the download instead of failing right
# away.
APT_MAX_RETRY=3
for i in $(seq 1 "$APT_MAX_RETRY"); do
sudo apt-get update -q
sudo apt-get install -y \
libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd \
gcc-7 g++-7 ninja-build tidy \
&& break
if [ "$i" -eq "$APT_MAX_RETRY" ]; then
echo 'apt-get failed, giving up...'
exit 1
fi
echo 'apt-get failed, retrying...'
sleep 5s
done
QEMUBASE="qemu-linux-x86_64-5.1.0"
wget https://ziglang.org/deps/$QEMUBASE.tar.xz
tar xf $QEMUBASE.tar.xz
PATH=$PWD/$QEMUBASE/bin:$PATH
WASMTIME="wasmtime-v0.20.0-x86_64-linux"
wget https://github.com/bytecodealliance/wasmtime/releases/download/v0.20.0/$WASMTIME.tar.xz
tar xf $WASMTIME.tar.xz
PATH=$PWD/$WASMTIME:$PATH
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
export CC=gcc-7
export CXX=g++-7
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja
ninja install
./zig build test -Denable-qemu -Denable-wasmtime
# look for HTML errors
tidy -qe ../zig-cache/langref.html
VERSION="$(./zig version)"
if [ "${BUILD_REASON}" != "PullRequest" ]; then
ARTIFACTSDIR="$BUILDDIR/artifacts"
mkdir "$ARTIFACTSDIR"
docker run -i --mount type=bind,source="$ARTIFACTSDIR",target=/z ziglang/static-base:llvm11-x86_64-1 -j2 $BUILD_SOURCEVERSION
TARBALL="$(ls $ARTIFACTSDIR)"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$ARTIFACTSDIR/$TARBALL" s3://ziglang.org/builds/
SHASUM=$(sha256sum $ARTIFACTSDIR/$TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $ARTIFACTSDIR/$TARBALL)
JSONFILE="linux-$GITBRANCH.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/x86_64-linux-$VERSION.json"
# `set -x` causes these variables to be mangled.
# See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html
set +x
echo "##vso[task.setvariable variable=tarball;isOutput=true]$TARBALL"
echo "##vso[task.setvariable variable=shasum;isOutput=true]$SHASUM"
echo "##vso[task.setvariable variable=bytesize;isOutput=true]$BYTESIZE"
echo "##vso[task.setvariable variable=version;isOutput=true]$VERSION"
fi

View File

@@ -3,82 +3,68 @@
set -x
set -e
brew update && brew install ncurses s3cmd
brew install s3cmd
ZIGDIR="$(pwd)"
ARCH="x86_64"
TARGET="$ARCH-macos-none"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.10.0-dev.4560+828735ac0"
CACHE_BASENAME="zig+llvm+lld+clang-$ARCH-macos-gnu-0.6.0+1c9ef63a"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j2"
rm -rf $PREFIX
cd $HOME
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
ZIG="$PREFIX/bin/zig"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
NATIVE_LIBC_TXT="$HOME/native_libc.txt"
$ZIG libc > "$NATIVE_LIBC_TXT"
export ZIG_LIBC="$NATIVE_LIBC_TXT"
export CC="$ZIG cc"
export CXX="$ZIG c++"
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX="stage3-release" \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_TARGET_TRIPLE="$ARCH-native-gnu" \
-DZIG_TARGET_MCPU="baseline" \
-DZIG_STATIC=ON
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
unset ZIG_LIBC
make $JOBS install
stage3-release/bin/zig build test docs \
--zig-lib-dir "$(pwd)/../lib" \
-Denable-macos-sdk \
-Dstatic-llvm \
-Dskip-non-native \
--search-prefix "$PREFIX"
# Here we rebuild zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"
make $JOBS install
# Produce the experimental std lib documentation.
mkdir -p "stage3-release/doc/std"
stage3-release/bin/zig test "$(pwd)/../lib/std/std.zig" \
--zig-lib-dir "$(pwd)/../lib" \
-femit-docs="$(pwd)/stage3-release/doc/std" \
-fno-emit-bin
release/bin/zig build test
if [ "${BUILD_REASON}" != "PullRequest" ]; then
# Remove the unnecessary bin dir in stage3-release/bin/zig
mv stage3-release/bin/zig stage3-release/
rmdir stage3-release/bin
mv ../LICENSE release/
mv ../zig-cache/langref.html release/
mv release/bin/zig release/
rmdir release/bin
# Remove the unnecessary zig dir in stage3-release/lib/zig/std/std.zig
mv stage3-release/lib/zig stage3-release/lib2
rmdir stage3-release/lib
mv stage3-release/lib2 stage3-release/lib
mv ../LICENSE stage3-release/
mv ../zig-cache/langref.html stage3-release/doc
VERSION=$(stage3-release/zig version)
VERSION=$(release/zig version)
DIRNAME="zig-macos-$ARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv stage3-release "$DIRNAME"
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
@@ -102,5 +88,4 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
echo "##vso[task.setvariable variable=tarball;isOutput=true]$TARBALL"
echo "##vso[task.setvariable variable=shasum;isOutput=true]$SHASUM"
echo "##vso[task.setvariable variable=bytesize;isOutput=true]$BYTESIZE"
echo "##vso[task.setvariable variable=version;isOutput=true]$VERSION"
fi

View File

@@ -1,8 +1,10 @@
jobs:
- job: BuildMacOS
pool:
vmImage: 'macOS-11'
vmImage: 'macOS-10.15'
timeoutInMinutes: 360
steps:
- task: DownloadSecureFile@1
inputs:
@@ -10,157 +12,56 @@ jobs:
- script: ci/azure/macos_script
name: main
displayName: 'Build and test'
- job: BuildWindows
timeoutInMinutes: 360
- job: BuildLinux
pool:
vmImage: 'windows-2019'
variables:
TARGET: 'x86_64-windows-gnu'
ZIG_LLVM_CLANG_LLD_NAME: 'zig+llvm+lld+clang-${{ variables.TARGET }}-0.10.0-dev.4560+828735ac0'
ZIG_LLVM_CLANG_LLD_URL: 'https://ziglang.org/deps/${{ variables.ZIG_LLVM_CLANG_LLD_NAME }}.zip'
vmImage: 'ubuntu-18.04'
timeoutInMinutes: 360
steps:
- pwsh: |
(New-Object Net.WebClient).DownloadFile("$(ZIG_LLVM_CLANG_LLD_URL)", "${ZIG_LLVM_CLANG_LLD_NAME}.zip")
& 'C:\Program Files\7-Zip\7z.exe' x "${ZIG_LLVM_CLANG_LLD_NAME}.zip"
name: install
displayName: 'Install ZIG/LLVM/CLANG/LLD'
- pwsh: |
Set-Variable -Name ZIGLIBDIR -Value "$(Get-Location)\lib"
Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release"
Set-Variable -Name ZIGPREFIXPATH -Value "$(Get-Location)\$(ZIG_LLVM_CLANG_LLD_NAME)"
function CheckLastExitCode {
if (!$?) {
exit 1
}
return 0
}
# Make the `zig version` number consistent.
# This will affect the `zig build` command below which uses `git describe`.
git config core.abbrev 9
git fetch --tags
if ((git rev-parse --is-shallow-repository) -eq "true") {
git fetch --unshallow # `git describe` won't work on a shallow repo
}
& "$ZIGPREFIXPATH\bin\zig.exe" build `
--prefix "$ZIGINSTALLDIR" `
--search-prefix "$ZIGPREFIXPATH" `
--zig-lib-dir "$ZIGLIBDIR" `
-Denable-stage1 `
-Dstatic-llvm `
-Drelease `
-Dstrip `
-Duse-zig-libcxx `
-Dtarget=$(TARGET)
CheckLastExitCode
name: build
displayName: 'Build'
- pwsh: |
Set-Variable -Name ZIGLIBDIR -Value "$(Get-Location)\lib"
Set-Variable -Name ZIGINSTALLDIR -Value "$(Get-Location)\stage3-release"
Set-Variable -Name ZIGPREFIXPATH -Value "$(Get-Location)\$(ZIG_LLVM_CLANG_LLD_NAME)"
function CheckLastExitCode {
if (!$?) {
exit 1
}
return 0
}
& "$ZIGINSTALLDIR\bin\zig.exe" build test docs `
--search-prefix "$ZIGPREFIXPATH" `
-Dstatic-llvm `
-Dskip-non-native
CheckLastExitCode
# Produce the experimental std lib documentation.
mkdir "$ZIGINSTALLDIR\doc\std" -force
& "$ZIGINSTALLDIR\bin\zig.exe" test "$ZIGLIBDIR\std\std.zig" `
--zig-lib-dir "$ZIGLIBDIR" `
-femit-docs="$ZIGINSTALLDIR\doc\std" `
-fno-emit-bin
name: test
displayName: 'Test'
- task: DownloadSecureFile@1
inputs:
name: aws_credentials
secureFile: aws_credentials
- pwsh: |
$Env:AWS_SHARED_CREDENTIALS_FILE = "$Env:DOWNLOADSECUREFILE_SECUREFILEPATH"
# Workaround Azure networking issue
# https://github.com/aws/aws-cli/issues/5749
$Env:AWS_EC2_METADATA_DISABLED = "true"
$Env:AWS_REGION = "us-west-2"
mv LICENSE stage3-release/
mv zig-cache/langref.html stage3-release/
mv stage3-release/bin/zig.exe stage3-release/
rmdir stage3-release/bin
# Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig
mv stage3-release/lib/zig stage3-release/lib2
rmdir stage3-release/lib
mv stage3-release/lib2 stage3-release/lib
Set-Variable -Name VERSION -Value $(./stage3-release/zig.exe version)
Set-Variable -Name DIRNAME -Value "zig-windows-x86_64-$VERSION"
Set-Variable -Name TARBALL -Value "$DIRNAME.zip"
mv stage3-release "$DIRNAME"
7z a "$TARBALL" "$DIRNAME"
aws s3 cp `
"$TARBALL" `
s3://ziglang.org/builds/ `
--acl public-read `
--cache-control 'public, max-age=31536000, immutable'
Set-Variable -Name SHASUM -Value (Get-FileHash "$TARBALL" -Algorithm SHA256 | select-object -ExpandProperty Hash).ToLower()
Set-Variable -Name BYTESIZE -Value (Get-Item "$TARBALL").length
Set-Variable -Name JSONFILE -Value "windows-${Env:BUILD_SOURCEBRANCHNAME}.json"
echo $null > $JSONFILE
echo ('{"tarball": "' + $TARBALL + '",') >> $JSONFILE
echo ('"shasum": "' + $SHASUM + '",') >> $JSONFILE
echo ('"size": ' + $BYTESIZE + '}' ) >> $JSONFILE
aws s3 cp `
"$JSONFILE" `
s3://ziglang.org/builds/ `
--acl public-read `
--cache-control 'max-age=0, must-revalidate'
aws s3 cp `
"$JSONFILE" `
"s3://ziglang.org/builds/x86_64-windows-${VERSION}.json" `
--acl public-read
echo "##vso[task.setvariable variable=tarball;isOutput=true]$TARBALL"
echo "##vso[task.setvariable variable=shasum;isOutput=true]$SHASUM"
echo "##vso[task.setvariable variable=bytesize;isOutput=true]$BYTESIZE"
name: upload
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
displayName: 'Upload'
secureFile: s3cfg
- script: ci/azure/linux_script
name: main
displayName: 'Build and test'
- job: BuildWindows
pool:
vmImage: 'windows-2019'
timeoutInMinutes: 360
steps:
- powershell: |
(New-Object Net.WebClient).DownloadFile("https://github.com/msys2/msys2-installer/releases/download/2020-09-03/msys2-base-x86_64-20200903.sfx.exe", "sfx.exe")
.\sfx.exe -y -o\
del sfx.exe
displayName: Download/Extract/Install MSYS2
- script: |
@REM install updated filesystem package first without dependency checking
@REM because of: https://github.com/msys2/MSYS2-packages/issues/2021
%CD:~0,2%\msys64\usr\bin\bash -lc "pacman --noconfirm -Sydd filesystem"
displayName: Workaround filesystem dash MSYS2 dependency issue
- script: |
%CD:~0,2%\msys64\usr\bin\bash -lc "pacman --noconfirm -Syuu"
%CD:~0,2%\msys64\usr\bin\bash -lc "pacman --noconfirm -Syuu"
displayName: Update MSYS2
- task: DownloadSecureFile@1
inputs:
secureFile: s3cfg
- script: ci/azure/windows_msvc_script.bat
name: main
displayName: 'Build and test'
- job: OnMasterSuccess
dependsOn:
- BuildMacOS
- BuildLinux
- BuildWindows
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
strategy:
maxParallel: 1
pool:
vmImage: 'ubuntu-20.04'
vmImage: 'ubuntu-18.04'
variables:
version: $[ dependencies.BuildMacOS.outputs['main.version'] ]
version: $[ dependencies.BuildLinux.outputs['main.version'] ]
steps:
- task: DownloadSecureFile@1
inputs:

View File

@@ -0,0 +1,11 @@
#!/bin/sh
set -x
set -e
pacman -Su --needed --noconfirm
pacman -S --needed --noconfirm wget p7zip python3-pip tar xz
pip install s3cmd
wget -nv "https://ziglang.org/deps/llvm%2bclang%2blld-11.0.0-x86_64-windows-msvc-release-mt.tar.xz"
tar xf llvm+clang+lld-11.0.0-x86_64-windows-msvc-release-mt.tar.xz

View File

@@ -0,0 +1,44 @@
@echo on
SET "SRCROOT=%cd%"
SET "PREVPATH=%PATH%"
SET "PREVMSYSEM=%MSYSTEM%"
set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
SET "MSYSTEM=MINGW64"
bash -lc "cd ${SRCROOT} && ci/azure/windows_msvc_install" || exit /b
SET "PATH=%PREVPATH%"
SET "MSYSTEM=%PREVMSYSTEM%"
SET "ZIGBUILDDIR=%SRCROOT%\build"
SET "ZIGINSTALLDIR=%ZIGBUILDDIR%\dist"
SET "ZIGPREFIXPATH=%SRCROOT%\llvm+clang+lld-11.0.0-x86_64-windows-msvc-release-mt"
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
REM Make the `zig version` number consistent.
REM This will affect the cmake command below.
git.exe config core.abbrev 9
mkdir %ZIGBUILDDIR%
cd %ZIGBUILDDIR%
cmake.exe .. -Thost=x64 -G"Visual Studio 16 2019" -A x64 "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release || exit /b
msbuild /maxcpucount /p:Configuration=Release INSTALL.vcxproj || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-behavior -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-stage2 -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-fmt -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-std -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-compiler-rt -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-compare-output -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-standalone -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-stack-traces -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-cli -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-asm-link -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-runtime-safety -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-translate-c -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-run-translated-c -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build docs || exit /b
set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
SET "MSYSTEM=MINGW64"
bash -lc "cd ${SRCROOT} && ci/azure/windows_upload" || exit /b

41
ci/azure/windows_upload Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/sh
set -x
set -e
if [ "${BUILD_REASON}" != "PullRequest" ]; then
cd "$ZIGBUILDDIR"
mv ../LICENSE dist/
mv ../zig-cache/langref.html dist/
mv dist/bin/zig.exe dist/
rmdir dist/bin
VERSION=$(dist/zig.exe version)
DIRNAME="zig-windows-x86_64-$VERSION"
TARBALL="$DIRNAME.zip"
mv dist "$DIRNAME"
7z a "$TARBALL" "$DIRNAME"
# mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd -c "$DOWNLOADSECUREFILE_SECUREFILEPATH" put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(sha256sum $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="windows-$GITBRANCH.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd -c "$DOWNLOADSECUREFILE_SECUREFILEPATH" put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd -c "$DOWNLOADSECUREFILE_SECUREFILEPATH" put -P "$JSONFILE" "s3://ziglang.org/builds/x86_64-windows-$VERSION.json"
# `set -x` causes these variables to be mangled.
# See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html
set +x
echo "##vso[task.setvariable variable=tarball;isOutput=true]$TARBALL"
echo "##vso[task.setvariable variable=shasum;isOutput=true]$SHASUM"
echo "##vso[task.setvariable variable=bytesize;isOutput=true]$BYTESIZE"
fi

View File

@@ -1,92 +1,13 @@
---
kind: pipeline
type: docker
name: test-aarch64-linux-musl
platform:
os: linux
arch: arm64
steps:
- name: build
image: ziglang/static-base:llvm15-aarch64-3
commands:
- ./ci/drone/linux_script_build
- name: behavior
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
commands:
- ./ci/drone/test_linux_behavior
- name: std_Debug
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
commands:
- ./ci/drone/test_linux_std_Debug
- name: std_ReleaseSafe
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
commands:
- ./ci/drone/test_linux_std_ReleaseSafe
- name: std_ReleaseFast
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
commands:
- ./ci/drone/test_linux_std_ReleaseFast
- name: std_ReleaseSmall
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
commands:
- ./ci/drone/test_linux_std_ReleaseSmall
- name: misc
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
commands:
- ./ci/drone/test_linux_misc
- name: cases
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
commands:
- ./ci/drone/test_linux_cases
- name: standalone
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
commands:
- ./ci/drone/test_linux_standalone
- name: docs
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
commands:
- ./ci/drone/test_linux_docs
- name: finalize
depends_on:
- build
- behavior
- std_Debug
- std_ReleaseSafe
- std_ReleaseFast
- std_ReleaseSmall
- misc
- cases
image: ziglang/static-base:llvm15-aarch64-3
- name: build-and-test
image: ziglang/static-base:llvm11-aarch64-1
environment:
SRHT_OAUTH_TOKEN:
from_secret: SRHT_OAUTH_TOKEN
@@ -95,4 +16,4 @@ steps:
AWS_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY
commands:
- ./ci/drone/linux_script_finalize
- ./ci/drone/linux_script

58
ci/drone/linux_script Executable file
View File

@@ -0,0 +1,58 @@
#!/bin/sh
set -x
set -e
TRIPLEARCH="$(uname -m)"
BUILDDIR="$(pwd)"
DISTDIR="$(pwd)/dist"
apk update
apk add py3-pip xz perl-utils jq curl samurai
pip3 install s3cmd
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=$DISTDIR" -DZIG_STATIC=ON -DCMAKE_PREFIX_PATH=/deps/local -GNinja
samu install
./zig build test -Dskip-release -Dskip-non-native
if [ -z "$DRONE_PULL_REQUEST" ]; then
mv ../LICENSE "$DISTDIR/"
mv ../zig-cache/langref.html "$DISTDIR/"
mv "$DISTDIR/bin/zig" "$DISTDIR/"
rmdir "$DISTDIR/bin"
GITBRANCH="$DRONE_BRANCH"
VERSION="$("$DISTDIR/zig" version)"
DIRNAME="zig-linux-$TRIPLEARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv "$DISTDIR" "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="$TRIPLEARCH-linux-$GITBRANCH.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$TRIPLEARCH-linux-$VERSION.json"
if [ "$GITBRANCH" = "master" ]; then
# avoid leaking oauth token
set +x
cd "$BUILDDIR"
./ci/srht/on_master_success "$VERSION" "$SRHT_OAUTH_TOKEN"
fi
fi

View File

@@ -1,58 +0,0 @@
#!/bin/sh
set -x
set -e
ARCH="$(uname -m)"
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
PREFIX="/deps/local"
ZIG="$PREFIX/bin/zig"
TARGET="$ARCH-linux-musl"
MCPU="baseline"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
# The `CMAKE_AR` parameter will consider any spaces to
# be part of the executable path rather than CLI args, so we have
# to create wrapper scripts for `zig ar` and zig ranlib`.
cat <<'ENDFILE' >$PREFIX/bin/ar
#!/bin/sh
/deps/local/bin/zig ar $@
ENDFILE
cat <<'ENDFILE' >$PREFIX/bin/ranlib
#!/bin/sh
/deps/local/bin/zig ranlib $@
ENDFILE
chmod +x "$PREFIX/bin/ar"
chmod +x "$PREFIX/bin/ranlib"
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
mkdir build
cd build
cmake .. \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_AR="$PREFIX/bin/ar" \
-DCMAKE_RANLIB="$PREFIX/bin/ranlib" \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-GNinja
# Now CMake will use Zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
samu install

View File

@@ -1,54 +0,0 @@
#!/bin/sh
set -x
set -e
ARCH="$(uname -m)"
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
if [ -n "$DRONE_PULL_REQUEST" ]; then
exit 0
fi
cd build
# Remove the unnecessary bin dir in $INSTALL_PREFIX/bin/zig
mv "$INSTALL_PREFIX/bin/zig" "$INSTALL_PREFIX/"
rmdir "$INSTALL_PREFIX/bin"
# Remove the unnecessary zig dir in $INSTALL_PREFIX/lib/zig/std/std.zig
mv "$INSTALL_PREFIX/lib/zig" "$INSTALL_PREFIX/lib2"
rmdir "$INSTALL_PREFIX/lib"
mv "$INSTALL_PREFIX/lib2" "$INSTALL_PREFIX/lib"
mv ../LICENSE "$INSTALL_PREFIX/"
mv ../zig-cache/langref.html "$INSTALL_PREFIX/doc/"
GITBRANCH="$DRONE_BRANCH"
VERSION="$("$INSTALL_PREFIX/zig" version)"
DIRNAME="zig-linux-$ARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv "$INSTALL_PREFIX" "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="tarball.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-linux-$VERSION.json"
if [ "$GITBRANCH" = "master" ]; then
# avoid leaking oauth token
set +x
cd "$DRONE_WORKSPACE"
./ci/srht/on_master_success "$VERSION" "$SRHT_OAUTH_TOKEN"
fi

View File

@@ -1,10 +0,0 @@
#!/bin/sh
set -x
set -e
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
ZIG="$INSTALL_PREFIX/bin/zig"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
$ZIG build test-behavior -Dskip-non-native --zig-lib-dir lib

View File

@@ -1,12 +0,0 @@
#!/bin/sh
set -x
set -e
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
ZIG="$INSTALL_PREFIX/bin/zig"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
# test building self-hosted without LLVM
$ZIG build -Dskip-non-native --zig-lib-dir lib
$ZIG build test-cases -Dskip-non-native --zig-lib-dir lib

View File

@@ -1,10 +0,0 @@
#!/bin/sh
set -x
set -e
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
ZIG="$INSTALL_PREFIX/bin/zig"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
$ZIG build docs --zig-lib-dir lib

View File

@@ -1,17 +0,0 @@
#!/bin/sh
set -x
set -e
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
ZIG="$INSTALL_PREFIX/bin/zig"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
$ZIG build test-compiler-rt -Dskip-non-native --zig-lib-dir lib
$ZIG build test-compare-output -Dskip-non-native --zig-lib-dir lib
$ZIG build test-universal-libc -Dskip-non-native --zig-lib-dir lib
$ZIG build test-stack-traces -Dskip-non-native --zig-lib-dir lib
$ZIG build test-cli -Dskip-non-native --zig-lib-dir lib
$ZIG build test-asm-link -Dskip-non-native --zig-lib-dir lib
$ZIG build test-translate-c -Dskip-non-native --zig-lib-dir lib
$ZIG build test-fmt --zig-lib-dir lib

View File

@@ -1,10 +0,0 @@
#!/bin/sh
set -x
set -e
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
ZIG="$INSTALL_PREFIX/bin/zig"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
$ZIG build test-standalone -Dskip-non-native --zig-lib-dir lib -Dskip-release-safe

View File

@@ -1,23 +0,0 @@
#!/bin/sh
set -x
set -e
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
ZIG="$INSTALL_PREFIX/bin/zig"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
$ZIG build test-std \
--zig-lib-dir lib \
-Dskip-release-safe \
-Dskip-release-fast \
-Dskip-release-small \
-Dskip-non-native \
-Dskip-single-threaded
# Produce the experimental std lib documentation.
mkdir -p "$INSTALL_PREFIX/doc/std"
$ZIG test "$DRONE_WORKSPACE/lib/std/std.zig" \
--zig-lib-dir "$DRONE_WORKSPACE/lib" \
-femit-docs="$INSTALL_PREFIX/doc/std" \
-fno-emit-bin

View File

@@ -1,17 +0,0 @@
#!/bin/sh
set -x
set -e
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
ZIG="$INSTALL_PREFIX/bin/zig"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
$ZIG build test-std \
--zig-lib-dir lib \
-Dskip-debug \
-Dskip-release-safe \
-Dskip-release-small \
-Dskip-non-native \
-Dskip-single-threaded \
-Dskip-libc

View File

@@ -1,17 +0,0 @@
#!/bin/sh
set -x
set -e
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
ZIG="$INSTALL_PREFIX/bin/zig"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
$ZIG build test-std \
--zig-lib-dir lib \
-Dskip-debug \
-Dskip-release-fast \
-Dskip-release-small \
-Dskip-non-native \
-Dskip-single-threaded \
-Dskip-libc

View File

@@ -1,17 +0,0 @@
#!/bin/sh
set -x
set -e
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
ZIG="$INSTALL_PREFIX/bin/zig"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
$ZIG build test-std \
--zig-lib-dir lib \
-Dskip-debug \
-Dskip-release-safe \
-Dskip-release-fast \
-Dskip-non-native \
-Dskip-single-threaded \
-Dskip-libc

View File

@@ -4,13 +4,12 @@ set -x
set -e
sudo pkg update -fq
sudo pkg install -y cmake py39-s3cmd wget curl jq samurai
sudo pkg install -y cmake py27-s3cmd wget curl jq
ZIGDIR="$(pwd)"
TARGET="x86_64-freebsd-gnu"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.10.0-dev.4560+828735ac0"
CACHE_BASENAME="llvm+clang+lld-11.0.0-x86_64-freebsd-release"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j$(sysctl -n hw.ncpu)"
cd $HOME
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
@@ -21,8 +20,6 @@ cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
# SourceHut reports that it is a terminal that supports escape codes, but it
# is a filthy liar. Here we tell Zig to not try to send any terminal escape
@@ -31,62 +28,23 @@ export TERM=dumb
mkdir build
cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$PREFIX \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-GNinja
# TODO: eliminate this workaround. Without this, zig does not end up passing
# -isystem /usr/include when building libc++, resulting in #include <sys/endian.h>
# "file not found" errors.
echo "include_dir=/usr/include" >>libc.txt
echo "sys_include_dir=/usr/include" >>libc.txt
echo "crt_dir=/usr/lib" >>libc.txt
echo "msvc_lib_dir=" >>libc.txt
echo "kernel32_lib_dir=" >>libc.txt
echo "gcc_dir=" >>libc.txt
ZIG_LIBC_TXT="$(pwd)/libc.txt"
ZIG_LIBC="$ZIG_LIBC_TXT" samu install
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PREFIX "-DCMAKE_INSTALL_PREFIX=$(pwd)/release" -DZIG_STATIC=ON
make $JOBS install
# Here we skip some tests to save time.
stage3/bin/zig build test docs \
--zig-lib-dir "$(pwd)/../lib" \
-Dstatic-llvm \
--search-prefix "$PREFIX" \
-Dskip-stage1 \
-Dskip-non-native
# Produce the experimental std lib documentation.
mkdir -p "stage3/doc/std"
stage3/bin/zig test "$(pwd)/../lib/std/std.zig" \
--zig-lib-dir "$(pwd)/../lib" \
-femit-docs="$(pwd)/stage3/doc/std/" \
-fno-emit-bin
release/bin/zig build test -Dskip-compile-errors -Dskip-non-native
if [ -f ~/.s3cfg ]; then
# Remove the unnecessary bin dir in stage3/bin/zig
mv stage3/bin/zig stage3/
rmdir stage3/bin
# Remove the unnecessary zig dir in stage3/lib/zig/std/std.zig
mv stage3/lib/zig stage3/lib2
rmdir stage3/lib
mv stage3/lib2 stage3/lib
mv ../LICENSE stage3/
mv ../zig-cache/langref.html stage3/doc/
mv ../LICENSE release/
mv ../zig-cache/langref.html release/
mv release/bin/zig release/
rmdir release/bin
GITBRANCH=$(basename $GITHUB_REF)
VERSION=$(stage3/zig version)
VERSION=$(release/zig version)
DIRNAME="zig-freebsd-x86_64-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv stage3 "$DIRNAME"
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/

View File

@@ -1,630 +0,0 @@
{
"master": {
"version": "{{MASTER_VERSION}}",
"date": "{{MASTER_DATE}}",
"docs": "https://ziglang.org/documentation/master/",
"stdDocs": "https://ziglang.org/documentation/master/std/",
"src": {
"tarball": "https://ziglang.org/builds/{{SRC_TARBALL}}",
"shasum": "{{SRC_SHASUM}}",
"size": "{{SRC_BYTESIZE}}"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/builds/{{X86_64_FREEBSD_TARBALL}}",
"shasum": "{{X86_64_FREEBSD_SHASUM}}",
"size": "{{X86_64_FREEBSD_BYTESIZE}}"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/builds/{{X86_64_MACOS_TARBALL}}",
"shasum": "{{X86_64_MACOS_SHASUM}}",
"size": "{{X86_64_MACOS_BYTESIZE}}"
},
"aarch64-macos": {
"tarball": "https://ziglang.org/builds/{{AARCH64_MACOS_TARBALL}}",
"shasum": "{{AARCH64_MACOS_SHASUM}}",
"size": "{{AARCH64_MACOS_BYTESIZE}}"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/builds/{{X86_64_WINDOWS_TARBALL}}",
"shasum": "{{X86_64_WINDOWS_SHASUM}}",
"size": "{{X86_64_WINDOWS_BYTESIZE}}"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/builds/{{X86_64_LINUX_TARBALL}}",
"shasum": "{{X86_64_LINUX_SHASUM}}",
"size": "{{X86_64_LINUX_BYTESIZE}}"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/builds/{{AARCH64_LINUX_TARBALL}}",
"shasum": "{{AARCH64_LINUX_SHASUM}}",
"size": "{{AARCH64_LINUX_BYTESIZE}}"
}
},
"0.9.1": {
"date": "2022-02-14",
"docs": "https://ziglang.org/documentation/0.9.1/",
"stdDocs": "https://ziglang.org/documentation/0.9.1/std/",
"notes": "https://ziglang.org/download/0.9.1/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.9.1/zig-0.9.1.tar.xz",
"shasum": "38cf4e84481f5facc766ba72783e7462e08d6d29a5d47e3b75c8ee3142485210",
"size": "13940828"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.9.1/zig-bootstrap-0.9.1.tar.xz",
"shasum": "0a8e221c71860d8975c15662b3ed3bd863e81c4fe383455a596e5e0e490d6109",
"size": "42488812"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.9.1/zig-freebsd-x86_64-0.9.1.tar.xz",
"shasum": "4e06009bd3ede34b72757eec1b5b291b30aa0d5046dadd16ecb6b34a02411254",
"size": "39028848"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.9.1/zig-linux-aarch64-0.9.1.tar.xz",
"shasum": "5d99a39cded1870a3fa95d4de4ce68ac2610cca440336cfd252ffdddc2b90e66",
"size": "37034860"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.9.1/zig-linux-armv7a-0.9.1.tar.xz",
"shasum": "6de64456cb4757a555816611ea697f86fba7681d8da3e1863fa726a417de49be",
"size": "37974652"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.9.1/zig-linux-i386-0.9.1.tar.xz",
"shasum": "e776844fecd2e62fc40d94718891057a1dbca1816ff6013369e9a38c874374ca",
"size": "44969172"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.9.1/zig-linux-riscv64-0.9.1.tar.xz",
"shasum": "208dea53662c2c52777bd9e3076115d2126a4f71aed7f2ff3b8fe224dc3881aa",
"size": "39390868"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.9.1/zig-linux-x86_64-0.9.1.tar.xz",
"shasum": "be8da632c1d3273f766b69244d80669fe4f5e27798654681d77c992f17c237d7",
"size": "41011464"
},
"aarch64-macos": {
"tarball": "https://ziglang.org/download/0.9.1/zig-macos-aarch64-0.9.1.tar.xz",
"shasum": "8c473082b4f0f819f1da05de2dbd0c1e891dff7d85d2c12b6ee876887d438287",
"size": "38995640"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.9.1/zig-macos-x86_64-0.9.1.tar.xz",
"shasum": "2d94984972d67292b55c1eb1c00de46580e9916575d083003546e9a01166754c",
"size": "43713044"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.9.1/zig-windows-i386-0.9.1.zip",
"shasum": "74a640ed459914b96bcc572183a8db687bed0af08c30d2ea2f8eba03ae930f69",
"size": "67929868"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.9.1/zig-windows-x86_64-0.9.1.zip",
"shasum": "443da53387d6ae8ba6bac4b3b90e9fef4ecbe545e1c5fa3a89485c36f5c0e3a2",
"size": "65047697"
},
"aarch64-windows": {
"tarball": "https://ziglang.org/download/0.9.1/zig-windows-aarch64-0.9.1.zip",
"shasum": "621bf95f54dc3ff71466c5faae67479419951d7489e40e87fd26d195825fb842",
"size": "61478151"
}
},
"0.9.0": {
"date": "2021-12-20",
"docs": "https://ziglang.org/documentation/0.9.0/",
"stdDocs": "https://ziglang.org/documentation/0.9.0/std/",
"notes": "https://ziglang.org/download/0.9.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.9.0/zig-0.9.0.tar.xz",
"shasum": "cd1be83b12f8269cc5965e59877b49fdd8fa638efb6995ac61eb4cea36a2e381",
"size": "13928772"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.9.0/zig-bootstrap-0.9.0.tar.xz",
"shasum": "16b0bdf0bc0a5ed1e0950e08481413d806192e06443a512347526647b2baeabc",
"size": "42557736"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.9.0/zig-freebsd-x86_64-0.9.0.tar.xz",
"shasum": "c95afe679b7cc4110dc2ecd3606c83a699718b7a958d6627f74c20886333e194",
"size": "41293236"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.9.0/zig-linux-aarch64-0.9.0.tar.xz",
"shasum": "1524fedfdbade2dbc9bae1ed98ad38fa7f2114c9a3e94da0d652573c75efbc5a",
"size": "40008396"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.9.0/zig-linux-armv7a-0.9.0.tar.xz",
"shasum": "50225dee6e6448a63ee96383a34d9fe3bba34ae8da1a0c8619bde2cdfc1df87d",
"size": "41196876"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.9.0/zig-linux-i386-0.9.0.tar.xz",
"shasum": "b0dcf688349268c883292acdd55eaa3c13d73b9146e4b990fad95b84a2ac528b",
"size": "47408656"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.9.0/zig-linux-riscv64-0.9.0.tar.xz",
"shasum": "85466de07504767ed37f59782672ad41bbdf43d6480fafd07f45543278b07620",
"size": "44171420"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.9.0/zig-linux-x86_64-0.9.0.tar.xz",
"shasum": "5c55344a877d557fb1b28939785474eb7f4f2f327aab55293998f501f7869fa6",
"size": "43420796"
},
"aarch64-macos": {
"tarball": "https://ziglang.org/download/0.9.0/zig-macos-aarch64-0.9.0.tar.xz",
"shasum": "3991c70594d61d09fb4b316157a7c1d87b1d4ec159e7a5ecd11169ff74cad832",
"size": "39013392"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.9.0/zig-macos-x86_64-0.9.0.tar.xz",
"shasum": "c5280eeec4d6e5ea5ce5b448dc9a7c4bdd85ecfed4c1b96aa0835e48b36eccf0",
"size": "43764596"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.9.0/zig-windows-i386-0.9.0.zip",
"shasum": "bb839434afc75092015cf4c33319d31463c18512bc01dd719aedf5dcbc368466",
"size": "67946715"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.9.0/zig-windows-x86_64-0.9.0.zip",
"shasum": "084ea2646850aaf068234b0f1a92b914ed629be47075e835f8a67d55c21d880e",
"size": "65045849"
},
"aarch64-windows": {
"tarball": "https://ziglang.org/download/0.9.0/zig-windows-aarch64-0.9.0.zip",
"shasum": "f9018725e3fb2e8992b17c67034726971156eb190685018a9ac8c3a9f7a22340",
"size": "61461921"
}
},
"0.8.1": {
"date": "2021-09-06",
"docs": "https://ziglang.org/documentation/0.8.1/",
"stdDocs": "https://ziglang.org/documentation/0.8.1/std/",
"notes": "https://ziglang.org/download/0.8.1/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.8.1/zig-0.8.1.tar.xz",
"shasum": "8c428e14a0a89cb7a15a6768424a37442292858cdb695e2eb503fa3c7bf47f1a",
"size": "12650228"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.8.1/zig-bootstrap-0.8.1.tar.xz",
"shasum": "fa1239247f830ecd51c42537043f5220e4d1dfefdc54356fa419616a0efb3902",
"size": "43613464"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.8.1/zig-freebsd-x86_64-0.8.1.tar.xz",
"shasum": "fc4f6478bcf3a9fce1b8ef677a91694f476dd35be6d6c9c4f44a8b76eedbe176",
"size": "39150924"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.8.1/zig-linux-aarch64-0.8.1.tar.xz",
"shasum": "2166dc9f2d8df387e8b4122883bb979d739281e1ff3f3d5483fec3a23b957510",
"size": "37605932"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.8.1/zig-linux-armv7a-0.8.1.tar.xz",
"shasum": "5ba58141805e2519f38cf8e715933cbf059f4f3dade92c71838cce341045de05",
"size": "39185876"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.8.1/zig-linux-i386-0.8.1.tar.xz",
"shasum": "2f3e84f30492b5f1c5f97cecc0166f07a8a8d50c5f85dbb3a6ef2a4ee6f915e6",
"size": "44782932"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.8.1/zig-linux-riscv64-0.8.1.tar.xz",
"shasum": "4adfaf147b025917c03367462fe5018aaa9edbc6439ef9cd0da2b074ae960554",
"size": "41234480"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.8.1/zig-linux-x86_64-0.8.1.tar.xz",
"shasum": "6c032fc61b5d77a3f3cf781730fa549f8f059ffdb3b3f6ad1c2994d2b2d87983",
"size": "41250060"
},
"aarch64-macos": {
"tarball": "https://ziglang.org/download/0.8.1/zig-macos-aarch64-0.8.1.tar.xz",
"shasum": "5351297e3b8408213514b29c0a938002c5cf9f97eee28c2f32920e1227fd8423",
"size": "35340712"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.8.1/zig-macos-x86_64-0.8.1.tar.xz",
"shasum": "16b0e1defe4c1807f2e128f72863124bffdd906cefb21043c34b673bf85cd57f",
"size": "39946200"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.8.1/zig-windows-i386-0.8.1.zip",
"shasum": "099605051eb0452a947c8eab8fbbc7e43833c8376d267e94e41131c289a1c535",
"size": "64152358"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.8.1/zig-windows-x86_64-0.8.1.zip",
"shasum": "43573db14cd238f7111d6bdf37492d363f11ecd1eba802567a172f277d003926",
"size": "61897838"
}
},
"0.8.0": {
"date": "2021-06-04",
"docs": "https://ziglang.org/documentation/0.8.0/",
"stdDocs": "https://ziglang.org/documentation/0.8.0/std/",
"notes": "https://ziglang.org/download/0.8.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.8.0/zig-0.8.0.tar.xz",
"shasum": "03a828d00c06b2e3bb8b7ff706997fd76bf32503b08d759756155b6e8c981e77",
"size": "12614896"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.8.0/zig-bootstrap-0.8.0.tar.xz",
"shasum": "10600bc9c01f92e343f40d6ecc0ad05d67d27c3e382bce75524c0639cd8ca178",
"size": "43574248"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.8.0/zig-freebsd-x86_64-0.8.0.tar.xz",
"shasum": "0d3ccc436c8c0f50fd55462f72f8492d98723c7218ffc2a8a1831967d81b4bdc",
"size": "39125332"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.8.0/zig-linux-aarch64-0.8.0.tar.xz",
"shasum": "ee204ca2c2037952cf3f8b10c609373a08a291efa4af7b3c73be0f2b27720470",
"size": "37575428"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.8.0/zig-linux-armv7a-0.8.0.tar.xz",
"shasum": "d00b8bd97b79f45d6f5da956983bafeaa082e6c2ae8c6e1c6d4faa22fa29b320",
"size": "38884212"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.8.0/zig-linux-i386-0.8.0.tar.xz",
"shasum": "96e43ee6ed81c3c63401f456bd1c58ee6d42373a43cb324f5cf4974ca0998865",
"size": "42136032"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.8.0/zig-linux-riscv64-0.8.0.tar.xz",
"shasum": "75997527a78cdab64c40c43d9df39c01c4cdb557bb3992a869838371a204cfea",
"size": "40016268"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.8.0/zig-linux-x86_64-0.8.0.tar.xz",
"shasum": "502625d3da3ae595c5f44a809a87714320b7a40e6dff4a895b5fa7df3391d01e",
"size": "41211184"
},
"aarch64-macos": {
"tarball": "https://ziglang.org/download/0.8.0/zig-macos-aarch64-0.8.0.tar.xz",
"shasum": "b32d13f66d0e1ff740b3326d66a469ee6baddbd7211fa111c066d3bd57683111",
"size": "35292180"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.8.0/zig-macos-x86_64-0.8.0.tar.xz",
"shasum": "279f9360b5cb23103f0395dc4d3d0d30626e699b1b4be55e98fd985b62bc6fbe",
"size": "39969312"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.8.0/zig-windows-i386-0.8.0.zip",
"shasum": "b6ec9aa6cd6f3872fcb30d43ff411802d82008a0c4142ee49e208a09b2c1c5fe",
"size": "61507213"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.8.0/zig-windows-x86_64-0.8.0.zip",
"shasum": "8580fbbf3afb72e9b495c7f8aeac752a03475ae0bbcf5d787f3775c7e1f4f807",
"size": "61766193"
}
},
"0.7.1": {
"date": "2020-12-13",
"docs": "https://ziglang.org/documentation/0.7.1/",
"stdDocs": "https://ziglang.org/documentation/0.7.1/std/",
"notes": "https://ziglang.org/download/0.7.1/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.7.1/zig-0.7.1.tar.xz",
"shasum": "2db3b944ab368d955b48743d9f7c963b8f96de1a441ba5a35e197237cc6dae44",
"size": "10711824"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.7.1/zig-bootstrap-0.7.1.tar.xz",
"shasum": "040f27c1fae4b0cac0a2782aecdb691f6a2f8e89db6a6ed35024c31c304fd9b2",
"size": "40232612"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.7.1/zig-freebsd-x86_64-0.7.1.tar.xz",
"shasum": "e73c1dca35791a3183fdd5ecde0443ebbe180942efceafe651886034fb8def09",
"size": "39066808"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-aarch64-0.7.1.tar.xz",
"shasum": "48ec90eba407e4587ddef7eecef25fec7e13587eb98e3b83c5f2f5fff2a5cbe7",
"size": "33780552"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-armv7a-0.7.1.tar.xz",
"shasum": "5a0662e07b4c4968665e1f97558f8591f6facec45d2e0ff5715e661743107ceb",
"size": "35813504"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-i386-0.7.1.tar.xz",
"shasum": "4882e052e5f83690bd0334bb4fc1702b5403cb3a3d2aa63fd7d6043d8afecba3",
"size": "39230912"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-riscv64-0.7.1.tar.xz",
"shasum": "187294bfd35983348c3fe042901b42e67e7e36ab7f77a5f969d21c0051f4d21f",
"size": "37454812"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-x86_64-0.7.1.tar.xz",
"shasum": "18c7b9b200600f8bcde1cd8d7f1f578cbc3676241ce36d771937ce19a8159b8d",
"size": "37848176"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.7.1/zig-macos-x86_64-0.7.1.tar.xz",
"shasum": "845cb17562978af0cf67e3993f4e33330525eaf01ead9386df9105111e3bc519",
"size": "36211076"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.7.1/zig-windows-i386-0.7.1.zip",
"shasum": "a1b9a7421e13153e07fd2e2c93ff29aad64d83105b8fcdafa633dbe689caf1c0",
"size": "54374983"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.7.1/zig-windows-x86_64-0.7.1.zip",
"shasum": "4818a8a65b4672bc52c0ae7f14d014e0eb8caf10f12c0745176820384cea296a",
"size": "54909997"
}
},
"0.7.0": {
"date": "2020-11-08",
"docs": "https://ziglang.org/documentation/0.7.0/",
"stdDocs": "https://ziglang.org/documentation/0.7.0/std/",
"notes": "https://ziglang.org/download/0.7.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.7.0/zig-0.7.0.tar.xz",
"shasum": "0efd2cf6c3b05723db80e9cf193bc55150bba84ca41f855a90f53fc756445f83",
"size": "10683920"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.7.0/zig-bootstrap-0.7.0.tar.xz",
"shasum": "f073beaf5c53c8c57c0d374cbfcb332ef92ad703173edba0d9e0f2ed28401b72",
"size": "40200436"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.7.0/zig-freebsd-x86_64-0.7.0.tar.xz",
"shasum": "a0c926272ee4ae720034b4a6a1dc98399d76156dd84182554740f0ca8a41fc99",
"size": "34798992"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-aarch64-0.7.0.tar.xz",
"shasum": "f89933bac87d44be82325754ff88423020c81c7032a6fc41cfeb81e982eeab9b",
"size": "33096140"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-armv7a-0.7.0.tar.xz",
"shasum": "011c267e25a96ee160505a560c441daa045359a9d50e13ab1bada9d75c95db2d",
"size": "35157584"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-i386-0.7.0.tar.xz",
"shasum": "4bb2072cd363bcb1cbeb4872ff5cbc1f683b02d0cc1f90c46e3ea7422ce53222",
"size": "38530596"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-riscv64-0.7.0.tar.xz",
"shasum": "40dff81faa6f232ac40abbf88b9371f3cc932b6e09c423b94387c9ea580cb7be",
"size": "36759992"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-x86_64-0.7.0.tar.xz",
"shasum": "e619b1c6094c095b932767f527aee2507f847ea981513ff8a08aab0fd730e0ac",
"size": "37154432"
},
"aarch64-macos": {
"tarball": "https://ziglang.org/download/0.7.0/zig-macos-aarch64-0.7.0.tar.xz",
"shasum": "338238035734db74ea4f30e500a4893bf741d38305c10952d5e39fa05bdb057d",
"size": "33739424"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.7.0/zig-macos-x86_64-0.7.0.tar.xz",
"shasum": "94063f9a311cbbf7a2e0a12295e09437182cf950f18cb0eb30ea9893f3677f24",
"size": "35258328"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.7.0/zig-windows-i386-0.7.0.zip",
"shasum": "b1e520aacbfbd645ff3521b3eb4d44166d9a0288b8725e4b001f8b50a425eb2e",
"size": "53390517"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.7.0/zig-windows-x86_64-0.7.0.zip",
"shasum": "965f56c0a36f9cda2125e3a348bc654f7f155e2804c3667d231775ec228f8553",
"size": "53943784"
}
},
"0.6.0": {
"date": "2020-04-13",
"docs": "https://ziglang.org/documentation/0.6.0/",
"stdDocs": "https://ziglang.org/documentation/0.6.0/std/",
"notes": "https://ziglang.org/download/0.6.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.6.0/zig-0.6.0.tar.xz",
"shasum": "5d167dc19354282dd35dd17b38e99e1763713b9be8a4ba9e9e69284e059e7204",
"size": "10349552"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.6.0/zig-bootstrap-0.6.0.tar.xz",
"shasum": "5e0e4dc878b3dd0c1852a442b174f0732e8c07869a8fcd226b71a93b89b381ab",
"size": "38469948"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.6.0/zig-freebsd-x86_64-0.6.0.tar.xz",
"shasum": "190ff79c1eb56805a315d7c7a51082e32f62926250c0702b36760c225e1634a3",
"size": "36974604"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-aarch64-0.6.0.tar.xz",
"shasum": "e7520efd42cfa02be48c2e430d08fe1f3cbb999d21d9f0d3ffd0febb976b2f41",
"size": "37090044"
},
"armv6kz-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-armv6kz-0.6.0.tar.xz",
"shasum": "36b6493b3fed43eb1f0000e765798ad31a6bb7d7fd3f553ac1c3761dbc919b82",
"size": "39133452"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-armv7a-0.6.0.tar.xz",
"shasum": "946969abe357def95ca9cbbfcebfcf2d90cf967bcd3f48ee87662e32d91d8f35",
"size": "39143748"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-i386-0.6.0.tar.xz",
"shasum": "a97a2f9ae21575743cdd763c1917d49400d83fc562ef64582b18bade43eb24ce",
"size": "44877640"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-riscv64-0.6.0.tar.xz",
"shasum": "68ddee43f7503c8ae5f26a921f3602c34719a02ed2241f528c0b8b888cc14b38",
"size": "41993144"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-x86_64-0.6.0.tar.xz",
"shasum": "08fd3c757963630645441c2772362e9c2294020c44f14fce1b89f45de0dc1253",
"size": "44766320"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.6.0/zig-macos-x86_64-0.6.0.tar.xz",
"shasum": "17270360e87ddc49f737e760047b2fac49f1570a824a306119b1194ac4093895",
"size": "42573184"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.6.0/zig-windows-i386-0.6.0.zip",
"shasum": "3b0a02618743e92175990dc6d1a787bb95ff62c4cda016f1c14c7786f575f8ca",
"size": "60446431"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.6.0/zig-windows-x86_64-0.6.0.zip",
"shasum": "c3b897832523e1026e10b2d8d55d7f895185c0a27a63681f3a23219c3f1c38f4",
"size": "49065511"
}
},
"0.5.0": {
"date": "2019-09-30",
"docs": "https://ziglang.org/documentation/0.5.0/",
"notes": "https://ziglang.org/download/0.5.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.5.0/zig-0.5.0.tar.xz",
"shasum": "55ae16960f152bcb9cf98b4f8570902d0e559a141abf927f0d3555b7cc838a31",
"size": "10956132"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.5.0/zig-freebsd-x86_64-0.5.0.tar.xz",
"shasum": "9e1f4d36c3d584c0aa01f20eb4cd0a0eef3eee5af23e483b8414de55feab6ab6",
"size": "33650744"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.5.0/zig-macos-x86_64-0.5.0.tar.xz",
"shasum": "28702cc05745c7c0bd450487d5f4091bf0a1ad279b35eb9a640ce3e3a15b300d",
"size": "37898664"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.5.0/zig-windows-x86_64-0.5.0.zip",
"shasum": "58141323db8d84a5af62746be5f9140bc161ee760ef33dc91a887bf9ac021976",
"size": "44871804"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.5.0/zig-linux-x86_64-0.5.0.tar.xz",
"shasum": "43e8f8a8b8556edd373ddf9c1ef3ca6cf852d4d09fe07d5736d12fefedd2b4f7",
"size": "40895068"
}
},
"0.4.0": {
"date": "2019-04-08",
"docs": "https://ziglang.org/documentation/0.4.0/",
"notes": "https://ziglang.org/download/0.4.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.4.0/zig-0.4.0.tar.xz",
"shasum": "fec1f3f6b359a3d942e0a7f9157b3b30cde83927627a0e1ea95c54de3c526cfc",
"size": "5348776"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.4.0/zig-freebsd-x86_64-0.4.0.tar.xz",
"shasum": "3d557c91ac36d8262eb1733bb5f261c95944f9b635e43386e3d00a3272818c30",
"size": "27269672"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.4.0/zig-macos-x86_64-0.4.0.tar.xz",
"shasum": "67c932982484d017c5111e54af9f33f15e8e05c6bc5346a55e04052159c964a8",
"size": "30841504"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.4.0/zig-windows-x86_64-0.4.0.zip",
"shasum": "fbc3dd205e064c263063f69f600bedb18e3d0aa2efa747a63ef6cafb6d73f127",
"size": "35800101"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.4.0/zig-linux-x86_64-0.4.0.tar.xz",
"shasum": "fb1954e2fb556a01f8079a08130e88f70084e08978ff853bb2b1986d8c39d84e",
"size": "32876100"
}
},
"0.3.0": {
"date": "2018-09-28",
"docs": "https://ziglang.org/documentation/0.3.0/",
"notes": "https://ziglang.org/download/0.3.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.3.0/zig-0.3.0.tar.xz",
"shasum": "d70af604f3a8622f3393d93abb3e056bf60351e32d121e6fa4fe03d8d41e1f5a",
"size": "2335592"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.3.0/zig-macos-x86_64-0.3.0.tar.xz",
"shasum": "19dec1f1943ab7be26823376d466f7e456143deb34e17502778a949034dc2e7e",
"size": "23712696"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.3.0/zig-windows-x86_64-0.3.0.zip",
"shasum": "bb568c03950958f8bb3472139c3ab5ed74547c8c694ab50f404c202faf51baf4",
"size": "22524425"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.3.0/zig-linux-x86_64-0.3.0.tar.xz",
"shasum": "b378d0aae30cb54f28494e7bc4efbc9bfb6326f47bfb302e8b5287af777b2f3c",
"size": "25209304"
}
},
"0.2.0": {
"date": "2018-03-15",
"docs": "https://ziglang.org/documentation/0.2.0/",
"notes": "https://ziglang.org/download/0.2.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.2.0/zig-0.2.0.tar.xz",
"shasum": "29c9beb172737f4d5019b88ceae829ae8bc6512fb4386cfbf895ae2b42aa6965",
"size": "1940832"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.2.0/zig-win64-0.2.0.zip",
"shasum": "4f8a2979941a1f081ec8e545cca0b72608c0db1c5a3fd377a94db40649dcd3d4",
"size": "21076274"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.2.0/zig-linux-x86_64-0.2.0.tar.xz",
"shasum": "209c6fb745d42474c0a73d6f291c7ae3a38b6a1b6b641eea285a7f840cc1a890",
"size": "22551928"
}
},
"0.1.1": {
"date": "2017-10-17",
"docs": "https://ziglang.org/documentation/0.1.1/",
"notes": "https://ziglang.org/download/0.1.1/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.1.1/zig-0.1.1.tar.xz",
"shasum": "ffca0cfb263485287e19cc997b08701fcd5f24b700345bcdc3dd8074f5a104e0",
"size": "1659716"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.1.1/zig-win64-0.1.1.zip",
"shasum": "6fc88bef531af7e567fe30bf60da1487b86833cbee84c7a2f3e317030aa5b660",
"size": "19757776"
}
}
}

View File

@@ -1,97 +0,0 @@
#!/bin/sh
set -x
set -e
sudo pkgin -y update
sudo pkgin -y upgrade
sudo pkgin -y install cmake samurai curl jq py27-s3cmd wget clang
ZIGDIR="$(pwd)"
CACHE_BASENAME="zig+llvm+lld+clang-x86_64-netbsd-gnu-0.8.0"
PREFIX="$HOME/$CACHE_BASENAME"
cd $HOME
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
# SourceHut reports that it is a terminal that supports escape codes, but it
# is a filthy liar. Here we tell Zig to not try to send any terminal escape
# codes to show progress.
export TERM=dumb
mkdir build
cd build
export CC="$PREFIX/bin/zigcc"
export CXX="$PREFIX/bin/zigcxx"
echo "#!/bin/sh
env CC=\"clang\" $PREFIX/bin/zig cc \"\$@\"" > $CC
echo "#!/bin/sh
env CC=\"clang\" $PREFIX/bin/zig c++ \"\$@\"" > $CXX
chmod +x $CC
chmod +x $CXX
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$PREFIX \
"-DCMAKE_INSTALL_PREFIX=$(pwd)/release" \
-DZIG_STATIC=ON \
-DZIG_TARGET_TRIPLE=x86_64-netbsd-none \
-GNinja
samu install
unset CC
unset CXX
# TODO ld.lld: error: undefined symbol: main
#>>> referenced by crt0-common.c
#>>> /usr/lib/crt0.o:(___start)
#release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test
# Here we skip some tests to save time.
release/bin/zig build test -Dskip-stage1 -Dskip-non-native
if [ -f ~/.s3cfg ]; then
mv ../LICENSE release/
mv ../zig-cache/langref.html release/
mv release/bin/zig release/
rmdir release/bin
GITBRANCH=$(basename $GITHUB_REF)
VERSION=$(release/zig version)
DIRNAME="zig-netbsd-x86_64-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="netbsd-$GITBRANCH.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/x86_64-netbsd-$VERSION.json"
if [ "$GITBRANCH" = "master" ]; then
# avoid leaking oauth token
set +x
OAUTH_TOKEN="$(cat ~/.oauth_token)"
cd "$ZIGDIR"
./ci/srht/on_master_success "$VERSION" "$OAUTH_TOKEN"
fi
fi

View File

@@ -15,16 +15,6 @@ VERSION="$1"
OAUTH_TOKEN="$2"
YML_FILE="tmp.yml"
if [ -z "$VERSION" ]; then
echo "missing VERSION parameter"
exit 1
fi
if [ -z "$OAUTH_TOKEN" ]; then
echo "missing OAUTH_TOKEN parameter"
exit 1
fi
cat <<EOF >"$YML_FILE"
image: alpine/latest
packages:
@@ -34,7 +24,6 @@ packages:
- xz
secrets:
- 51bfddf5-86a6-4e01-8576-358c72a4a0a4
- 44e2bd57-1d07-42bf-925e-22a36119041d
sources:
- https://github.com/ziglang/zig
tasks:

View File

@@ -1,99 +0,0 @@
const std = @import("std");
const path = std.fs.path;
const mem = std.mem;
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
const out_dir = "out";
try std.fs.cwd().makePath(out_dir);
{
const out_file = out_dir ++ path.sep_str ++ "index.json";
const in_file = "index.json";
try render(allocator, in_file, out_file, .plain);
}
}
fn render(
allocator: mem.Allocator,
in_file: []const u8,
out_file: []const u8,
fmt: enum {
html,
plain,
},
) !void {
const in_contents = try std.fs.cwd().readFileAlloc(allocator, in_file, 1 * 1024 * 1024);
var vars = try std.process.getEnvMap(allocator);
var buffer = std.ArrayList(u8).init(allocator);
defer buffer.deinit();
const State = enum {
Start,
OpenBrace,
VarName,
EndBrace,
};
const writer = buffer.writer();
var state = State.Start;
var var_name_start: usize = undefined;
var line: usize = 1;
for (in_contents) |byte, index| {
switch (state) {
State.Start => switch (byte) {
'{' => {
state = State.OpenBrace;
},
else => try writer.writeByte(byte),
},
State.OpenBrace => switch (byte) {
'{' => {
state = State.VarName;
var_name_start = index + 1;
},
else => {
try writer.writeByte('{');
try writer.writeByte(byte);
state = State.Start;
},
},
State.VarName => switch (byte) {
'}' => {
const var_name = in_contents[var_name_start..index];
if (vars.get(var_name)) |value| {
const trimmed = mem.trim(u8, value, " \r\n");
if (fmt == .html and mem.endsWith(u8, var_name, "BYTESIZE")) {
const size = try std.fmt.parseInt(u64, trimmed, 10);
try writer.print("{:.1}", .{std.fmt.fmtIntSizeDec(size)});
} else {
try writer.writeAll(trimmed);
}
} else {
std.debug.print("line {d}: missing variable: {s}\n", .{ line, var_name });
try writer.writeAll("(missing)");
}
state = State.EndBrace;
},
else => {},
},
State.EndBrace => switch (byte) {
'}' => {
state = State.Start;
},
else => {
std.debug.print("line {d}: invalid byte: '0x{x}'", .{ line, byte });
std.process.exit(1);
},
},
}
if (byte == '\n') {
line += 1;
}
}
try std.fs.cwd().writeFile(out_file, buffer.items);
}

View File

@@ -12,43 +12,30 @@ NATIVE_TARBALL="zig-linux-$(uname -m)-$VERSION.tar.xz"
AARCH64_LINUX_JSON_URL="https://ziglang.org/builds/aarch64-linux-$VERSION.json"
X86_64_LINUX_JSON_URL="https://ziglang.org/builds/x86_64-linux-$VERSION.json"
X86_64_WINDOWS_JSON_URL="https://ziglang.org/builds/x86_64-windows-$VERSION.json"
AARCH64_MACOS_JSON_URL="https://ziglang.org/builds/aarch64-macos-$VERSION.json"
X86_64_MACOS_JSON_URL="https://ziglang.org/builds/x86_64-macos-$VERSION.json"
X86_64_FREEBSD_JSON_URL="https://ziglang.org/builds/x86_64-freebsd-$VERSION.json"
#X86_64_NETBSD_JSON_URL="https://ziglang.org/builds/x86_64-netbsd-$VERSION.json"
# If any of these fail, it's not really this job failing; rather we have detected
# that this job will be called again later when other jobs have completed.
curl --fail -I "$AARCH64_LINUX_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_LINUX_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_WINDOWS_JSON_URL" >/dev/null || exit 0
curl --fail -I "$AARCH64_MACOS_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_MACOS_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_FREEBSD_JSON_URL" >/dev/null || exit 0
#curl --fail -I "$X86_64_NETBSD_JSON_URL" >/dev/null || exit 0
# Without --user, this gave me:
# ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied
pip3 install s3cmd --user
S3CMD="$HOME/.local/bin/s3cmd"
# This is the user when pushing to the website repo.
git config --global user.email "ziggy@ziglang.org"
git config --global user.name "Ziggy"
# Refresh this with `ssh-keyscan github.com` from a trusted Internet connection.
# We hard code the public key here to detect man-in-the-middle attacks.
echo "github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" >> ~/.ssh/known_hosts
# We don't want the .git folder inside the tarball.
rm -rf .git
cd "$HOME"
wget "https://ziglang.org/builds/$NATIVE_TARBALL"
tar xf "$NATIVE_TARBALL"
ZIGDIR="$(pwd)/$(basename $NATIVE_TARBALL .tar.xz)"
ZIGDIR=$(basename $NATIVE_TARBALL .tar.xz)
ZIG="$ZIGDIR/zig"
LANGREF="$ZIGDIR/doc/langref.html"
LANGREF="$ZIGDIR/langref.html"
SRCTARBALLDIR="zig-$VERSION"
export SRC_TARBALL="$SRCTARBALLDIR.tar.xz"
mv "$SRCDIR" "$SRCTARBALLDIR"
@@ -61,11 +48,6 @@ export X86_64_WINDOWS_TARBALL="$(echo "$X86_64_WINDOWS_JSON" | jq .tarball -r)"
export X86_64_WINDOWS_BYTESIZE="$(echo "$X86_64_WINDOWS_JSON" | jq .size -r)"
export X86_64_WINDOWS_SHASUM="$(echo "$X86_64_WINDOWS_JSON" | jq .shasum -r)"
AARCH64_MACOS_JSON=$(curl --fail "$AARCH64_MACOS_JSON_URL" || exit 1)
export AARCH64_MACOS_TARBALL="$(echo "$AARCH64_MACOS_JSON" | jq .tarball -r)"
export AARCH64_MACOS_BYTESIZE="$(echo "$AARCH64_MACOS_JSON" | jq .size -r)"
export AARCH64_MACOS_SHASUM="$(echo "$AARCH64_MACOS_JSON" | jq .shasum -r)"
X86_64_MACOS_JSON=$(curl --fail "$X86_64_MACOS_JSON_URL" || exit 1)
export X86_64_MACOS_TARBALL="$(echo "$X86_64_MACOS_JSON" | jq .tarball -r)"
export X86_64_MACOS_BYTESIZE="$(echo "$X86_64_MACOS_JSON" | jq .size -r)"
@@ -86,65 +68,13 @@ export X86_64_FREEBSD_TARBALL="$(echo "$X86_64_FREEBSD_JSON" | jq .tarball -r)"
export X86_64_FREEBSD_BYTESIZE="$(echo "$X86_64_FREEBSD_JSON" | jq .size -r)"
export X86_64_FREEBSD_SHASUM="$(echo "$X86_64_FREEBSD_JSON" | jq .shasum -r)"
#X86_64_NETBSD_JSON=$(curl --fail "$X86_64_NETBSD_JSON_URL" || exit 1)
#export X86_64_NETBSD_TARBALL="$(echo "$X86_64_NETBSD_JSON" | jq .tarball -r)"
#export X86_64_NETBSD_BYTESIZE="$(echo "$X86_64_NETBSD_JSON" | jq .size -r)"
#export X86_64_NETBSD_SHASUM="$(echo "$X86_64_NETBSD_JSON" | jq .shasum -r)"
git clone https://github.com/ziglang/www.ziglang.org --depth 1
cd www.ziglang.org
export MASTER_DATE="$(date +%Y-%m-%d)"
export MASTER_VERSION="$VERSION"
"../$ZIG" run update-download-page.zig
# Create index.json and update the website repo.
cd "$SRCTARBALLDIR/ci/srht"
"$ZIG" run update-download-page.zig
CIDIR="$(pwd)"
cd "$HOME"
# Update autodocs and langref directly to S3 in order to prevent the
# www.ziglang.org git repo from growing too big.
# Please do not edit this script to pre-compress the artifacts before they hit
# S3. This prevents the website from working on browsers that do not support gzip
# encoding. Cloudfront will automatically compress files if they are less than
# 9.5 MiB, and the client advertises itself as capable of decompressing.
# The data.js file is currently 16 MiB. In order to fix this problem, we need to do
# one of the following things:
# * Reduce the size of data.js to less than 9.5 MiB.
# * Figure out how to adjust the Cloudfront settings to increase the max size for
# auto-compressed objects.
# * Migrate to fastly.
$S3CMD put -P --no-mime-magic \
--add-header="Cache-Control: max-age=0, must-revalidate" \
"$LANGREF" s3://ziglang.org/documentation/master/index.html
$S3CMD put -P --no-mime-magic \
--add-header="Cache-Control: max-age=0, must-revalidate" \
"$ZIGDIR/doc/std/index.html" s3://ziglang.org/documentation/master/std/index.html
$S3CMD put -P --no-mime-magic \
--add-header="Cache-Control: max-age=0, must-revalidate" \
"$ZIGDIR/doc/std/main.js" s3://ziglang.org/documentation/master/std/main.js
$S3CMD put -P --no-mime-magic \
--add-header="Cache-Control: max-age=0, must-revalidate" \
"$ZIGDIR/doc/std/data.js" s3://ziglang.org/documentation/master/std/data.js
$S3CMD put -P --no-mime-magic --recursive \
--add-header="Cache-Control: max-age=0, must-revalidate" \
-m "text/html" \
"$ZIGDIR/doc/std/src/" s3://ziglang.org/documentation/master/std/src/
$S3CMD put -P --no-mime-magic \
--add-header="cache-control: public, max-age=31536000, immutable" \
"$HOME/$SRC_TARBALL" s3://ziglang.org/builds/
git clone --depth 1 git@github.com:ziglang/www.ziglang.org.git
cd www.ziglang.org
WWWDIR="$(pwd)"
cd "$WWWDIR"
cp "$CIDIR/out/index.json" data/releases.json
git add data/releases.json
git commit -m "CI: update releases"
git push origin master
$S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536000, immutable" "../$SRC_TARBALL" s3://ziglang.org/builds/
$S3CMD put -P --no-mime-magic "../$LANGREF" s3://ziglang.org/documentation/master/index.html --add-header="Cache-Control: max-age=0, must-revalidate"
$S3CMD put -P --no-mime-magic www/download/index.html s3://ziglang.org/download/index.html --add-header="Cache-Control: max-age=0, must-revalidate"
$S3CMD put -P --no-mime-magic www/download/index.json s3://ziglang.org/download/index.json --add-header="Cache-Control: max-age=0, must-revalidate"

View File

@@ -1,20 +0,0 @@
#!/bin/sh
set -x
set -e
RELEASE_STAGING="$DRONE_WORKSPACE/_release/staging"
TARGET="aarch64-macos-none"
MCPU="apple_a14"
INSTALL_PREFIX="$DRONE_WORKSPACE/$TARGET"
SEARCH_PREFIX="/deps/$TARGET"
"$RELEASE_STAGING/bin/zig" build \
--prefix "$INSTALL_PREFIX" \
--search-prefix "$SEARCH_PREFIX" \
-Dstatic-llvm \
-Drelease \
-Dstrip \
-Dtarget="$TARGET" \
-Dcpu="$MCPU" \
-Denable-stage1

View File

@@ -1,10 +0,0 @@
#!/bin/sh
set -x
set -e
# Make the `zig version` number consistent.
# This will affect the cmake commands that follow.
# This is in its own script because git does not support this command
# being run concurrently with itself.
git config core.abbrev 9

View File

@@ -1,88 +0,0 @@
---
kind: pipeline
type: docker
name: x86_64-linux
platform:
os: linux
arch: amd64
workspace:
path: /workspace
steps:
- name: configure_git
image: ci/debian-amd64:11.1-12
commands:
- ./ci/zinc/configure_git
- name: test_stage3_debug
depends_on:
- configure_git
image: ci/debian-amd64:11.1-12
commands:
- ./ci/zinc/linux_test_stage3_debug
- name: test_stage3_release
depends_on:
- configure_git
image: ci/debian-amd64:11.1-12
commands:
- ./ci/zinc/linux_test_stage3_release
- name: build_aarch64_macos
depends_on:
- test_stage3_release
image: ci/debian-amd64:11.1-12
commands:
- ./ci/zinc/build_aarch64_macos
- name: linux_package
depends_on:
- test_stage3_debug
- test_stage3_release
when:
branch:
- master
event:
- push
image: ci/debian-amd64:11.1-12
environment:
AWS_ACCESS_KEY_ID:
from_secret: AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY
commands:
- ./ci/zinc/linux_package
- name: macos_package
depends_on:
- test_stage3_debug
- build_aarch64_macos
when:
branch:
- master
event:
- push
image: ci/debian-amd64:11.1-12
environment:
AWS_ACCESS_KEY_ID:
from_secret: AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY
commands:
- ./ci/zinc/macos_package
- name: notify_lavahut
depends_on:
- macos_package
- linux_package
when:
branch:
- master
event:
- push
image: ci/debian-amd64:11.1-12
environment:
SRHT_OAUTH_TOKEN:
from_secret: SRHT_OAUTH_TOKEN
commands:
- ./ci/zinc/notify_lavahut

View File

@@ -1,45 +0,0 @@
#!/bin/sh
set -x
set -e
ARCH="$(uname -m)"
OS="linux"
RELEASE_STAGING="$DRONE_WORKSPACE/_release/staging"
VERSION=$($RELEASE_STAGING/bin/zig version)
BASENAME="zig-$OS-$ARCH-$VERSION"
TARBALL="$BASENAME.tar.xz"
# This runs concurrently with the macos_package script, so it should not make
# any changes to the filesystem that will cause problems for the other script.
cp -r "$RELEASE_STAGING" "$BASENAME"
# Remove the unnecessary bin dir in $prefix/bin/zig
mv $BASENAME/bin/zig $BASENAME/
rmdir $BASENAME/bin
# Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig
mv $BASENAME/lib/zig $BASENAME/lib2
rmdir $BASENAME/lib
mv $BASENAME/lib2 $BASENAME/lib
tar cfJ "$TARBALL" "$BASENAME"
SHASUM=$(sha256sum $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
MANIFEST="manifest-$TARGET.json"
touch $MANIFEST
echo "{\"tarball\": \"$TARBALL\"," >>$MANIFEST
echo "\"shasum\": \"$SHASUM\"," >>$MANIFEST
echo "\"size\": \"$BYTESIZE\"}" >>$MANIFEST
# Publish artifact.
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
# Publish manifest.
s3cmd put -P --add-header="cache-control: max-age=0, must-revalidate" "$MANIFEST" "s3://ziglang.org/builds/$ARCH-$OS-$VERSION.json"
# Explicit exit helps show last command duration.
exit

View File

@@ -1,62 +0,0 @@
#!/bin/sh
set -x
set -e
ARCH="$(uname -m)"
DEPS_LOCAL="/deps/local"
OLD_ZIG="$DEPS_LOCAL/bin/zig"
TARGET="${ARCH}-linux-musl"
MCPU="baseline"
export PATH=$DEPS_LOCAL/bin:$PATH
echo "building stage3-debug with zig version $($OLD_ZIG version)"
# Override the cache directories so that we don't clobber with the release
# testing script which is running concurrently and in the same directory.
# Normally we want processes to cooperate, but in this case we want them isolated.
export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-cache-local-debug"
export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-cache-global-debug"
export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU"
mkdir build-debug
cd build-debug
cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/stage3" \
-DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_STATIC=ON \
-DZIG_USE_LLVM_CONFIG=OFF \
-GNinja
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
echo "Looking for non-conforming code formatting..."
stage3/bin/zig fmt --check .. \
--exclude ../test/cases/ \
--exclude ../build-debug \
--exclude ../build-release \
--exclude "$ZIG_LOCAL_CACHE_DIR" \
--exclude "$ZIG_GLOBAL_CACHE_DIR"
# simultaneously test building self-hosted without LLVM and with 32-bit arm
stage3/bin/zig build -Dtarget=arm-linux-musleabihf
stage3/bin/zig build test \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dtarget=native-native-musl \
--search-prefix "$DEPS_LOCAL" \
--zig-lib-dir "$(pwd)/../lib"
# Explicit exit helps show last command duration.
exit

View File

@@ -1,60 +0,0 @@
#!/bin/sh
set -x
set -e
ARCH="$(uname -m)"
DEPS_LOCAL="/deps/local"
RELEASE_STAGING="$DRONE_WORKSPACE/_release/staging"
OLD_ZIG="$DEPS_LOCAL/bin/zig"
TARGET="${ARCH}-linux-musl"
MCPU="baseline"
export PATH=$DEPS_LOCAL/bin:$PATH
echo "building stage3-release with zig version $($OLD_ZIG version)"
export CC="$OLD_ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$OLD_ZIG c++ -target $TARGET -mcpu=$MCPU"
mkdir build-release
cd build-release
cmake .. \
-DCMAKE_INSTALL_PREFIX="$RELEASE_STAGING" \
-DCMAKE_PREFIX_PATH="$DEPS_LOCAL" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-GNinja
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
ninja install
"$RELEASE_STAGING/bin/zig" build test docs \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
-Dtarget=native-native-musl \
--search-prefix "$DEPS_LOCAL" \
--zig-lib-dir "$(pwd)/../lib"
# Produce the experimental std lib documentation.
mkdir -p "$RELEASE_STAGING/doc/std"
"$RELEASE_STAGING/bin/zig" test ../lib/std/std.zig \
-femit-docs=$RELEASE_STAGING/doc/std \
-fno-emit-bin \
--zig-lib-dir "$(pwd)/../lib"
cp ../LICENSE $RELEASE_STAGING/
cp ../zig-cache/langref.html $RELEASE_STAGING/doc/
# Look for HTML errors.
tidy --drop-empty-elements no -qe $RELEASE_STAGING/doc/langref.html
# Explicit exit helps show last command duration.
exit

View File

@@ -1,49 +0,0 @@
#!/bin/sh
set -x
set -e
ARCH="aarch64"
OS=macos
ZIG_PREFIX="$DRONE_WORKSPACE/_release/staging"
VERSION=$($ZIG_PREFIX/bin/zig version)
TARGET="$ARCH-$OS-none"
INSTALL_PREFIX="$DRONE_WORKSPACE/$TARGET"
BASENAME="zig-$OS-$ARCH-$VERSION"
TARBALL="$BASENAME.tar.xz"
# This runs concurrently with the linux_package script, so it should not make
# any changes to the filesystem that will cause problems for the other script.
# Remove the unnecessary bin dir in $prefix/bin/zig
mv $INSTALL_PREFIX/bin/zig $INSTALL_PREFIX/
rmdir $INSTALL_PREFIX/bin
# Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig
mv $INSTALL_PREFIX/lib/zig $INSTALL_PREFIX/lib2
rmdir $INSTALL_PREFIX/lib
mv $INSTALL_PREFIX/lib2 $INSTALL_PREFIX/lib
cp -r "$ZIG_PREFIX/doc" "$INSTALL_PREFIX/"
cp "$ZIG_PREFIX/LICENSE" "$INSTALL_PREFIX/"
mv "$INSTALL_PREFIX" "$BASENAME"
tar cfJ "$TARBALL" "$BASENAME"
SHASUM=$(sha256sum $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
MANIFEST="manifest-$TARGET.json"
touch $MANIFEST
echo "{\"tarball\": \"$TARBALL\"," >>$MANIFEST
echo "\"shasum\": \"$SHASUM\"," >>$MANIFEST
echo "\"size\": \"$BYTESIZE\"}" >>$MANIFEST
# Publish artifact.
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
# Publish manifest.
s3cmd put -P --add-header="cache-control: max-age=0, must-revalidate" "$MANIFEST" "s3://ziglang.org/builds/$ARCH-$OS-$VERSION.json"
# Explicit exit helps show last command duration.
exit

View File

@@ -1,9 +0,0 @@
#!/bin/sh
set +x # Avoid leaking oauth token.
set -e
ZIG_PREFIX="$DRONE_WORKSPACE/_release/staging"
VERSION=$($ZIG_PREFIX/bin/zig version)
cd $DRONE_WORKSPACE
./ci/srht/on_master_success "$VERSION" "$SRHT_OAUTH_TOKEN"

View File

@@ -8,33 +8,45 @@
# CLANG_LIBDIRS
find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
HINTS ${LLVM_INCLUDE_DIRS}
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
PATHS
/usr/lib/llvm/11/include
/usr/lib/llvm-11/include
/usr/lib/llvm-11.0/include
/usr/local/llvm110/include
/usr/local/llvm11/include
/mingw64/include
)
if(${LLVM_LINK_MODE} STREQUAL "shared")
if(ZIG_PREFER_CLANG_CPP_DYLIB)
find_library(CLANG_LIBRARIES
NAMES
libclang-cpp.so.15
clang-cpp-15.0
clang-cpp150
clang-cpp-11.0
clang-cpp110
clang-cpp
NAMES_PER_DIR
HINTS "${LLVM_LIBDIRS}"
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
PATHS
${CLANG_LIBDIRS}
/usr/lib/llvm/11/lib
/usr/lib/llvm/11/lib64
/usr/lib/llvm-11/lib
/usr/local/llvm110/lib
/usr/local/llvm11/lib
)
else()
endif()
if(NOT CLANG_LIBRARIES)
macro(FIND_AND_ADD_CLANG_LIB _libname_)
string(TOUPPER ${_libname_} _prettylibname_)
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} NAMES_PER_DIR
HINTS "${LLVM_LIBDIRS}"
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_}
PATHS
${CLANG_LIBDIRS}
/usr/lib/llvm/11/lib
/usr/lib/llvm-11/lib
/usr/lib/llvm-11.0/lib
/usr/local/llvm110/lib
/usr/local/llvm11/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:\\msys64\\mingw64\\lib
)
if(CLANG_${_prettylibname_}_LIB)
set(CLANG_LIBRARIES ${CLANG_LIBRARIES} ${CLANG_${_prettylibname_}_LIB})
@@ -64,8 +76,6 @@ else()
FIND_AND_ADD_CLANG_LIB(clangCrossTU)
FIND_AND_ADD_CLANG_LIB(clangIndex)
FIND_AND_ADD_CLANG_LIB(clangToolingCore)
FIND_AND_ADD_CLANG_LIB(clangExtractAPI)
FIND_AND_ADD_CLANG_LIB(clangSupport)
endif()
include(FindPackageHandleStandardArgs)

View File

@@ -7,51 +7,46 @@
# LLD_LIBRARIES
find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
HINTS ${LLVM_INCLUDE_DIRS}
PATHS
/usr/lib/llvm-15/include
/usr/local/llvm150/include
/usr/local/llvm15/include
/usr/local/opt/llvm@15/include
/opt/homebrew/opt/llvm@15/include
/usr/lib/llvm-11/include
/usr/local/llvm110/include
/usr/local/llvm11/include
/mingw64/include)
find_library(LLD_LIBRARY NAMES lld-15.0 lld150 lld NAMES_PER_DIR
HINTS ${LLVM_LIBDIRS}
find_library(LLD_LIBRARY NAMES lld-11.0 lld110 lld
PATHS
/usr/lib/llvm-15/lib
/usr/local/llvm150/lib
/usr/local/llvm15/lib
/usr/local/opt/llvm@15/lib
/opt/homebrew/opt/llvm@15/lib
/usr/lib/llvm-11/lib
/usr/local/llvm110/lib
/usr/local/llvm11/lib
)
if(EXISTS ${LLD_LIBRARY})
set(LLD_LIBRARIES ${LLD_LIBRARY})
else()
macro(FIND_AND_ADD_LLD_LIB _libname_)
string(TOUPPER ${_libname_} _prettylibname_)
find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_} NAMES_PER_DIR
HINTS ${LLVM_LIBDIRS}
find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_}
PATHS
${LLD_LIBDIRS}
/usr/lib/llvm-15/lib
/usr/local/llvm150/lib
/usr/local/llvm15/lib
/usr/local/opt/llvm@15/lib
/opt/homebrew/opt/llvm@15/lib
/usr/lib/llvm-11/lib
/usr/local/llvm110/lib
/usr/local/llvm11/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:/msys64/mingw64/lib)
if(LLD_${_prettylibname_}_LIB)
set(LLD_LIBRARIES ${LLD_LIBRARIES} ${LLD_${_prettylibname_}_LIB})
if(LLD_${_prettylibname_}_LIB)
set(LLD_LIBRARIES ${LLD_LIBRARIES} ${LLD_${_prettylibname_}_LIB})
endif()
endmacro(FIND_AND_ADD_LLD_LIB)
FIND_AND_ADD_LLD_LIB(lldDriver)
FIND_AND_ADD_LLD_LIB(lldMinGW)
FIND_AND_ADD_LLD_LIB(lldELF)
FIND_AND_ADD_LLD_LIB(lldCOFF)
FIND_AND_ADD_LLD_LIB(lldWasm)
FIND_AND_ADD_LLD_LIB(lldMachO)
FIND_AND_ADD_LLD_LIB(lldWasm)
FIND_AND_ADD_LLD_LIB(lldReaderWriter)
FIND_AND_ADD_LLD_LIB(lldCore)
FIND_AND_ADD_LLD_LIB(lldYAML)
FIND_AND_ADD_LLD_LIB(lldCommon)
endif()

View File

@@ -6,149 +6,150 @@
# LLVM_INCLUDE_DIRS
# LLVM_LIBRARIES
# LLVM_LIBDIRS
# LLVM_LINK_MODE
find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h
PATHS
/usr/lib/llvm/11/include
/usr/lib/llvm-11/include
/usr/lib/llvm-11.0/include
/usr/local/llvm11/include
/usr/local/llvm110/include
/mingw64/include
)
if(ZIG_USE_LLVM_CONFIG)
set(LLVM_CONFIG_ERROR_MESSAGES "")
while(1)
unset(LLVM_CONFIG_EXE CACHE)
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-15 llvm-config-15.0 llvm-config150 llvm-config15 llvm-config NAMES_PER_DIR
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-15.0.0/bin")
if(ZIG_PREFER_CLANG_CPP_DYLIB)
find_library(LLVM_LIBRARIES
NAMES
LLVM-11.0
LLVM-11
LLVM-110
LLVM
PATHS
${LLVM_LIBDIRS}
/usr/lib/llvm/11/lib
/usr/lib/llvm/11/lib64
/usr/lib/llvm-11/lib
/usr/local/llvm11/lib
/usr/local/llvm110/lib
)
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
if (NOT LLVM_CONFIG_ERROR_MESSAGES STREQUAL "")
list(JOIN LLVM_CONFIG_ERROR_MESSAGES "\n" LLVM_CONFIG_ERROR_MESSAGE)
message(FATAL_ERROR ${LLVM_CONFIG_ERROR_MESSAGE})
else()
message(FATAL_ERROR "unable to find llvm-config")
endif()
endif()
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-11 llvm-config-11.0 llvm-config110 llvm-config11 llvm-config
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-11.0.0/bin")
# Check that this LLVM is the right version
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --version
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
endif()
get_filename_component(LLVM_CONFIG_DIR "${LLVM_CONFIG_EXE}" DIRECTORY)
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 15 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 16 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 16)
# Save the error message, in case this is the last llvm-config we find
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "expected LLVM 15.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
endif()
# Ignore this directory and try the search again
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
continue()
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --version
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Check that this LLVM supports linking as a shared/static library, if requested
if (ZIG_SHARED_LLVM OR ZIG_STATIC_LLVM)
if (ZIG_SHARED_LLVM)
set(STATIC_OR_SHARED_LINK "--link-shared")
elseif (ZIG_STATIC_LLVM)
set(STATIC_OR_SHARED_LINK "--link-static")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 11)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 12)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 12)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
elseif(("${ZIG_TARGET_TRIPLE}" STREQUAL "native") OR ZIG_PREFER_LLVM_CONFIG)
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-11 llvm-config-11.0 llvm-config110 llvm-config11 llvm-config
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-11.0.0/bin")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libs ${STATIC_OR_SHARED_LINK}
OUTPUT_QUIET
ERROR_VARIABLE LLVM_CONFIG_ERROR
ERROR_STRIP_TRAILING_WHITESPACE)
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
endif()
if (LLVM_CONFIG_ERROR)
# Save the error message, in case this is the last llvm-config we find
if (ZIG_SHARED_LLVM)
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 15.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
else()
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 15.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
endif()
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
endif()
# Ignore this directory and try the search again
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
continue()
endif()
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --version
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --targets-built
OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
function(NEED_TARGET TARGET_NAME)
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 11)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 12)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 12)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --targets-built
OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
function(NEED_TARGET TARGET_NAME)
list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index)
if (${_index} EQUAL -1)
# Save the error message, in case this is the last llvm-config we find
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM (according to ${LLVM_CONFIG_EXE}) is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.")
# Ignore this directory and try the search again
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
continue()
message(FATAL_ERROR "LLVM (according to ${LLVM_CONFIG_EXE}) is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.")
endif()
endfunction(NEED_TARGET)
NEED_TARGET("AArch64")
NEED_TARGET("AMDGPU")
NEED_TARGET("ARM")
NEED_TARGET("AVR")
NEED_TARGET("BPF")
NEED_TARGET("Hexagon")
NEED_TARGET("Lanai")
NEED_TARGET("Mips")
NEED_TARGET("MSP430")
NEED_TARGET("NVPTX")
NEED_TARGET("PowerPC")
NEED_TARGET("RISCV")
NEED_TARGET("Sparc")
NEED_TARGET("SystemZ")
NEED_TARGET("VE")
NEED_TARGET("WebAssembly")
NEED_TARGET("X86")
NEED_TARGET("XCore")
endfunction(NEED_TARGET)
NEED_TARGET("AArch64")
NEED_TARGET("AMDGPU")
NEED_TARGET("ARM")
NEED_TARGET("AVR")
NEED_TARGET("BPF")
NEED_TARGET("Hexagon")
NEED_TARGET("Lanai")
NEED_TARGET("Mips")
NEED_TARGET("MSP430")
NEED_TARGET("NVPTX")
NEED_TARGET("PowerPC")
NEED_TARGET("RISCV")
NEED_TARGET("Sparc")
NEED_TARGET("SystemZ")
NEED_TARGET("WebAssembly")
NEED_TARGET("X86")
NEED_TARGET("XCore")
# Got it!
break()
endwhile()
if(ZIG_SHARED_LLVM OR ZIG_STATIC_LLVM)
if(ZIG_STATIC_LLVM)
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libfiles ${STATIC_OR_SHARED_LINK}
COMMAND ${LLVM_CONFIG_EXE} --libfiles --link-static
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libdir ${STATIC_OR_SHARED_LINK}
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --system-libs ${STATIC_OR_SHARED_LINK}
COMMAND ${LLVM_CONFIG_EXE} --system-libs --link-static
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --shared-mode ${STATIC_OR_SHARED_LINK}
OUTPUT_VARIABLE LLVM_LINK_MODE
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
COMMAND ${LLVM_CONFIG_EXE} --libdir --link-static
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
endif()
if(NOT LLVM_LIBRARIES)
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libs
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libdir
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --system-libs
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
@@ -156,32 +157,17 @@ if(ZIG_USE_LLVM_CONFIG)
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --shared-mode
OUTPUT_VARIABLE LLVM_LINK_MODE
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if (${LLVM_LINK_MODE} STREQUAL "shared")
# We always ask for the system libs corresponding to static linking,
# since on some distros LLD is only available as a static library
# and we need these libraries to link it successfully
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --system-libs --link-static
OUTPUT_VARIABLE LLVM_STATIC_SYSTEM_LIBS_SPACES
ERROR_QUIET # Some installations have no static libs, we just ignore the failure
COMMAND ${LLVM_CONFIG_EXE} --libdir
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_STATIC_SYSTEM_LIBS "${LLVM_STATIC_SYSTEM_LIBS_SPACES}")
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS} ${LLVM_STATIC_SYSTEM_LIBS})
else()
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --includedir
OUTPUT_VARIABLE LLVM_INCLUDE_DIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_INCLUDE_DIRS "${LLVM_INCLUDE_DIRS_SPACES}")
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
if(NOT LLVM_LIBRARIES)
find_library(LLVM_LIBRARIES NAMES LLVM LLVM-11 LLVM-11.0)
endif()
link_directories("${CMAKE_PREFIX_PATH}/lib")
link_directories("${LLVM_LIBDIRS}")
@@ -191,75 +177,95 @@ else()
macro(FIND_AND_ADD_LLVM_LIB _libname_)
string(TOUPPER ${_libname_} _prettylibname_)
find_library(LLVM_${_prettylibname_}_LIB
NAMES ${_libname_} NAMES_PER_DIR)
find_library(LLVM_${_prettylibname_}_LIB NAMES ${_libname_}
PATHS
${LLVM_LIBDIRS}
/usr/lib/llvm/11/lib
/usr/lib/llvm-11/lib
/usr/lib/llvm-11.0/lib
/usr/local/llvm110/lib
/usr/local/llvm11/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:\\msys64\\mingw64\\lib)
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_${_prettylibname_}_LIB})
endmacro(FIND_AND_ADD_LLVM_LIB)
set(LLVM_LINK_MODE "static")
# This list can be re-generated with `llvm-config --libfiles` and then
# reformatting using your favorite text editor. Note we do not execute
# `llvm-config` here because we are cross compiling.
FIND_AND_ADD_LLVM_LIB(LLVMWindowsManifest)
FIND_AND_ADD_LLVM_LIB(LLVMWindowsDriver)
FIND_AND_ADD_LLVM_LIB(LLVMXRay)
FIND_AND_ADD_LLVM_LIB(LLVMLibDriver)
FIND_AND_ADD_LLVM_LIB(LLVMDlltoolDriver)
FIND_AND_ADD_LLVM_LIB(LLVMCoverage)
FIND_AND_ADD_LLVM_LIB(LLVMWindowsManifest)
FIND_AND_ADD_LLVM_LIB(LLVMSymbolize)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)
FIND_AND_ADD_LLVM_LIB(LLVMOrcError)
FIND_AND_ADD_LLVM_LIB(LLVMJITLink)
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
FIND_AND_ADD_LLVM_LIB(LLVMMCA)
FIND_AND_ADD_LLVM_LIB(LLVMLTO)
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
FIND_AND_ADD_LLVM_LIB(LLVMObjCARCOpts)
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
FIND_AND_ADD_LLVM_LIB(LLVMLineEditor)
FIND_AND_ADD_LLVM_LIB(LLVMLibDriver)
FIND_AND_ADD_LLVM_LIB(LLVMInterpreter)
FIND_AND_ADD_LLVM_LIB(LLVMFuzzMutate)
FIND_AND_ADD_LLVM_LIB(LLVMMCJIT)
FIND_AND_ADD_LLVM_LIB(LLVMExecutionEngine)
FIND_AND_ADD_LLVM_LIB(LLVMRuntimeDyld)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinker)
FIND_AND_ADD_LLVM_LIB(LLVMDlltoolDriver)
FIND_AND_ADD_LLVM_LIB(LLVMOption)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
FIND_AND_ADD_LLVM_LIB(LLVMCoverage)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDesc)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreInfo)
FIND_AND_ADD_LLVM_LIB(LLVMX86TargetMCA)
FIND_AND_ADD_LLVM_LIB(LLVMX86Disassembler)
FIND_AND_ADD_LLVM_LIB(LLVMX86AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMX86CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMX86AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMX86Desc)
FIND_AND_ADD_LLVM_LIB(LLVMX86Info)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyDesc)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyUtils)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyInfo)
FIND_AND_ADD_LLVM_LIB(LLVMVEDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMVEAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMVECodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMVEDesc)
FIND_AND_ADD_LLVM_LIB(LLVMVEInfo)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZDesc)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZInfo)
FIND_AND_ADD_LLVM_LIB(LLVMSparcDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMSparcAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMSparcCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMSparcAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMSparcDesc)
FIND_AND_ADD_LLVM_LIB(LLVMSparcInfo)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVDesc)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVUtils)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVInfo)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCDesc)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCInfo)
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXDesc)
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXInfo)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Disassembler)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Desc)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Info)
FIND_AND_ADD_LLVM_LIB(LLVMMipsDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMMipsAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMipsCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMMipsAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMipsDesc)
FIND_AND_ADD_LLVM_LIB(LLVMMipsInfo)
FIND_AND_ADD_LLVM_LIB(LLVMLanaiDisassembler)
@@ -273,72 +279,44 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMHexagonDesc)
FIND_AND_ADD_LLVM_LIB(LLVMHexagonInfo)
FIND_AND_ADD_LLVM_LIB(LLVMBPFDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMBPFAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMBPFCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMBPFAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMBPFDesc)
FIND_AND_ADD_LLVM_LIB(LLVMBPFInfo)
FIND_AND_ADD_LLVM_LIB(LLVMAVRDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMAVRAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAVRCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMAVRAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAVRDesc)
FIND_AND_ADD_LLVM_LIB(LLVMAVRInfo)
FIND_AND_ADD_LLVM_LIB(LLVMARMDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMARMAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMARMCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMARMAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMARMDesc)
FIND_AND_ADD_LLVM_LIB(LLVMARMUtils)
FIND_AND_ADD_LLVM_LIB(LLVMARMInfo)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUTargetMCA)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMMIRParser)
FIND_AND_ADD_LLVM_LIB(LLVMipo)
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
FIND_AND_ADD_LLVM_LIB(LLVMIRReader)
FIND_AND_ADD_LLVM_LIB(LLVMAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUDesc)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUUtils)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUInfo)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Disassembler)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Desc)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Utils)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Info)
FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)
FIND_AND_ADD_LLVM_LIB(LLVMMCJIT)
FIND_AND_ADD_LLVM_LIB(LLVMJITLink)
FIND_AND_ADD_LLVM_LIB(LLVMInterpreter)
FIND_AND_ADD_LLVM_LIB(LLVMExecutionEngine)
FIND_AND_ADD_LLVM_LIB(LLVMRuntimeDyld)
FIND_AND_ADD_LLVM_LIB(LLVMOrcTargetProcess)
FIND_AND_ADD_LLVM_LIB(LLVMOrcShared)
FIND_AND_ADD_LLVM_LIB(LLVMDWP)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
FIND_AND_ADD_LLVM_LIB(LLVMOption)
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
FIND_AND_ADD_LLVM_LIB(LLVMObjCopy)
FIND_AND_ADD_LLVM_LIB(LLVMMCA)
FIND_AND_ADD_LLVM_LIB(LLVMMCDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMLTO)
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMCFGuard)
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
FIND_AND_ADD_LLVM_LIB(LLVMObjCARCOpts)
FIND_AND_ADD_LLVM_LIB(LLVMipo)
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenACC)
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinker)
FIND_AND_ADD_LLVM_LIB(LLVMGlobalISel)
FIND_AND_ADD_LLVM_LIB(LLVMMIRParser)
FIND_AND_ADD_LLVM_LIB(LLVMAsmPrinter)
FIND_AND_ADD_LLVM_LIB(LLVMSelectionDAG)
FIND_AND_ADD_LLVM_LIB(LLVMAsmPrinter)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARF)
FIND_AND_ADD_LLVM_LIB(LLVMCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMIRReader)
FIND_AND_ADD_LLVM_LIB(LLVMAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMInterfaceStub)
FIND_AND_ADD_LLVM_LIB(LLVMFileCheck)
FIND_AND_ADD_LLVM_LIB(LLVMFuzzMutate)
FIND_AND_ADD_LLVM_LIB(LLVMTarget)
FIND_AND_ADD_LLVM_LIB(LLVMScalarOpts)
FIND_AND_ADD_LLVM_LIB(LLVMInstCombine)
@@ -347,26 +325,23 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMBitWriter)
FIND_AND_ADD_LLVM_LIB(LLVMAnalysis)
FIND_AND_ADD_LLVM_LIB(LLVMProfileData)
FIND_AND_ADD_LLVM_LIB(LLVMSymbolize)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoMSF)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARF)
FIND_AND_ADD_LLVM_LIB(LLVMObject)
FIND_AND_ADD_LLVM_LIB(LLVMTextAPI)
FIND_AND_ADD_LLVM_LIB(LLVMMCParser)
FIND_AND_ADD_LLVM_LIB(LLVMMC)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoCodeView)
FIND_AND_ADD_LLVM_LIB(LLVMBitReader)
FIND_AND_ADD_LLVM_LIB(LLVMFuzzerCLI)
FIND_AND_ADD_LLVM_LIB(LLVMCore)
FIND_AND_ADD_LLVM_LIB(LLVMRemarks)
FIND_AND_ADD_LLVM_LIB(LLVMBitstreamReader)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMCParser)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Desc)
FIND_AND_ADD_LLVM_LIB(LLVMMC)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoCodeView)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoMSF)
FIND_AND_ADD_LLVM_LIB(LLVMBinaryFormat)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Utils)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Info)
FIND_AND_ADD_LLVM_LIB(LLVMSupport)
FIND_AND_ADD_LLVM_LIB(LLVMDemangle)
get_filename_component(LLVM_LIBDIRS "${LLVM_LLVMCORE_LIB}" DIRECTORY)
find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h)
endif()
include(FindPackageHandleStandardArgs)

View File

@@ -1,19 +1,29 @@
set(ZIG_INSTALL_ARGS build ${ZIG_BUILD_ARGS} --prefix "${CMAKE_INSTALL_PREFIX}")
execute_process(
COMMAND "${ZIG_EXECUTABLE}" ${ZIG_INSTALL_ARGS}
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE _result)
message("-- Installing: ${CMAKE_INSTALL_PREFIX}/lib")
if(NOT EXISTS ${zig_EXE})
message("::")
message(":: ERROR: Executable not found")
message(":: (execute_process)")
message("::")
message(":: executable: ${zig_EXE}")
message("::")
message(FATAL_ERROR)
endif()
execute_process(COMMAND ${zig_EXE} ${ZIG_INSTALL_ARGS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE _result
)
if(_result)
message("::")
message(":: ERROR: ${_result}")
message(":: (execute_process)")
list(JOIN ZIG_INSTALL_ARGS " " s_INSTALL_LIBSTAGE2_ARGS)
string(REPLACE ";" " " s_INSTALL_LIBSTAGE2_ARGS "${ZIG_INSTALL_ARGS}")
message("::")
message(":: argv: ${ZIG_EXECUTABLE} ${s_INSTALL_LIBSTAGE2_ARGS}")
message(":: argv: ${zig_EXE} ${s_INSTALL_LIBSTAGE2_ARGS}")
set(_args ${ZIG_EXECUTABLE} ${ZIG_INSTALL_ARGS})
set(_args ${zig_EXE} ${ZIG_INSTALL_ARGS})
list(LENGTH _args _len)
math(EXPR _len "${_len} - 1")
message("::")

View File

@@ -3,10 +3,6 @@
#if defined(__BIG_ENDIAN__)
#define BIGENDIAN 1
#elif defined(_BIG_ENDIAN) && (_BIG_ENDIAN == 1)
#define BIGENDIAN 1
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define BIGENDIAN 1
#elif defined(__ARMEB__)
#define BIGENDIAN 1
#elif defined(__THUMBEB__)
@@ -19,12 +15,20 @@
#define BIGENDIAN 1
#elif defined(__MIPSEB__)
#define BIGENDIAN 1
#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define BIGENDIAN 1
#elif defined(_BIG_ENDIAN)
#define BIGENDIAN 1
#elif defined(__sparc)
#define BIGENDIAN 1
#elif defined(__sparc__)
#define BIGENDIAN 1
#elif defined(_POWER)
#define BIGENDIAN 1
#elif defined(__powerpc__)
#define BIGENDIAN 1
#elif defined(__ppc__)
#define BIGENDIAN 1
#elif defined(__hpux)
#define BIGENDIAN 1
#elif defined(__hppa)
@@ -33,13 +37,7 @@
#define BIGENDIAN 1
#elif defined(__s390__)
#define BIGENDIAN 1
#endif
#if defined(__LITTLE_ENDIAN__)
#define LITTLEENDIAN 1
#elif defined(_LITTLE_ENDIAN) && (_LITTLE_ENDIAN == 1)
#define LITTLEENDIAN 1
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#elif defined(__LITTLE_ENDIAN__)
#define LITTLEENDIAN 1
#elif defined(__ARMEL__)
#define LITTLEENDIAN 1
@@ -53,6 +51,10 @@
#define LITTLEENDIAN 1
#elif defined(__MIPSEL__)
#define LITTLEENDIAN 1
#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define LITTLEENDIAN 1
#elif defined(_LITTLE_ENDIAN)
#define LITTLEENDIAN 1
#elif defined(__i386__)
#define LITTLEENDIAN 1
#elif defined(__alpha__)
@@ -81,11 +83,7 @@
#define LITTLEENDIAN 1
#elif defined(__bfin__)
#define LITTLEENDIAN 1
#endif
#if defined(LITTLEENDIAN) && defined(BIGENDIAN)
#error unable to detect endianness
#elif !defined(LITTLEENDIAN) && !defined(BIGENDIAN)
#else
#error unable to detect endianness
#endif

View File

@@ -37,7 +37,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef primitiveTypes_h
#define primitiveTypes_h 1
#include "platform.h"
#include <stdint.h>
#ifdef SOFTFLOAT_FAST_INT64

View File

@@ -37,7 +37,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef softfloat_types_h
#define softfloat_types_h 1
#include "platform.h"
#include <stdint.h>
/*----------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,352 +0,0 @@
const root = @import("@build");
const std = @import("std");
const builtin = @import("builtin");
const io = std.io;
const fmt = std.fmt;
const Builder = std.build.Builder;
const mem = std.mem;
const process = std.process;
const ArrayList = std.ArrayList;
const File = std.fs.File;
pub fn main() !void {
// Here we use an ArenaAllocator backed by a DirectAllocator because a build is a short-lived,
// one shot program. We don't need to waste time freeing memory and finding places to squish
// bytes into. So we free everything all at once at the very end.
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
var args = try process.argsAlloc(allocator);
defer process.argsFree(allocator, args);
// skip my own exe name
var arg_idx: usize = 1;
const zig_exe = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected path to zig compiler\n", .{});
return error.InvalidArgs;
};
const build_root = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected build root directory path\n", .{});
return error.InvalidArgs;
};
const cache_root = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected cache root directory path\n", .{});
return error.InvalidArgs;
};
const global_cache_root = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected global cache root directory path\n", .{});
return error.InvalidArgs;
};
const builder = try Builder.create(
allocator,
zig_exe,
build_root,
cache_root,
global_cache_root,
);
defer builder.destroy();
var targets = ArrayList([]const u8).init(allocator);
var debug_log_scopes = ArrayList([]const u8).init(allocator);
const stderr_stream = io.getStdErr().writer();
const stdout_stream = io.getStdOut().writer();
var install_prefix: ?[]const u8 = null;
var dir_list = Builder.DirList{};
// before arg parsing, check for the NO_COLOR environment variable
// if it exists, default the color setting to .off
// explicit --color arguments will still override this setting.
builder.color = if (std.process.hasEnvVarConstant("NO_COLOR")) .off else .auto;
while (nextArg(args, &arg_idx)) |arg| {
if (mem.startsWith(u8, arg, "-D")) {
const option_contents = arg[2..];
if (option_contents.len == 0) {
std.debug.print("Expected option name after '-D'\n\n", .{});
return usageAndErr(builder, false, stderr_stream);
}
if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
const option_name = option_contents[0..name_end];
const option_value = option_contents[name_end + 1 ..];
if (try builder.addUserInputOption(option_name, option_value))
return usageAndErr(builder, false, stderr_stream);
} else {
if (try builder.addUserInputFlag(option_contents))
return usageAndErr(builder, false, stderr_stream);
}
} else if (mem.startsWith(u8, arg, "-")) {
if (mem.eql(u8, arg, "--verbose")) {
builder.verbose = true;
} else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
return usage(builder, false, stdout_stream);
} else if (mem.eql(u8, arg, "-p") or mem.eql(u8, arg, "--prefix")) {
install_prefix = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after {s}\n\n", .{arg});
return usageAndErr(builder, false, stderr_stream);
};
} else if (mem.eql(u8, arg, "--prefix-lib-dir")) {
dir_list.lib_dir = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after {s}\n\n", .{arg});
return usageAndErr(builder, false, stderr_stream);
};
} else if (mem.eql(u8, arg, "--prefix-exe-dir")) {
dir_list.exe_dir = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after {s}\n\n", .{arg});
return usageAndErr(builder, false, stderr_stream);
};
} else if (mem.eql(u8, arg, "--prefix-include-dir")) {
dir_list.include_dir = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after {s}\n\n", .{arg});
return usageAndErr(builder, false, stderr_stream);
};
} else if (mem.eql(u8, arg, "--sysroot")) {
const sysroot = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after --sysroot\n\n", .{});
return usageAndErr(builder, false, stderr_stream);
};
builder.sysroot = sysroot;
} else if (mem.eql(u8, arg, "--search-prefix")) {
const search_prefix = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after --search-prefix\n\n", .{});
return usageAndErr(builder, false, stderr_stream);
};
builder.addSearchPrefix(search_prefix);
} else if (mem.eql(u8, arg, "--libc")) {
const libc_file = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after --libc\n\n", .{});
return usageAndErr(builder, false, stderr_stream);
};
builder.libc_file = libc_file;
} else if (mem.eql(u8, arg, "--color")) {
const next_arg = nextArg(args, &arg_idx) orelse {
std.debug.print("expected [auto|on|off] after --color", .{});
return usageAndErr(builder, false, stderr_stream);
};
builder.color = std.meta.stringToEnum(@TypeOf(builder.color), next_arg) orelse {
std.debug.print("expected [auto|on|off] after --color, found '{s}'", .{next_arg});
return usageAndErr(builder, false, stderr_stream);
};
} else if (mem.eql(u8, arg, "--zig-lib-dir")) {
builder.override_lib_dir = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after --zig-lib-dir\n\n", .{});
return usageAndErr(builder, false, stderr_stream);
};
} else if (mem.eql(u8, arg, "--debug-log")) {
const next_arg = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after {s}\n\n", .{arg});
return usageAndErr(builder, false, stderr_stream);
};
try debug_log_scopes.append(next_arg);
} else if (mem.eql(u8, arg, "--glibc-runtimes")) {
builder.glibc_runtimes_dir = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after --glibc-runtimes\n\n", .{});
return usageAndErr(builder, false, stderr_stream);
};
} else if (mem.eql(u8, arg, "--verbose-link")) {
builder.verbose_link = true;
} else if (mem.eql(u8, arg, "--verbose-air")) {
builder.verbose_air = true;
} else if (mem.eql(u8, arg, "--verbose-llvm-ir")) {
builder.verbose_llvm_ir = true;
} else if (mem.eql(u8, arg, "--verbose-cimport")) {
builder.verbose_cimport = true;
} else if (mem.eql(u8, arg, "--verbose-cc")) {
builder.verbose_cc = true;
} else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) {
builder.verbose_llvm_cpu_features = true;
} else if (mem.eql(u8, arg, "--prominent-compile-errors")) {
builder.prominent_compile_errors = true;
} else if (mem.eql(u8, arg, "-fwine")) {
builder.enable_wine = true;
} else if (mem.eql(u8, arg, "-fno-wine")) {
builder.enable_wine = false;
} else if (mem.eql(u8, arg, "-fqemu")) {
builder.enable_qemu = true;
} else if (mem.eql(u8, arg, "-fno-qemu")) {
builder.enable_qemu = false;
} else if (mem.eql(u8, arg, "-fwasmtime")) {
builder.enable_wasmtime = true;
} else if (mem.eql(u8, arg, "-fno-wasmtime")) {
builder.enable_wasmtime = false;
} else if (mem.eql(u8, arg, "-frosetta")) {
builder.enable_rosetta = true;
} else if (mem.eql(u8, arg, "-fno-rosetta")) {
builder.enable_rosetta = false;
} else if (mem.eql(u8, arg, "-fdarling")) {
builder.enable_darling = true;
} else if (mem.eql(u8, arg, "-fno-darling")) {
builder.enable_darling = false;
} else if (mem.eql(u8, arg, "-fstage1")) {
builder.use_stage1 = true;
} else if (mem.eql(u8, arg, "-fno-stage1")) {
builder.use_stage1 = false;
} else if (mem.eql(u8, arg, "-freference-trace")) {
builder.reference_trace = 256;
} else if (mem.startsWith(u8, arg, "-freference-trace=")) {
const num = arg["-freference-trace=".len..];
builder.reference_trace = std.fmt.parseUnsigned(u32, num, 10) catch |err| {
std.debug.print("unable to parse reference_trace count '{s}': {s}", .{ num, @errorName(err) });
process.exit(1);
};
} else if (mem.eql(u8, arg, "-fno-reference-trace")) {
builder.reference_trace = null;
} else if (mem.eql(u8, arg, "--")) {
builder.args = argsRest(args, arg_idx);
break;
} else {
std.debug.print("Unrecognized argument: {s}\n\n", .{arg});
return usageAndErr(builder, false, stderr_stream);
}
} else {
try targets.append(arg);
}
}
builder.debug_log_scopes = debug_log_scopes.items;
builder.resolveInstallPrefix(install_prefix, dir_list);
try runBuild(builder);
if (builder.validateUserInputDidItFail())
return usageAndErr(builder, true, stderr_stream);
builder.make(targets.items) catch |err| {
switch (err) {
error.InvalidStepName => {
return usageAndErr(builder, true, stderr_stream);
},
error.UncleanExit => process.exit(1),
else => return err,
}
};
}
fn runBuild(builder: *Builder) anyerror!void {
switch (@typeInfo(@typeInfo(@TypeOf(root.build)).Fn.return_type.?)) {
.Void => root.build(builder),
.ErrorUnion => try root.build(builder),
else => @compileError("expected return type of build to be 'void' or '!void'"),
}
}
fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void {
// run the build script to collect the options
if (!already_ran_build) {
builder.resolveInstallPrefix(null, .{});
try runBuild(builder);
}
try out_stream.print(
\\Usage: {s} build [steps] [options]
\\
\\Steps:
\\
, .{builder.zig_exe});
const allocator = builder.allocator;
for (builder.top_level_steps.items) |top_level_step| {
const name = if (&top_level_step.step == builder.default_step)
try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name})
else
top_level_step.step.name;
try out_stream.print(" {s:<28} {s}\n", .{ name, top_level_step.description });
}
try out_stream.writeAll(
\\
\\General Options:
\\ -p, --prefix [path] Override default install prefix
\\ --prefix-lib-dir [path] Override default library directory path
\\ --prefix-exe-dir [path] Override default executable directory path
\\ --prefix-include-dir [path] Override default include directory path
\\
\\ --sysroot [path] Set the system root directory (usually /)
\\ --search-prefix [path] Add a path to look for binaries, libraries, headers
\\ --libc [file] Provide a file which specifies libc paths
\\
\\ -fdarling, -fno-darling Integration with system-installed Darling to
\\ execute macOS programs on Linux hosts
\\ (default: no)
\\ -fqemu, -fno-qemu Integration with system-installed QEMU to execute
\\ foreign-architecture programs on Linux hosts
\\ (default: no)
\\ --glibc-runtimes [path] Enhances QEMU integration by providing glibc built
\\ for multiple foreign architectures, allowing
\\ execution of non-native programs that link with glibc.
\\ -frosetta, -fno-rosetta Rely on Rosetta to execute x86_64 programs on
\\ ARM64 macOS hosts. (default: no)
\\ -fwasmtime, -fno-wasmtime Integration with system-installed wasmtime to
\\ execute WASI binaries. (default: no)
\\ -fwine, -fno-wine Integration with system-installed Wine to execute
\\ Windows programs on Linux hosts. (default: no)
\\
\\ -h, --help Print this help and exit
\\ --verbose Print commands before executing them
\\ --color [auto|off|on] Enable or disable colored error messages
\\ --prominent-compile-errors Output compile errors formatted for a human to read
\\
\\Project-Specific Options:
\\
);
if (builder.available_options_list.items.len == 0) {
try out_stream.print(" (none)\n", .{});
} else {
for (builder.available_options_list.items) |option| {
const name = try fmt.allocPrint(allocator, " -D{s}=[{s}]", .{
option.name,
@tagName(option.type_id),
});
defer allocator.free(name);
try out_stream.print("{s:<30} {s}\n", .{ name, option.description });
if (option.enum_options) |enum_options| {
const padding = " " ** 33;
try out_stream.writeAll(padding ++ "Supported Values:\n");
for (enum_options) |enum_option| {
try out_stream.print(padding ++ " {s}\n", .{enum_option});
}
}
}
}
try out_stream.writeAll(
\\
\\Advanced Options:
\\ -fstage1 Force using bootstrap compiler as the codegen backend
\\ -fno-stage1 Prevent using bootstrap compiler as the codegen backend
\\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
\\ -fno-reference-trace Disable reference trace
\\ --build-file [file] Override path to build.zig
\\ --cache-dir [path] Override path to local Zig cache directory
\\ --global-cache-dir [path] Override path to global Zig cache directory
\\ --zig-lib-dir [arg] Override path to Zig lib directory
\\ --debug-log [scope] Enable debugging the compiler
\\ --verbose-link Enable compiler debug output for linking
\\ --verbose-air Enable compiler debug output for Zig AIR
\\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
\\ --verbose-cimport Enable compiler debug output for C imports
\\ --verbose-cc Enable compiler debug output for C compilation
\\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features
\\
);
}
fn usageAndErr(builder: *Builder, already_ran_build: bool, out_stream: anytype) void {
usage(builder, already_ran_build, out_stream) catch {};
process.exit(1);
}
fn nextArg(args: [][]const u8, idx: *usize) ?[]const u8 {
if (idx.* >= args.len) return null;
defer idx.* += 1;
return args[idx.*];
}
fn argsRest(args: [][]const u8, idx: usize) ?[][]const u8 {
if (idx >= args.len) return null;
return args[idx..];
}

555
lib/c.zig
View File

@@ -1,555 +0,0 @@
//! This is Zig's multi-target implementation of libc.
//! When builtin.link_libc is true, we need to export all the functions and
//! provide an entire C API.
const std = @import("std");
const builtin = @import("builtin");
const math = std.math;
const isNan = std.math.isNan;
const maxInt = std.math.maxInt;
const native_os = builtin.os.tag;
const native_arch = builtin.cpu.arch;
const native_abi = builtin.abi;
const is_wasm = switch (native_arch) {
.wasm32, .wasm64 => true,
else => false,
};
const is_msvc = switch (native_abi) {
.msvc => true,
else => false,
};
const is_freestanding = switch (native_os) {
.freestanding => true,
else => false,
};
comptime {
if (is_freestanding and is_wasm and builtin.link_libc) {
@export(wasm_start, .{ .name = "_start", .linkage = .Strong });
}
if (native_os == .linux) {
@export(clone, .{ .name = "clone" });
}
if (builtin.link_libc) {
@export(strcmp, .{ .name = "strcmp", .linkage = .Strong });
@export(strncmp, .{ .name = "strncmp", .linkage = .Strong });
@export(strerror, .{ .name = "strerror", .linkage = .Strong });
@export(strlen, .{ .name = "strlen", .linkage = .Strong });
@export(strcpy, .{ .name = "strcpy", .linkage = .Strong });
@export(strncpy, .{ .name = "strncpy", .linkage = .Strong });
@export(strcat, .{ .name = "strcat", .linkage = .Strong });
@export(strncat, .{ .name = "strncat", .linkage = .Strong });
} else if (is_msvc) {
@export(_fltused, .{ .name = "_fltused", .linkage = .Strong });
}
}
// Avoid dragging in the runtime safety mechanisms into this .o file,
// unless we're trying to test this file.
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
@setCold(true);
_ = error_return_trace;
if (builtin.is_test) {
std.debug.panic("{s}", .{msg});
}
switch (native_os) {
.freestanding, .other, .amdhsa, .amdpal => while (true) {},
else => std.os.abort(),
}
}
extern fn main(argc: c_int, argv: [*:null]?[*:0]u8) c_int;
fn wasm_start() callconv(.C) void {
_ = main(0, undefined);
}
var _fltused: c_int = 1;
fn strcpy(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {
var i: usize = 0;
while (src[i] != 0) : (i += 1) {
dest[i] = src[i];
}
dest[i] = 0;
return dest;
}
test "strcpy" {
var s1: [9:0]u8 = undefined;
s1[0] = 0;
_ = strcpy(&s1, "foobarbaz");
try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
}
fn strncpy(dest: [*:0]u8, src: [*:0]const u8, n: usize) callconv(.C) [*:0]u8 {
var i: usize = 0;
while (i < n and src[i] != 0) : (i += 1) {
dest[i] = src[i];
}
while (i < n) : (i += 1) {
dest[i] = 0;
}
return dest;
}
test "strncpy" {
var s1: [9:0]u8 = undefined;
s1[0] = 0;
_ = strncpy(&s1, "foobarbaz", @sizeOf(@TypeOf(s1)));
try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
}
fn strcat(dest: [*:0]u8, src: [*:0]const u8) callconv(.C) [*:0]u8 {
var dest_end: usize = 0;
while (dest[dest_end] != 0) : (dest_end += 1) {}
var i: usize = 0;
while (src[i] != 0) : (i += 1) {
dest[dest_end + i] = src[i];
}
dest[dest_end + i] = 0;
return dest;
}
test "strcat" {
var s1: [9:0]u8 = undefined;
s1[0] = 0;
_ = strcat(&s1, "foo");
_ = strcat(&s1, "bar");
_ = strcat(&s1, "baz");
try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
}
fn strncat(dest: [*:0]u8, src: [*:0]const u8, avail: usize) callconv(.C) [*:0]u8 {
var dest_end: usize = 0;
while (dest[dest_end] != 0) : (dest_end += 1) {}
var i: usize = 0;
while (i < avail and src[i] != 0) : (i += 1) {
dest[dest_end + i] = src[i];
}
dest[dest_end + i] = 0;
return dest;
}
test "strncat" {
var s1: [9:0]u8 = undefined;
s1[0] = 0;
_ = strncat(&s1, "foo1111", 3);
_ = strncat(&s1, "bar1111", 3);
_ = strncat(&s1, "baz1111", 3);
try std.testing.expectEqualSlices(u8, "foobarbaz", std.mem.sliceTo(&s1, 0));
}
fn strcmp(s1: [*:0]const u8, s2: [*:0]const u8) callconv(.C) c_int {
return std.cstr.cmp(s1, s2);
}
fn strlen(s: [*:0]const u8) callconv(.C) usize {
return std.mem.len(s);
}
fn strncmp(_l: [*:0]const u8, _r: [*:0]const u8, _n: usize) callconv(.C) c_int {
if (_n == 0) return 0;
var l = _l;
var r = _r;
var n = _n - 1;
while (l[0] != 0 and r[0] != 0 and n != 0 and l[0] == r[0]) {
l += 1;
r += 1;
n -= 1;
}
return @as(c_int, l[0]) - @as(c_int, r[0]);
}
fn strerror(errnum: c_int) callconv(.C) [*:0]const u8 {
_ = errnum;
return "TODO strerror implementation";
}
test "strncmp" {
try std.testing.expect(strncmp("a", "b", 1) < 0);
try std.testing.expect(strncmp("a", "c", 1) < 0);
try std.testing.expect(strncmp("b", "a", 1) > 0);
try std.testing.expect(strncmp("\xff", "\x02", 1) > 0);
}
// TODO we should be able to put this directly in std/linux/x86_64.zig but
// it causes a segfault in release mode. this is a workaround of calling it
// across .o file boundaries. fix comptime @ptrCast of nakedcc functions.
fn clone() callconv(.Naked) void {
switch (native_arch) {
.i386 => {
// __clone(func, stack, flags, arg, ptid, tls, ctid)
// +8, +12, +16, +20, +24, +28, +32
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// eax, ebx, ecx, edx, esi, edi
asm volatile (
\\ push %%ebp
\\ mov %%esp,%%ebp
\\ push %%ebx
\\ push %%esi
\\ push %%edi
\\ // Setup the arguments
\\ mov 16(%%ebp),%%ebx
\\ mov 12(%%ebp),%%ecx
\\ and $-16,%%ecx
\\ sub $20,%%ecx
\\ mov 20(%%ebp),%%eax
\\ mov %%eax,4(%%ecx)
\\ mov 8(%%ebp),%%eax
\\ mov %%eax,0(%%ecx)
\\ mov 24(%%ebp),%%edx
\\ mov 28(%%ebp),%%esi
\\ mov 32(%%ebp),%%edi
\\ mov $120,%%eax
\\ int $128
\\ test %%eax,%%eax
\\ jnz 1f
\\ pop %%eax
\\ xor %%ebp,%%ebp
\\ call *%%eax
\\ mov %%eax,%%ebx
\\ xor %%eax,%%eax
\\ inc %%eax
\\ int $128
\\ hlt
\\1:
\\ pop %%edi
\\ pop %%esi
\\ pop %%ebx
\\ pop %%ebp
\\ ret
);
},
.x86_64 => {
asm volatile (
\\ xor %%eax,%%eax
\\ mov $56,%%al // SYS_clone
\\ mov %%rdi,%%r11
\\ mov %%rdx,%%rdi
\\ mov %%r8,%%rdx
\\ mov %%r9,%%r8
\\ mov 8(%%rsp),%%r10
\\ mov %%r11,%%r9
\\ and $-16,%%rsi
\\ sub $8,%%rsi
\\ mov %%rcx,(%%rsi)
\\ syscall
\\ test %%eax,%%eax
\\ jnz 1f
\\ xor %%ebp,%%ebp
\\ pop %%rdi
\\ call *%%r9
\\ mov %%eax,%%edi
\\ xor %%eax,%%eax
\\ mov $60,%%al // SYS_exit
\\ syscall
\\ hlt
\\1: ret
\\
);
},
.aarch64 => {
// __clone(func, stack, flags, arg, ptid, tls, ctid)
// x0, x1, w2, x3, x4, x5, x6
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// x8, x0, x1, x2, x3, x4
asm volatile (
\\ // align stack and save func,arg
\\ and x1,x1,#-16
\\ stp x0,x3,[x1,#-16]!
\\
\\ // syscall
\\ uxtw x0,w2
\\ mov x2,x4
\\ mov x3,x5
\\ mov x4,x6
\\ mov x8,#220 // SYS_clone
\\ svc #0
\\
\\ cbz x0,1f
\\ // parent
\\ ret
\\ // child
\\1: ldp x1,x0,[sp],#16
\\ blr x1
\\ mov x8,#93 // SYS_exit
\\ svc #0
);
},
.arm, .thumb => {
// __clone(func, stack, flags, arg, ptid, tls, ctid)
// r0, r1, r2, r3, +0, +4, +8
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// r7 r0, r1, r2, r3, r4
asm volatile (
\\ stmfd sp!,{r4,r5,r6,r7}
\\ mov r7,#120
\\ mov r6,r3
\\ mov r5,r0
\\ mov r0,r2
\\ and r1,r1,#-16
\\ ldr r2,[sp,#16]
\\ ldr r3,[sp,#20]
\\ ldr r4,[sp,#24]
\\ svc 0
\\ tst r0,r0
\\ beq 1f
\\ ldmfd sp!,{r4,r5,r6,r7}
\\ bx lr
\\
\\1: mov r0,r6
\\ bl 3f
\\2: mov r7,#1
\\ svc 0
\\ b 2b
\\3: bx r5
);
},
.riscv64 => {
// __clone(func, stack, flags, arg, ptid, tls, ctid)
// a0, a1, a2, a3, a4, a5, a6
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// a7 a0, a1, a2, a3, a4
asm volatile (
\\ # Save func and arg to stack
\\ addi a1, a1, -16
\\ sd a0, 0(a1)
\\ sd a3, 8(a1)
\\
\\ # Call SYS_clone
\\ mv a0, a2
\\ mv a2, a4
\\ mv a3, a5
\\ mv a4, a6
\\ li a7, 220 # SYS_clone
\\ ecall
\\
\\ beqz a0, 1f
\\ # Parent
\\ ret
\\
\\ # Child
\\1: ld a1, 0(sp)
\\ ld a0, 8(sp)
\\ jalr a1
\\
\\ # Exit
\\ li a7, 93 # SYS_exit
\\ ecall
);
},
.mips, .mipsel => {
// __clone(func, stack, flags, arg, ptid, tls, ctid)
// 3, 4, 5, 6, 7, 8, 9
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// 2 4, 5, 6, 7, 8
asm volatile (
\\ # Save function pointer and argument pointer on new thread stack
\\ and $5, $5, -8
\\ subu $5, $5, 16
\\ sw $4, 0($5)
\\ sw $7, 4($5)
\\ # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid)
\\ move $4, $6
\\ lw $6, 16($sp)
\\ lw $7, 20($sp)
\\ lw $9, 24($sp)
\\ subu $sp, $sp, 16
\\ sw $9, 16($sp)
\\ li $2, 4120
\\ syscall
\\ beq $7, $0, 1f
\\ nop
\\ addu $sp, $sp, 16
\\ jr $ra
\\ subu $2, $0, $2
\\1:
\\ beq $2, $0, 1f
\\ nop
\\ addu $sp, $sp, 16
\\ jr $ra
\\ nop
\\1:
\\ lw $25, 0($sp)
\\ lw $4, 4($sp)
\\ jalr $25
\\ nop
\\ move $4, $2
\\ li $2, 4001
\\ syscall
);
},
.powerpc => {
// __clone(func, stack, flags, arg, ptid, tls, ctid)
// 3, 4, 5, 6, 7, 8, 9
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// 0 3, 4, 5, 6, 7
asm volatile (
\\# store non-volatile regs r30, r31 on stack in order to put our
\\# start func and its arg there
\\stwu 30, -16(1)
\\stw 31, 4(1)
\\
\\# save r3 (func) into r30, and r6(arg) into r31
\\mr 30, 3
\\mr 31, 6
\\
\\# create initial stack frame for new thread
\\clrrwi 4, 4, 4
\\li 0, 0
\\stwu 0, -16(4)
\\
\\#move c into first arg
\\mr 3, 5
\\#mr 4, 4
\\mr 5, 7
\\mr 6, 8
\\mr 7, 9
\\
\\# move syscall number into r0
\\li 0, 120
\\
\\sc
\\
\\# check for syscall error
\\bns+ 1f # jump to label 1 if no summary overflow.
\\#else
\\neg 3, 3 #negate the result (errno)
\\1:
\\# compare sc result with 0
\\cmpwi cr7, 3, 0
\\
\\# if not 0, jump to end
\\bne cr7, 2f
\\
\\#else: we're the child
\\#call funcptr: move arg (d) into r3
\\mr 3, 31
\\#move r30 (funcptr) into CTR reg
\\mtctr 30
\\# call CTR reg
\\bctrl
\\# mov SYS_exit into r0 (the exit param is already in r3)
\\li 0, 1
\\sc
\\
\\2:
\\
\\# restore stack
\\lwz 30, 0(1)
\\lwz 31, 4(1)
\\addi 1, 1, 16
\\
\\blr
);
},
.powerpc64, .powerpc64le => {
// __clone(func, stack, flags, arg, ptid, tls, ctid)
// 3, 4, 5, 6, 7, 8, 9
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// 0 3, 4, 5, 6, 7
asm volatile (
\\ # create initial stack frame for new thread
\\ clrrdi 4, 4, 4
\\ li 0, 0
\\ stdu 0,-32(4)
\\
\\ # save fn and arg to child stack
\\ std 3, 8(4)
\\ std 6, 16(4)
\\
\\ # shuffle args into correct registers and call SYS_clone
\\ mr 3, 5
\\ #mr 4, 4
\\ mr 5, 7
\\ mr 6, 8
\\ mr 7, 9
\\ li 0, 120 # SYS_clone = 120
\\ sc
\\
\\ # if error, negate return (errno)
\\ bns+ 1f
\\ neg 3, 3
\\
\\1:
\\ # if we're the parent, return
\\ cmpwi cr7, 3, 0
\\ bnelr cr7
\\
\\ # we're the child. call fn(arg)
\\ ld 3, 16(1)
\\ ld 12, 8(1)
\\ mtctr 12
\\ bctrl
\\
\\ # call SYS_exit. exit code is already in r3 from fn return value
\\ li 0, 1 # SYS_exit = 1
\\ sc
);
},
.sparc64 => {
// __clone(func, stack, flags, arg, ptid, tls, ctid)
// i0, i1, i2, i3, i4, i5, sp
// syscall(SYS_clone, flags, stack, ptid, tls, ctid)
// g1 o0, o1, o2, o3, o4
asm volatile (
\\ save %%sp, -192, %%sp
\\ # Save the func pointer and the arg pointer
\\ mov %%i0, %%g2
\\ mov %%i3, %%g3
\\ # Shuffle the arguments
\\ mov 217, %%g1
\\ mov %%i2, %%o0
\\ # Add some extra space for the initial frame
\\ sub %%i1, 176 + 2047, %%o1
\\ mov %%i4, %%o2
\\ mov %%i5, %%o3
\\ ldx [%%fp + 0x8af], %%o4
\\ t 0x6d
\\ bcs,pn %%xcc, 2f
\\ nop
\\ # The child pid is returned in o0 while o1 tells if this
\\ # process is # the child (=1) or the parent (=0).
\\ brnz %%o1, 1f
\\ nop
\\ # Parent process, return the child pid
\\ mov %%o0, %%i0
\\ ret
\\ restore
\\1:
\\ # Child process, call func(arg)
\\ mov %%g0, %%fp
\\ call %%g2
\\ mov %%g3, %%o0
\\ # Exit
\\ mov 1, %%g1
\\ t 0x6d
\\2:
\\ # The syscall failed
\\ sub %%g0, %%o0, %%i0
\\ ret
\\ restore
);
},
else => @compileError("Implement clone() for this arch."),
}
}

View File

@@ -1,217 +0,0 @@
pub const panic = @import("compiler_rt/common.zig").panic;
comptime {
_ = @import("compiler_rt/atomics.zig");
_ = @import("compiler_rt/addf3.zig");
_ = @import("compiler_rt/addhf3.zig");
_ = @import("compiler_rt/addsf3.zig");
_ = @import("compiler_rt/adddf3.zig");
_ = @import("compiler_rt/addtf3.zig");
_ = @import("compiler_rt/addxf3.zig");
_ = @import("compiler_rt/subhf3.zig");
_ = @import("compiler_rt/subsf3.zig");
_ = @import("compiler_rt/subdf3.zig");
_ = @import("compiler_rt/subtf3.zig");
_ = @import("compiler_rt/subxf3.zig");
_ = @import("compiler_rt/mulf3.zig");
_ = @import("compiler_rt/mulhf3.zig");
_ = @import("compiler_rt/mulsf3.zig");
_ = @import("compiler_rt/muldf3.zig");
_ = @import("compiler_rt/multf3.zig");
_ = @import("compiler_rt/mulxf3.zig");
_ = @import("compiler_rt/mulc3.zig");
_ = @import("compiler_rt/mulhc3.zig");
_ = @import("compiler_rt/mulsc3.zig");
_ = @import("compiler_rt/muldc3.zig");
_ = @import("compiler_rt/mulxc3.zig");
_ = @import("compiler_rt/multc3.zig");
_ = @import("compiler_rt/divc3.zig");
_ = @import("compiler_rt/divhc3.zig");
_ = @import("compiler_rt/divsc3.zig");
_ = @import("compiler_rt/divdc3.zig");
_ = @import("compiler_rt/divxc3.zig");
_ = @import("compiler_rt/divtc3.zig");
_ = @import("compiler_rt/neghf2.zig");
_ = @import("compiler_rt/negsf2.zig");
_ = @import("compiler_rt/negdf2.zig");
_ = @import("compiler_rt/negtf2.zig");
_ = @import("compiler_rt/negxf2.zig");
_ = @import("compiler_rt/comparef.zig");
_ = @import("compiler_rt/cmphf2.zig");
_ = @import("compiler_rt/cmpsf2.zig");
_ = @import("compiler_rt/cmpdf2.zig");
_ = @import("compiler_rt/cmptf2.zig");
_ = @import("compiler_rt/cmpxf2.zig");
_ = @import("compiler_rt/gehf2.zig");
_ = @import("compiler_rt/gesf2.zig");
_ = @import("compiler_rt/gedf2.zig");
_ = @import("compiler_rt/gexf2.zig");
_ = @import("compiler_rt/getf2.zig");
_ = @import("compiler_rt/unordhf2.zig");
_ = @import("compiler_rt/unordsf2.zig");
_ = @import("compiler_rt/unorddf2.zig");
_ = @import("compiler_rt/unordxf2.zig");
_ = @import("compiler_rt/unordtf2.zig");
_ = @import("compiler_rt/extendf.zig");
_ = @import("compiler_rt/extendhfsf2.zig");
_ = @import("compiler_rt/extendhfdf2.zig");
_ = @import("compiler_rt/extendhftf2.zig");
_ = @import("compiler_rt/extendhfxf2.zig");
_ = @import("compiler_rt/extendsfdf2.zig");
_ = @import("compiler_rt/extendsftf2.zig");
_ = @import("compiler_rt/extendsfxf2.zig");
_ = @import("compiler_rt/extenddftf2.zig");
_ = @import("compiler_rt/extenddfxf2.zig");
_ = @import("compiler_rt/extendxftf2.zig");
_ = @import("compiler_rt/truncf.zig");
_ = @import("compiler_rt/truncsfhf2.zig");
_ = @import("compiler_rt/truncdfhf2.zig");
_ = @import("compiler_rt/truncdfsf2.zig");
_ = @import("compiler_rt/truncxfhf2.zig");
_ = @import("compiler_rt/truncxfsf2.zig");
_ = @import("compiler_rt/truncxfdf2.zig");
_ = @import("compiler_rt/trunctfhf2.zig");
_ = @import("compiler_rt/trunctfsf2.zig");
_ = @import("compiler_rt/trunctfdf2.zig");
_ = @import("compiler_rt/trunctfxf2.zig");
_ = @import("compiler_rt/divhf3.zig");
_ = @import("compiler_rt/divsf3.zig");
_ = @import("compiler_rt/divdf3.zig");
_ = @import("compiler_rt/divxf3.zig");
_ = @import("compiler_rt/divtf3.zig");
_ = @import("compiler_rt/sin.zig");
_ = @import("compiler_rt/cos.zig");
_ = @import("compiler_rt/sincos.zig");
_ = @import("compiler_rt/ceil.zig");
_ = @import("compiler_rt/exp.zig");
_ = @import("compiler_rt/exp2.zig");
_ = @import("compiler_rt/fabs.zig");
_ = @import("compiler_rt/floor.zig");
_ = @import("compiler_rt/fma.zig");
_ = @import("compiler_rt/fmax.zig");
_ = @import("compiler_rt/fmin.zig");
_ = @import("compiler_rt/fmod.zig");
_ = @import("compiler_rt/log.zig");
_ = @import("compiler_rt/log10.zig");
_ = @import("compiler_rt/log2.zig");
_ = @import("compiler_rt/round.zig");
_ = @import("compiler_rt/sqrt.zig");
_ = @import("compiler_rt/tan.zig");
_ = @import("compiler_rt/trunc.zig");
_ = @import("compiler_rt/stack_probe.zig");
_ = @import("compiler_rt/divti3.zig");
_ = @import("compiler_rt/modti3.zig");
_ = @import("compiler_rt/multi3.zig");
_ = @import("compiler_rt/udivti3.zig");
_ = @import("compiler_rt/udivmodti4.zig");
_ = @import("compiler_rt/umodti3.zig");
_ = @import("compiler_rt/int_to_float.zig");
_ = @import("compiler_rt/floatsihf.zig");
_ = @import("compiler_rt/floatsisf.zig");
_ = @import("compiler_rt/floatsidf.zig");
_ = @import("compiler_rt/floatsitf.zig");
_ = @import("compiler_rt/floatsixf.zig");
_ = @import("compiler_rt/floatdihf.zig");
_ = @import("compiler_rt/floatdisf.zig");
_ = @import("compiler_rt/floatdidf.zig");
_ = @import("compiler_rt/floatditf.zig");
_ = @import("compiler_rt/floatdixf.zig");
_ = @import("compiler_rt/floattihf.zig");
_ = @import("compiler_rt/floattisf.zig");
_ = @import("compiler_rt/floattidf.zig");
_ = @import("compiler_rt/floattitf.zig");
_ = @import("compiler_rt/floattixf.zig");
_ = @import("compiler_rt/floatundihf.zig");
_ = @import("compiler_rt/floatundisf.zig");
_ = @import("compiler_rt/floatundidf.zig");
_ = @import("compiler_rt/floatunditf.zig");
_ = @import("compiler_rt/floatundixf.zig");
_ = @import("compiler_rt/floatunsihf.zig");
_ = @import("compiler_rt/floatunsisf.zig");
_ = @import("compiler_rt/floatunsidf.zig");
_ = @import("compiler_rt/floatunsitf.zig");
_ = @import("compiler_rt/floatunsixf.zig");
_ = @import("compiler_rt/floatuntihf.zig");
_ = @import("compiler_rt/floatuntisf.zig");
_ = @import("compiler_rt/floatuntidf.zig");
_ = @import("compiler_rt/floatuntitf.zig");
_ = @import("compiler_rt/floatuntixf.zig");
_ = @import("compiler_rt/float_to_int.zig");
_ = @import("compiler_rt/fixhfsi.zig");
_ = @import("compiler_rt/fixhfdi.zig");
_ = @import("compiler_rt/fixhfti.zig");
_ = @import("compiler_rt/fixsfsi.zig");
_ = @import("compiler_rt/fixsfdi.zig");
_ = @import("compiler_rt/fixsfti.zig");
_ = @import("compiler_rt/fixdfsi.zig");
_ = @import("compiler_rt/fixdfdi.zig");
_ = @import("compiler_rt/fixdfti.zig");
_ = @import("compiler_rt/fixtfsi.zig");
_ = @import("compiler_rt/fixtfdi.zig");
_ = @import("compiler_rt/fixtfti.zig");
_ = @import("compiler_rt/fixxfsi.zig");
_ = @import("compiler_rt/fixxfdi.zig");
_ = @import("compiler_rt/fixxfti.zig");
_ = @import("compiler_rt/fixunshfsi.zig");
_ = @import("compiler_rt/fixunshfdi.zig");
_ = @import("compiler_rt/fixunshfti.zig");
_ = @import("compiler_rt/fixunssfsi.zig");
_ = @import("compiler_rt/fixunssfdi.zig");
_ = @import("compiler_rt/fixunssfti.zig");
_ = @import("compiler_rt/fixunsdfsi.zig");
_ = @import("compiler_rt/fixunsdfdi.zig");
_ = @import("compiler_rt/fixunsdfti.zig");
_ = @import("compiler_rt/fixunstfsi.zig");
_ = @import("compiler_rt/fixunstfdi.zig");
_ = @import("compiler_rt/fixunstfti.zig");
_ = @import("compiler_rt/fixunsxfsi.zig");
_ = @import("compiler_rt/fixunsxfdi.zig");
_ = @import("compiler_rt/fixunsxfti.zig");
_ = @import("compiler_rt/count0bits.zig");
_ = @import("compiler_rt/parity.zig");
_ = @import("compiler_rt/popcount.zig");
_ = @import("compiler_rt/bswap.zig");
_ = @import("compiler_rt/int.zig");
_ = @import("compiler_rt/shift.zig");
_ = @import("compiler_rt/negXi2.zig");
_ = @import("compiler_rt/muldi3.zig");
_ = @import("compiler_rt/absv.zig");
_ = @import("compiler_rt/absvsi2.zig");
_ = @import("compiler_rt/absvdi2.zig");
_ = @import("compiler_rt/absvti2.zig");
_ = @import("compiler_rt/negv.zig");
_ = @import("compiler_rt/addo.zig");
_ = @import("compiler_rt/subo.zig");
_ = @import("compiler_rt/mulo.zig");
_ = @import("compiler_rt/cmp.zig");
_ = @import("compiler_rt/os_version_check.zig");
_ = @import("compiler_rt/emutls.zig");
_ = @import("compiler_rt/arm.zig");
_ = @import("compiler_rt/aulldiv.zig");
_ = @import("compiler_rt/aullrem.zig");
_ = @import("compiler_rt/clear_cache.zig");
_ = @import("compiler_rt/memcpy.zig");
_ = @import("compiler_rt/memset.zig");
_ = @import("compiler_rt/memmove.zig");
_ = @import("compiler_rt/memcmp.zig");
_ = @import("compiler_rt/bcmp.zig");
}

View File

@@ -1,508 +0,0 @@
If hardware lacks basic or specialized functionality, compiler-rt adds such functionality
for basic arithmetic(s).
One such example is 64-bit integer multiplication on 32-bit x86.
Goals:
1. zig as linker for object files produced by other compilers
=> `function compatibility` to compiler-rt and libgcc for same-named functions
* compatibility conflict between compiler-rt and libgcc: prefer compiler-rt
2. `symbol-level compatibility` low-priority compared to emitted calls by llvm
* symbol-level compatibility: libgcc even lower priority
3. add zig-specific language runtime features, see #7265
* example: arbitrary bit width integer arithmetic
* lower to call those functions for e.g. multiplying two i12345 numbers together
* proper naming + documention for standardizing (allow languages to follow our exmaple)
Current status (tracking libgcc documentation):
- Integer library routines => almost implemented
- Soft float library routines => finished
- Decimal float library routines => unimplemented (~120 functions)
- Fixed-point fractional library routines => unimplemented (~300 functions)
- Exception handling routines => unclear, if supported (~32+x undocumented functions)
- Miscellaneous routines => unclear, if supported (cache control and stack function)
- No zig-specific language runtime features in compiler-rt yet
This library is automatically built as-needed for the compilation target and
then statically linked and therefore is a transparent dependency for the
programmer.
For details see `../compiler_rt.zig`.
The routines in this folder are listed below.
Routines are annotated as `type source routine // description`, with `routine`
being the name used in aforementioned `compiler_rt.zig`.
`dev` means deviating from compiler_rt, `port` ported, `source` is the
information source for the implementation, `none` means unimplemented.
Some examples for the naming convention are:
- dev source name_routine, name_routine2 various implementations for performance, simplicity etc
- port llvm compiler-rt library routines from [LLVM](http://compiler-rt.llvm.org/)
* LLVM emits library calls to compiler-rt, if the hardware lacks functionality
- port musl libc routines from [musl](https://musl.libc.org/)
If the library or information source is uncommon, use the entry `other` for `source`.
Please do not break the search by inserting entries in another format than `impl space source`.
Bugs should be solved by trying to duplicate the bug upstream, if possible.
* If the bug exists upstream, get it fixed upstream and port the fix downstream to Zig.
* If the bug only exists in Zig, use the corresponding C code and debug
both implementations side by side to figure out what is wrong.
## Integer library routines
#### Integer Bit operations
- dev HackersDelight __clzsi2 // count leading zeros
- dev HackersDelight __clzdi2 // count leading zeros
- dev HackersDelight __clzti2 // count leading zeros
- dev HackersDelight __ctzsi2 // count trailing zeros
- dev HackersDelight __ctzdi2 // count trailing zeros
- dev HackersDelight __ctzti2 // count trailing zeros
- dev __ctzsi2 __ffssi2 // find least significant 1 bit
- dev __ctzsi2 __ffsdi2 // find least significant 1 bit
- dev __ctzsi2 __ffsti2 // find least significant 1 bit
- dev BitTwiddlingHacks __paritysi2 // bit parity
- dev BitTwiddlingHacks __paritydi2 // bit parity
- dev BitTwiddlingHacks __parityti2 // bit parity
- dev TAOCP __popcountsi2 // bit population
- dev TAOCP __popcountdi2 // bit population
- dev TAOCP __popcountti2 // bit population
- dev other __bswapsi2 // a byteswapped
- dev other __bswapdi2 // a byteswapped
- dev other __bswapti2 // a byteswapped
#### Integer Comparison
- port llvm __cmpsi2 // a,b: i32, (a<b)-> 0, (a==b) -> 1, (a>b) -> 2
- port llvm __cmpdi2 // a,b: i64
- port llvm __cmpti2 // a,b: i128
- port llvm __ucmpsi2 // a,b: u32, (a<b)-> 0, (a==b) -> 1, (a>b) -> 2
- port llvm __ucmpdi2 // a,b: u64
- port llvm __ucmpti2 // a,b: u128
#### Integer Arithmetic
- none none __ashlsi3 // a,b: i32, a << b unused in llvm, TODO (e.g. used by rl78)
- port llvm __ashldi3 // a,b: u64
- port llvm __ashlti3 // a,b: u128
- none none __ashrsi3 // a,b: i32, a >> b arithmetic (sign fill) TODO (e.g. used by rl78)
- port llvm __ashrdi3 // ..
- port llvm __ashrti3 //
- none none __lshrsi3 // a,b: i32, a >> b logical (zero fill) TODO (e.g. used by rl78)
- port llvm __lshrdi3 //
- port llvm __lshrti3 //
- port llvm __negdi2 // a: i32, -a, symbol-level compatibility with libgcc
- port llvm __negti2 // unnecessary: unused in backends
- port llvm __mulsi3 // a,b: i32, a * b
- port llvm __muldi3 //
- port llvm __multi3 //
- port llvm __divsi3 // a,b: i32, a / b
- port llvm __divdi3 //
- port llvm __divti3 //
- port llvm __udivsi3 // a,b: u32, a / b
- port llvm __udivdi3 //
- port llvm __udivti3 //
- port llvm __modsi3 // a,b: i32, a % b
- port llvm __moddi3 //
- port llvm __modti3 //
- port llvm __umodsi3 // a,b: u32, a % b
- port llvm __umoddi3 //
- port llvm __umodti3 //
- port llvm __udivmoddi4 // a,b: u32, a / b, rem.* = a % b unsigned
- port llvm __udivmodti4 //
- port llvm __udivmodsi4 //
- port llvm __divmodsi4 // a,b: i32, a / b, rem.* = a % b signed, ARM
- port llvm __divmoddi4 //
#### Integer Arithmetic with trapping overflow
- dev BitTwiddlingHacks __absvsi2 // abs(a)
- dev BitTwiddlingHacks __absvdi2 // abs(a)
- dev BitTwiddlingHacks __absvti2 // abs(a)
- port llvm __negvsi2 // -a symbol-level compatibility: libgcc
- port llvm __negvdi2 // -a unnecessary: unused in backends
- port llvm __negvti2 // -a
- TODO upstreaming __addvsi3..__mulvti3 after testing panics works
- dev HackersDelight __addvsi3 // a + b
- dev HackersDelight __addvdi3 //
- dev HackersDelight __addvti3 //
- dev HackersDelight __subvsi3 // a - b
- dev HackersDelight __subvdi3 //
- dev HackersDelight __subvti3 //
- dev HackersDelight __mulvsi3 // a * b
- dev HackersDelight __mulvdi3 //
- dev HackersDelight __mulvti3 //
#### Integer Arithmetic which returns if overflow (would be faster without pointer)
- dev HackersDelight __addosi4 // a + b, overflow->ov.*=1 else 0
- dev HackersDelight __addodi4 // (completeness + performance, llvm does not use them)
- dev HackersDelight __addoti4 //
- dev HackersDelight __subosi4 // a - b, overflow->ov.*=1 else 0
- dev HackersDelight __subodi4 // (completeness + performance, llvm does not use them)
- dev HackersDelight __suboti4 //
- dev HackersDelight __mulosi4 // a * b, overflow->ov.*=1 else 0
- dev HackersDelight __mulodi4 // (required by llvm)
- dev HackersDelight __muloti4 //
## Float library routines
TODO: review source of implementation
#### Float Conversion
- dev other __extendsfdf2 // a: f32 -> f64, TODO: missing tests
- dev other __extendsftf2 // a: f32 -> f128
- dev llvm __extendsfxf2 // a: f32 -> f80, TODO: missing tests
- dev other __extenddftf2 // a: f64 -> f128
- dev llvm __extenddfxf2 // a: f64 -> f80
- dev other __truncdfsf2 // a: f64 -> f32, rounding towards zero
- dev other __trunctfdf2 // a: f128-> f64
- dev other __trunctfsf2 // a: f128-> f32
- dev llvm __truncxfsf2 // a: f80 -> f32, TODO: missing tests
- dev llvm __truncxfdf2 // a: f80 -> f64, TODO: missing tests
- dev unclear __fixsfsi // a: f32 -> i32, rounding towards zero
- dev unclear __fixdfsi // a: f64 -> i32
- dev unclear __fixtfsi // a: f128-> i32
- dev unclear __fixxfsi // a: f80 -> i32, TODO: missing tests
- dev unclear __fixsfdi // a: f32 -> i64, rounding towards zero
- dev unclear __fixdfdi // ..
- dev unclear __fixtfdi //
- dev unclear __fixxfdi // TODO: missing tests
- dev unclear __fixsfti // a: f32 -> i128, rounding towards zero
- dev unclear __fixdfti // ..
- dev unclear __fixtfdi //
- dev unclear __fixxfti // TODO: missing tests
- dev unclear __fixunssfsi // a: f32 -> u32, rounding towards zero. negative values become 0.
- dev unclear __fixunsdfsi // ..
- dev unclear __fixunstfsi //
- dev unclear __fixunsxfsi // TODO: missing tests
- dev unclear __fixunssfdi // a: f32 -> u64, rounding towards zero. negative values become 0.
- dev unclear __fixunsdfdi //
- dev unclear __fixunstfdi //
- dev unclear __fixunsxfdi // TODO: missing tests
- dev unclear __fixunssfti // a: f32 -> u128, rounding towards zero. negative values become 0.
- dev unclear __fixunsdfti //
- dev unclear __fixunstfdi //
- dev unclear __fixunsxfti // TODO: some more tests needed for base coverage
- dev unclear __floatsisf // a: i32 -> f32
- dev unclear __floatsidf // a: i32 -> f64, TODO: missing tests
- dev unclear __floatsitf // ..
- dev unclear __floatsixf // TODO: missing tests
- dev unclear __floatdisf // a: i64 -> f32
- dev unclear __floatdidf //
- dev unclear __floatditf //
- dev unclear __floatdixf // TODO: missing tests
- dev unclear __floattisf // a: i128-> f32
- dev unclear __floattidf //
- dev unclear __floattitf //
- dev unclear __floattixf // TODO: missing tests
- dev unclear __floatunsisf // a: u32 -> f32
- dev unclear __floatunsidf // TODO: missing tests
- dev unclear __floatunsitf //
- dev unclear __floatunsixf // TODO: missing tests
- dev unclear __floatundisf // a: u64 -> f32
- dev unclear __floatundidf //
- dev unclear __floatunditf //
- dev unclear __floatundixf // TODO: missing tests
- dev unclear __floatuntisf // a: u128-> f32
- dev unclear __floatuntidf //
- dev unclear __floatuntitf //
- dev unclear __floatuntixf // TODO: missing tests
#### Float Comparison
- dev other __cmpsf2 // a,b:f32, (a<b)->-1,(a==b)->0,(a>b)->1,Nan->1
- dev other __cmpdf2 // exported from __lesf2, __ledf2, __letf2 (below)
- dev other __cmptf2 // But: if NaN is a possibility, use another routine.
- dev other __unordsf2 // a,b:f32, (a==+-NaN or b==+-NaN) -> !=0, else -> 0
- dev other __unorddf2 // __only reliable for (input!=NaN)__
- dev other __unordtf2 // TODO: missing tests
- dev other __eqsf2 // (a!=NaN) and (b!=Nan) and (a==b) -> output=0
- dev other __eqdf2 //
- dev other __eqtf2 //
- dev other __nesf2 // (a==NaN) or (b==Nan) or (a!=b) -> output!=0
- dev other __nedf2 //
- dev other __netf2 // __eqtf2 and __netf2 have same return value -> tested with __eqsf2
- dev other __gesf2 // (a!=Nan) and (b!=Nan) and (a>=b) -> output>=0
- dev other __gedf2 //
- dev other __getf2 // TODO: missing tests
- dev other __ltsf2 // (a!=Nan) and (b!=Nan) and (a<b) -> output<0
- dev other __ltdf2 //
- dev other __lttf2 // TODO: missing tests
- dev other __lesf2 // (a!=Nan) and (b!=Nan) and (a<=b) -> output<=0
- dev other __ledf2 //
- dev other __letf2 // TODO: missing tests
- dev other __gtsf2 // (a!=Nan) and (b!=Nan) and (a>b) -> output>0
- dev other __gtdf2 //
- dev other __gttf2 // TODO: missing tests
#### Float Arithmetic
- dev unclear __addsf3 // a + b f32, TODO: missing tests
- dev unclear __adddf3 // a + b f64, TODO: missing tests
- dev unclear __addtf3 // a + b f128
- dev unclear __addxf3 // a + b f80
- dev unclear __aeabi_fadd // a + b f64 ARM: AAPCS
- dev unclear __aeabi_dadd // a + b f64 ARM: AAPCS
- dev unclear __subsf3 // a - b, TODO: missing tests
- dev unclear __subdf3 // a - b, TODO: missing tests
- dev unclear __subtf3 // a - b
- dev unclear __subxf3 // a - b f80, TODO: missing tests
- dev unclear __aeabi_fsub // a - b f64 ARM: AAPCS
- dev unclear __aeabi_dsub // a - b f64 ARM: AAPCS
- dev unclear __mulsf3 // a * b, TODO: missing tests
- dev unclear __muldf3 // a * b, TODO: missing tests
- dev unclear __multf3 // a * b
- dev unclear __mulxf3 // a * b
- dev unclear __divsf3 // a / b, TODO: review tests
- dev unclear __divdf3 // a / b, TODO: review tests
- dev unclear __divtf3 // a / b
- dev unclear __divxf3 // a / b
- dev unclear __negsf2 // -a symbol-level compatibility: libgcc uses this for the rl78
- dev unclear __negdf2 // -a unnecessary: can be lowered directly to a xor
- dev unclear __negtf2 // -a, TODO: missing tests
- dev unclear __negxf2 // -a, TODO: missing tests
#### Floating point raised to integer power
- dev unclear __powisf2 // a ^ b, TODO
- dev unclear __powidf2 //
- dev unclear __powitf2 //
- dev unclear __powixf2 //
- dev unclear __mulsc3 // (a+ib) * (c+id)
- dev unclear __muldc3 //
- dev unclear __multc3 //
- dev unclear __mulxc3 //
- dev unclear __divsc3 // (a+ib) * / (c+id)
- dev unclear __divdc3 //
- dev unclear __divtc3 //
- dev unclear __divxc3 //
## Decimal float library routines
BID means Binary Integer Decimal encoding, DPD means Densely Packed Decimal encoding.
BID should be only chosen for binary data, DPD for decimal data (ASCII, Unicode etc).
If possible, use BCD instead of DPD to represent numbers not accurately representable
in binary like the number 0.2.
All routines are TODO.
#### Decimal float Conversion
- __dpd_extendsddd2 // dec32->dec64
- __bid_extendsddd2 // dec32->dec64
- __dpd_extendsdtd2 // dec32->dec128
- __bid_extendsdtd2 // dec32->dec128
- __dpd_extendddtd2 // dec64->dec128
- __bid_extendddtd2 // dec64->dec128
- __dpd_truncddsd2 // dec64->dec32
- __bid_truncddsd2 // dec64->dec32
- __dpd_trunctdsd2 // dec128->dec32
- __bid_trunctdsd2 // dec128->dec32
- __dpd_trunctddd2 // dec128->dec64
- __bid_trunctddd2 // dec128->dec64
- __dpd_extendsfdd // float->dec64
- __bid_extendsfdd // float->dec64
- __dpd_extendsftd // float->dec128
- __bid_extendsftd // float->dec128
- __dpd_extenddftd // double->dec128
- __bid_extenddftd // double->dec128
- __dpd_extendxftd // long double->dec128
- __bid_extendxftd // long double->dec128
- __dpd_truncdfsd // double->dec32
- __bid_truncdfsd // double->dec32
- __dpd_truncxfsd // long double->dec32
- __bid_truncxfsd // long double->dec32
- __dpd_trunctfsd // long double->dec32
- __bid_trunctfsd // long double->dec32
- __dpd_truncxfdd // long double->dec64
- __bid_truncxfdd // long double->dec64
- __dpd_trunctfdd // long double->dec64
- __bid_trunctfdd // long double->dec64
- __dpd_truncddsf // dec64->float
- __bid_truncddsf // dec64->float
- __dpd_trunctdsf // dec128->float
- __bid_trunctdsf // dec128->float
- __dpd_extendsddf // dec32->double
- __bid_extendsddf // dec32->double
- __dpd_trunctddf // dec128->double
- __bid_trunctddf // dec128->double
- __dpd_extendsdxf // dec32->long double
- __bid_extendsdxf // dec32->long double
- __dpd_extendddxf // dec64->long double
- __bid_extendddxf // dec64->long double
- __dpd_trunctdxf // dec128->long double
- __bid_trunctdxf // dec128->long double
- __dpd_extendsdtf // dec32->long double
- __bid_extendsdtf // dec32->long double
- __dpd_extendddtf // dec64->long double
- __bid_extendddtf // dec64->long double
Same size conversion:
- __dpd_extendsfsd // float->dec32
- __bid_extendsfsd // float->dec32
- __dpd_extenddfdd // double->dec64
- __bid_extenddfdd // double->dec64
- __dpd_extendtftd //long double->dec128
- __bid_extendtftd //long double->dec128
- __dpd_truncsdsf // dec32->float
- __bid_truncsdsf // dec32->float
- __dpd_truncdddf // dec64->float
- __bid_truncdddf // dec64->float
- __dpd_trunctdtf // dec128->long double
- __bid_trunctdtf // dec128->long double
- __dpd_fixsdsi // dec32->int
- __bid_fixsdsi // dec32->int
- __dpd_fixddsi // dec64->int
- __bid_fixddsi // dec64->int
- __dpd_fixtdsi // dec128->int
- __bid_fixtdsi // dec128->int
- __dpd_fixsddi // dec32->long
- __bid_fixsddi // dec32->long
- __dpd_fixdddi // dec64->long
- __bid_fixdddi // dec64->long
- __dpd_fixtddi // dec128->long
- __bid_fixtddi // dec128->long
- __dpd_fixunssdsi // dec32->unsigned int, All negative values become zero.
- __bid_fixunssdsi // dec32->unsigned int
- __dpd_fixunsddsi // dec64->unsigned int
- __bid_fixunsddsi // dec64->unsigned int
- __dpd_fixunstdsi // dec128->unsigned int
- __bid_fixunstdsi // dec128->unsigned int
- __dpd_fixunssddi // dec32->unsigned long, All negative values become zero.
- __bid_fixunssddi // dec32->unsigned long
- __dpd_fixunsdddi // dec64->unsigned long
- __bid_fixunsdddi // dec64->unsigned long
- __dpd_fixunstddi // dec128->unsigned long
- __bid_fixunstddi // dec128->unsigned long
- __dpd_floatsisd // int->dec32
- __bid_floatsisd // int->dec32
- __dpd_floatsidd // int->dec64
- __bid_floatsidd // int->dec64
- __dpd_floatsitd // int->dec128
- __bid_floatsitd // int->dec128
- __dpd_floatdisd // long->dec32
- __bid_floatdisd // long->dec32
- __dpd_floatdidd // long->dec64
- __bid_floatdidd // long->dec64
- __dpd_floatditd // long->dec128
- __bid_floatditd // long->dec128
- __dpd_floatunssisd // unsigned int->dec32
- __bid_floatunssisd // unsigned int->dec32
- __dpd_floatunssidd // unsigned int->dec64
- __bid_floatunssidd // unsigned int->dec64
- __dpd_floatunssitd // unsigned int->dec128
- __bid_floatunssitd // unsigned int->dec128
- __dpd_floatunsdisd // unsigned long->dec32
- __bid_floatunsdisd // unsigned long->dec32
- __dpd_floatunsdidd // unsigned long->dec64
- __bid_floatunsdidd // unsigned long->dec64
- __dpd_floatunsditd // unsigned long->dec128
- __bid_floatunsditd // unsigned long->dec128
#### Decimal float Comparison
All decimal float comparison routines return c_int.
- __dpd_unordsd2 // a,b: dec32, a +-NaN or a +-NaN -> 1(nonzero), else -> 0
- __bid_unordsd2 // a,b: dec32
- __dpd_unorddd2 // a,b: dec64
- __bid_unorddd2 // a,b: dec64
- __dpd_unordtd2 // a,b: dec128
- __bid_unordtd2 // a,b: dec128
- __dpd_eqsd2 // a,b: dec32, a!=+-NaN and b!=+-Nan and a==b -> 0, else -> 1(nonzero)
- __bid_eqsd2 // a,b: dec32
- __dpd_eqdd2 // a,b: dec64
- __bid_eqdd2 // a,b: dec64
- __dpd_eqtd2 // a,b: dec128
- __bid_eqtd2 // a,b: dec128
- __dpd_nesd2 // a,b: dec32, a==+-NaN or b==+-NaN or a!=b -> 1(nonzero), else -> 0
- __bid_nesd2 // a,b: dec32
- __dpd_nedd2 // a,b: dec64
- __bid_nedd2 // a,b: dec64
- __dpd_netd2 // a,b: dec128
- __bid_netd2 // a,b: dec128
- __dpd_gesd2 // a,b: dec32, a!=+-NaN and b!=+-NaN and a>=b -> >=0, else -> <0
- __bid_gesd2 // a,b: dec32
- __dpd_gedd2 // a,b: dec64
- __bid_gedd2 // a,b: dec64
- __dpd_getd2 // a,b: dec128
- __bid_getd2 // a,b: dec128
- __dpd_ltsd2 // a,b: dec32, a!=+-NaN and b!=+-NaN and a<b -> <0, else -> >=0
- __bid_ltsd2 // a,b: dec32
- __dpd_ltdd2 // a,b: dec64
- __bid_ltdd2 // a,b: dec64
- __dpd_lttd2 // a,b: dec128
- __bid_lttd2 // a,b: dec128
- __dpd_lesd2 // a,b: dec32, a!=+-NaN and b!=+-NaN and a<=b -> <=0, else -> >=0
- __bid_lesd2 // a,b: dec32
- __dpd_ledd2 // a,b: dec64
- __bid_ledd2 // a,b: dec64
- __dpd_letd2 // a,b: dec128
- __bid_letd2 // a,b: dec128
- __dpd_gtsd2 // a,b: dec32, a!=+-NaN and b!=+-NaN and a>b -> >0, else -> <=0
- __bid_gtsd2 // a,b: dec32
- __dpd_gtdd2 // a,b: dec64
- __bid_gtdd2 // a,b: dec64
- __dpd_gttd2 // a,b: dec128
- __bid_gttd2 // a,b: dec128
#### Decimal float Arithmetic
These numbers include options with routines for +-0 and +-Nan.
- __dpd_addsd3 // a,b: dec32 -> dec32, a + b
- __bid_addsd3 // a,b: dec32 -> dec32
- __dpd_adddd3 // a,b: dec64 -> dec64
- __bid_adddd3 // a,b: dec64 -> dec64
- __dpd_addtd3 // a,b: dec128-> dec128
- __bid_addtd3 // a,b: dec128-> dec128
- __dpd_subsd3 // a,b: dec32, a - b
- __bid_subsd3 // a,b: dec32 -> dec32
- __dpd_subdd3 // a,b: dec64 ..
- __bid_subdd3 // a,b: dec64
- __dpd_subtd3 // a,b: dec128
- __bid_subtd3 // a,b: dec128
- __dpd_mulsd3 // a,b: dec32, a * b
- __bid_mulsd3 // a,b: dec32 -> dec32
- __dpd_muldd3 // a,b: dec64 ..
- __bid_muldd3 // a,b: dec64
- __dpd_multd3 // a,b: dec128
- __bid_multd3 // a,b: dec128
- __dpd_divsd3 // a,b: dec32, a / b
- __bid_divsd3 // a,b: dec32 -> dec32
- __dpd_divdd3 // a,b: dec64 ..
- __bid_divdd3 // a,b: dec64
- __dpd_divtd3 // a,b: dec128
- __bid_divtd3 // a,b: dec128
- __dpd_negsd2 // a,b: dec32, -a
- __bid_negsd2 // a,b: dec32 -> dec32
- __dpd_negdd2 // a,b: dec64 ..
- __bid_negdd2 // a,b: dec64
- __dpd_negtd2 // a,b: dec128
- __bid_negtd2 // a,b: dec128
## Fixed-point fractional library routines
TODO
Too unclear for work items:
- Miscellaneous routines => unclear, if supported (cache control and stack functions)
- Zig-specific language runtime features, for example "Arbitrary length integer library routines"

View File

@@ -1,26 +0,0 @@
/// absv - absolute oVerflow
/// * @panic if value can not be represented
pub inline fn absv(comptime ST: type, a: ST) ST {
const UT = switch (ST) {
i32 => u32,
i64 => u64,
i128 => u128,
else => unreachable,
};
// taken from Bit Twiddling Hacks
// compute the integer absolute value (abs) without branching
var x: ST = a;
const N: UT = @bitSizeOf(ST);
const sign: ST = a >> N - 1;
x +%= sign;
x ^= sign;
if (x < 0)
@panic("compiler_rt absv: overflow");
return x;
}
test {
_ = @import("absvsi2_test.zig");
_ = @import("absvdi2_test.zig");
_ = @import("absvti2_test.zig");
}

View File

@@ -1,12 +0,0 @@
const common = @import("./common.zig");
const absv = @import("./absv.zig").absv;
pub const panic = common.panic;
comptime {
@export(__absvdi2, .{ .name = "__absvdi2", .linkage = common.linkage });
}
pub fn __absvdi2(a: i64) callconv(.C) i64 {
return absv(i64, a);
}

View File

@@ -1,31 +0,0 @@
const testing = @import("std").testing;
const __absvdi2 = @import("absvdi2.zig").__absvdi2;
fn test__absvdi2(a: i64, expected: i64) !void {
var result = __absvdi2(a);
try testing.expectEqual(expected, result);
}
test "absvdi2" {
// -2^63 <= i64 <= 2^63-1
// 2^63 = 9223372036854775808
// 2^63-1 = 9223372036854775807
// TODO write panic handler for testing panics
//try test__absvdi2(-9223372036854775808, -5); // tested with return -5; and panic
try test__absvdi2(-9223372036854775807, 9223372036854775807);
try test__absvdi2(-9223372036854775806, 9223372036854775806);
try test__absvdi2(-9223372036854775805, 9223372036854775805);
try test__absvdi2(-9223372036854775804, 9223372036854775804);
try test__absvdi2(-42, 42);
try test__absvdi2(-7, 7);
try test__absvdi2(-1, 1);
try test__absvdi2(0, 0);
try test__absvdi2(1, 1);
try test__absvdi2(7, 7);
try test__absvdi2(42, 42);
try test__absvdi2(9223372036854775804, 9223372036854775804);
try test__absvdi2(9223372036854775805, 9223372036854775805);
try test__absvdi2(9223372036854775806, 9223372036854775806);
try test__absvdi2(9223372036854775807, 9223372036854775807);
}

View File

@@ -1,12 +0,0 @@
const common = @import("./common.zig");
const absv = @import("./absv.zig").absv;
pub const panic = common.panic;
comptime {
@export(__absvsi2, .{ .name = "__absvsi2", .linkage = common.linkage });
}
pub fn __absvsi2(a: i32) callconv(.C) i32 {
return absv(i32, a);
}

View File

@@ -1,31 +0,0 @@
const testing = @import("std").testing;
const __absvsi2 = @import("absvsi2.zig").__absvsi2;
fn test__absvsi2(a: i32, expected: i32) !void {
var result = __absvsi2(a);
try testing.expectEqual(expected, result);
}
test "absvsi2" {
// -2^31 <= i32 <= 2^31-1
// 2^31 = 2147483648
// 2^31-1 = 2147483647
// TODO write panic handler for testing panics
//try test__absvsi2(-2147483648, -5); // tested with return -5; and panic
try test__absvsi2(-2147483647, 2147483647);
try test__absvsi2(-2147483646, 2147483646);
try test__absvsi2(-2147483645, 2147483645);
try test__absvsi2(-2147483644, 2147483644);
try test__absvsi2(-42, 42);
try test__absvsi2(-7, 7);
try test__absvsi2(-1, 1);
try test__absvsi2(0, 0);
try test__absvsi2(1, 1);
try test__absvsi2(7, 7);
try test__absvsi2(42, 42);
try test__absvsi2(2147483644, 2147483644);
try test__absvsi2(2147483645, 2147483645);
try test__absvsi2(2147483646, 2147483646);
try test__absvsi2(2147483647, 2147483647);
}

View File

@@ -1,12 +0,0 @@
const common = @import("./common.zig");
const absv = @import("./absv.zig").absv;
pub const panic = common.panic;
comptime {
@export(__absvti2, .{ .name = "__absvti2", .linkage = common.linkage });
}
pub fn __absvti2(a: i128) callconv(.C) i128 {
return absv(i128, a);
}

View File

@@ -1,31 +0,0 @@
const testing = @import("std").testing;
const __absvti2 = @import("absvti2.zig").__absvti2;
fn test__absvti2(a: i128, expected: i128) !void {
var result = __absvti2(a);
try testing.expectEqual(expected, result);
}
test "absvti2" {
// -2^127 <= i128 <= 2^127-1
// 2^127 = 170141183460469231731687303715884105728
// 2^127+1 = 170141183460469231731687303715884105727
// TODO write panic handler for testing panics
//try test__absvti2(-170141183460469231731687303715884105728, -5); // tested with return -5; and panic
try test__absvti2(-170141183460469231731687303715884105727, 170141183460469231731687303715884105727);
try test__absvti2(-170141183460469231731687303715884105726, 170141183460469231731687303715884105726);
try test__absvti2(-170141183460469231731687303715884105725, 170141183460469231731687303715884105725);
try test__absvti2(-170141183460469231731687303715884105724, 170141183460469231731687303715884105724);
try test__absvti2(-42, 42);
try test__absvti2(-7, 7);
try test__absvti2(-1, 1);
try test__absvti2(0, 0);
try test__absvti2(1, 1);
try test__absvti2(7, 7);
try test__absvti2(42, 42);
try test__absvti2(170141183460469231731687303715884105724, 170141183460469231731687303715884105724);
try test__absvti2(170141183460469231731687303715884105725, 170141183460469231731687303715884105725);
try test__absvti2(170141183460469231731687303715884105726, 170141183460469231731687303715884105726);
try test__absvti2(170141183460469231731687303715884105727, 170141183460469231731687303715884105727);
}

View File

@@ -1,20 +0,0 @@
const common = @import("./common.zig");
const addf3 = @import("./addf3.zig").addf3;
pub const panic = common.panic;
comptime {
if (common.want_aeabi) {
@export(__aeabi_dadd, .{ .name = "__aeabi_dadd", .linkage = common.linkage });
} else {
@export(__adddf3, .{ .name = "__adddf3", .linkage = common.linkage });
}
}
fn __adddf3(a: f64, b: f64) callconv(.C) f64 {
return addf3(f64, a, b);
}
fn __aeabi_dadd(a: f64, b: f64) callconv(.AAPCS) f64 {
return addf3(f64, a, b);
}

View File

@@ -1,172 +0,0 @@
const std = @import("std");
const math = std.math;
const common = @import("./common.zig");
const normalize = common.normalize;
/// Ported from:
///
/// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/lib/builtins/fp_add_impl.inc
pub inline fn addf3(comptime T: type, a: T, b: T) T {
const bits = @typeInfo(T).Float.bits;
const Z = std.meta.Int(.unsigned, bits);
const S = std.meta.Int(.unsigned, bits - @clz(@as(Z, bits) - 1));
const typeWidth = bits;
const significandBits = math.floatMantissaBits(T);
const fractionalBits = math.floatFractionalBits(T);
const exponentBits = math.floatExponentBits(T);
const signBit = (@as(Z, 1) << (significandBits + exponentBits));
const maxExponent = ((1 << exponentBits) - 1);
const integerBit = (@as(Z, 1) << fractionalBits);
const quietBit = integerBit >> 1;
const significandMask = (@as(Z, 1) << significandBits) - 1;
const absMask = signBit - 1;
const qnanRep = @bitCast(Z, math.nan(T)) | quietBit;
var aRep = @bitCast(Z, a);
var bRep = @bitCast(Z, b);
const aAbs = aRep & absMask;
const bAbs = bRep & absMask;
const infRep = @bitCast(Z, math.inf(T));
// Detect if a or b is zero, infinity, or NaN.
if (aAbs -% @as(Z, 1) >= infRep - @as(Z, 1) or
bAbs -% @as(Z, 1) >= infRep - @as(Z, 1))
{
// NaN + anything = qNaN
if (aAbs > infRep) return @bitCast(T, @bitCast(Z, a) | quietBit);
// anything + NaN = qNaN
if (bAbs > infRep) return @bitCast(T, @bitCast(Z, b) | quietBit);
if (aAbs == infRep) {
// +/-infinity + -/+infinity = qNaN
if ((@bitCast(Z, a) ^ @bitCast(Z, b)) == signBit) {
return @bitCast(T, qnanRep);
}
// +/-infinity + anything remaining = +/- infinity
else {
return a;
}
}
// anything remaining + +/-infinity = +/-infinity
if (bAbs == infRep) return b;
// zero + anything = anything
if (aAbs == 0) {
// but we need to get the sign right for zero + zero
if (bAbs == 0) {
return @bitCast(T, @bitCast(Z, a) & @bitCast(Z, b));
} else {
return b;
}
}
// anything + zero = anything
if (bAbs == 0) return a;
}
// Swap a and b if necessary so that a has the larger absolute value.
if (bAbs > aAbs) {
const temp = aRep;
aRep = bRep;
bRep = temp;
}
// Extract the exponent and significand from the (possibly swapped) a and b.
var aExponent = @intCast(i32, (aRep >> significandBits) & maxExponent);
var bExponent = @intCast(i32, (bRep >> significandBits) & maxExponent);
var aSignificand = aRep & significandMask;
var bSignificand = bRep & significandMask;
// Normalize any denormals, and adjust the exponent accordingly.
if (aExponent == 0) aExponent = normalize(T, &aSignificand);
if (bExponent == 0) bExponent = normalize(T, &bSignificand);
// The sign of the result is the sign of the larger operand, a. If they
// have opposite signs, we are performing a subtraction; otherwise addition.
const resultSign = aRep & signBit;
const subtraction = (aRep ^ bRep) & signBit != 0;
// Shift the significands to give us round, guard and sticky, and or in the
// implicit significand bit. (If we fell through from the denormal path it
// was already set by normalize( ), but setting it twice won't hurt
// anything.)
aSignificand = (aSignificand | integerBit) << 3;
bSignificand = (bSignificand | integerBit) << 3;
// Shift the significand of b by the difference in exponents, with a sticky
// bottom bit to get rounding correct.
const @"align" = @intCast(u32, aExponent - bExponent);
if (@"align" != 0) {
if (@"align" < typeWidth) {
const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) @as(Z, 1) else 0;
bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky;
} else {
bSignificand = 1; // sticky; b is known to be non-zero.
}
}
if (subtraction) {
aSignificand -= bSignificand;
// If a == -b, return +zero.
if (aSignificand == 0) return @bitCast(T, @as(Z, 0));
// If partial cancellation occured, we need to left-shift the result
// and adjust the exponent:
if (aSignificand < integerBit << 3) {
const shift = @intCast(i32, @clz(aSignificand)) - @intCast(i32, @clz(integerBit << 3));
aSignificand <<= @intCast(S, shift);
aExponent -= shift;
}
} else { // addition
aSignificand += bSignificand;
// If the addition carried up, we need to right-shift the result and
// adjust the exponent:
if (aSignificand & (integerBit << 4) != 0) {
const sticky = aSignificand & 1;
aSignificand = aSignificand >> 1 | sticky;
aExponent += 1;
}
}
// If we have overflowed the type, return +/- infinity:
if (aExponent >= maxExponent) return @bitCast(T, infRep | resultSign);
if (aExponent <= 0) {
// Result is denormal; the exponent and round/sticky bits are zero.
// All we need to do is shift the significand and apply the correct sign.
aSignificand >>= @intCast(S, 4 - aExponent);
return @bitCast(T, resultSign | aSignificand);
}
// Low three bits are round, guard, and sticky.
const roundGuardSticky = aSignificand & 0x7;
// Shift the significand into place, and mask off the integer bit, if it's implicit.
var result = (aSignificand >> 3) & significandMask;
// Insert the exponent and sign.
result |= @intCast(Z, aExponent) << significandBits;
result |= resultSign;
// Final rounding. The result may overflow to infinity, but that is the
// correct result in that case.
if (roundGuardSticky > 0x4) result += 1;
if (roundGuardSticky == 0x4) result += result & 1;
// Restore any explicit integer bit, if it was rounded off
if (significandBits != fractionalBits) {
if ((result >> significandBits) != 0) result |= integerBit;
}
return @bitCast(T, result);
}
test {
_ = @import("addf3_test.zig");
}

View File

@@ -1,156 +0,0 @@
// Ported from:
//
// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/addtf3_test.c
// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/test/builtins/Unit/subtf3_test.c
const std = @import("std");
const math = std.math;
const qnan128 = @bitCast(f128, @as(u128, 0x7fff800000000000) << 64);
const __addtf3 = @import("addtf3.zig").__addtf3;
const __addxf3 = @import("addxf3.zig").__addxf3;
const __subtf3 = @import("subtf3.zig").__subtf3;
fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
const x = __addtf3(a, b);
const rep = @bitCast(u128, x);
const hi = @intCast(u64, rep >> 64);
const lo = @truncate(u64, rep);
if (hi == expected_hi and lo == expected_lo) {
return;
}
// test other possible NaN representation (signal NaN)
else if (expected_hi == 0x7fff800000000000 and expected_lo == 0x0) {
if ((hi & 0x7fff000000000000) == 0x7fff000000000000 and
((hi & 0xffffffffffff) > 0 or lo > 0))
{
return;
}
}
return error.TestFailed;
}
test "addtf3" {
try test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
// NaN + any = NaN
try test__addtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
// inf + inf = inf
try test__addtf3(math.inf(f128), math.inf(f128), 0x7fff000000000000, 0x0);
// inf + any = inf
try test__addtf3(math.inf(f128), 0x1.2335653452436234723489432abcdefp+5, 0x7fff000000000000, 0x0);
// any + any
try test__addtf3(0x1.23456734245345543849abcdefp+5, 0x1.edcba52449872455634654321fp-1, 0x40042afc95c8b579, 0x61e58dd6c51eb77c);
try test__addtf3(0x1.edcba52449872455634654321fp-1, 0x1.23456734245345543849abcdefp+5, 0x40042afc95c8b579, 0x61e58dd6c51eb77c);
}
fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) !void {
const x = __subtf3(a, b);
const rep = @bitCast(u128, x);
const hi = @intCast(u64, rep >> 64);
const lo = @truncate(u64, rep);
if (hi == expected_hi and lo == expected_lo) {
return;
}
// test other possible NaN representation (signal NaN)
else if (expected_hi == 0x7fff800000000000 and expected_lo == 0x0) {
if ((hi & 0x7fff000000000000) == 0x7fff000000000000 and
((hi & 0xffffffffffff) > 0 or lo > 0))
{
return;
}
}
return error.TestFailed;
}
test "subtf3" {
// qNaN - any = qNaN
try test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
// NaN + any = NaN
try test__subtf3(@bitCast(f128, (@as(u128, 0x7fff000000000000) << 64) | @as(u128, 0x800030000000)), 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
// inf - any = inf
try test__subtf3(math.inf(f128), 0x1.23456789abcdefp+5, 0x7fff000000000000, 0x0);
// any + any
try test__subtf3(0x1.234567829a3bcdef5678ade36734p+5, 0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x40041b8af1915166, 0xa44a7bca780a166c);
try test__subtf3(0x1.ee9d7c52354a6936ab8d7654321fp-1, 0x1.234567829a3bcdef5678ade36734p+5, 0xc0041b8af1915166, 0xa44a7bca780a166c);
}
const qnan80 = @bitCast(f80, @bitCast(u80, math.nan(f80)) | (1 << (math.floatFractionalBits(f80) - 1)));
fn test__addxf3(a: f80, b: f80, expected: u80) !void {
const x = __addxf3(a, b);
const rep = @bitCast(u80, x);
if (rep == expected)
return;
if (math.isNan(@bitCast(f80, expected)) and math.isNan(x))
return; // We don't currently test NaN payload propagation
return error.TestFailed;
}
test "addxf3" {
// NaN + any = NaN
try test__addxf3(qnan80, 0x1.23456789abcdefp+5, @bitCast(u80, qnan80));
try test__addxf3(@bitCast(f80, @as(u80, 0x7fff_8000_8000_3000_0000)), 0x1.23456789abcdefp+5, @bitCast(u80, qnan80));
// any + NaN = NaN
try test__addxf3(0x1.23456789abcdefp+5, qnan80, @bitCast(u80, qnan80));
try test__addxf3(0x1.23456789abcdefp+5, @bitCast(f80, @as(u80, 0x7fff_8000_8000_3000_0000)), @bitCast(u80, qnan80));
// NaN + inf = NaN
try test__addxf3(qnan80, math.inf(f80), @bitCast(u80, qnan80));
// inf + NaN = NaN
try test__addxf3(math.inf(f80), qnan80, @bitCast(u80, qnan80));
// inf + inf = inf
try test__addxf3(math.inf(f80), math.inf(f80), @bitCast(u80, math.inf(f80)));
// inf + -inf = NaN
try test__addxf3(math.inf(f80), -math.inf(f80), @bitCast(u80, qnan80));
// -inf + inf = NaN
try test__addxf3(-math.inf(f80), math.inf(f80), @bitCast(u80, qnan80));
// inf + any = inf
try test__addxf3(math.inf(f80), 0x1.2335653452436234723489432abcdefp+5, @bitCast(u80, math.inf(f80)));
// any + inf = inf
try test__addxf3(0x1.2335653452436234723489432abcdefp+5, math.inf(f80), @bitCast(u80, math.inf(f80)));
// any + any
try test__addxf3(0x1.23456789abcdp+5, 0x1.dcba987654321p+5, 0x4005_BFFFFFFFFFFFC400);
try test__addxf3(0x1.23456734245345543849abcdefp+5, 0x1.edcba52449872455634654321fp-1, 0x4004_957E_4AE4_5ABC_B0F3);
try test__addxf3(0x1.ffff_ffff_ffff_fffcp+0, 0x1.0p-63, 0x3FFF_FFFFFFFFFFFFFFFF); // exact
try test__addxf3(0x1.ffff_ffff_ffff_fffep+0, 0x0.0p0, 0x3FFF_FFFFFFFFFFFFFFFF); // exact
try test__addxf3(0x1.ffff_ffff_ffff_fffcp+0, 0x1.4p-63, 0x3FFF_FFFFFFFFFFFFFFFF); // round down
try test__addxf3(0x1.ffff_ffff_ffff_fffcp+0, 0x1.8p-63, 0x4000_8000000000000000); // round up to even
try test__addxf3(0x1.ffff_ffff_ffff_fffcp+0, 0x1.cp-63, 0x4000_8000000000000000); // round up
try test__addxf3(0x1.ffff_ffff_ffff_fffcp+0, 0x2.0p-63, 0x4000_8000000000000000); // exact
try test__addxf3(0x1.ffff_ffff_ffff_fffcp+0, 0x2.1p-63, 0x4000_8000000000000000); // round down
try test__addxf3(0x1.ffff_ffff_ffff_fffcp+0, 0x3.0p-63, 0x4000_8000000000000000); // round down to even
try test__addxf3(0x1.ffff_ffff_ffff_fffcp+0, 0x3.1p-63, 0x4000_8000000000000001); // round up
try test__addxf3(0x1.ffff_ffff_ffff_fffcp+0, 0x4.0p-63, 0x4000_8000000000000001); // exact
try test__addxf3(0x1.0fff_ffff_ffff_fffep+0, 0x1.0p-63, 0x3FFF_8800000000000000); // exact
try test__addxf3(0x1.0fff_ffff_ffff_fffep+0, 0x1.7p-63, 0x3FFF_8800000000000000); // round down
try test__addxf3(0x1.0fff_ffff_ffff_fffep+0, 0x1.8p-63, 0x3FFF_8800000000000000); // round down to even
try test__addxf3(0x1.0fff_ffff_ffff_fffep+0, 0x1.9p-63, 0x3FFF_8800000000000001); // round up
try test__addxf3(0x1.0fff_ffff_ffff_fffep+0, 0x2.0p-63, 0x3FFF_8800000000000001); // exact
try test__addxf3(0x0.ffff_ffff_ffff_fffcp-16382, 0x0.0000_0000_0000_0002p-16382, 0x0000_7FFFFFFFFFFFFFFF); // exact
try test__addxf3(0x0.1fff_ffff_ffff_fffcp-16382, 0x0.0000_0000_0000_0002p-16382, 0x0000_0FFFFFFFFFFFFFFF); // exact
}

View File

@@ -1,12 +0,0 @@
const common = @import("./common.zig");
const addf3 = @import("./addf3.zig").addf3;
pub const panic = common.panic;
comptime {
@export(__addhf3, .{ .name = "__addhf3", .linkage = common.linkage });
}
fn __addhf3(a: f16, b: f16) callconv(.C) f16 {
return addf3(f16, a, b);
}

View File

@@ -1,48 +0,0 @@
const std = @import("std");
const builtin = @import("builtin");
const is_test = builtin.is_test;
const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
pub const panic = @import("common.zig").panic;
comptime {
@export(__addosi4, .{ .name = "__addosi4", .linkage = linkage });
@export(__addodi4, .{ .name = "__addodi4", .linkage = linkage });
@export(__addoti4, .{ .name = "__addoti4", .linkage = linkage });
}
// addo - add overflow
// * return a+%b.
// * return if a+b overflows => 1 else => 0
// - addoXi4_generic as default
inline fn addoXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
@setRuntimeSafety(builtin.is_test);
overflow.* = 0;
var sum: ST = a +% b;
// Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract
// Let sum = a +% b == a + b + carry == wraparound addition.
// Overflow in a+b+carry occurs, iff a and b have opposite signs
// and the sign of a+b+carry is the same as a (or equivalently b).
// Slower routine: res = ~(a ^ b) & ((sum ^ a)
// Faster routine: res = (sum ^ a) & (sum ^ b)
// Overflow occured, iff (res < 0)
if (((sum ^ a) & (sum ^ b)) < 0)
overflow.* = 1;
return sum;
}
pub fn __addosi4(a: i32, b: i32, overflow: *c_int) callconv(.C) i32 {
return addoXi4_generic(i32, a, b, overflow);
}
pub fn __addodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 {
return addoXi4_generic(i64, a, b, overflow);
}
pub fn __addoti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
return addoXi4_generic(i128, a, b, overflow);
}
test {
_ = @import("addosi4_test.zig");
_ = @import("addodi4_test.zig");
_ = @import("addoti4_test.zig");
}

View File

@@ -1,77 +0,0 @@
const addv = @import("addo.zig");
const std = @import("std");
const testing = std.testing;
const math = std.math;
fn test__addodi4(a: i64, b: i64) !void {
var result_ov: c_int = undefined;
var expected_ov: c_int = undefined;
var result = addv.__addodi4(a, b, &result_ov);
var expected: i64 = simple_addodi4(a, b, &expected_ov);
try testing.expectEqual(expected, result);
try testing.expectEqual(expected_ov, result_ov);
}
fn simple_addodi4(a: i64, b: i64, overflow: *c_int) i64 {
overflow.* = 0;
const min: i64 = math.minInt(i64);
const max: i64 = math.maxInt(i64);
if (((a > 0) and (b > max - a)) or
((a < 0) and (b < min - a)))
overflow.* = 1;
return a +% b;
}
test "addodi4" {
const min: i64 = math.minInt(i64);
const max: i64 = math.maxInt(i64);
var i: i64 = 1;
while (i < max) : (i *|= 2) {
try test__addodi4(i, i);
try test__addodi4(-i, -i);
try test__addodi4(i, -i);
try test__addodi4(-i, i);
}
// edge cases
// 0 + 0 = 0
// MIN + MIN overflow
// MAX + MAX overflow
// 0 + MIN MIN
// 0 + MAX MAX
// MIN + 0 MIN
// MAX + 0 MAX
// MIN + MAX -1
// MAX + MIN -1
try test__addodi4(0, 0);
try test__addodi4(min, min);
try test__addodi4(max, max);
try test__addodi4(0, min);
try test__addodi4(0, max);
try test__addodi4(min, 0);
try test__addodi4(max, 0);
try test__addodi4(min, max);
try test__addodi4(max, min);
// derived edge cases
// MIN+1 + MIN overflow
// MAX-1 + MAX overflow
// 1 + MIN = MIN+1
// -1 + MIN overflow
// -1 + MAX = MAX-1
// +1 + MAX overflow
// MIN + 1 = MIN+1
// MIN + -1 overflow
// MAX + 1 overflow
// MAX + -1 = MAX-1
try test__addodi4(min + 1, min);
try test__addodi4(max - 1, max);
try test__addodi4(1, min);
try test__addodi4(-1, min);
try test__addodi4(-1, max);
try test__addodi4(1, max);
try test__addodi4(min, 1);
try test__addodi4(min, -1);
try test__addodi4(max, -1);
try test__addodi4(max, 1);
}

View File

@@ -1,78 +0,0 @@
const addv = @import("addo.zig");
const testing = @import("std").testing;
fn test__addosi4(a: i32, b: i32) !void {
var result_ov: c_int = undefined;
var expected_ov: c_int = undefined;
var result = addv.__addosi4(a, b, &result_ov);
var expected: i32 = simple_addosi4(a, b, &expected_ov);
try testing.expectEqual(expected, result);
try testing.expectEqual(expected_ov, result_ov);
}
fn simple_addosi4(a: i32, b: i32, overflow: *c_int) i32 {
overflow.* = 0;
const min: i32 = -2147483648;
const max: i32 = 2147483647;
if (((a > 0) and (b > max - a)) or
((a < 0) and (b < min - a)))
overflow.* = 1;
return a +% b;
}
test "addosi4" {
// -2^31 <= i32 <= 2^31-1
// 2^31 = 2147483648
// 2^31-1 = 2147483647
const min: i32 = -2147483648;
const max: i32 = 2147483647;
var i: i32 = 1;
while (i < max) : (i *|= 2) {
try test__addosi4(i, i);
try test__addosi4(-i, -i);
try test__addosi4(i, -i);
try test__addosi4(-i, i);
}
// edge cases
// 0 + 0 = 0
// MIN + MIN overflow
// MAX + MAX overflow
// 0 + MIN MIN
// 0 + MAX MAX
// MIN + 0 MIN
// MAX + 0 MAX
// MIN + MAX -1
// MAX + MIN -1
try test__addosi4(0, 0);
try test__addosi4(min, min);
try test__addosi4(max, max);
try test__addosi4(0, min);
try test__addosi4(0, max);
try test__addosi4(min, 0);
try test__addosi4(max, 0);
try test__addosi4(min, max);
try test__addosi4(max, min);
// derived edge cases
// MIN+1 + MIN overflow
// MAX-1 + MAX overflow
// 1 + MIN = MIN+1
// -1 + MIN overflow
// -1 + MAX = MAX-1
// +1 + MAX overflow
// MIN + 1 = MIN+1
// MIN + -1 overflow
// MAX + 1 overflow
// MAX + -1 = MAX-1
try test__addosi4(min + 1, min);
try test__addosi4(max - 1, max);
try test__addosi4(1, min);
try test__addosi4(-1, min);
try test__addosi4(-1, max);
try test__addosi4(1, max);
try test__addosi4(min, 1);
try test__addosi4(min, -1);
try test__addosi4(max, -1);
try test__addosi4(max, 1);
}

View File

@@ -1,77 +0,0 @@
const addv = @import("addo.zig");
const std = @import("std");
const testing = std.testing;
const math = std.math;
fn test__addoti4(a: i128, b: i128) !void {
var result_ov: c_int = undefined;
var expected_ov: c_int = undefined;
var result = addv.__addoti4(a, b, &result_ov);
var expected: i128 = simple_addoti4(a, b, &expected_ov);
try testing.expectEqual(expected, result);
try testing.expectEqual(expected_ov, result_ov);
}
fn simple_addoti4(a: i128, b: i128, overflow: *c_int) i128 {
overflow.* = 0;
const min: i128 = math.minInt(i128);
const max: i128 = math.maxInt(i128);
if (((a > 0) and (b > max - a)) or
((a < 0) and (b < min - a)))
overflow.* = 1;
return a +% b;
}
test "addoti4" {
const min: i128 = math.minInt(i128);
const max: i128 = math.maxInt(i128);
var i: i128 = 1;
while (i < max) : (i *|= 2) {
try test__addoti4(i, i);
try test__addoti4(-i, -i);
try test__addoti4(i, -i);
try test__addoti4(-i, i);
}
// edge cases
// 0 + 0 = 0
// MIN + MIN overflow
// MAX + MAX overflow
// 0 + MIN MIN
// 0 + MAX MAX
// MIN + 0 MIN
// MAX + 0 MAX
// MIN + MAX -1
// MAX + MIN -1
try test__addoti4(0, 0);
try test__addoti4(min, min);
try test__addoti4(max, max);
try test__addoti4(0, min);
try test__addoti4(0, max);
try test__addoti4(min, 0);
try test__addoti4(max, 0);
try test__addoti4(min, max);
try test__addoti4(max, min);
// derived edge cases
// MIN+1 + MIN overflow
// MAX-1 + MAX overflow
// 1 + MIN = MIN+1
// -1 + MIN overflow
// -1 + MAX = MAX-1
// +1 + MAX overflow
// MIN + 1 = MIN+1
// MIN + -1 overflow
// MAX + 1 overflow
// MAX + -1 = MAX-1
try test__addoti4(min + 1, min);
try test__addoti4(max - 1, max);
try test__addoti4(1, min);
try test__addoti4(-1, min);
try test__addoti4(-1, max);
try test__addoti4(1, max);
try test__addoti4(min, 1);
try test__addoti4(min, -1);
try test__addoti4(max, -1);
try test__addoti4(max, 1);
}

View File

@@ -1,20 +0,0 @@
const common = @import("./common.zig");
const addf3 = @import("./addf3.zig").addf3;
pub const panic = common.panic;
comptime {
if (common.want_aeabi) {
@export(__aeabi_fadd, .{ .name = "__aeabi_fadd", .linkage = common.linkage });
} else {
@export(__addsf3, .{ .name = "__addsf3", .linkage = common.linkage });
}
}
fn __addsf3(a: f32, b: f32) callconv(.C) f32 {
return addf3(f32, a, b);
}
fn __aeabi_fadd(a: f32, b: f32) callconv(.AAPCS) f32 {
return addf3(f32, a, b);
}

View File

@@ -1,21 +0,0 @@
const common = @import("./common.zig");
const addf3 = @import("./addf3.zig").addf3;
pub const panic = common.panic;
comptime {
if (common.want_ppc_abi) {
@export(__addtf3, .{ .name = "__addkf3", .linkage = common.linkage });
} else if (common.want_sparc_abi) {
@export(_Qp_add, .{ .name = "_Qp_add", .linkage = common.linkage });
}
@export(__addtf3, .{ .name = "__addtf3", .linkage = common.linkage });
}
pub fn __addtf3(a: f128, b: f128) callconv(.C) f128 {
return addf3(f128, a, b);
}
fn _Qp_add(c: *f128, a: *f128, b: *f128) callconv(.C) void {
c.* = addf3(f128, a.*, b.*);
}

View File

@@ -1,12 +0,0 @@
const common = @import("./common.zig");
const addf3 = @import("./addf3.zig").addf3;
pub const panic = common.panic;
comptime {
@export(__addxf3, .{ .name = "__addxf3", .linkage = common.linkage });
}
pub fn __addxf3(a: f80, b: f80) callconv(.C) f80 {
return addf3(f80, a, b);
}

View File

@@ -1,188 +0,0 @@
// ARM specific builtins
const std = @import("std");
const builtin = @import("builtin");
const arch = builtin.cpu.arch;
const common = @import("common.zig");
pub const panic = common.panic;
comptime {
if (!builtin.is_test) {
if (arch.isARM() or arch.isThumb()) {
@export(__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = common.linkage });
@export(__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = common.linkage });
@export(__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = common.linkage });
@export(__aeabi_ldivmod, .{ .name = "__aeabi_ldivmod", .linkage = common.linkage });
@export(__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = common.linkage });
@export(__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = common.linkage });
@export(__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = common.linkage });
@export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = common.linkage });
@export(__aeabi_memcpy4, .{ .name = "__aeabi_memcpy4", .linkage = common.linkage });
@export(__aeabi_memcpy8, .{ .name = "__aeabi_memcpy8", .linkage = common.linkage });
@export(__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = common.linkage });
@export(__aeabi_memmove4, .{ .name = "__aeabi_memmove4", .linkage = common.linkage });
@export(__aeabi_memmove8, .{ .name = "__aeabi_memmove8", .linkage = common.linkage });
@export(__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = common.linkage });
@export(__aeabi_memset4, .{ .name = "__aeabi_memset4", .linkage = common.linkage });
@export(__aeabi_memset8, .{ .name = "__aeabi_memset8", .linkage = common.linkage });
@export(__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = common.linkage });
@export(__aeabi_memclr4, .{ .name = "__aeabi_memclr4", .linkage = common.linkage });
@export(__aeabi_memclr8, .{ .name = "__aeabi_memclr8", .linkage = common.linkage });
if (builtin.os.tag == .linux) {
@export(__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = common.linkage });
}
}
}
}
const __divmodsi4 = @import("int.zig").__divmodsi4;
const __udivmodsi4 = @import("int.zig").__udivmodsi4;
const __divmoddi4 = @import("int.zig").__divmoddi4;
const __udivmoddi4 = @import("int.zig").__udivmoddi4;
extern fn memset(dest: ?[*]u8, c: u8, n: usize) ?[*]u8;
extern fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) ?[*]u8;
extern fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) ?[*]u8;
pub fn __aeabi_memcpy(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memcpy(dest, src, n);
}
pub fn __aeabi_memcpy4(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memcpy(dest, src, n);
}
pub fn __aeabi_memcpy8(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memcpy(dest, src, n);
}
pub fn __aeabi_memmove(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memmove(dest, src, n);
}
pub fn __aeabi_memmove4(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memmove(dest, src, n);
}
pub fn __aeabi_memmove8(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memmove(dest, src, n);
}
pub fn __aeabi_memset(dest: [*]u8, n: usize, c: u8) callconv(.AAPCS) void {
@setRuntimeSafety(false);
// This is dentical to the standard `memset` definition but with the last
// two arguments swapped
_ = memset(dest, c, n);
}
pub fn __aeabi_memset4(dest: [*]u8, n: usize, c: u8) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memset(dest, c, n);
}
pub fn __aeabi_memset8(dest: [*]u8, n: usize, c: u8) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memset(dest, c, n);
}
pub fn __aeabi_memclr(dest: [*]u8, n: usize) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memset(dest, 0, n);
}
pub fn __aeabi_memclr4(dest: [*]u8, n: usize) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memset(dest, 0, n);
}
pub fn __aeabi_memclr8(dest: [*]u8, n: usize) callconv(.AAPCS) void {
@setRuntimeSafety(false);
_ = memset(dest, 0, n);
}
// Dummy functions to avoid errors during the linking phase
pub fn __aeabi_unwind_cpp_pr0() callconv(.AAPCS) void {}
pub fn __aeabi_unwind_cpp_pr1() callconv(.AAPCS) void {}
pub fn __aeabi_unwind_cpp_pr2() callconv(.AAPCS) void {}
// This function can only clobber r0 according to the ABI
pub fn __aeabi_read_tp() callconv(.Naked) void {
@setRuntimeSafety(false);
asm volatile (
\\ mrc p15, 0, r0, c13, c0, 3
\\ bx lr
);
unreachable;
}
// The following functions are wrapped in an asm block to ensure the required
// calling convention is always respected
pub fn __aeabi_uidivmod() callconv(.Naked) void {
@setRuntimeSafety(false);
// Divide r0 by r1; the quotient goes in r0, the remainder in r1
asm volatile (
\\ push {lr}
\\ sub sp, #4
\\ mov r2, sp
\\ bl __udivmodsi4
\\ ldr r1, [sp]
\\ add sp, #4
\\ pop {pc}
::: "memory");
unreachable;
}
pub fn __aeabi_uldivmod() callconv(.Naked) void {
@setRuntimeSafety(false);
// Divide r1:r0 by r3:r2; the quotient goes in r1:r0, the remainder in r3:r2
asm volatile (
\\ push {r4, lr}
\\ sub sp, #16
\\ add r4, sp, #8
\\ str r4, [sp]
\\ bl __udivmoddi4
\\ ldr r2, [sp, #8]
\\ ldr r3, [sp, #12]
\\ add sp, #16
\\ pop {r4, pc}
::: "memory");
unreachable;
}
pub fn __aeabi_idivmod() callconv(.Naked) void {
@setRuntimeSafety(false);
// Divide r0 by r1; the quotient goes in r0, the remainder in r1
asm volatile (
\\ push {lr}
\\ sub sp, #4
\\ mov r2, sp
\\ bl __divmodsi4
\\ ldr r1, [sp]
\\ add sp, #4
\\ pop {pc}
::: "memory");
unreachable;
}
pub fn __aeabi_ldivmod() callconv(.Naked) void {
@setRuntimeSafety(false);
// Divide r1:r0 by r3:r2; the quotient goes in r1:r0, the remainder in r3:r2
asm volatile (
\\ push {r4, lr}
\\ sub sp, #16
\\ add r4, sp, #8
\\ str r4, [sp]
\\ bl __divmoddi4
\\ ldr r2, [sp, #8]
\\ ldr r3, [sp, #12]
\\ add sp, #16
\\ pop {r4, pc}
::: "memory");
unreachable;
}

View File

@@ -1,32 +0,0 @@
const __ashldi3 = @import("shift.zig").__ashldi3;
const testing = @import("std").testing;
fn test__ashldi3(a: i64, b: i32, expected: u64) !void {
const x = __ashldi3(a, b);
try testing.expectEqual(@bitCast(i64, expected), x);
}
test "ashldi3" {
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
}

View File

@@ -1,46 +0,0 @@
const __ashlti3 = @import("shift.zig").__ashlti3;
const testing = @import("std").testing;
fn test__ashlti3(a: i128, b: i32, expected: i128) !void {
const x = __ashlti3(a, b);
try testing.expectEqual(expected, x);
}
test "ashlti3" {
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642BFDB97530ECA8642A)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C857FB72EA61D950C854)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xEDCBA9876543215FEDCBA98765432150)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x876543215FEDCBA98765432150000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x0ECA8642BFDB97530ECA8642A0000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x1D950C857FB72EA61D950C8540000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x3B2A190AFF6E5D4C3B2A190A80000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x76543215FEDCBA987654321500000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xECA8642BFDB97530ECA8642A00000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xD950C857FB72EA61D950C85400000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xB2A190AFF6E5D4C3B2A190A800000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x6543215FEDCBA9876543215000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x5FEDCBA9876543215000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xBFDB97530ECA8642A000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x7FB72EA61D950C854000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190A8000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFEDCBA98765432150000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642A0000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C8540000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190A80000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xEDCBA987654321500000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x87654321500000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x0ECA8642A00000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x1D950C85400000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x3B2A190A800000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x76543215000000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xECA8642A000000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xD950C854000000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xB2A190A8000000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x65432150000000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x50000000000000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xA0000000000000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x40000000000000000000000000000000)));
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x80000000000000000000000000000000)));
}

View File

@@ -1,55 +0,0 @@
const __ashrdi3 = @import("shift.zig").__ashrdi3;
const testing = @import("std").testing;
fn test__ashrdi3(a: i64, b: i32, expected: u64) !void {
const x = __ashrdi3(a, b);
try testing.expectEqual(@bitCast(i64, expected), x);
}
test "ashrdi3" {
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
}

View File

@@ -1,56 +0,0 @@
const __ashrti3 = @import("shift.zig").__ashrti3;
const testing = @import("std").testing;
fn test__ashrti3(a: i128, b: i32, expected: i128) !void {
const x = __ashrti3(a, b);
try testing.expectEqual(expected, x);
}
test "ashrti3" {
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFFB72EA61D950C857FB72EA61D950C85)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xFFDB97530ECA8642BFDB97530ECA8642)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xFFEDCBA9876543215FEDCBA987654321)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0xFFFFFFFFEDCBA9876543215FEDCBA987)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFB72EA61D950C857FB72EA61)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFDB97530ECA8642BFDB97530)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFB72EA61D950C857FB72EA6)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFDB97530ECA8642BFDB9753)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
}

View File

@@ -1,512 +0,0 @@
const std = @import("std");
const builtin = @import("builtin");
const cpu = builtin.cpu;
const arch = cpu.arch;
const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
pub const panic = @import("common.zig").panic;
// This parameter is true iff the target architecture supports the bare minimum
// to implement the atomic load/store intrinsics.
// Some architectures support atomic load/stores but no CAS, but we ignore this
// detail to keep the export logic clean and because we need some kind of CAS to
// implement the spinlocks.
const supports_atomic_ops = switch (arch) {
.msp430, .avr, .bpfel, .bpfeb => false,
.arm, .armeb, .thumb, .thumbeb =>
// The ARM v6m ISA has no ldrex/strex and so it's impossible to do CAS
// operations (unless we're targeting Linux, the kernel provides a way to
// perform CAS operations).
// XXX: The Linux code path is not implemented yet.
!std.Target.arm.featureSetHas(builtin.cpu.features, .has_v6m),
else => true,
};
// The size (in bytes) of the biggest object that the architecture can
// load/store atomically.
// Objects bigger than this threshold require the use of a lock.
const largest_atomic_size = switch (arch) {
// On SPARC systems that lacks CAS and/or swap instructions, the only
// available atomic operation is a test-and-set (`ldstub`), so we force
// every atomic memory access to go through the lock.
.sparc, .sparcel => if (cpu.features.featureSetHas(.hasleoncasa)) @sizeOf(usize) else 0,
// XXX: On x86/x86_64 we could check the presence of cmpxchg8b/cmpxchg16b
// and set this parameter accordingly.
else => @sizeOf(usize),
};
// The size (in bytes) of the smallest atomic object that the architecture can
// perform fetch/exchange atomically. Note, this does not encompass load and store.
// Objects smaller than this threshold are implemented in terms of compare-exchange
// of a larger value.
const smallest_atomic_fetch_exch_size = switch (arch) {
// On AMDGPU, there are no instructions for atomic operations other than load and store
// (as of LLVM 15), and so these need to be implemented in terms of atomic CAS.
.amdgcn => @sizeOf(u32),
else => @sizeOf(u8),
};
const cache_line_size = 64;
const SpinlockTable = struct {
// Allocate ~4096 bytes of memory for the spinlock table
const max_spinlocks = 64;
const Spinlock = struct {
// SPARC ldstub instruction will write a 255 into the memory location.
// We'll use that as a sign that the lock is currently held.
// See also: Section B.7 in SPARCv8 spec & A.29 in SPARCv9 spec.
const sparc_lock: type = enum(u8) { Unlocked = 0, Locked = 255 };
const other_lock: type = enum(usize) { Unlocked = 0, Locked };
// Prevent false sharing by providing enough padding between two
// consecutive spinlock elements
v: if (arch.isSPARC()) sparc_lock else other_lock align(cache_line_size) = .Unlocked,
fn acquire(self: *@This()) void {
while (true) {
const flag = if (comptime arch.isSPARC()) flag: {
break :flag asm volatile ("ldstub [%[addr]], %[flag]"
: [flag] "=r" (-> @TypeOf(self.v)),
: [addr] "r" (&self.v),
: "memory"
);
} else flag: {
break :flag @atomicRmw(@TypeOf(self.v), &self.v, .Xchg, .Locked, .Acquire);
};
switch (flag) {
.Unlocked => break,
.Locked => {},
}
}
}
fn release(self: *@This()) void {
if (comptime arch.isSPARC()) {
_ = asm volatile ("clrb [%[addr]]"
:
: [addr] "r" (&self.v),
: "memory"
);
} else {
@atomicStore(@TypeOf(self.v), &self.v, .Unlocked, .Release);
}
}
};
list: [max_spinlocks]Spinlock = [_]Spinlock{.{}} ** max_spinlocks,
// The spinlock table behaves as a really simple hash table, mapping
// addresses to spinlocks. The mapping is not unique but that's only a
// performance problem as the lock will be contended by more than a pair of
// threads.
fn get(self: *@This(), address: usize) *Spinlock {
var sl = &self.list[(address >> 3) % max_spinlocks];
sl.acquire();
return sl;
}
};
var spinlocks: SpinlockTable = SpinlockTable{};
// The following builtins do not respect the specified memory model and instead
// uses seq_cst, the strongest one, for simplicity sake.
// Generic version of GCC atomic builtin functions.
// Those work on any object no matter the pointer alignment nor its size.
fn __atomic_load(size: u32, src: [*]u8, dest: [*]u8, model: i32) callconv(.C) void {
_ = model;
var sl = spinlocks.get(@ptrToInt(src));
defer sl.release();
@memcpy(dest, src, size);
}
fn __atomic_store(size: u32, dest: [*]u8, src: [*]u8, model: i32) callconv(.C) void {
_ = model;
var sl = spinlocks.get(@ptrToInt(dest));
defer sl.release();
@memcpy(dest, src, size);
}
fn __atomic_exchange(size: u32, ptr: [*]u8, val: [*]u8, old: [*]u8, model: i32) callconv(.C) void {
_ = model;
var sl = spinlocks.get(@ptrToInt(ptr));
defer sl.release();
@memcpy(old, ptr, size);
@memcpy(ptr, val, size);
}
fn __atomic_compare_exchange(
size: u32,
ptr: [*]u8,
expected: [*]u8,
desired: [*]u8,
success: i32,
failure: i32,
) callconv(.C) i32 {
_ = success;
_ = failure;
var sl = spinlocks.get(@ptrToInt(ptr));
defer sl.release();
for (ptr[0..size]) |b, i| {
if (expected[i] != b) break;
} else {
// The two objects, ptr and expected, are equal
@memcpy(ptr, desired, size);
return 1;
}
@memcpy(expected, ptr, size);
return 0;
}
// Specialized versions of the GCC atomic builtin functions.
// LLVM emits those iff the object size is known and the pointers are correctly
// aligned.
inline fn atomic_load_N(comptime T: type, src: *T, model: i32) T {
_ = model;
if (@sizeOf(T) > largest_atomic_size) {
var sl = spinlocks.get(@ptrToInt(src));
defer sl.release();
return src.*;
} else {
return @atomicLoad(T, src, .SeqCst);
}
}
fn __atomic_load_1(src: *u8, model: i32) callconv(.C) u8 {
return atomic_load_N(u8, src, model);
}
fn __atomic_load_2(src: *u16, model: i32) callconv(.C) u16 {
return atomic_load_N(u16, src, model);
}
fn __atomic_load_4(src: *u32, model: i32) callconv(.C) u32 {
return atomic_load_N(u32, src, model);
}
fn __atomic_load_8(src: *u64, model: i32) callconv(.C) u64 {
return atomic_load_N(u64, src, model);
}
inline fn atomic_store_N(comptime T: type, dst: *T, value: T, model: i32) void {
_ = model;
if (@sizeOf(T) > largest_atomic_size) {
var sl = spinlocks.get(@ptrToInt(dst));
defer sl.release();
dst.* = value;
} else {
@atomicStore(T, dst, value, .SeqCst);
}
}
fn __atomic_store_1(dst: *u8, value: u8, model: i32) callconv(.C) void {
return atomic_store_N(u8, dst, value, model);
}
fn __atomic_store_2(dst: *u16, value: u16, model: i32) callconv(.C) void {
return atomic_store_N(u16, dst, value, model);
}
fn __atomic_store_4(dst: *u32, value: u32, model: i32) callconv(.C) void {
return atomic_store_N(u32, dst, value, model);
}
fn __atomic_store_8(dst: *u64, value: u64, model: i32) callconv(.C) void {
return atomic_store_N(u64, dst, value, model);
}
fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T {
const WideAtomic = std.meta.Int(.unsigned, smallest_atomic_fetch_exch_size * 8);
const addr = @ptrToInt(ptr);
const wide_addr = addr & ~(@as(T, smallest_atomic_fetch_exch_size) - 1);
const wide_ptr = @alignCast(smallest_atomic_fetch_exch_size, @intToPtr(*WideAtomic, wide_addr));
const inner_offset = addr & (@as(T, smallest_atomic_fetch_exch_size) - 1);
const inner_shift = @intCast(std.math.Log2Int(T), inner_offset * 8);
const mask = @as(WideAtomic, std.math.maxInt(T)) << inner_shift;
var wide_old = @atomicLoad(WideAtomic, wide_ptr, .SeqCst);
while (true) {
const old = @truncate(T, (wide_old & mask) >> inner_shift);
const new = update(val, old);
const wide_new = wide_old & ~mask | (@as(WideAtomic, new) << inner_shift);
if (@cmpxchgWeak(WideAtomic, wide_ptr, wide_old, wide_new, .SeqCst, .SeqCst)) |new_wide_old| {
wide_old = new_wide_old;
} else {
return old;
}
}
}
inline fn atomic_exchange_N(comptime T: type, ptr: *T, val: T, model: i32) T {
_ = model;
if (@sizeOf(T) > largest_atomic_size) {
var sl = spinlocks.get(@ptrToInt(ptr));
defer sl.release();
const value = ptr.*;
ptr.* = val;
return value;
} else if (@sizeOf(T) < smallest_atomic_fetch_exch_size) {
// Machine does not support this type, but it does support a larger type.
const Updater = struct {
fn update(new: T, old: T) T {
_ = old;
return new;
}
};
return wideUpdate(T, ptr, val, Updater.update);
} else {
return @atomicRmw(T, ptr, .Xchg, val, .SeqCst);
}
}
fn __atomic_exchange_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
return atomic_exchange_N(u8, ptr, val, model);
}
fn __atomic_exchange_2(ptr: *u16, val: u16, model: i32) callconv(.C) u16 {
return atomic_exchange_N(u16, ptr, val, model);
}
fn __atomic_exchange_4(ptr: *u32, val: u32, model: i32) callconv(.C) u32 {
return atomic_exchange_N(u32, ptr, val, model);
}
fn __atomic_exchange_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
return atomic_exchange_N(u64, ptr, val, model);
}
inline fn atomic_compare_exchange_N(
comptime T: type,
ptr: *T,
expected: *T,
desired: T,
success: i32,
failure: i32,
) i32 {
_ = success;
_ = failure;
if (@sizeOf(T) > largest_atomic_size) {
var sl = spinlocks.get(@ptrToInt(ptr));
defer sl.release();
const value = ptr.*;
if (value == expected.*) {
ptr.* = desired;
return 1;
}
expected.* = value;
return 0;
} else {
if (@cmpxchgStrong(T, ptr, expected.*, desired, .SeqCst, .SeqCst)) |old_value| {
expected.* = old_value;
return 0;
}
return 1;
}
}
fn __atomic_compare_exchange_1(ptr: *u8, expected: *u8, desired: u8, success: i32, failure: i32) callconv(.C) i32 {
return atomic_compare_exchange_N(u8, ptr, expected, desired, success, failure);
}
fn __atomic_compare_exchange_2(ptr: *u16, expected: *u16, desired: u16, success: i32, failure: i32) callconv(.C) i32 {
return atomic_compare_exchange_N(u16, ptr, expected, desired, success, failure);
}
fn __atomic_compare_exchange_4(ptr: *u32, expected: *u32, desired: u32, success: i32, failure: i32) callconv(.C) i32 {
return atomic_compare_exchange_N(u32, ptr, expected, desired, success, failure);
}
fn __atomic_compare_exchange_8(ptr: *u64, expected: *u64, desired: u64, success: i32, failure: i32) callconv(.C) i32 {
return atomic_compare_exchange_N(u64, ptr, expected, desired, success, failure);
}
inline fn fetch_op_N(comptime T: type, comptime op: std.builtin.AtomicRmwOp, ptr: *T, val: T, model: i32) T {
_ = model;
const Updater = struct {
fn update(new: T, old: T) T {
return switch (op) {
.Add => old +% new,
.Sub => old -% new,
.And => old & new,
.Nand => ~(old & new),
.Or => old | new,
.Xor => old ^ new,
else => @compileError("unsupported atomic op"),
};
}
};
if (@sizeOf(T) > largest_atomic_size) {
var sl = spinlocks.get(@ptrToInt(ptr));
defer sl.release();
const value = ptr.*;
ptr.* = Updater.update(val, value);
return value;
} else if (@sizeOf(T) < smallest_atomic_fetch_exch_size) {
// Machine does not support this type, but it does support a larger type.
return wideUpdate(T, ptr, val, Updater.update);
}
return @atomicRmw(T, ptr, op, val, .SeqCst);
}
fn __atomic_fetch_add_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
return fetch_op_N(u8, .Add, ptr, val, model);
}
fn __atomic_fetch_add_2(ptr: *u16, val: u16, model: i32) callconv(.C) u16 {
return fetch_op_N(u16, .Add, ptr, val, model);
}
fn __atomic_fetch_add_4(ptr: *u32, val: u32, model: i32) callconv(.C) u32 {
return fetch_op_N(u32, .Add, ptr, val, model);
}
fn __atomic_fetch_add_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
return fetch_op_N(u64, .Add, ptr, val, model);
}
fn __atomic_fetch_sub_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
return fetch_op_N(u8, .Sub, ptr, val, model);
}
fn __atomic_fetch_sub_2(ptr: *u16, val: u16, model: i32) callconv(.C) u16 {
return fetch_op_N(u16, .Sub, ptr, val, model);
}
fn __atomic_fetch_sub_4(ptr: *u32, val: u32, model: i32) callconv(.C) u32 {
return fetch_op_N(u32, .Sub, ptr, val, model);
}
fn __atomic_fetch_sub_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
return fetch_op_N(u64, .Sub, ptr, val, model);
}
fn __atomic_fetch_and_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
return fetch_op_N(u8, .And, ptr, val, model);
}
fn __atomic_fetch_and_2(ptr: *u16, val: u16, model: i32) callconv(.C) u16 {
return fetch_op_N(u16, .And, ptr, val, model);
}
fn __atomic_fetch_and_4(ptr: *u32, val: u32, model: i32) callconv(.C) u32 {
return fetch_op_N(u32, .And, ptr, val, model);
}
fn __atomic_fetch_and_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
return fetch_op_N(u64, .And, ptr, val, model);
}
fn __atomic_fetch_or_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
return fetch_op_N(u8, .Or, ptr, val, model);
}
fn __atomic_fetch_or_2(ptr: *u16, val: u16, model: i32) callconv(.C) u16 {
return fetch_op_N(u16, .Or, ptr, val, model);
}
fn __atomic_fetch_or_4(ptr: *u32, val: u32, model: i32) callconv(.C) u32 {
return fetch_op_N(u32, .Or, ptr, val, model);
}
fn __atomic_fetch_or_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
return fetch_op_N(u64, .Or, ptr, val, model);
}
fn __atomic_fetch_xor_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
return fetch_op_N(u8, .Xor, ptr, val, model);
}
fn __atomic_fetch_xor_2(ptr: *u16, val: u16, model: i32) callconv(.C) u16 {
return fetch_op_N(u16, .Xor, ptr, val, model);
}
fn __atomic_fetch_xor_4(ptr: *u32, val: u32, model: i32) callconv(.C) u32 {
return fetch_op_N(u32, .Xor, ptr, val, model);
}
fn __atomic_fetch_xor_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
return fetch_op_N(u64, .Xor, ptr, val, model);
}
fn __atomic_fetch_nand_1(ptr: *u8, val: u8, model: i32) callconv(.C) u8 {
return fetch_op_N(u8, .Nand, ptr, val, model);
}
fn __atomic_fetch_nand_2(ptr: *u16, val: u16, model: i32) callconv(.C) u16 {
return fetch_op_N(u16, .Nand, ptr, val, model);
}
fn __atomic_fetch_nand_4(ptr: *u32, val: u32, model: i32) callconv(.C) u32 {
return fetch_op_N(u32, .Nand, ptr, val, model);
}
fn __atomic_fetch_nand_8(ptr: *u64, val: u64, model: i32) callconv(.C) u64 {
return fetch_op_N(u64, .Nand, ptr, val, model);
}
comptime {
if (supports_atomic_ops) {
@export(__atomic_load, .{ .name = "__atomic_load", .linkage = linkage });
@export(__atomic_store, .{ .name = "__atomic_store", .linkage = linkage });
@export(__atomic_exchange, .{ .name = "__atomic_exchange", .linkage = linkage });
@export(__atomic_compare_exchange, .{ .name = "__atomic_compare_exchange", .linkage = linkage });
@export(__atomic_fetch_add_1, .{ .name = "__atomic_fetch_add_1", .linkage = linkage });
@export(__atomic_fetch_add_2, .{ .name = "__atomic_fetch_add_2", .linkage = linkage });
@export(__atomic_fetch_add_4, .{ .name = "__atomic_fetch_add_4", .linkage = linkage });
@export(__atomic_fetch_add_8, .{ .name = "__atomic_fetch_add_8", .linkage = linkage });
@export(__atomic_fetch_sub_1, .{ .name = "__atomic_fetch_sub_1", .linkage = linkage });
@export(__atomic_fetch_sub_2, .{ .name = "__atomic_fetch_sub_2", .linkage = linkage });
@export(__atomic_fetch_sub_4, .{ .name = "__atomic_fetch_sub_4", .linkage = linkage });
@export(__atomic_fetch_sub_8, .{ .name = "__atomic_fetch_sub_8", .linkage = linkage });
@export(__atomic_fetch_and_1, .{ .name = "__atomic_fetch_and_1", .linkage = linkage });
@export(__atomic_fetch_and_2, .{ .name = "__atomic_fetch_and_2", .linkage = linkage });
@export(__atomic_fetch_and_4, .{ .name = "__atomic_fetch_and_4", .linkage = linkage });
@export(__atomic_fetch_and_8, .{ .name = "__atomic_fetch_and_8", .linkage = linkage });
@export(__atomic_fetch_or_1, .{ .name = "__atomic_fetch_or_1", .linkage = linkage });
@export(__atomic_fetch_or_2, .{ .name = "__atomic_fetch_or_2", .linkage = linkage });
@export(__atomic_fetch_or_4, .{ .name = "__atomic_fetch_or_4", .linkage = linkage });
@export(__atomic_fetch_or_8, .{ .name = "__atomic_fetch_or_8", .linkage = linkage });
@export(__atomic_fetch_xor_1, .{ .name = "__atomic_fetch_xor_1", .linkage = linkage });
@export(__atomic_fetch_xor_2, .{ .name = "__atomic_fetch_xor_2", .linkage = linkage });
@export(__atomic_fetch_xor_4, .{ .name = "__atomic_fetch_xor_4", .linkage = linkage });
@export(__atomic_fetch_xor_8, .{ .name = "__atomic_fetch_xor_8", .linkage = linkage });
@export(__atomic_fetch_nand_1, .{ .name = "__atomic_fetch_nand_1", .linkage = linkage });
@export(__atomic_fetch_nand_2, .{ .name = "__atomic_fetch_nand_2", .linkage = linkage });
@export(__atomic_fetch_nand_4, .{ .name = "__atomic_fetch_nand_4", .linkage = linkage });
@export(__atomic_fetch_nand_8, .{ .name = "__atomic_fetch_nand_8", .linkage = linkage });
@export(__atomic_load_1, .{ .name = "__atomic_load_1", .linkage = linkage });
@export(__atomic_load_2, .{ .name = "__atomic_load_2", .linkage = linkage });
@export(__atomic_load_4, .{ .name = "__atomic_load_4", .linkage = linkage });
@export(__atomic_load_8, .{ .name = "__atomic_load_8", .linkage = linkage });
@export(__atomic_store_1, .{ .name = "__atomic_store_1", .linkage = linkage });
@export(__atomic_store_2, .{ .name = "__atomic_store_2", .linkage = linkage });
@export(__atomic_store_4, .{ .name = "__atomic_store_4", .linkage = linkage });
@export(__atomic_store_8, .{ .name = "__atomic_store_8", .linkage = linkage });
@export(__atomic_exchange_1, .{ .name = "__atomic_exchange_1", .linkage = linkage });
@export(__atomic_exchange_2, .{ .name = "__atomic_exchange_2", .linkage = linkage });
@export(__atomic_exchange_4, .{ .name = "__atomic_exchange_4", .linkage = linkage });
@export(__atomic_exchange_8, .{ .name = "__atomic_exchange_8", .linkage = linkage });
@export(__atomic_compare_exchange_1, .{ .name = "__atomic_compare_exchange_1", .linkage = linkage });
@export(__atomic_compare_exchange_2, .{ .name = "__atomic_compare_exchange_2", .linkage = linkage });
@export(__atomic_compare_exchange_4, .{ .name = "__atomic_compare_exchange_4", .linkage = linkage });
@export(__atomic_compare_exchange_8, .{ .name = "__atomic_compare_exchange_8", .linkage = linkage });
}
}

View File

@@ -1,30 +0,0 @@
const std = @import("std");
const common = @import("./common.zig");
comptime {
@export(bcmp, .{ .name = "bcmp", .linkage = common.linkage });
}
pub fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) c_int {
@setRuntimeSafety(false);
var index: usize = 0;
while (index != n) : (index += 1) {
if (vl[index] != vr[index]) {
return 1;
}
}
return 0;
}
test "bcmp" {
const base_arr = &[_]u8{ 1, 1, 1 };
const arr1 = &[_]u8{ 1, 1, 1 };
const arr2 = &[_]u8{ 1, 0, 1 };
const arr3 = &[_]u8{ 1, 2, 1 };
try std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0);
try std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0);
try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0);
}

View File

@@ -1,85 +0,0 @@
const std = @import("std");
const builtin = @import("builtin");
const common = @import("common.zig");
pub const panic = common.panic;
comptime {
@export(__bswapsi2, .{ .name = "__bswapsi2", .linkage = common.linkage });
@export(__bswapdi2, .{ .name = "__bswapdi2", .linkage = common.linkage });
@export(__bswapti2, .{ .name = "__bswapti2", .linkage = common.linkage });
}
// bswap - byteswap
// - bswapXi2 for unoptimized big and little endian
// ie for u32
// DE AD BE EF <- little|big endian
// FE BE AD DE <- big|little endian
// ff 00 00 00 >> 3*8 (leftmost byte)
// 00 ff 00 00 >> 1*8 (2nd left byte)
// 00 00 ff 00 << 1*8 (2n right byte)
// 00 00 00 ff << 3*8 (rightmost byte)
inline fn bswapXi2(comptime T: type, a: T) T {
switch (@bitSizeOf(T)) {
32 => {
// zig fmt: off
return (((a & 0xff000000) >> 24)
| ((a & 0x00ff0000) >> 8 )
| ((a & 0x0000ff00) << 8 )
| ((a & 0x000000ff) << 24));
// zig fmt: on
},
64 => {
// zig fmt: off
return (((a & 0xff00000000000000) >> 56)
| ((a & 0x00ff000000000000) >> 40 )
| ((a & 0x0000ff0000000000) >> 24 )
| ((a & 0x000000ff00000000) >> 8 )
| ((a & 0x00000000ff000000) << 8 )
| ((a & 0x0000000000ff0000) << 24 )
| ((a & 0x000000000000ff00) << 40 )
| ((a & 0x00000000000000ff) << 56));
// zig fmt: on
},
128 => {
// zig fmt: off
return (((a & 0xff000000000000000000000000000000) >> 120)
| ((a & 0x00ff0000000000000000000000000000) >> 104)
| ((a & 0x0000ff00000000000000000000000000) >> 88 )
| ((a & 0x000000ff000000000000000000000000) >> 72 )
| ((a & 0x00000000ff0000000000000000000000) >> 56 )
| ((a & 0x0000000000ff00000000000000000000) >> 40 )
| ((a & 0x000000000000ff000000000000000000) >> 24 )
| ((a & 0x00000000000000ff0000000000000000) >> 8 )
| ((a & 0x0000000000000000ff00000000000000) << 8 )
| ((a & 0x000000000000000000ff000000000000) << 24 )
| ((a & 0x00000000000000000000ff0000000000) << 40 )
| ((a & 0x0000000000000000000000ff00000000) << 56 )
| ((a & 0x000000000000000000000000ff000000) << 72 )
| ((a & 0x00000000000000000000000000ff0000) << 88 )
| ((a & 0x0000000000000000000000000000ff00) << 104)
| ((a & 0x000000000000000000000000000000ff) << 120));
// zig fmt: on
},
else => unreachable,
}
}
pub fn __bswapsi2(a: u32) callconv(.C) u32 {
return bswapXi2(u32, a);
}
pub fn __bswapdi2(a: u64) callconv(.C) u64 {
return bswapXi2(u64, a);
}
pub fn __bswapti2(a: u128) callconv(.C) u128 {
return bswapXi2(u128, a);
}
test {
_ = @import("bswapsi2_test.zig");
_ = @import("bswapdi2_test.zig");
_ = @import("bswapti2_test.zig");
}

View File

@@ -1,21 +0,0 @@
const bswap = @import("bswap.zig");
const testing = @import("std").testing;
fn test__bswapdi2(a: u64, expected: u64) !void {
var result = bswap.__bswapdi2(a);
try testing.expectEqual(expected, result);
}
test "bswapdi2" {
try test__bswapdi2(0x0123456789abcdef, 0xefcdab8967452301); // 0..f
try test__bswapdi2(0xefcdab8967452301, 0x0123456789abcdef);
try test__bswapdi2(0x89abcdef01234567, 0x67452301efcdab89); // 8..f0..7
try test__bswapdi2(0x67452301efcdab89, 0x89abcdef01234567);
try test__bswapdi2(0xdeadbeefdeadbeef, 0xefbeaddeefbeadde); // deadbeefdeadbeef
try test__bswapdi2(0xefbeaddeefbeadde, 0xdeadbeefdeadbeef);
try test__bswapdi2(0xdeadfacedeadface, 0xcefaaddecefaadde); // deadfacedeadface
try test__bswapdi2(0xcefaaddecefaadde, 0xdeadfacedeadface);
try test__bswapdi2(0xaaaaaaaaaaaaaaaa, 0xaaaaaaaaaaaaaaaa); // uninitialized memory
try test__bswapdi2(0x0000000000000000, 0x0000000000000000); // 0s
try test__bswapdi2(0xffffffffffffffff, 0xffffffffffffffff); // fs
}

View File

@@ -1,21 +0,0 @@
const bswap = @import("bswap.zig");
const testing = @import("std").testing;
fn test__bswapsi2(a: u32, expected: u32) !void {
var result = bswap.__bswapsi2(a);
try testing.expectEqual(expected, result);
}
test "bswapsi2" {
try test__bswapsi2(0x01234567, 0x67452301); // 0..7
try test__bswapsi2(0x67452301, 0x01234567);
try test__bswapsi2(0x89abcdef, 0xefcdab89); // 8..f
try test__bswapsi2(0xefcdab89, 0x89abcdef);
try test__bswapsi2(0xdeadbeef, 0xefbeadde); // deadbeef
try test__bswapsi2(0xefbeadde, 0xdeadbeef);
try test__bswapsi2(0xdeadface, 0xcefaadde); // deadface
try test__bswapsi2(0xcefaadde, 0xdeadface);
try test__bswapsi2(0xaaaaaaaa, 0xaaaaaaaa); // uninitialized memory
try test__bswapsi2(0x00000000, 0x00000000); // 0s
try test__bswapsi2(0xffffffff, 0xffffffff); // fs
}

View File

@@ -1,21 +0,0 @@
const bswap = @import("bswap.zig");
const testing = @import("std").testing;
fn test__bswapti2(a: u128, expected: u128) !void {
var result = bswap.__bswapti2(a);
try testing.expectEqual(expected, result);
}
test "bswapti2" {
try test__bswapti2(0x0123456789abcdef0123456789abcdef, 0xefcdab8967452301efcdab8967452301); // 0..f
try test__bswapti2(0xefcdab8967452301efcdab8967452301, 0x0123456789abcdef0123456789abcdef);
try test__bswapti2(0x89abcdef0123456789abcdef01234567, 0x67452301efcdab8967452301efcdab89); // 8..f0..7
try test__bswapti2(0x67452301efcdab8967452301efcdab89, 0x89abcdef0123456789abcdef01234567);
try test__bswapti2(0xdeadbeefdeadbeefdeadbeefdeadbeef, 0xefbeaddeefbeaddeefbeaddeefbeadde); // deadbeefdeadbeef
try test__bswapti2(0xefbeaddeefbeaddeefbeaddeefbeadde, 0xdeadbeefdeadbeefdeadbeefdeadbeef);
try test__bswapti2(0xdeadfacedeadfacedeadfacedeadface, 0xcefaaddecefaaddecefaaddecefaadde); // deadfacedeadface
try test__bswapti2(0xcefaaddecefaaddecefaaddecefaadde, 0xdeadfacedeadfacedeadfacedeadface);
try test__bswapti2(0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); // uninitialized memory
try test__bswapti2(0x00000000000000000000000000000000, 0x00000000000000000000000000000000); // 0s
try test__bswapti2(0xffffffffffffffffffffffffffffffff, 0xffffffffffffffffffffffffffffffff); // fs
}

View File

@@ -1,182 +0,0 @@
//! Ported from musl, which is MIT licensed.
//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//!
//! https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
//! https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c
const std = @import("std");
const builtin = @import("builtin");
const arch = builtin.cpu.arch;
const math = std.math;
const expect = std.testing.expect;
const common = @import("common.zig");
pub const panic = common.panic;
comptime {
@export(__ceilh, .{ .name = "__ceilh", .linkage = common.linkage });
@export(ceilf, .{ .name = "ceilf", .linkage = common.linkage });
@export(ceil, .{ .name = "ceil", .linkage = common.linkage });
@export(__ceilx, .{ .name = "__ceilx", .linkage = common.linkage });
if (common.want_ppc_abi) {
@export(ceilq, .{ .name = "ceilf128", .linkage = common.linkage });
}
@export(ceilq, .{ .name = "ceilq", .linkage = common.linkage });
@export(ceill, .{ .name = "ceill", .linkage = common.linkage });
}
pub fn __ceilh(x: f16) callconv(.C) f16 {
// TODO: more efficient implementation
return @floatCast(f16, ceilf(x));
}
pub fn ceilf(x: f32) callconv(.C) f32 {
var u = @bitCast(u32, x);
var e = @intCast(i32, (u >> 23) & 0xFF) - 0x7F;
var m: u32 = undefined;
// TODO: Shouldn't need this explicit check.
if (x == 0.0) {
return x;
}
if (e >= 23) {
return x;
} else if (e >= 0) {
m = @as(u32, 0x007FFFFF) >> @intCast(u5, e);
if (u & m == 0) {
return x;
}
math.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 31 == 0) {
u += m;
}
u &= ~m;
return @bitCast(f32, u);
} else {
math.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 31 != 0) {
return -0.0;
} else {
return 1.0;
}
}
}
pub fn ceil(x: f64) callconv(.C) f64 {
const f64_toint = 1.0 / math.floatEps(f64);
const u = @bitCast(u64, x);
const e = (u >> 52) & 0x7FF;
var y: f64 = undefined;
if (e >= 0x3FF + 52 or x == 0) {
return x;
}
if (u >> 63 != 0) {
y = x - f64_toint + f64_toint - x;
} else {
y = x + f64_toint - f64_toint - x;
}
if (e <= 0x3FF - 1) {
math.doNotOptimizeAway(y);
if (u >> 63 != 0) {
return -0.0;
} else {
return 1.0;
}
} else if (y < 0) {
return x + y + 1;
} else {
return x + y;
}
}
pub fn __ceilx(x: f80) callconv(.C) f80 {
// TODO: more efficient implementation
return @floatCast(f80, ceilq(x));
}
pub fn ceilq(x: f128) callconv(.C) f128 {
const f128_toint = 1.0 / math.floatEps(f128);
const u = @bitCast(u128, x);
const e = (u >> 112) & 0x7FFF;
var y: f128 = undefined;
if (e >= 0x3FFF + 112 or x == 0) return x;
if (u >> 127 != 0) {
y = x - f128_toint + f128_toint - x;
} else {
y = x + f128_toint - f128_toint - x;
}
if (e <= 0x3FFF - 1) {
math.doNotOptimizeAway(y);
if (u >> 127 != 0) {
return -0.0;
} else {
return 1.0;
}
} else if (y < 0) {
return x + y + 1;
} else {
return x + y;
}
}
pub fn ceill(x: c_longdouble) callconv(.C) c_longdouble {
switch (@typeInfo(c_longdouble).Float.bits) {
16 => return __ceilh(x),
32 => return ceilf(x),
64 => return ceil(x),
80 => return __ceilx(x),
128 => return ceilq(x),
else => @compileError("unreachable"),
}
}
test "ceil32" {
try expect(ceilf(1.3) == 2.0);
try expect(ceilf(-1.3) == -1.0);
try expect(ceilf(0.2) == 1.0);
}
test "ceil64" {
try expect(ceil(1.3) == 2.0);
try expect(ceil(-1.3) == -1.0);
try expect(ceil(0.2) == 1.0);
}
test "ceil128" {
try expect(ceilq(1.3) == 2.0);
try expect(ceilq(-1.3) == -1.0);
try expect(ceilq(0.2) == 1.0);
}
test "ceil32.special" {
try expect(ceilf(0.0) == 0.0);
try expect(ceilf(-0.0) == -0.0);
try expect(math.isPositiveInf(ceilf(math.inf(f32))));
try expect(math.isNegativeInf(ceilf(-math.inf(f32))));
try expect(math.isNan(ceilf(math.nan(f32))));
}
test "ceil64.special" {
try expect(ceil(0.0) == 0.0);
try expect(ceil(-0.0) == -0.0);
try expect(math.isPositiveInf(ceil(math.inf(f64))));
try expect(math.isNegativeInf(ceil(-math.inf(f64))));
try expect(math.isNan(ceil(math.nan(f64))));
}
test "ceil128.special" {
try expect(ceilq(0.0) == 0.0);
try expect(ceilq(-0.0) == -0.0);
try expect(math.isPositiveInf(ceilq(math.inf(f128))));
try expect(math.isNegativeInf(ceilq(-math.inf(f128))));
try expect(math.isNan(ceilq(math.nan(f128))));
}

View File

@@ -1,325 +0,0 @@
const clz = @import("count0bits.zig");
const testing = @import("std").testing;
fn test__clzdi2(a: u64, expected: i64) !void {
var x = @bitCast(i64, a);
var result = clz.__clzdi2(x);
try testing.expectEqual(expected, result);
}
test "clzdi2" {
try test__clzdi2(0x00800000_00000000, 8);
try test__clzdi2(0x01000000_00000000, 7);
try test__clzdi2(0x02000000_00000000, 6);
try test__clzdi2(0x03000000_00000000, 6);
try test__clzdi2(0x04000000_00000000, 5);
try test__clzdi2(0x05000000_00000000, 5);
try test__clzdi2(0x06000000_00000000, 5);
try test__clzdi2(0x07000000_00000000, 5);
try test__clzdi2(0x08000000_00000000, 4);
try test__clzdi2(0x09000000_00000000, 4);
try test__clzdi2(0x0A000000_00000000, 4);
try test__clzdi2(0x0B000000_00000000, 4);
try test__clzdi2(0x0C000000_00000000, 4);
try test__clzdi2(0x0D000000_00000000, 4);
try test__clzdi2(0x0E000000_00000000, 4);
try test__clzdi2(0x0F000000_00000000, 4);
try test__clzdi2(0x10000000_00000000, 3);
try test__clzdi2(0x11000000_00000000, 3);
try test__clzdi2(0x12000000_00000000, 3);
try test__clzdi2(0x13000000_00000000, 3);
try test__clzdi2(0x14000000_00000000, 3);
try test__clzdi2(0x15000000_00000000, 3);
try test__clzdi2(0x16000000_00000000, 3);
try test__clzdi2(0x17000000_00000000, 3);
try test__clzdi2(0x18000000_00000000, 3);
try test__clzdi2(0x19000000_00000000, 3);
try test__clzdi2(0x1A000000_00000000, 3);
try test__clzdi2(0x1B000000_00000000, 3);
try test__clzdi2(0x1C000000_00000000, 3);
try test__clzdi2(0x1D000000_00000000, 3);
try test__clzdi2(0x1E000000_00000000, 3);
try test__clzdi2(0x1F000000_00000000, 3);
try test__clzdi2(0x20000000_00000000, 2);
try test__clzdi2(0x21000000_00000000, 2);
try test__clzdi2(0x22000000_00000000, 2);
try test__clzdi2(0x23000000_00000000, 2);
try test__clzdi2(0x24000000_00000000, 2);
try test__clzdi2(0x25000000_00000000, 2);
try test__clzdi2(0x26000000_00000000, 2);
try test__clzdi2(0x27000000_00000000, 2);
try test__clzdi2(0x28000000_00000000, 2);
try test__clzdi2(0x29000000_00000000, 2);
try test__clzdi2(0x2A000000_00000000, 2);
try test__clzdi2(0x2B000000_00000000, 2);
try test__clzdi2(0x2C000000_00000000, 2);
try test__clzdi2(0x2D000000_00000000, 2);
try test__clzdi2(0x2E000000_00000000, 2);
try test__clzdi2(0x2F000000_00000000, 2);
try test__clzdi2(0x30000000_00000000, 2);
try test__clzdi2(0x31000000_00000000, 2);
try test__clzdi2(0x32000000_00000000, 2);
try test__clzdi2(0x33000000_00000000, 2);
try test__clzdi2(0x34000000_00000000, 2);
try test__clzdi2(0x35000000_00000000, 2);
try test__clzdi2(0x36000000_00000000, 2);
try test__clzdi2(0x37000000_00000000, 2);
try test__clzdi2(0x38000000_00000000, 2);
try test__clzdi2(0x39000000_00000000, 2);
try test__clzdi2(0x3A000000_00000000, 2);
try test__clzdi2(0x3B000000_00000000, 2);
try test__clzdi2(0x3C000000_00000000, 2);
try test__clzdi2(0x3D000000_00000000, 2);
try test__clzdi2(0x3E000000_00000000, 2);
try test__clzdi2(0x3F000000_00000000, 2);
try test__clzdi2(0x40000000_00000000, 1);
try test__clzdi2(0x41000000_00000000, 1);
try test__clzdi2(0x42000000_00000000, 1);
try test__clzdi2(0x43000000_00000000, 1);
try test__clzdi2(0x44000000_00000000, 1);
try test__clzdi2(0x45000000_00000000, 1);
try test__clzdi2(0x46000000_00000000, 1);
try test__clzdi2(0x47000000_00000000, 1);
try test__clzdi2(0x48000000_00000000, 1);
try test__clzdi2(0x49000000_00000000, 1);
try test__clzdi2(0x4A000000_00000000, 1);
try test__clzdi2(0x4B000000_00000000, 1);
try test__clzdi2(0x4C000000_00000000, 1);
try test__clzdi2(0x4D000000_00000000, 1);
try test__clzdi2(0x4E000000_00000000, 1);
try test__clzdi2(0x4F000000_00000000, 1);
try test__clzdi2(0x50000000_00000000, 1);
try test__clzdi2(0x51000000_00000000, 1);
try test__clzdi2(0x52000000_00000000, 1);
try test__clzdi2(0x53000000_00000000, 1);
try test__clzdi2(0x54000000_00000000, 1);
try test__clzdi2(0x55000000_00000000, 1);
try test__clzdi2(0x56000000_00000000, 1);
try test__clzdi2(0x57000000_00000000, 1);
try test__clzdi2(0x58000000_00000000, 1);
try test__clzdi2(0x59000000_00000000, 1);
try test__clzdi2(0x5A000000_00000000, 1);
try test__clzdi2(0x5B000000_00000000, 1);
try test__clzdi2(0x5C000000_00000000, 1);
try test__clzdi2(0x5D000000_00000000, 1);
try test__clzdi2(0x5E000000_00000000, 1);
try test__clzdi2(0x5F000000_00000000, 1);
try test__clzdi2(0x60000000_00000000, 1);
try test__clzdi2(0x61000000_00000000, 1);
try test__clzdi2(0x62000000_00000000, 1);
try test__clzdi2(0x63000000_00000000, 1);
try test__clzdi2(0x64000000_00000000, 1);
try test__clzdi2(0x65000000_00000000, 1);
try test__clzdi2(0x66000000_00000000, 1);
try test__clzdi2(0x67000000_00000000, 1);
try test__clzdi2(0x68000000_00000000, 1);
try test__clzdi2(0x69000000_00000000, 1);
try test__clzdi2(0x6A000000_00000000, 1);
try test__clzdi2(0x6B000000_00000000, 1);
try test__clzdi2(0x6C000000_00000000, 1);
try test__clzdi2(0x6D000000_00000000, 1);
try test__clzdi2(0x6E000000_00000000, 1);
try test__clzdi2(0x6F000000_00000000, 1);
try test__clzdi2(0x70000000_00000000, 1);
try test__clzdi2(0x71000000_00000000, 1);
try test__clzdi2(0x72000000_00000000, 1);
try test__clzdi2(0x73000000_00000000, 1);
try test__clzdi2(0x74000000_00000000, 1);
try test__clzdi2(0x75000000_00000000, 1);
try test__clzdi2(0x76000000_00000000, 1);
try test__clzdi2(0x77000000_00000000, 1);
try test__clzdi2(0x78000000_00000000, 1);
try test__clzdi2(0x79000000_00000000, 1);
try test__clzdi2(0x7A000000_00000000, 1);
try test__clzdi2(0x7B000000_00000000, 1);
try test__clzdi2(0x7C000000_00000000, 1);
try test__clzdi2(0x7D000000_00000000, 1);
try test__clzdi2(0x7E000000_00000000, 1);
try test__clzdi2(0x7F000000_00000000, 1);
try test__clzdi2(0x80000000_00000000, 0);
try test__clzdi2(0x81000000_00000000, 0);
try test__clzdi2(0x82000000_00000000, 0);
try test__clzdi2(0x83000000_00000000, 0);
try test__clzdi2(0x84000000_00000000, 0);
try test__clzdi2(0x85000000_00000000, 0);
try test__clzdi2(0x86000000_00000000, 0);
try test__clzdi2(0x87000000_00000000, 0);
try test__clzdi2(0x88000000_00000000, 0);
try test__clzdi2(0x89000000_00000000, 0);
try test__clzdi2(0x8A000000_00000000, 0);
try test__clzdi2(0x8B000000_00000000, 0);
try test__clzdi2(0x8C000000_00000000, 0);
try test__clzdi2(0x8D000000_00000000, 0);
try test__clzdi2(0x8E000000_00000000, 0);
try test__clzdi2(0x8F000000_00000000, 0);
try test__clzdi2(0x90000000_00000000, 0);
try test__clzdi2(0x91000000_00000000, 0);
try test__clzdi2(0x92000000_00000000, 0);
try test__clzdi2(0x93000000_00000000, 0);
try test__clzdi2(0x94000000_00000000, 0);
try test__clzdi2(0x95000000_00000000, 0);
try test__clzdi2(0x96000000_00000000, 0);
try test__clzdi2(0x97000000_00000000, 0);
try test__clzdi2(0x98000000_00000000, 0);
try test__clzdi2(0x99000000_00000000, 0);
try test__clzdi2(0x9A000000_00000000, 0);
try test__clzdi2(0x9B000000_00000000, 0);
try test__clzdi2(0x9C000000_00000000, 0);
try test__clzdi2(0x9D000000_00000000, 0);
try test__clzdi2(0x9E000000_00000000, 0);
try test__clzdi2(0x9F000000_00000000, 0);
try test__clzdi2(0xA0000000_00000000, 0);
try test__clzdi2(0xA1000000_00000000, 0);
try test__clzdi2(0xA2000000_00000000, 0);
try test__clzdi2(0xA3000000_00000000, 0);
try test__clzdi2(0xA4000000_00000000, 0);
try test__clzdi2(0xA5000000_00000000, 0);
try test__clzdi2(0xA6000000_00000000, 0);
try test__clzdi2(0xA7000000_00000000, 0);
try test__clzdi2(0xA8000000_00000000, 0);
try test__clzdi2(0xA9000000_00000000, 0);
try test__clzdi2(0xAA000000_00000000, 0);
try test__clzdi2(0xAB000000_00000000, 0);
try test__clzdi2(0xAC000000_00000000, 0);
try test__clzdi2(0xAD000000_00000000, 0);
try test__clzdi2(0xAE000000_00000000, 0);
try test__clzdi2(0xAF000000_00000000, 0);
try test__clzdi2(0xB0000000_00000000, 0);
try test__clzdi2(0xB1000000_00000000, 0);
try test__clzdi2(0xB2000000_00000000, 0);
try test__clzdi2(0xB3000000_00000000, 0);
try test__clzdi2(0xB4000000_00000000, 0);
try test__clzdi2(0xB5000000_00000000, 0);
try test__clzdi2(0xB6000000_00000000, 0);
try test__clzdi2(0xB7000000_00000000, 0);
try test__clzdi2(0xB8000000_00000000, 0);
try test__clzdi2(0xB9000000_00000000, 0);
try test__clzdi2(0xBA000000_00000000, 0);
try test__clzdi2(0xBB000000_00000000, 0);
try test__clzdi2(0xBC000000_00000000, 0);
try test__clzdi2(0xBD000000_00000000, 0);
try test__clzdi2(0xBE000000_00000000, 0);
try test__clzdi2(0xBF000000_00000000, 0);
try test__clzdi2(0xC0000000_00000000, 0);
try test__clzdi2(0xC1000000_00000000, 0);
try test__clzdi2(0xC2000000_00000000, 0);
try test__clzdi2(0xC3000000_00000000, 0);
try test__clzdi2(0xC4000000_00000000, 0);
try test__clzdi2(0xC5000000_00000000, 0);
try test__clzdi2(0xC6000000_00000000, 0);
try test__clzdi2(0xC7000000_00000000, 0);
try test__clzdi2(0xC8000000_00000000, 0);
try test__clzdi2(0xC9000000_00000000, 0);
try test__clzdi2(0xCA000000_00000000, 0);
try test__clzdi2(0xCB000000_00000000, 0);
try test__clzdi2(0xCC000000_00000000, 0);
try test__clzdi2(0xCD000000_00000000, 0);
try test__clzdi2(0xCE000000_00000000, 0);
try test__clzdi2(0xCF000000_00000000, 0);
try test__clzdi2(0xD0000000_00000000, 0);
try test__clzdi2(0xD1000000_00000000, 0);
try test__clzdi2(0xD2000000_00000000, 0);
try test__clzdi2(0xD3000000_00000000, 0);
try test__clzdi2(0xD4000000_00000000, 0);
try test__clzdi2(0xD5000000_00000000, 0);
try test__clzdi2(0xD6000000_00000000, 0);
try test__clzdi2(0xD7000000_00000000, 0);
try test__clzdi2(0xD8000000_00000000, 0);
try test__clzdi2(0xD9000000_00000000, 0);
try test__clzdi2(0xDA000000_00000000, 0);
try test__clzdi2(0xDB000000_00000000, 0);
try test__clzdi2(0xDC000000_00000000, 0);
try test__clzdi2(0xDD000000_00000000, 0);
try test__clzdi2(0xDE000000_00000000, 0);
try test__clzdi2(0xDF000000_00000000, 0);
try test__clzdi2(0xE0000000_00000000, 0);
try test__clzdi2(0xE1000000_00000000, 0);
try test__clzdi2(0xE2000000_00000000, 0);
try test__clzdi2(0xE3000000_00000000, 0);
try test__clzdi2(0xE4000000_00000000, 0);
try test__clzdi2(0xE5000000_00000000, 0);
try test__clzdi2(0xE6000000_00000000, 0);
try test__clzdi2(0xE7000000_00000000, 0);
try test__clzdi2(0xE8000000_00000000, 0);
try test__clzdi2(0xE9000000_00000000, 0);
try test__clzdi2(0xEA000000_00000000, 0);
try test__clzdi2(0xEB000000_00000000, 0);
try test__clzdi2(0xEC000000_00000000, 0);
try test__clzdi2(0xED000000_00000000, 0);
try test__clzdi2(0xEE000000_00000000, 0);
try test__clzdi2(0xEF000000_00000000, 0);
try test__clzdi2(0xF0000000_00000000, 0);
try test__clzdi2(0xF1000000_00000000, 0);
try test__clzdi2(0xF2000000_00000000, 0);
try test__clzdi2(0xF3000000_00000000, 0);
try test__clzdi2(0xF4000000_00000000, 0);
try test__clzdi2(0xF5000000_00000000, 0);
try test__clzdi2(0xF6000000_00000000, 0);
try test__clzdi2(0xF7000000_00000000, 0);
try test__clzdi2(0xF8000000_00000000, 0);
try test__clzdi2(0xF9000000_00000000, 0);
try test__clzdi2(0xFA000000_00000000, 0);
try test__clzdi2(0xFB000000_00000000, 0);
try test__clzdi2(0xFC000000_00000000, 0);
try test__clzdi2(0xFD000000_00000000, 0);
try test__clzdi2(0xFE000000_00000000, 0);
try test__clzdi2(0xFF000000_00000000, 0);
try test__clzdi2(0x00000000_00000000, 64);
try test__clzdi2(0x00000000_00000001, 63);
try test__clzdi2(0x00000000_00000002, 62);
try test__clzdi2(0x00000000_00000004, 61);
try test__clzdi2(0x00000000_00000008, 60);
try test__clzdi2(0x00000000_00000010, 59);
try test__clzdi2(0x00000000_00000020, 58);
try test__clzdi2(0x00000000_00000040, 57);
try test__clzdi2(0x00000000_00000080, 56);
try test__clzdi2(0x00000000_00000100, 55);
try test__clzdi2(0x00000000_00000200, 54);
try test__clzdi2(0x00000000_00000400, 53);
try test__clzdi2(0x00000000_00000800, 52);
try test__clzdi2(0x00000000_00001000, 51);
try test__clzdi2(0x00000000_00002000, 50);
try test__clzdi2(0x00000000_00004000, 49);
try test__clzdi2(0x00000000_00008000, 48);
try test__clzdi2(0x00000000_00010000, 47);
try test__clzdi2(0x00000000_00020000, 46);
try test__clzdi2(0x00000000_00040000, 45);
try test__clzdi2(0x00000000_00080000, 44);
try test__clzdi2(0x00000000_00100000, 43);
try test__clzdi2(0x00000000_00200000, 42);
try test__clzdi2(0x00000000_00400000, 41);
try test__clzdi2(0x00000000_00800000, 40);
try test__clzdi2(0x00000000_01000000, 39);
try test__clzdi2(0x00000000_02000000, 38);
try test__clzdi2(0x00000000_04000000, 37);
try test__clzdi2(0x00000000_08000000, 36);
try test__clzdi2(0x00000000_10000000, 35);
try test__clzdi2(0x00000000_20000000, 34);
try test__clzdi2(0x00000000_40000000, 33);
try test__clzdi2(0x00000000_80000000, 32);
try test__clzdi2(0x00000001_00000000, 31);
try test__clzdi2(0x00000002_00000000, 30);
try test__clzdi2(0x00000004_00000000, 29);
try test__clzdi2(0x00000008_00000000, 28);
try test__clzdi2(0x00000010_00000000, 27);
try test__clzdi2(0x00000020_00000000, 26);
try test__clzdi2(0x00000040_00000000, 25);
try test__clzdi2(0x00000080_00000000, 24);
try test__clzdi2(0x00000100_00000000, 23);
try test__clzdi2(0x00000200_00000000, 22);
try test__clzdi2(0x00000400_00000000, 21);
try test__clzdi2(0x00000800_00000000, 20);
try test__clzdi2(0x00001000_00000000, 19);
try test__clzdi2(0x00002000_00000000, 18);
try test__clzdi2(0x00004000_00000000, 17);
try test__clzdi2(0x00008000_00000000, 16);
try test__clzdi2(0x00010000_00000000, 15);
try test__clzdi2(0x00020000_00000000, 14);
try test__clzdi2(0x00040000_00000000, 13);
try test__clzdi2(0x00080000_00000000, 12);
try test__clzdi2(0x00100000_00000000, 11);
try test__clzdi2(0x00200000_00000000, 10);
try test__clzdi2(0x00400000_00000000, 9);
}

View File

@@ -1,308 +0,0 @@
const builtin = @import("builtin");
const clz = @import("count0bits.zig");
const testing = @import("std").testing;
fn test__clzsi2(a: u32, expected: i32) !void {
// stage1 and stage2 diverge on function pointer semantics
switch (builtin.zig_backend) {
.stage1 => {
// Use of `var` here is working around a stage1 bug.
var nakedClzsi2 = clz.__clzsi2;
var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2);
var x = @bitCast(i32, a);
var result = actualClzsi2(x);
try testing.expectEqual(expected, result);
},
else => {
const nakedClzsi2 = clz.__clzsi2;
const actualClzsi2 = @ptrCast(*const fn (a: i32) callconv(.C) i32, &nakedClzsi2);
const x = @bitCast(i32, a);
const result = actualClzsi2(x);
try testing.expectEqual(expected, result);
},
}
}
test "clzsi2" {
try test__clzsi2(0x00800000, 8);
try test__clzsi2(0x01000000, 7);
try test__clzsi2(0x02000000, 6);
try test__clzsi2(0x03000000, 6);
try test__clzsi2(0x04000000, 5);
try test__clzsi2(0x05000000, 5);
try test__clzsi2(0x06000000, 5);
try test__clzsi2(0x07000000, 5);
try test__clzsi2(0x08000000, 4);
try test__clzsi2(0x09000000, 4);
try test__clzsi2(0x0A000000, 4);
try test__clzsi2(0x0B000000, 4);
try test__clzsi2(0x0C000000, 4);
try test__clzsi2(0x0D000000, 4);
try test__clzsi2(0x0E000000, 4);
try test__clzsi2(0x0F000000, 4);
try test__clzsi2(0x10000000, 3);
try test__clzsi2(0x11000000, 3);
try test__clzsi2(0x12000000, 3);
try test__clzsi2(0x13000000, 3);
try test__clzsi2(0x14000000, 3);
try test__clzsi2(0x15000000, 3);
try test__clzsi2(0x16000000, 3);
try test__clzsi2(0x17000000, 3);
try test__clzsi2(0x18000000, 3);
try test__clzsi2(0x19000000, 3);
try test__clzsi2(0x1A000000, 3);
try test__clzsi2(0x1B000000, 3);
try test__clzsi2(0x1C000000, 3);
try test__clzsi2(0x1D000000, 3);
try test__clzsi2(0x1E000000, 3);
try test__clzsi2(0x1F000000, 3);
try test__clzsi2(0x20000000, 2);
try test__clzsi2(0x21000000, 2);
try test__clzsi2(0x22000000, 2);
try test__clzsi2(0x23000000, 2);
try test__clzsi2(0x24000000, 2);
try test__clzsi2(0x25000000, 2);
try test__clzsi2(0x26000000, 2);
try test__clzsi2(0x27000000, 2);
try test__clzsi2(0x28000000, 2);
try test__clzsi2(0x29000000, 2);
try test__clzsi2(0x2A000000, 2);
try test__clzsi2(0x2B000000, 2);
try test__clzsi2(0x2C000000, 2);
try test__clzsi2(0x2D000000, 2);
try test__clzsi2(0x2E000000, 2);
try test__clzsi2(0x2F000000, 2);
try test__clzsi2(0x30000000, 2);
try test__clzsi2(0x31000000, 2);
try test__clzsi2(0x32000000, 2);
try test__clzsi2(0x33000000, 2);
try test__clzsi2(0x34000000, 2);
try test__clzsi2(0x35000000, 2);
try test__clzsi2(0x36000000, 2);
try test__clzsi2(0x37000000, 2);
try test__clzsi2(0x38000000, 2);
try test__clzsi2(0x39000000, 2);
try test__clzsi2(0x3A000000, 2);
try test__clzsi2(0x3B000000, 2);
try test__clzsi2(0x3C000000, 2);
try test__clzsi2(0x3D000000, 2);
try test__clzsi2(0x3E000000, 2);
try test__clzsi2(0x3F000000, 2);
try test__clzsi2(0x40000000, 1);
try test__clzsi2(0x41000000, 1);
try test__clzsi2(0x42000000, 1);
try test__clzsi2(0x43000000, 1);
try test__clzsi2(0x44000000, 1);
try test__clzsi2(0x45000000, 1);
try test__clzsi2(0x46000000, 1);
try test__clzsi2(0x47000000, 1);
try test__clzsi2(0x48000000, 1);
try test__clzsi2(0x49000000, 1);
try test__clzsi2(0x4A000000, 1);
try test__clzsi2(0x4B000000, 1);
try test__clzsi2(0x4C000000, 1);
try test__clzsi2(0x4D000000, 1);
try test__clzsi2(0x4E000000, 1);
try test__clzsi2(0x4F000000, 1);
try test__clzsi2(0x50000000, 1);
try test__clzsi2(0x51000000, 1);
try test__clzsi2(0x52000000, 1);
try test__clzsi2(0x53000000, 1);
try test__clzsi2(0x54000000, 1);
try test__clzsi2(0x55000000, 1);
try test__clzsi2(0x56000000, 1);
try test__clzsi2(0x57000000, 1);
try test__clzsi2(0x58000000, 1);
try test__clzsi2(0x59000000, 1);
try test__clzsi2(0x5A000000, 1);
try test__clzsi2(0x5B000000, 1);
try test__clzsi2(0x5C000000, 1);
try test__clzsi2(0x5D000000, 1);
try test__clzsi2(0x5E000000, 1);
try test__clzsi2(0x5F000000, 1);
try test__clzsi2(0x60000000, 1);
try test__clzsi2(0x61000000, 1);
try test__clzsi2(0x62000000, 1);
try test__clzsi2(0x63000000, 1);
try test__clzsi2(0x64000000, 1);
try test__clzsi2(0x65000000, 1);
try test__clzsi2(0x66000000, 1);
try test__clzsi2(0x67000000, 1);
try test__clzsi2(0x68000000, 1);
try test__clzsi2(0x69000000, 1);
try test__clzsi2(0x6A000000, 1);
try test__clzsi2(0x6B000000, 1);
try test__clzsi2(0x6C000000, 1);
try test__clzsi2(0x6D000000, 1);
try test__clzsi2(0x6E000000, 1);
try test__clzsi2(0x6F000000, 1);
try test__clzsi2(0x70000000, 1);
try test__clzsi2(0x71000000, 1);
try test__clzsi2(0x72000000, 1);
try test__clzsi2(0x73000000, 1);
try test__clzsi2(0x74000000, 1);
try test__clzsi2(0x75000000, 1);
try test__clzsi2(0x76000000, 1);
try test__clzsi2(0x77000000, 1);
try test__clzsi2(0x78000000, 1);
try test__clzsi2(0x79000000, 1);
try test__clzsi2(0x7A000000, 1);
try test__clzsi2(0x7B000000, 1);
try test__clzsi2(0x7C000000, 1);
try test__clzsi2(0x7D000000, 1);
try test__clzsi2(0x7E000000, 1);
try test__clzsi2(0x7F000000, 1);
try test__clzsi2(0x80000000, 0);
try test__clzsi2(0x81000000, 0);
try test__clzsi2(0x82000000, 0);
try test__clzsi2(0x83000000, 0);
try test__clzsi2(0x84000000, 0);
try test__clzsi2(0x85000000, 0);
try test__clzsi2(0x86000000, 0);
try test__clzsi2(0x87000000, 0);
try test__clzsi2(0x88000000, 0);
try test__clzsi2(0x89000000, 0);
try test__clzsi2(0x8A000000, 0);
try test__clzsi2(0x8B000000, 0);
try test__clzsi2(0x8C000000, 0);
try test__clzsi2(0x8D000000, 0);
try test__clzsi2(0x8E000000, 0);
try test__clzsi2(0x8F000000, 0);
try test__clzsi2(0x90000000, 0);
try test__clzsi2(0x91000000, 0);
try test__clzsi2(0x92000000, 0);
try test__clzsi2(0x93000000, 0);
try test__clzsi2(0x94000000, 0);
try test__clzsi2(0x95000000, 0);
try test__clzsi2(0x96000000, 0);
try test__clzsi2(0x97000000, 0);
try test__clzsi2(0x98000000, 0);
try test__clzsi2(0x99000000, 0);
try test__clzsi2(0x9A000000, 0);
try test__clzsi2(0x9B000000, 0);
try test__clzsi2(0x9C000000, 0);
try test__clzsi2(0x9D000000, 0);
try test__clzsi2(0x9E000000, 0);
try test__clzsi2(0x9F000000, 0);
try test__clzsi2(0xA0000000, 0);
try test__clzsi2(0xA1000000, 0);
try test__clzsi2(0xA2000000, 0);
try test__clzsi2(0xA3000000, 0);
try test__clzsi2(0xA4000000, 0);
try test__clzsi2(0xA5000000, 0);
try test__clzsi2(0xA6000000, 0);
try test__clzsi2(0xA7000000, 0);
try test__clzsi2(0xA8000000, 0);
try test__clzsi2(0xA9000000, 0);
try test__clzsi2(0xAA000000, 0);
try test__clzsi2(0xAB000000, 0);
try test__clzsi2(0xAC000000, 0);
try test__clzsi2(0xAD000000, 0);
try test__clzsi2(0xAE000000, 0);
try test__clzsi2(0xAF000000, 0);
try test__clzsi2(0xB0000000, 0);
try test__clzsi2(0xB1000000, 0);
try test__clzsi2(0xB2000000, 0);
try test__clzsi2(0xB3000000, 0);
try test__clzsi2(0xB4000000, 0);
try test__clzsi2(0xB5000000, 0);
try test__clzsi2(0xB6000000, 0);
try test__clzsi2(0xB7000000, 0);
try test__clzsi2(0xB8000000, 0);
try test__clzsi2(0xB9000000, 0);
try test__clzsi2(0xBA000000, 0);
try test__clzsi2(0xBB000000, 0);
try test__clzsi2(0xBC000000, 0);
try test__clzsi2(0xBD000000, 0);
try test__clzsi2(0xBE000000, 0);
try test__clzsi2(0xBF000000, 0);
try test__clzsi2(0xC0000000, 0);
try test__clzsi2(0xC1000000, 0);
try test__clzsi2(0xC2000000, 0);
try test__clzsi2(0xC3000000, 0);
try test__clzsi2(0xC4000000, 0);
try test__clzsi2(0xC5000000, 0);
try test__clzsi2(0xC6000000, 0);
try test__clzsi2(0xC7000000, 0);
try test__clzsi2(0xC8000000, 0);
try test__clzsi2(0xC9000000, 0);
try test__clzsi2(0xCA000000, 0);
try test__clzsi2(0xCB000000, 0);
try test__clzsi2(0xCC000000, 0);
try test__clzsi2(0xCD000000, 0);
try test__clzsi2(0xCE000000, 0);
try test__clzsi2(0xCF000000, 0);
try test__clzsi2(0xD0000000, 0);
try test__clzsi2(0xD1000000, 0);
try test__clzsi2(0xD2000000, 0);
try test__clzsi2(0xD3000000, 0);
try test__clzsi2(0xD4000000, 0);
try test__clzsi2(0xD5000000, 0);
try test__clzsi2(0xD6000000, 0);
try test__clzsi2(0xD7000000, 0);
try test__clzsi2(0xD8000000, 0);
try test__clzsi2(0xD9000000, 0);
try test__clzsi2(0xDA000000, 0);
try test__clzsi2(0xDB000000, 0);
try test__clzsi2(0xDC000000, 0);
try test__clzsi2(0xDD000000, 0);
try test__clzsi2(0xDE000000, 0);
try test__clzsi2(0xDF000000, 0);
try test__clzsi2(0xE0000000, 0);
try test__clzsi2(0xE1000000, 0);
try test__clzsi2(0xE2000000, 0);
try test__clzsi2(0xE3000000, 0);
try test__clzsi2(0xE4000000, 0);
try test__clzsi2(0xE5000000, 0);
try test__clzsi2(0xE6000000, 0);
try test__clzsi2(0xE7000000, 0);
try test__clzsi2(0xE8000000, 0);
try test__clzsi2(0xE9000000, 0);
try test__clzsi2(0xEA000000, 0);
try test__clzsi2(0xEB000000, 0);
try test__clzsi2(0xEC000000, 0);
try test__clzsi2(0xED000000, 0);
try test__clzsi2(0xEE000000, 0);
try test__clzsi2(0xEF000000, 0);
try test__clzsi2(0xF0000000, 0);
try test__clzsi2(0xF1000000, 0);
try test__clzsi2(0xF2000000, 0);
try test__clzsi2(0xF3000000, 0);
try test__clzsi2(0xF4000000, 0);
try test__clzsi2(0xF5000000, 0);
try test__clzsi2(0xF6000000, 0);
try test__clzsi2(0xF7000000, 0);
try test__clzsi2(0xF8000000, 0);
try test__clzsi2(0xF9000000, 0);
try test__clzsi2(0xFA000000, 0);
try test__clzsi2(0xFB000000, 0);
try test__clzsi2(0xFC000000, 0);
try test__clzsi2(0xFD000000, 0);
try test__clzsi2(0xFE000000, 0);
try test__clzsi2(0xFF000000, 0);
// arm and thumb1 assume input a != 0
//try test__clzsi2(0x00000000, 32);
try test__clzsi2(0x00000001, 31);
try test__clzsi2(0x00000002, 30);
try test__clzsi2(0x00000004, 29);
try test__clzsi2(0x00000008, 28);
try test__clzsi2(0x00000010, 27);
try test__clzsi2(0x00000020, 26);
try test__clzsi2(0x00000040, 25);
try test__clzsi2(0x00000080, 24);
try test__clzsi2(0x00000100, 23);
try test__clzsi2(0x00000200, 22);
try test__clzsi2(0x00000400, 21);
try test__clzsi2(0x00000800, 20);
try test__clzsi2(0x00001000, 19);
try test__clzsi2(0x00002000, 18);
try test__clzsi2(0x00004000, 17);
try test__clzsi2(0x00008000, 16);
try test__clzsi2(0x00010000, 15);
try test__clzsi2(0x00020000, 14);
try test__clzsi2(0x00040000, 13);
try test__clzsi2(0x00080000, 12);
try test__clzsi2(0x00100000, 11);
try test__clzsi2(0x00200000, 10);
try test__clzsi2(0x00400000, 9);
}

View File

@@ -1,391 +0,0 @@
const clz = @import("count0bits.zig");
const testing = @import("std").testing;
fn test__clzti2(a: u128, expected: i64) !void {
var x = @bitCast(i128, a);
var result = clz.__clzti2(x);
try testing.expectEqual(expected, result);
}
test "clzti2" {
try test__clzti2(0x00800000_00000000_00000000_00000000, 8);
try test__clzti2(0x01000000_00000000_00000000_00000000, 7);
try test__clzti2(0x02000000_00000000_00000000_00000000, 6);
try test__clzti2(0x03000000_00000000_00000000_00000000, 6);
try test__clzti2(0x04000000_00000000_00000000_00000000, 5);
try test__clzti2(0x05000000_00000000_00000000_00000000, 5);
try test__clzti2(0x06000000_00000000_00000000_00000000, 5);
try test__clzti2(0x07000000_00000000_00000000_00000000, 5);
try test__clzti2(0x08000000_00000000_00000000_00000000, 4);
try test__clzti2(0x09000000_00000000_00000000_00000000, 4);
try test__clzti2(0x0A000000_00000000_00000000_00000000, 4);
try test__clzti2(0x0B000000_00000000_00000000_00000000, 4);
try test__clzti2(0x0C000000_00000000_00000000_00000000, 4);
try test__clzti2(0x0D000000_00000000_00000000_00000000, 4);
try test__clzti2(0x0E000000_00000000_00000000_00000000, 4);
try test__clzti2(0x0F000000_00000000_00000000_00000000, 4);
try test__clzti2(0x10000000_00000000_00000000_00000000, 3);
try test__clzti2(0x11000000_00000000_00000000_00000000, 3);
try test__clzti2(0x12000000_00000000_00000000_00000000, 3);
try test__clzti2(0x13000000_00000000_00000000_00000000, 3);
try test__clzti2(0x14000000_00000000_00000000_00000000, 3);
try test__clzti2(0x15000000_00000000_00000000_00000000, 3);
try test__clzti2(0x16000000_00000000_00000000_00000000, 3);
try test__clzti2(0x17000000_00000000_00000000_00000000, 3);
try test__clzti2(0x18000000_00000000_00000000_00000000, 3);
try test__clzti2(0x19000000_00000000_00000000_00000000, 3);
try test__clzti2(0x1A000000_00000000_00000000_00000000, 3);
try test__clzti2(0x1B000000_00000000_00000000_00000000, 3);
try test__clzti2(0x1C000000_00000000_00000000_00000000, 3);
try test__clzti2(0x1D000000_00000000_00000000_00000000, 3);
try test__clzti2(0x1E000000_00000000_00000000_00000000, 3);
try test__clzti2(0x1F000000_00000000_00000000_00000000, 3);
try test__clzti2(0x20000000_00000000_00000000_00000000, 2);
try test__clzti2(0x21000000_00000000_00000000_00000000, 2);
try test__clzti2(0x22000000_00000000_00000000_00000000, 2);
try test__clzti2(0x23000000_00000000_00000000_00000000, 2);
try test__clzti2(0x24000000_00000000_00000000_00000000, 2);
try test__clzti2(0x25000000_00000000_00000000_00000000, 2);
try test__clzti2(0x26000000_00000000_00000000_00000000, 2);
try test__clzti2(0x27000000_00000000_00000000_00000000, 2);
try test__clzti2(0x28000000_00000000_00000000_00000000, 2);
try test__clzti2(0x29000000_00000000_00000000_00000000, 2);
try test__clzti2(0x2A000000_00000000_00000000_00000000, 2);
try test__clzti2(0x2B000000_00000000_00000000_00000000, 2);
try test__clzti2(0x2C000000_00000000_00000000_00000000, 2);
try test__clzti2(0x2D000000_00000000_00000000_00000000, 2);
try test__clzti2(0x2E000000_00000000_00000000_00000000, 2);
try test__clzti2(0x2F000000_00000000_00000000_00000000, 2);
try test__clzti2(0x30000000_00000000_00000000_00000000, 2);
try test__clzti2(0x31000000_00000000_00000000_00000000, 2);
try test__clzti2(0x32000000_00000000_00000000_00000000, 2);
try test__clzti2(0x33000000_00000000_00000000_00000000, 2);
try test__clzti2(0x34000000_00000000_00000000_00000000, 2);
try test__clzti2(0x35000000_00000000_00000000_00000000, 2);
try test__clzti2(0x36000000_00000000_00000000_00000000, 2);
try test__clzti2(0x37000000_00000000_00000000_00000000, 2);
try test__clzti2(0x38000000_00000000_00000000_00000000, 2);
try test__clzti2(0x39000000_00000000_00000000_00000000, 2);
try test__clzti2(0x3A000000_00000000_00000000_00000000, 2);
try test__clzti2(0x3B000000_00000000_00000000_00000000, 2);
try test__clzti2(0x3C000000_00000000_00000000_00000000, 2);
try test__clzti2(0x3D000000_00000000_00000000_00000000, 2);
try test__clzti2(0x3E000000_00000000_00000000_00000000, 2);
try test__clzti2(0x3F000000_00000000_00000000_00000000, 2);
try test__clzti2(0x40000000_00000000_00000000_00000000, 1);
try test__clzti2(0x41000000_00000000_00000000_00000000, 1);
try test__clzti2(0x42000000_00000000_00000000_00000000, 1);
try test__clzti2(0x43000000_00000000_00000000_00000000, 1);
try test__clzti2(0x44000000_00000000_00000000_00000000, 1);
try test__clzti2(0x45000000_00000000_00000000_00000000, 1);
try test__clzti2(0x46000000_00000000_00000000_00000000, 1);
try test__clzti2(0x47000000_00000000_00000000_00000000, 1);
try test__clzti2(0x48000000_00000000_00000000_00000000, 1);
try test__clzti2(0x49000000_00000000_00000000_00000000, 1);
try test__clzti2(0x4A000000_00000000_00000000_00000000, 1);
try test__clzti2(0x4B000000_00000000_00000000_00000000, 1);
try test__clzti2(0x4C000000_00000000_00000000_00000000, 1);
try test__clzti2(0x4D000000_00000000_00000000_00000000, 1);
try test__clzti2(0x4E000000_00000000_00000000_00000000, 1);
try test__clzti2(0x4F000000_00000000_00000000_00000000, 1);
try test__clzti2(0x50000000_00000000_00000000_00000000, 1);
try test__clzti2(0x51000000_00000000_00000000_00000000, 1);
try test__clzti2(0x52000000_00000000_00000000_00000000, 1);
try test__clzti2(0x53000000_00000000_00000000_00000000, 1);
try test__clzti2(0x54000000_00000000_00000000_00000000, 1);
try test__clzti2(0x55000000_00000000_00000000_00000000, 1);
try test__clzti2(0x56000000_00000000_00000000_00000000, 1);
try test__clzti2(0x57000000_00000000_00000000_00000000, 1);
try test__clzti2(0x58000000_00000000_00000000_00000000, 1);
try test__clzti2(0x59000000_00000000_00000000_00000000, 1);
try test__clzti2(0x5A000000_00000000_00000000_00000000, 1);
try test__clzti2(0x5B000000_00000000_00000000_00000000, 1);
try test__clzti2(0x5C000000_00000000_00000000_00000000, 1);
try test__clzti2(0x5D000000_00000000_00000000_00000000, 1);
try test__clzti2(0x5E000000_00000000_00000000_00000000, 1);
try test__clzti2(0x5F000000_00000000_00000000_00000000, 1);
try test__clzti2(0x60000000_00000000_00000000_00000000, 1);
try test__clzti2(0x61000000_00000000_00000000_00000000, 1);
try test__clzti2(0x62000000_00000000_00000000_00000000, 1);
try test__clzti2(0x63000000_00000000_00000000_00000000, 1);
try test__clzti2(0x64000000_00000000_00000000_00000000, 1);
try test__clzti2(0x65000000_00000000_00000000_00000000, 1);
try test__clzti2(0x66000000_00000000_00000000_00000000, 1);
try test__clzti2(0x67000000_00000000_00000000_00000000, 1);
try test__clzti2(0x68000000_00000000_00000000_00000000, 1);
try test__clzti2(0x69000000_00000000_00000000_00000000, 1);
try test__clzti2(0x6A000000_00000000_00000000_00000000, 1);
try test__clzti2(0x6B000000_00000000_00000000_00000000, 1);
try test__clzti2(0x6C000000_00000000_00000000_00000000, 1);
try test__clzti2(0x6D000000_00000000_00000000_00000000, 1);
try test__clzti2(0x6E000000_00000000_00000000_00000000, 1);
try test__clzti2(0x6F000000_00000000_00000000_00000000, 1);
try test__clzti2(0x70000000_00000000_00000000_00000000, 1);
try test__clzti2(0x71000000_00000000_00000000_00000000, 1);
try test__clzti2(0x72000000_00000000_00000000_00000000, 1);
try test__clzti2(0x73000000_00000000_00000000_00000000, 1);
try test__clzti2(0x74000000_00000000_00000000_00000000, 1);
try test__clzti2(0x75000000_00000000_00000000_00000000, 1);
try test__clzti2(0x76000000_00000000_00000000_00000000, 1);
try test__clzti2(0x77000000_00000000_00000000_00000000, 1);
try test__clzti2(0x78000000_00000000_00000000_00000000, 1);
try test__clzti2(0x79000000_00000000_00000000_00000000, 1);
try test__clzti2(0x7A000000_00000000_00000000_00000000, 1);
try test__clzti2(0x7B000000_00000000_00000000_00000000, 1);
try test__clzti2(0x7C000000_00000000_00000000_00000000, 1);
try test__clzti2(0x7D000000_00000000_00000000_00000000, 1);
try test__clzti2(0x7E000000_00000000_00000000_00000000, 1);
try test__clzti2(0x7F000000_00000000_00000000_00000000, 1);
try test__clzti2(0x80000000_00000000_00000000_00000000, 0);
try test__clzti2(0x81000000_00000000_00000000_00000000, 0);
try test__clzti2(0x82000000_00000000_00000000_00000000, 0);
try test__clzti2(0x83000000_00000000_00000000_00000000, 0);
try test__clzti2(0x84000000_00000000_00000000_00000000, 0);
try test__clzti2(0x85000000_00000000_00000000_00000000, 0);
try test__clzti2(0x86000000_00000000_00000000_00000000, 0);
try test__clzti2(0x87000000_00000000_00000000_00000000, 0);
try test__clzti2(0x88000000_00000000_00000000_00000000, 0);
try test__clzti2(0x89000000_00000000_00000000_00000000, 0);
try test__clzti2(0x8A000000_00000000_00000000_00000000, 0);
try test__clzti2(0x8B000000_00000000_00000000_00000000, 0);
try test__clzti2(0x8C000000_00000000_00000000_00000000, 0);
try test__clzti2(0x8D000000_00000000_00000000_00000000, 0);
try test__clzti2(0x8E000000_00000000_00000000_00000000, 0);
try test__clzti2(0x8F000000_00000000_00000000_00000000, 0);
try test__clzti2(0x90000000_00000000_00000000_00000000, 0);
try test__clzti2(0x91000000_00000000_00000000_00000000, 0);
try test__clzti2(0x92000000_00000000_00000000_00000000, 0);
try test__clzti2(0x93000000_00000000_00000000_00000000, 0);
try test__clzti2(0x94000000_00000000_00000000_00000000, 0);
try test__clzti2(0x95000000_00000000_00000000_00000000, 0);
try test__clzti2(0x96000000_00000000_00000000_00000000, 0);
try test__clzti2(0x97000000_00000000_00000000_00000000, 0);
try test__clzti2(0x98000000_00000000_00000000_00000000, 0);
try test__clzti2(0x99000000_00000000_00000000_00000000, 0);
try test__clzti2(0x9A000000_00000000_00000000_00000000, 0);
try test__clzti2(0x9B000000_00000000_00000000_00000000, 0);
try test__clzti2(0x9C000000_00000000_00000000_00000000, 0);
try test__clzti2(0x9D000000_00000000_00000000_00000000, 0);
try test__clzti2(0x9E000000_00000000_00000000_00000000, 0);
try test__clzti2(0x9F000000_00000000_00000000_00000000, 0);
try test__clzti2(0xA0000000_00000000_00000000_00000000, 0);
try test__clzti2(0xA1000000_00000000_00000000_00000000, 0);
try test__clzti2(0xA2000000_00000000_00000000_00000000, 0);
try test__clzti2(0xA3000000_00000000_00000000_00000000, 0);
try test__clzti2(0xA4000000_00000000_00000000_00000000, 0);
try test__clzti2(0xA5000000_00000000_00000000_00000000, 0);
try test__clzti2(0xA6000000_00000000_00000000_00000000, 0);
try test__clzti2(0xA7000000_00000000_00000000_00000000, 0);
try test__clzti2(0xA8000000_00000000_00000000_00000000, 0);
try test__clzti2(0xA9000000_00000000_00000000_00000000, 0);
try test__clzti2(0xAA000000_00000000_00000000_00000000, 0);
try test__clzti2(0xAB000000_00000000_00000000_00000000, 0);
try test__clzti2(0xAC000000_00000000_00000000_00000000, 0);
try test__clzti2(0xAD000000_00000000_00000000_00000000, 0);
try test__clzti2(0xAE000000_00000000_00000000_00000000, 0);
try test__clzti2(0xAF000000_00000000_00000000_00000000, 0);
try test__clzti2(0xB0000000_00000000_00000000_00000000, 0);
try test__clzti2(0xB1000000_00000000_00000000_00000000, 0);
try test__clzti2(0xB2000000_00000000_00000000_00000000, 0);
try test__clzti2(0xB3000000_00000000_00000000_00000000, 0);
try test__clzti2(0xB4000000_00000000_00000000_00000000, 0);
try test__clzti2(0xB5000000_00000000_00000000_00000000, 0);
try test__clzti2(0xB6000000_00000000_00000000_00000000, 0);
try test__clzti2(0xB7000000_00000000_00000000_00000000, 0);
try test__clzti2(0xB8000000_00000000_00000000_00000000, 0);
try test__clzti2(0xB9000000_00000000_00000000_00000000, 0);
try test__clzti2(0xBA000000_00000000_00000000_00000000, 0);
try test__clzti2(0xBB000000_00000000_00000000_00000000, 0);
try test__clzti2(0xBC000000_00000000_00000000_00000000, 0);
try test__clzti2(0xBD000000_00000000_00000000_00000000, 0);
try test__clzti2(0xBE000000_00000000_00000000_00000000, 0);
try test__clzti2(0xBF000000_00000000_00000000_00000000, 0);
try test__clzti2(0xC0000000_00000000_00000000_00000000, 0);
try test__clzti2(0xC1000000_00000000_00000000_00000000, 0);
try test__clzti2(0xC2000000_00000000_00000000_00000000, 0);
try test__clzti2(0xC3000000_00000000_00000000_00000000, 0);
try test__clzti2(0xC4000000_00000000_00000000_00000000, 0);
try test__clzti2(0xC5000000_00000000_00000000_00000000, 0);
try test__clzti2(0xC6000000_00000000_00000000_00000000, 0);
try test__clzti2(0xC7000000_00000000_00000000_00000000, 0);
try test__clzti2(0xC8000000_00000000_00000000_00000000, 0);
try test__clzti2(0xC9000000_00000000_00000000_00000000, 0);
try test__clzti2(0xCA000000_00000000_00000000_00000000, 0);
try test__clzti2(0xCB000000_00000000_00000000_00000000, 0);
try test__clzti2(0xCC000000_00000000_00000000_00000000, 0);
try test__clzti2(0xCD000000_00000000_00000000_00000000, 0);
try test__clzti2(0xCE000000_00000000_00000000_00000000, 0);
try test__clzti2(0xCF000000_00000000_00000000_00000000, 0);
try test__clzti2(0xD0000000_00000000_00000000_00000000, 0);
try test__clzti2(0xD1000000_00000000_00000000_00000000, 0);
try test__clzti2(0xD2000000_00000000_00000000_00000000, 0);
try test__clzti2(0xD3000000_00000000_00000000_00000000, 0);
try test__clzti2(0xD4000000_00000000_00000000_00000000, 0);
try test__clzti2(0xD5000000_00000000_00000000_00000000, 0);
try test__clzti2(0xD6000000_00000000_00000000_00000000, 0);
try test__clzti2(0xD7000000_00000000_00000000_00000000, 0);
try test__clzti2(0xD8000000_00000000_00000000_00000000, 0);
try test__clzti2(0xD9000000_00000000_00000000_00000000, 0);
try test__clzti2(0xDA000000_00000000_00000000_00000000, 0);
try test__clzti2(0xDB000000_00000000_00000000_00000000, 0);
try test__clzti2(0xDC000000_00000000_00000000_00000000, 0);
try test__clzti2(0xDD000000_00000000_00000000_00000000, 0);
try test__clzti2(0xDE000000_00000000_00000000_00000000, 0);
try test__clzti2(0xDF000000_00000000_00000000_00000000, 0);
try test__clzti2(0xE0000000_00000000_00000000_00000000, 0);
try test__clzti2(0xE1000000_00000000_00000000_00000000, 0);
try test__clzti2(0xE2000000_00000000_00000000_00000000, 0);
try test__clzti2(0xE3000000_00000000_00000000_00000000, 0);
try test__clzti2(0xE4000000_00000000_00000000_00000000, 0);
try test__clzti2(0xE5000000_00000000_00000000_00000000, 0);
try test__clzti2(0xE6000000_00000000_00000000_00000000, 0);
try test__clzti2(0xE7000000_00000000_00000000_00000000, 0);
try test__clzti2(0xE8000000_00000000_00000000_00000000, 0);
try test__clzti2(0xE9000000_00000000_00000000_00000000, 0);
try test__clzti2(0xEA000000_00000000_00000000_00000000, 0);
try test__clzti2(0xEB000000_00000000_00000000_00000000, 0);
try test__clzti2(0xEC000000_00000000_00000000_00000000, 0);
try test__clzti2(0xED000000_00000000_00000000_00000000, 0);
try test__clzti2(0xEE000000_00000000_00000000_00000000, 0);
try test__clzti2(0xEF000000_00000000_00000000_00000000, 0);
try test__clzti2(0xF0000000_00000000_00000000_00000000, 0);
try test__clzti2(0xF1000000_00000000_00000000_00000000, 0);
try test__clzti2(0xF2000000_00000000_00000000_00000000, 0);
try test__clzti2(0xF3000000_00000000_00000000_00000000, 0);
try test__clzti2(0xF4000000_00000000_00000000_00000000, 0);
try test__clzti2(0xF5000000_00000000_00000000_00000000, 0);
try test__clzti2(0xF6000000_00000000_00000000_00000000, 0);
try test__clzti2(0xF7000000_00000000_00000000_00000000, 0);
try test__clzti2(0xF8000000_00000000_00000000_00000000, 0);
try test__clzti2(0xF9000000_00000000_00000000_00000000, 0);
try test__clzti2(0xFA000000_00000000_00000000_00000000, 0);
try test__clzti2(0xFB000000_00000000_00000000_00000000, 0);
try test__clzti2(0xFC000000_00000000_00000000_00000000, 0);
try test__clzti2(0xFD000000_00000000_00000000_00000000, 0);
try test__clzti2(0xFE000000_00000000_00000000_00000000, 0);
try test__clzti2(0xFF000000_00000000_00000000_00000000, 0);
try test__clzti2(0x00000000_00000000_00000000_00000000, 128);
try test__clzti2(0x00000000_00000000_00000000_00000001, 127);
try test__clzti2(0x00000000_00000000_00000000_00000002, 126);
try test__clzti2(0x00000000_00000000_00000000_00000004, 125);
try test__clzti2(0x00000000_00000000_00000000_00000008, 124);
try test__clzti2(0x00000000_00000000_00000000_00000010, 123);
try test__clzti2(0x00000000_00000000_00000000_00000020, 122);
try test__clzti2(0x00000000_00000000_00000000_00000040, 121);
try test__clzti2(0x00000000_00000000_00000000_00000080, 120);
try test__clzti2(0x00000000_00000000_00000000_00000100, 119);
try test__clzti2(0x00000000_00000000_00000000_00000200, 118);
try test__clzti2(0x00000000_00000000_00000000_00000400, 117);
try test__clzti2(0x00000000_00000000_00000000_00000800, 116);
try test__clzti2(0x00000000_00000000_00000000_00001000, 115);
try test__clzti2(0x00000000_00000000_00000000_00002000, 114);
try test__clzti2(0x00000000_00000000_00000000_00004000, 113);
try test__clzti2(0x00000000_00000000_00000000_00008000, 112);
try test__clzti2(0x00000000_00000000_00000000_00010000, 111);
try test__clzti2(0x00000000_00000000_00000000_00020000, 110);
try test__clzti2(0x00000000_00000000_00000000_00040000, 109);
try test__clzti2(0x00000000_00000000_00000000_00080000, 108);
try test__clzti2(0x00000000_00000000_00000000_00100000, 107);
try test__clzti2(0x00000000_00000000_00000000_00200000, 106);
try test__clzti2(0x00000000_00000000_00000000_00400000, 105);
try test__clzti2(0x00000000_00000000_00000000_00800000, 104);
try test__clzti2(0x00000000_00000000_00000000_01000000, 103);
try test__clzti2(0x00000000_00000000_00000000_02000000, 102);
try test__clzti2(0x00000000_00000000_00000000_04000000, 101);
try test__clzti2(0x00000000_00000000_00000000_08000000, 100);
try test__clzti2(0x00000000_00000000_00000000_10000000, 99);
try test__clzti2(0x00000000_00000000_00000000_20000000, 98);
try test__clzti2(0x00000000_00000000_00000000_40000000, 97);
try test__clzti2(0x00000000_00000000_00000000_80000000, 96);
try test__clzti2(0x00000000_00000000_00000001_00000000, 95);
try test__clzti2(0x00000000_00000000_00000002_00000000, 94);
try test__clzti2(0x00000000_00000000_00000004_00000000, 93);
try test__clzti2(0x00000000_00000000_00000008_00000000, 92);
try test__clzti2(0x00000000_00000000_00000010_00000000, 91);
try test__clzti2(0x00000000_00000000_00000020_00000000, 90);
try test__clzti2(0x00000000_00000000_00000040_00000000, 89);
try test__clzti2(0x00000000_00000000_00000080_00000000, 88);
try test__clzti2(0x00000000_00000000_00000100_00000000, 87);
try test__clzti2(0x00000000_00000000_00000200_00000000, 86);
try test__clzti2(0x00000000_00000000_00000400_00000000, 85);
try test__clzti2(0x00000000_00000000_00000800_00000000, 84);
try test__clzti2(0x00000000_00000000_00001000_00000000, 83);
try test__clzti2(0x00000000_00000000_00002000_00000000, 82);
try test__clzti2(0x00000000_00000000_00004000_00000000, 81);
try test__clzti2(0x00000000_00000000_00008000_00000000, 80);
try test__clzti2(0x00000000_00000000_00010000_00000000, 79);
try test__clzti2(0x00000000_00000000_00020000_00000000, 78);
try test__clzti2(0x00000000_00000000_00040000_00000000, 77);
try test__clzti2(0x00000000_00000000_00080000_00000000, 76);
try test__clzti2(0x00000000_00000000_00100000_00000000, 75);
try test__clzti2(0x00000000_00000000_00200000_00000000, 74);
try test__clzti2(0x00000000_00000000_00400000_00000000, 73);
try test__clzti2(0x00000000_00000000_00800000_00000000, 72);
try test__clzti2(0x00000000_00000000_01000000_00000000, 71);
try test__clzti2(0x00000000_00000000_02000000_00000000, 70);
try test__clzti2(0x00000000_00000000_04000000_00000000, 69);
try test__clzti2(0x00000000_00000000_08000000_00000000, 68);
try test__clzti2(0x00000000_00000000_10000000_00000000, 67);
try test__clzti2(0x00000000_00000000_20000000_00000000, 66);
try test__clzti2(0x00000000_00000000_40000000_00000000, 65);
try test__clzti2(0x00000000_00000000_80000000_00000000, 64);
try test__clzti2(0x00000000_00000001_00000000_00000000, 63);
try test__clzti2(0x00000000_00000002_00000000_00000000, 62);
try test__clzti2(0x00000000_00000004_00000000_00000000, 61);
try test__clzti2(0x00000000_00000008_00000000_00000000, 60);
try test__clzti2(0x00000000_00000010_00000000_00000000, 59);
try test__clzti2(0x00000000_00000020_00000000_00000000, 58);
try test__clzti2(0x00000000_00000040_00000000_00000000, 57);
try test__clzti2(0x00000000_00000080_00000000_00000000, 56);
try test__clzti2(0x00000000_00000100_00000000_00000000, 55);
try test__clzti2(0x00000000_00000200_00000000_00000000, 54);
try test__clzti2(0x00000000_00000400_00000000_00000000, 53);
try test__clzti2(0x00000000_00000800_00000000_00000000, 52);
try test__clzti2(0x00000000_00001000_00000000_00000000, 51);
try test__clzti2(0x00000000_00002000_00000000_00000000, 50);
try test__clzti2(0x00000000_00004000_00000000_00000000, 49);
try test__clzti2(0x00000000_00008000_00000000_00000000, 48);
try test__clzti2(0x00000000_00010000_00000000_00000000, 47);
try test__clzti2(0x00000000_00020000_00000000_00000000, 46);
try test__clzti2(0x00000000_00040000_00000000_00000000, 45);
try test__clzti2(0x00000000_00080000_00000000_00000000, 44);
try test__clzti2(0x00000000_00100000_00000000_00000000, 43);
try test__clzti2(0x00000000_00200000_00000000_00000000, 42);
try test__clzti2(0x00000000_00400000_00000000_00000000, 41);
try test__clzti2(0x00000000_00800000_00000000_00000000, 40);
try test__clzti2(0x00000000_01000000_00000000_00000000, 39);
try test__clzti2(0x00000000_02000000_00000000_00000000, 38);
try test__clzti2(0x00000000_04000000_00000000_00000000, 37);
try test__clzti2(0x00000000_08000000_00000000_00000000, 36);
try test__clzti2(0x00000000_10000000_00000000_00000000, 35);
try test__clzti2(0x00000000_20000000_00000000_00000000, 34);
try test__clzti2(0x00000000_40000000_00000000_00000000, 33);
try test__clzti2(0x00000000_80000000_00000000_00000000, 32);
try test__clzti2(0x00000001_00000000_00000000_00000000, 31);
try test__clzti2(0x00000002_00000000_00000000_00000000, 30);
try test__clzti2(0x00000004_00000000_00000000_00000000, 29);
try test__clzti2(0x00000008_00000000_00000000_00000000, 28);
try test__clzti2(0x00000010_00000000_00000000_00000000, 27);
try test__clzti2(0x00000020_00000000_00000000_00000000, 26);
try test__clzti2(0x00000040_00000000_00000000_00000000, 25);
try test__clzti2(0x00000080_00000000_00000000_00000000, 24);
try test__clzti2(0x00000100_00000000_00000000_00000000, 23);
try test__clzti2(0x00000200_00000000_00000000_00000000, 22);
try test__clzti2(0x00000400_00000000_00000000_00000000, 21);
try test__clzti2(0x00000800_00000000_00000000_00000000, 20);
try test__clzti2(0x00001000_00000000_00000000_00000000, 19);
try test__clzti2(0x00002000_00000000_00000000_00000000, 18);
try test__clzti2(0x00004000_00000000_00000000_00000000, 17);
try test__clzti2(0x00008000_00000000_00000000_00000000, 16);
try test__clzti2(0x00010000_00000000_00000000_00000000, 15);
try test__clzti2(0x00020000_00000000_00000000_00000000, 14);
try test__clzti2(0x00040000_00000000_00000000_00000000, 13);
try test__clzti2(0x00080000_00000000_00000000_00000000, 12);
try test__clzti2(0x00100000_00000000_00000000_00000000, 11);
try test__clzti2(0x00200000_00000000_00000000_00000000, 10);
try test__clzti2(0x00400000_00000000_00000000_00000000, 9);
}

View File

@@ -1,69 +0,0 @@
const std = @import("std");
const builtin = @import("builtin");
const is_test = builtin.is_test;
const common = @import("common.zig");
pub const panic = common.panic;
comptime {
@export(__cmpsi2, .{ .name = "__cmpsi2", .linkage = common.linkage });
@export(__cmpdi2, .{ .name = "__cmpdi2", .linkage = common.linkage });
@export(__cmpti2, .{ .name = "__cmpti2", .linkage = common.linkage });
@export(__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = common.linkage });
@export(__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = common.linkage });
@export(__ucmpti2, .{ .name = "__ucmpti2", .linkage = common.linkage });
}
// cmp - signed compare
// - cmpXi2_generic for unoptimized little and big endian
// ucmp - unsigned compare
// - ucmpXi2_generic for unoptimized little and big endian
// a < b => 0
// a == b => 1
// a > b => 2
inline fn XcmpXi2(comptime T: type, a: T, b: T) i32 {
var cmp1: i32 = 0;
var cmp2: i32 = 0;
if (a > b)
cmp1 = 1;
if (a < b)
cmp2 = 1;
return cmp1 - cmp2 + 1;
}
pub fn __cmpsi2(a: i32, b: i32) callconv(.C) i32 {
return XcmpXi2(i32, a, b);
}
pub fn __cmpdi2(a: i64, b: i64) callconv(.C) i32 {
return XcmpXi2(i64, a, b);
}
pub fn __cmpti2(a: i128, b: i128) callconv(.C) i32 {
return XcmpXi2(i128, a, b);
}
pub fn __ucmpsi2(a: u32, b: u32) callconv(.C) i32 {
return XcmpXi2(u32, a, b);
}
pub fn __ucmpdi2(a: u64, b: u64) callconv(.C) i32 {
return XcmpXi2(u64, a, b);
}
pub fn __ucmpti2(a: u128, b: u128) callconv(.C) i32 {
return XcmpXi2(u128, a, b);
}
test {
_ = @import("cmpsi2_test.zig");
_ = @import("cmpdi2_test.zig");
_ = @import("cmpti2_test.zig");
_ = @import("ucmpsi2_test.zig");
_ = @import("ucmpdi2_test.zig");
_ = @import("ucmpti2_test.zig");
}

View File

@@ -1,68 +0,0 @@
///! The quoted behavior definitions are from
///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines
const common = @import("./common.zig");
const comparef = @import("./comparef.zig");
pub const panic = common.panic;
comptime {
if (common.want_aeabi) {
@export(__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = common.linkage });
@export(__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = common.linkage });
@export(__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = common.linkage });
} else {
@export(__eqdf2, .{ .name = "__eqdf2", .linkage = common.linkage });
@export(__nedf2, .{ .name = "__nedf2", .linkage = common.linkage });
@export(__ledf2, .{ .name = "__ledf2", .linkage = common.linkage });
@export(__cmpdf2, .{ .name = "__cmpdf2", .linkage = common.linkage });
@export(__ltdf2, .{ .name = "__ltdf2", .linkage = common.linkage });
}
}
/// "These functions calculate a <=> b. That is, if a is less than b, they return -1;
/// if a is greater than b, they return 1; and if a and b are equal they return 0.
/// If either argument is NaN they return 1..."
///
/// Note that this matches the definition of `__ledf2`, `__eqdf2`, `__nedf2`, `__cmpdf2`,
/// and `__ltdf2`.
fn __cmpdf2(a: f64, b: f64) callconv(.C) i32 {
return @enumToInt(comparef.cmpf2(f64, comparef.LE, a, b));
}
/// "These functions return a value less than or equal to zero if neither argument is NaN,
/// and a is less than or equal to b."
pub fn __ledf2(a: f64, b: f64) callconv(.C) i32 {
return __cmpdf2(a, b);
}
/// "These functions return zero if neither argument is NaN, and a and b are equal."
/// Note that due to some kind of historical accident, __eqdf2 and __nedf2 are defined
/// to have the same return value.
pub fn __eqdf2(a: f64, b: f64) callconv(.C) i32 {
return __cmpdf2(a, b);
}
/// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal."
/// Note that due to some kind of historical accident, __eqdf2 and __nedf2 are defined
/// to have the same return value.
pub fn __nedf2(a: f64, b: f64) callconv(.C) i32 {
return __cmpdf2(a, b);
}
/// "These functions return a value less than zero if neither argument is NaN, and a
/// is strictly less than b."
pub fn __ltdf2(a: f64, b: f64) callconv(.C) i32 {
return __cmpdf2(a, b);
}
fn __aeabi_dcmpeq(a: f64, b: f64) callconv(.AAPCS) i32 {
return @boolToInt(comparef.cmpf2(f64, comparef.LE, a, b) == .Equal);
}
fn __aeabi_dcmplt(a: f64, b: f64) callconv(.AAPCS) i32 {
return @boolToInt(comparef.cmpf2(f64, comparef.LE, a, b) == .Less);
}
fn __aeabi_dcmple(a: f64, b: f64) callconv(.AAPCS) i32 {
return @boolToInt(comparef.cmpf2(f64, comparef.LE, a, b) != .Greater);
}

View File

@@ -1,105 +0,0 @@
const cmp = @import("cmp.zig");
const testing = @import("std").testing;
fn test__cmpdi2(a: i64, b: i64, expected: i64) !void {
var result = cmp.__cmpdi2(a, b);
try testing.expectEqual(expected, result);
}
test "cmpdi2" {
// minInt == -9223372036854775808
// maxInt == 9223372036854775807
// minInt/2 == -4611686018427387904
// maxInt/2 == 4611686018427387903
// 1. equality minInt, minInt+1, minInt/2, 0, maxInt/2, maxInt-1, maxInt
try test__cmpdi2(-9223372036854775808, -9223372036854775808, 1);
try test__cmpdi2(-9223372036854775807, -9223372036854775807, 1);
try test__cmpdi2(-4611686018427387904, -4611686018427387904, 1);
try test__cmpdi2(-1, -1, 1);
try test__cmpdi2(0, 0, 1);
try test__cmpdi2(1, 1, 1);
try test__cmpdi2(4611686018427387903, 4611686018427387903, 1);
try test__cmpdi2(9223372036854775806, 9223372036854775806, 1);
try test__cmpdi2(9223372036854775807, 9223372036854775807, 1);
// 2. cmp minInt, { minInt + 1, minInt/2, -1, 0, 1, maxInt/2, maxInt-1, maxInt}
try test__cmpdi2(-9223372036854775808, -9223372036854775807, 0);
try test__cmpdi2(-9223372036854775808, -4611686018427387904, 0);
try test__cmpdi2(-9223372036854775808, -1, 0);
try test__cmpdi2(-9223372036854775808, 0, 0);
try test__cmpdi2(-9223372036854775808, 1, 0);
try test__cmpdi2(-9223372036854775808, 4611686018427387903, 0);
try test__cmpdi2(-9223372036854775808, 9223372036854775806, 0);
try test__cmpdi2(-9223372036854775808, 9223372036854775807, 0);
// 3. cmp minInt+1, {minInt, minInt/2, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpdi2(-9223372036854775807, -9223372036854775808, 2);
try test__cmpdi2(-9223372036854775807, -4611686018427387904, 0);
try test__cmpdi2(-9223372036854775807, -1, 0);
try test__cmpdi2(-9223372036854775807, 0, 0);
try test__cmpdi2(-9223372036854775807, 1, 0);
try test__cmpdi2(-9223372036854775807, 4611686018427387903, 0);
try test__cmpdi2(-9223372036854775807, 9223372036854775806, 0);
try test__cmpdi2(-9223372036854775807, 9223372036854775807, 0);
// 4. cmp minInt/2, {minInt, minInt + 1, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpdi2(-4611686018427387904, -9223372036854775808, 2);
try test__cmpdi2(-4611686018427387904, -9223372036854775807, 2);
try test__cmpdi2(-4611686018427387904, -1, 0);
try test__cmpdi2(-4611686018427387904, 0, 0);
try test__cmpdi2(-4611686018427387904, 1, 0);
try test__cmpdi2(-4611686018427387904, 4611686018427387903, 0);
try test__cmpdi2(-4611686018427387904, 9223372036854775806, 0);
try test__cmpdi2(-4611686018427387904, 9223372036854775807, 0);
// 5. cmp -1, {minInt, minInt + 1, minInt/2, 0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpdi2(-1, -9223372036854775808, 2);
try test__cmpdi2(-1, -9223372036854775807, 2);
try test__cmpdi2(-1, -4611686018427387904, 2);
try test__cmpdi2(-1, 0, 0);
try test__cmpdi2(-1, 1, 0);
try test__cmpdi2(-1, 4611686018427387903, 0);
try test__cmpdi2(-1, 9223372036854775806, 0);
try test__cmpdi2(-1, 9223372036854775807, 0);
// 6. cmp 0, {minInt, minInt + 1, minInt/2, -1, 1, maxInt/2, maxInt-1, maxInt}
try test__cmpdi2(0, -9223372036854775808, 2);
try test__cmpdi2(0, -9223372036854775807, 2);
try test__cmpdi2(0, -4611686018427387904, 2);
try test__cmpdi2(0, -1, 2);
try test__cmpdi2(0, 1, 0);
try test__cmpdi2(0, 4611686018427387903, 0);
try test__cmpdi2(0, 9223372036854775806, 0);
try test__cmpdi2(0, 9223372036854775807, 0);
// 7. cmp 1, {minInt, minInt + 1, minInt/2, -1,0, maxInt/2, maxInt-1, maxInt}
try test__cmpdi2(1, -9223372036854775808, 2);
try test__cmpdi2(1, -9223372036854775807, 2);
try test__cmpdi2(1, -4611686018427387904, 2);
try test__cmpdi2(1, -1, 2);
try test__cmpdi2(1, 0, 2);
try test__cmpdi2(1, 4611686018427387903, 0);
try test__cmpdi2(1, 9223372036854775806, 0);
try test__cmpdi2(1, 9223372036854775807, 0);
// 8. cmp maxInt/2, {minInt, minInt + 1, minInt/2, -1,0,1, maxInt-1, maxInt}
try test__cmpdi2(4611686018427387903, -9223372036854775808, 2);
try test__cmpdi2(4611686018427387903, -9223372036854775807, 2);
try test__cmpdi2(4611686018427387903, -4611686018427387904, 2);
try test__cmpdi2(4611686018427387903, -1, 2);
try test__cmpdi2(4611686018427387903, 0, 2);
try test__cmpdi2(4611686018427387903, 1, 2);
try test__cmpdi2(4611686018427387903, 9223372036854775806, 0);
try test__cmpdi2(4611686018427387903, 9223372036854775807, 0);
// 9. cmp maxInt-1, {minInt, minInt + 1, minInt/2, -1,0,1, maxInt/2, maxInt}
try test__cmpdi2(9223372036854775806, -9223372036854775808, 2);
try test__cmpdi2(9223372036854775806, -9223372036854775807, 2);
try test__cmpdi2(9223372036854775806, -4611686018427387904, 2);
try test__cmpdi2(9223372036854775806, -1, 2);
try test__cmpdi2(9223372036854775806, 0, 2);
try test__cmpdi2(9223372036854775806, 1, 2);
try test__cmpdi2(9223372036854775806, 4611686018427387903, 2);
try test__cmpdi2(9223372036854775806, 9223372036854775807, 0);
// 10.cmp maxInt, {minInt, minInt + 1, minInt/2, -1,0,1, maxInt/2, maxInt-1, }
try test__cmpdi2(9223372036854775807, -9223372036854775808, 2);
try test__cmpdi2(9223372036854775807, -9223372036854775807, 2);
try test__cmpdi2(9223372036854775807, -4611686018427387904, 2);
try test__cmpdi2(9223372036854775807, -1, 2);
try test__cmpdi2(9223372036854775807, 0, 2);
try test__cmpdi2(9223372036854775807, 1, 2);
try test__cmpdi2(9223372036854775807, 4611686018427387903, 2);
try test__cmpdi2(9223372036854775807, 9223372036854775806, 2);
}

View File

@@ -1,50 +0,0 @@
///! The quoted behavior definitions are from
///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines
const common = @import("./common.zig");
const comparef = @import("./comparef.zig");
pub const panic = common.panic;
comptime {
@export(__eqhf2, .{ .name = "__eqhf2", .linkage = common.linkage });
@export(__nehf2, .{ .name = "__nehf2", .linkage = common.linkage });
@export(__lehf2, .{ .name = "__lehf2", .linkage = common.linkage });
@export(__cmphf2, .{ .name = "__cmphf2", .linkage = common.linkage });
@export(__lthf2, .{ .name = "__lthf2", .linkage = common.linkage });
}
/// "These functions calculate a <=> b. That is, if a is less than b, they return -1;
/// if a is greater than b, they return 1; and if a and b are equal they return 0.
/// If either argument is NaN they return 1..."
///
/// Note that this matches the definition of `__lehf2`, `__eqhf2`, `__nehf2`, `__cmphf2`,
/// and `__lthf2`.
fn __cmphf2(a: f16, b: f16) callconv(.C) i32 {
return @enumToInt(comparef.cmpf2(f16, comparef.LE, a, b));
}
/// "These functions return a value less than or equal to zero if neither argument is NaN,
/// and a is less than or equal to b."
pub fn __lehf2(a: f16, b: f16) callconv(.C) i32 {
return __cmphf2(a, b);
}
/// "These functions return zero if neither argument is NaN, and a and b are equal."
/// Note that due to some kind of historical accident, __eqhf2 and __nehf2 are defined
/// to have the same return value.
pub fn __eqhf2(a: f16, b: f16) callconv(.C) i32 {
return __cmphf2(a, b);
}
/// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal."
/// Note that due to some kind of historical accident, __eqhf2 and __nehf2 are defined
/// to have the same return value.
pub fn __nehf2(a: f16, b: f16) callconv(.C) i32 {
return __cmphf2(a, b);
}
/// "These functions return a value less than zero if neither argument is NaN, and a
/// is strictly less than b."
pub fn __lthf2(a: f16, b: f16) callconv(.C) i32 {
return __cmphf2(a, b);
}

View File

@@ -1,68 +0,0 @@
///! The quoted behavior definitions are from
///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines
const common = @import("./common.zig");
const comparef = @import("./comparef.zig");
pub const panic = common.panic;
comptime {
if (common.want_aeabi) {
@export(__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = common.linkage });
@export(__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = common.linkage });
@export(__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = common.linkage });
} else {
@export(__eqsf2, .{ .name = "__eqsf2", .linkage = common.linkage });
@export(__nesf2, .{ .name = "__nesf2", .linkage = common.linkage });
@export(__lesf2, .{ .name = "__lesf2", .linkage = common.linkage });
@export(__cmpsf2, .{ .name = "__cmpsf2", .linkage = common.linkage });
@export(__ltsf2, .{ .name = "__ltsf2", .linkage = common.linkage });
}
}
/// "These functions calculate a <=> b. That is, if a is less than b, they return -1;
/// if a is greater than b, they return 1; and if a and b are equal they return 0.
/// If either argument is NaN they return 1..."
///
/// Note that this matches the definition of `__lesf2`, `__eqsf2`, `__nesf2`, `__cmpsf2`,
/// and `__ltsf2`.
fn __cmpsf2(a: f32, b: f32) callconv(.C) i32 {
return @enumToInt(comparef.cmpf2(f32, comparef.LE, a, b));
}
/// "These functions return a value less than or equal to zero if neither argument is NaN,
/// and a is less than or equal to b."
pub fn __lesf2(a: f32, b: f32) callconv(.C) i32 {
return __cmpsf2(a, b);
}
/// "These functions return zero if neither argument is NaN, and a and b are equal."
/// Note that due to some kind of historical accident, __eqsf2 and __nesf2 are defined
/// to have the same return value.
pub fn __eqsf2(a: f32, b: f32) callconv(.C) i32 {
return __cmpsf2(a, b);
}
/// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal."
/// Note that due to some kind of historical accident, __eqsf2 and __nesf2 are defined
/// to have the same return value.
pub fn __nesf2(a: f32, b: f32) callconv(.C) i32 {
return __cmpsf2(a, b);
}
/// "These functions return a value less than zero if neither argument is NaN, and a
/// is strictly less than b."
pub fn __ltsf2(a: f32, b: f32) callconv(.C) i32 {
return __cmpsf2(a, b);
}
fn __aeabi_fcmpeq(a: f32, b: f32) callconv(.AAPCS) i32 {
return @boolToInt(comparef.cmpf2(f32, comparef.LE, a, b) == .Equal);
}
fn __aeabi_fcmplt(a: f32, b: f32) callconv(.AAPCS) i32 {
return @boolToInt(comparef.cmpf2(f32, comparef.LE, a, b) == .Less);
}
fn __aeabi_fcmple(a: f32, b: f32) callconv(.AAPCS) i32 {
return @boolToInt(comparef.cmpf2(f32, comparef.LE, a, b) != .Greater);
}

View File

@@ -1,105 +0,0 @@
const cmp = @import("cmp.zig");
const testing = @import("std").testing;
fn test__cmpsi2(a: i32, b: i32, expected: i32) !void {
var result = cmp.__cmpsi2(a, b);
try testing.expectEqual(expected, result);
}
test "cmpsi2" {
// minInt == -2147483648
// maxInt == 2147483647
// minInt/2 == -1073741824
// maxInt/2 == 1073741823
// 1. equality minInt, minInt+1, minInt/2, -1, 0, 1, maxInt/2, maxInt-1, maxInt
try test__cmpsi2(-2147483648, -2147483648, 1);
try test__cmpsi2(-2147483647, -2147483647, 1);
try test__cmpsi2(-1073741824, -1073741824, 1);
try test__cmpsi2(-1, -1, 1);
try test__cmpsi2(0, 0, 1);
try test__cmpsi2(1, 1, 1);
try test__cmpsi2(1073741823, 1073741823, 1);
try test__cmpsi2(2147483646, 2147483646, 1);
try test__cmpsi2(2147483647, 2147483647, 1);
// 2. cmp minInt, { minInt + 1, minInt/2, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(-2147483648, -2147483647, 0);
try test__cmpsi2(-2147483648, -1073741824, 0);
try test__cmpsi2(-2147483648, -1, 0);
try test__cmpsi2(-2147483648, 0, 0);
try test__cmpsi2(-2147483648, 1, 0);
try test__cmpsi2(-2147483648, 1073741823, 0);
try test__cmpsi2(-2147483648, 2147483646, 0);
try test__cmpsi2(-2147483648, 2147483647, 0);
// 3. cmp minInt+1, {minInt, minInt/2, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(-2147483647, -2147483648, 2);
try test__cmpsi2(-2147483647, -1073741824, 0);
try test__cmpsi2(-2147483647, -1, 0);
try test__cmpsi2(-2147483647, 0, 0);
try test__cmpsi2(-2147483647, 1, 0);
try test__cmpsi2(-2147483647, 1073741823, 0);
try test__cmpsi2(-2147483647, 2147483646, 0);
try test__cmpsi2(-2147483647, 2147483647, 0);
// 4. cmp minInt/2, {minInt, minInt + 1, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(-1073741824, -2147483648, 2);
try test__cmpsi2(-1073741824, -2147483647, 2);
try test__cmpsi2(-1073741824, -1, 0);
try test__cmpsi2(-1073741824, 0, 0);
try test__cmpsi2(-1073741824, 1, 0);
try test__cmpsi2(-1073741824, 1073741823, 0);
try test__cmpsi2(-1073741824, 2147483646, 0);
try test__cmpsi2(-1073741824, 2147483647, 0);
// 5. cmp -1, {minInt, minInt + 1, minInt/2, 0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(-1, -2147483648, 2);
try test__cmpsi2(-1, -2147483647, 2);
try test__cmpsi2(-1, -1073741824, 2);
try test__cmpsi2(-1, 0, 0);
try test__cmpsi2(-1, 1, 0);
try test__cmpsi2(-1, 1073741823, 0);
try test__cmpsi2(-1, 2147483646, 0);
try test__cmpsi2(-1, 2147483647, 0);
// 6. cmp 0, {minInt, minInt + 1, minInt/2, -1, 1, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(0, -2147483648, 2);
try test__cmpsi2(0, -2147483647, 2);
try test__cmpsi2(0, -1073741824, 2);
try test__cmpsi2(0, -1, 2);
try test__cmpsi2(0, 1, 0);
try test__cmpsi2(0, 1073741823, 0);
try test__cmpsi2(0, 2147483646, 0);
try test__cmpsi2(0, 2147483647, 0);
// 7. cmp 1, {minInt, minInt + 1, minInt/2, -1,0, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(1, -2147483648, 2);
try test__cmpsi2(1, -2147483647, 2);
try test__cmpsi2(1, -1073741824, 2);
try test__cmpsi2(1, -1, 2);
try test__cmpsi2(1, 0, 2);
try test__cmpsi2(1, 1073741823, 0);
try test__cmpsi2(1, 2147483646, 0);
try test__cmpsi2(1, 2147483647, 0);
// 8. cmp maxInt/2, {minInt, minInt + 1, minInt/2, -1, 0, 1, maxInt-1, maxInt}
try test__cmpsi2(1073741823, -2147483648, 2);
try test__cmpsi2(1073741823, -2147483647, 2);
try test__cmpsi2(1073741823, -1073741824, 2);
try test__cmpsi2(1073741823, -1, 2);
try test__cmpsi2(1073741823, 0, 2);
try test__cmpsi2(1073741823, 1, 2);
try test__cmpsi2(1073741823, 2147483646, 0);
try test__cmpsi2(1073741823, 2147483647, 0);
// 9. cmp maxInt-1, {minInt, minInt + 1, minInt/2, -1, 0, 1, maxInt/2, maxInt}
try test__cmpsi2(2147483646, -2147483648, 2);
try test__cmpsi2(2147483646, -2147483647, 2);
try test__cmpsi2(2147483646, -1073741824, 2);
try test__cmpsi2(2147483646, -1, 2);
try test__cmpsi2(2147483646, 0, 2);
try test__cmpsi2(2147483646, 1, 2);
try test__cmpsi2(2147483646, 1073741823, 2);
try test__cmpsi2(2147483646, 2147483647, 0);
// 10.cmp maxInt, {minInt, minInt + 1, minInt/2, -1, 0, 1, maxInt/2, maxInt-1, }
try test__cmpsi2(2147483647, -2147483648, 2);
try test__cmpsi2(2147483647, -2147483647, 2);
try test__cmpsi2(2147483647, -1073741824, 2);
try test__cmpsi2(2147483647, -1, 2);
try test__cmpsi2(2147483647, 0, 2);
try test__cmpsi2(2147483647, 1, 2);
try test__cmpsi2(2147483647, 1073741823, 2);
try test__cmpsi2(2147483647, 2147483646, 2);
}

View File

@@ -1,105 +0,0 @@
///! The quoted behavior definitions are from
///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines
const common = @import("./common.zig");
const comparef = @import("./comparef.zig");
pub const panic = common.panic;
comptime {
if (common.want_ppc_abi) {
@export(__eqtf2, .{ .name = "__eqkf2", .linkage = common.linkage });
@export(__netf2, .{ .name = "__nekf2", .linkage = common.linkage });
@export(__lttf2, .{ .name = "__ltkf2", .linkage = common.linkage });
@export(__letf2, .{ .name = "__lekf2", .linkage = common.linkage });
} else if (common.want_sparc_abi) {
@export(_Qp_cmp, .{ .name = "_Qp_cmp", .linkage = common.linkage });
@export(_Qp_feq, .{ .name = "_Qp_feq", .linkage = common.linkage });
@export(_Qp_fne, .{ .name = "_Qp_fne", .linkage = common.linkage });
@export(_Qp_flt, .{ .name = "_Qp_flt", .linkage = common.linkage });
@export(_Qp_fle, .{ .name = "_Qp_fle", .linkage = common.linkage });
@export(_Qp_fgt, .{ .name = "_Qp_fgt", .linkage = common.linkage });
@export(_Qp_fge, .{ .name = "_Qp_fge", .linkage = common.linkage });
}
@export(__eqtf2, .{ .name = "__eqtf2", .linkage = common.linkage });
@export(__netf2, .{ .name = "__netf2", .linkage = common.linkage });
@export(__letf2, .{ .name = "__letf2", .linkage = common.linkage });
@export(__cmptf2, .{ .name = "__cmptf2", .linkage = common.linkage });
@export(__lttf2, .{ .name = "__lttf2", .linkage = common.linkage });
}
/// "These functions calculate a <=> b. That is, if a is less than b, they return -1;
/// if a is greater than b, they return 1; and if a and b are equal they return 0.
/// If either argument is NaN they return 1..."
///
/// Note that this matches the definition of `__letf2`, `__eqtf2`, `__netf2`, `__cmptf2`,
/// and `__lttf2`.
fn __cmptf2(a: f128, b: f128) callconv(.C) i32 {
return @enumToInt(comparef.cmpf2(f128, comparef.LE, a, b));
}
/// "These functions return a value less than or equal to zero if neither argument is NaN,
/// and a is less than or equal to b."
fn __letf2(a: f128, b: f128) callconv(.C) i32 {
return __cmptf2(a, b);
}
/// "These functions return zero if neither argument is NaN, and a and b are equal."
/// Note that due to some kind of historical accident, __eqtf2 and __netf2 are defined
/// to have the same return value.
fn __eqtf2(a: f128, b: f128) callconv(.C) i32 {
return __cmptf2(a, b);
}
/// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal."
/// Note that due to some kind of historical accident, __eqtf2 and __netf2 are defined
/// to have the same return value.
fn __netf2(a: f128, b: f128) callconv(.C) i32 {
return __cmptf2(a, b);
}
/// "These functions return a value less than zero if neither argument is NaN, and a
/// is strictly less than b."
fn __lttf2(a: f128, b: f128) callconv(.C) i32 {
return __cmptf2(a, b);
}
const SparcFCMP = enum(i32) {
Equal = 0,
Less = 1,
Greater = 2,
Unordered = 3,
};
fn _Qp_cmp(a: *const f128, b: *const f128) callconv(.C) i32 {
return @enumToInt(comparef.cmpf2(f128, SparcFCMP, a.*, b.*));
}
fn _Qp_feq(a: *const f128, b: *const f128) callconv(.C) bool {
return @intToEnum(SparcFCMP, _Qp_cmp(a, b)) == .Equal;
}
fn _Qp_fne(a: *const f128, b: *const f128) callconv(.C) bool {
return @intToEnum(SparcFCMP, _Qp_cmp(a, b)) != .Equal;
}
fn _Qp_flt(a: *const f128, b: *const f128) callconv(.C) bool {
return @intToEnum(SparcFCMP, _Qp_cmp(a, b)) == .Less;
}
fn _Qp_fgt(a: *const f128, b: *const f128) callconv(.C) bool {
return @intToEnum(SparcFCMP, _Qp_cmp(a, b)) == .Greater;
}
fn _Qp_fge(a: *const f128, b: *const f128) callconv(.C) bool {
return switch (@intToEnum(SparcFCMP, _Qp_cmp(a, b))) {
.Equal, .Greater => true,
.Less, .Unordered => false,
};
}
fn _Qp_fle(a: *const f128, b: *const f128) callconv(.C) bool {
return switch (@intToEnum(SparcFCMP, _Qp_cmp(a, b))) {
.Equal, .Less => true,
.Greater, .Unordered => false,
};
}

View File

@@ -1,105 +0,0 @@
const cmp = @import("cmp.zig");
const testing = @import("std").testing;
fn test__cmpti2(a: i128, b: i128, expected: i128) !void {
var result = cmp.__cmpti2(a, b);
try testing.expectEqual(expected, result);
}
test "cmpti2" {
// minInt == -170141183460469231731687303715884105728
// maxInt == 170141183460469231731687303715884105727
// minInt/2 == -85070591730234615865843651857942052864
// maxInt/2 == 85070591730234615865843651857942052863
// 1. equality minInt, minInt+1, minInt/2, 0, maxInt/2, maxInt-1, maxInt
try test__cmpti2(-170141183460469231731687303715884105728, -170141183460469231731687303715884105728, 1);
try test__cmpti2(-170141183460469231731687303715884105727, -170141183460469231731687303715884105727, 1);
try test__cmpti2(-85070591730234615865843651857942052864, -85070591730234615865843651857942052864, 1);
try test__cmpti2(-1, -1, 1);
try test__cmpti2(0, 0, 1);
try test__cmpti2(1, 1, 1);
try test__cmpti2(85070591730234615865843651857942052863, 85070591730234615865843651857942052863, 1);
try test__cmpti2(170141183460469231731687303715884105726, 170141183460469231731687303715884105726, 1);
try test__cmpti2(170141183460469231731687303715884105727, 170141183460469231731687303715884105727, 1);
// 2. cmp minInt, { minInt + 1, minInt/2, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpti2(-170141183460469231731687303715884105728, -170141183460469231731687303715884105727, 0);
try test__cmpti2(-170141183460469231731687303715884105728, -85070591730234615865843651857942052864, 0);
try test__cmpti2(-170141183460469231731687303715884105728, -1, 0);
try test__cmpti2(-170141183460469231731687303715884105728, 0, 0);
try test__cmpti2(-170141183460469231731687303715884105728, 1, 0);
try test__cmpti2(-170141183460469231731687303715884105728, 85070591730234615865843651857942052863, 0);
try test__cmpti2(-170141183460469231731687303715884105728, 170141183460469231731687303715884105726, 0);
try test__cmpti2(-170141183460469231731687303715884105728, 170141183460469231731687303715884105727, 0);
// 3. cmp minInt+1, {minInt, minInt/2, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpti2(-170141183460469231731687303715884105727, -170141183460469231731687303715884105728, 2);
try test__cmpti2(-170141183460469231731687303715884105727, -85070591730234615865843651857942052864, 0);
try test__cmpti2(-170141183460469231731687303715884105727, -1, 0);
try test__cmpti2(-170141183460469231731687303715884105727, 0, 0);
try test__cmpti2(-170141183460469231731687303715884105727, 1, 0);
try test__cmpti2(-170141183460469231731687303715884105727, 85070591730234615865843651857942052863, 0);
try test__cmpti2(-170141183460469231731687303715884105727, 170141183460469231731687303715884105726, 0);
try test__cmpti2(-170141183460469231731687303715884105727, 170141183460469231731687303715884105727, 0);
// 4. cmp minInt/2, {minInt, minInt + 1, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpti2(-85070591730234615865843651857942052864, -170141183460469231731687303715884105728, 2);
try test__cmpti2(-85070591730234615865843651857942052864, -170141183460469231731687303715884105727, 2);
try test__cmpti2(-85070591730234615865843651857942052864, -1, 0);
try test__cmpti2(-85070591730234615865843651857942052864, 0, 0);
try test__cmpti2(-85070591730234615865843651857942052864, 1, 0);
try test__cmpti2(-85070591730234615865843651857942052864, 85070591730234615865843651857942052863, 0);
try test__cmpti2(-85070591730234615865843651857942052864, 170141183460469231731687303715884105726, 0);
try test__cmpti2(-85070591730234615865843651857942052864, 170141183460469231731687303715884105727, 0);
// 5. cmp -1, {minInt, minInt + 1, minInt/2, 0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpti2(-1, -170141183460469231731687303715884105728, 2);
try test__cmpti2(-1, -170141183460469231731687303715884105727, 2);
try test__cmpti2(-1, -85070591730234615865843651857942052864, 2);
try test__cmpti2(-1, 0, 0);
try test__cmpti2(-1, 1, 0);
try test__cmpti2(-1, 85070591730234615865843651857942052863, 0);
try test__cmpti2(-1, 170141183460469231731687303715884105726, 0);
try test__cmpti2(-1, 170141183460469231731687303715884105727, 0);
// 6. cmp 0, {minInt, minInt + 1, minInt/2, -1, 1, maxInt/2, maxInt-1, maxInt}
try test__cmpti2(0, -170141183460469231731687303715884105728, 2);
try test__cmpti2(0, -170141183460469231731687303715884105727, 2);
try test__cmpti2(0, -85070591730234615865843651857942052864, 2);
try test__cmpti2(0, -1, 2);
try test__cmpti2(0, 1, 0);
try test__cmpti2(0, 85070591730234615865843651857942052863, 0);
try test__cmpti2(0, 170141183460469231731687303715884105726, 0);
try test__cmpti2(0, 170141183460469231731687303715884105727, 0);
// 7. cmp 1, {minInt, minInt + 1, minInt/2, -1,0, maxInt/2, maxInt-1, maxInt}
try test__cmpti2(1, -170141183460469231731687303715884105728, 2);
try test__cmpti2(1, -170141183460469231731687303715884105727, 2);
try test__cmpti2(1, -85070591730234615865843651857942052864, 2);
try test__cmpti2(1, -1, 2);
try test__cmpti2(1, 0, 2);
try test__cmpti2(1, 85070591730234615865843651857942052863, 0);
try test__cmpti2(1, 170141183460469231731687303715884105726, 0);
try test__cmpti2(1, 170141183460469231731687303715884105727, 0);
// 8. cmp maxInt/2, {minInt, minInt + 1, minInt/2, -1,0,1, maxInt-1, maxInt}
try test__cmpti2(85070591730234615865843651857942052863, -170141183460469231731687303715884105728, 2);
try test__cmpti2(85070591730234615865843651857942052863, -170141183460469231731687303715884105727, 2);
try test__cmpti2(85070591730234615865843651857942052863, -85070591730234615865843651857942052864, 2);
try test__cmpti2(85070591730234615865843651857942052863, -1, 2);
try test__cmpti2(85070591730234615865843651857942052863, 0, 2);
try test__cmpti2(85070591730234615865843651857942052863, 1, 2);
try test__cmpti2(85070591730234615865843651857942052863, 170141183460469231731687303715884105726, 0);
try test__cmpti2(85070591730234615865843651857942052863, 170141183460469231731687303715884105727, 0);
// 9. cmp maxInt-1, {minInt, minInt + 1, minInt/2, -1,0,1, maxInt/2, maxInt}
try test__cmpti2(170141183460469231731687303715884105726, -170141183460469231731687303715884105728, 2);
try test__cmpti2(170141183460469231731687303715884105726, -170141183460469231731687303715884105727, 2);
try test__cmpti2(170141183460469231731687303715884105726, -85070591730234615865843651857942052864, 2);
try test__cmpti2(170141183460469231731687303715884105726, -1, 2);
try test__cmpti2(170141183460469231731687303715884105726, 0, 2);
try test__cmpti2(170141183460469231731687303715884105726, 1, 2);
try test__cmpti2(170141183460469231731687303715884105726, 85070591730234615865843651857942052863, 2);
try test__cmpti2(170141183460469231731687303715884105726, 170141183460469231731687303715884105727, 0);
// 10.cmp maxInt, {minInt, minInt + 1, minInt/2, -1,0,1, maxInt/2, maxInt-1, }
try test__cmpti2(170141183460469231731687303715884105727, -170141183460469231731687303715884105728, 2);
try test__cmpti2(170141183460469231731687303715884105727, -170141183460469231731687303715884105727, 2);
try test__cmpti2(170141183460469231731687303715884105727, -85070591730234615865843651857942052864, 2);
try test__cmpti2(170141183460469231731687303715884105727, -1, 2);
try test__cmpti2(170141183460469231731687303715884105727, 0, 2);
try test__cmpti2(170141183460469231731687303715884105727, 1, 2);
try test__cmpti2(170141183460469231731687303715884105727, 85070591730234615865843651857942052863, 2);
try test__cmpti2(170141183460469231731687303715884105727, 170141183460469231731687303715884105726, 2);
}

Some files were not shown because too many files have changed in this diff Show More