99 Commits

Author SHA1 Message Date
Andrew Kelley
12828c09d6 Release 0.8.1 2021-09-06 19:41:54 -07:00
Sebastian Ullrich
c72f584218 libunwind: fix unwinding through libunwind stack frames
Fixes #9591
2021-09-03 10:19:01 -07:00
Andrew Kelley
3617615e2d CI: update Linux and macOS tarballs to LLVM 12.0.1 2021-09-03 10:18:53 -07:00
Philip Åkesson
b3a4074358 std: Use truncating cast in WIFSTOPPED for Linux, FreeBSD and DragonFly
The intermediate value can be larger than an u16, so @truncate is needed
to match the behavior of musl.
2021-09-03 10:18:28 -07:00
Andrew Kelley
46f93807aa fix merge conflicts for this branch 2021-09-01 17:01:35 -07:00
Philipp Lühmann
5356151172 fix typo 2021-08-31 13:45:04 -07:00
Andrew Kelley
f7e08ea780 re-enable all the MIPS tests
LLVM 12.0.1 fixed the regressions from LLVM 12.0.0.

Closes #8155
2021-08-31 13:44:57 -07:00
Frank Denis
a1d532752f Don't define valgrind_support on macOS (#9612)
Unfortunately, Valgrind for macOS has been broken for years,
and the Homebrew formula is only for Linux.
2021-08-31 13:44:23 -07:00
Zach Banks
2588451967 std/ArrayList: Allow ArrayList(u0) to be created
Enable creating ArrayList with zero-sized types.
This type still tracks length, but does not allocate
additional memory.
2021-08-31 13:41:05 -07:00
Meghan Denny
551971b5c3 stage1: add c_longdouble mapping for s390x 2021-08-31 13:40:01 -07:00
Takeshi Yoneda
5d08e2b5d8 Wasm,libc: fix wasm-ld failure in matching libc symbols.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-08-31 13:39:15 -07:00
fn ⌃ ⌥
d38bd443ef Use -isysroot on Mojave too 2021-08-31 13:38:52 -07:00
David May
c9ab6baf06 Docs fix array/pointer/slice type coercion section (#9392)
* removed deprecated coercion: [X]T => [] const T

* Fixed tests and added desc for first test

* Improved heading
2021-08-31 13:35:24 -07:00
Alex Rønne Petersen
a45c0c5033 zig: -rdynamic now implies -fdll-export-fns unless the latter is explicitly set.
Fixes #9340.
2021-08-31 13:32:27 -07:00
Michal Ziulek
7b9612a922 Fixed compile error: 'bMenu' needs to casted. (#9426) 2021-08-31 13:31:41 -07:00
Biolunar
1cddcf4484 linux stdlib: fix definition of RW flags (#9428) 2021-08-31 13:31:27 -07:00
Frank Denis
b8a77f3d59 std.crypto: handle the top bit in 25519.field.fromBytes64() (#9435)
The only known use case for this is the hash-to-curve operation where the top bit is always cleared.

But the function is public, so let's make it work as one would expect in the general case.

Also fix the comment by the way.
2021-08-31 13:31:06 -07:00
Tau
d4e22e3eb6 Correct hasUniqueRepresentation for vectors
Closes #9333.
2021-07-21 12:30:56 -07:00
Andrew Kelley
d99f55b7cf std.ArrayList: add missing assertion in appendSliceAssumeCapacity 2021-07-21 12:30:37 -07:00
Isaac Freund
2561b1eb67 langref: remove incorrect statement on c_void
c_void is *not* simply `const c_void = opaque{};`. It has unique
semantics as any pointer type may coerce to `*c_void` which is not true
for an arbitrary `*opaque{}`.
2021-07-21 12:27:21 -07:00
Adam C
c1e444b07c FIX typo in doc comment for std.math.hypot (#9413) 2021-07-21 12:25:52 -07:00
Ryan Liptak
84154b10a2 Add inotify_rm_watch definition to c/linux.zig
Also make inotify_add_watch's pathname marked as nul-terminated
2021-07-21 12:25:10 -07:00
Ryan Liptak
ba47e09373 Add NotDir as possible error for os.inotify_add_watch
Possible when "mask contains IN_ONLYDIR and pathname is not a directory."
2021-07-21 12:25:05 -07:00
leesongun
1063bf696e Fix bigint_shl (#9305) 2021-07-21 12:24:53 -07:00
Jonathan Marler
3b8c4f07a4 clarify @bitSizeOf behavior 2021-07-21 12:24:47 -07:00
Martin Wickham
3dcbd489eb Fix libc include directories for the MSVC target 2021-07-21 12:22:09 -07:00
Malcolm Still
5582d20f04 Add waitid syscall on linux (#9335) 2021-07-21 12:22:03 -07:00
Andrew Kelley
13aedf09d6 mingw-w64: add odbc32 and dbghelp def files
related: #9124
2021-07-21 12:21:58 -07:00
Martin Wickham
cd078c518f Fix argument forwarding to LLVM on Windows 2021-07-21 12:21:48 -07:00
leesongun
ceebcfa317 Fix unexpected truncation behavior with comptime_int larger than u64 range (#9303)
Closes #9299
2021-07-06 21:30:58 -07:00
Jacob G-W
b26ab39836 remove really weird debugging statement from stage1 2021-07-06 21:30:46 -07:00
Nulo
eac9bfaa01 Link to the GPA now that it's on upstream 2021-07-06 21:30:24 -07:00
Nulo
8a83143316 CODE_OF_CONDUCT: change Freenode to Libera.chat 2021-07-06 21:30:15 -07:00
Andrew Kelley
3ef9bd5879 stage2: add the zig version to AstGen cache hash
This solves the problem of different versions of Zig having different
binary representations of ZIR code.

closes #9290
2021-07-03 15:31:29 -07:00
Veikka Tuominen
f385522ab0 stage2: fix @asyncCall parameter count
Closes #9269
2021-07-03 15:29:52 -07:00
Nameless
de028d5130 std/os/uefi: fix packed struct bitfields 2021-07-03 15:28:57 -07:00
Andrew Kelley
390a4ded98 Merge pull request #9258 from ziglang/shared-cache-locking
Shared Cache Locking
2021-07-03 15:28:29 -07:00
Andrew Kelley
b0be0c77d8 Merge pull request #9148 from marler8997/windowsChildOutput
finish ChildProcess collectOutputWindows
2021-07-03 15:25:22 -07:00
xackus
440da6bfad mark tsan as linguist-vendored 2021-07-03 15:24:28 -07:00
Jacob G-W
b7fe0db9d2 langref: make @setRuntimeSafety more correct 2021-07-03 15:24:18 -07:00
Andrew Kelley
d59fc1ac04 stage1: @shuffle type and mask params in comptime scope 2021-07-03 15:22:53 -07:00
Roman Frołow
9349c9c4b1 Docs clarification: local static variable (#8381) 2021-07-03 15:22:21 -07:00
Jacob G-W
6caa77ea52 docs: top level global assembly -> container level 2021-07-03 15:22:17 -07:00
Andrew Kelley
caddd7eb18 std.crypto.p256: fix neg function compile error
There was a typo here and the neg function referenced a non-existent
variable.
2021-07-03 15:19:50 -07:00
Andrew Kelley
2b6727c98f std.os.linux.bpf: fix incorrect usage of unexpectedErrno 2021-07-03 15:19:50 -07:00
Andrew Kelley
5ef70b8b87 mips: fix syscall_pipe
Previously the fd parameter was ignored and so the result would not get
populated. Now it passes the fd pointer to the inline assembly so that
the results can be observed.
2021-07-03 15:19:50 -07:00
Isaac Freund
e75dfbcb3f std/build: add --sysroot general option 2021-06-26 12:51:49 +02:00
Isaac Freund
16228e87d6 stage2: add --sysroot link option
This feature is necessary for cross-compiling code that dynamically
links system libraries, at least with the current feature set of lld.
2021-06-26 12:49:08 +02:00
Isaac Freund
3e4f3a1924 zig build: add --libc general option
This new option sets a default libc paths file to be used for all
LibExeObjSteps. Setting LibExeObjStep.libc_file overrides this default.

This is required to allow users to cross compile projects linking system
libraries without needing to patch the build.zig.
2021-06-26 12:41:05 +02:00
mason1920
939408289c Bring your own MAX_PATH_BYTES
Previous to #7082, users could overwrite PATH_MAX in the root file to support std.os.toPosixPath, permitting the "bring your own operating system" layer to implement the POSIX API for opening files. Unfortunately that is no longer the case.

This commit intends to fix what is arguably a regression from 0.7 in a way that doesn't break any code targeting 0.8.0, making it suitable to be included in a 0.8 patch release.
However in a future release that permits breaking changes, I am of the opinion that it would be beneficial to overwrite the value, even for "supported" operating systems. Same for all the other POSIX/BYOOS functions and values. However this is beyond the scope of this commit. Further discussion of this will be made into an issue in due time.
2021-06-21 16:18:59 -07:00
Andrew Kelley
d0575310dc Merge pull request #9168 from LemonBoy/fix-pie
std: Fix PIE startup sequence
2021-06-20 17:03:50 -07:00
LemonBoy
b72d55ea5f std: Make copy_file_range checks run at compile-time
* Avoid emitting the copy_file_range symbol at all to prevent link-time
  errors.
* Fix a bug in the check logic, the has_copy_file_range_syscall was
  set to the wrong value in case of ENOSYS
* If link_libc is true don't fall-back to the raw syscall approach,
  there's no policy about what to do in this case but let's follow what
  the other impls do.

Fixes #9146
2021-06-20 16:54:39 -07:00
pithlessly
c7dd3cc535 stage2 sema: change impl of @setCold to use zirSetCold (typo?) 2021-06-20 16:37:55 -07:00
Michael Dusan
96b77e030f macho: LC_RPATH: reserve byte for null-terminator 2021-06-20 16:36:27 -07:00
hadroncfy
cf6e2d318a HashMap.getOrPutAssumeCapacityAdapted should set key to undefined (#9138)
* std.hash_map.HashMap: getOrPutAssumeCapacityAdapted should set key to undefined

* add test for std.hash_map.HashMap.getOrPutAdapted
2021-06-20 16:26:01 -07:00
Andrew Kelley
1fe0142d1f AstGen: properly generate errdefer expressions when returning
`return` statements use a new function `nodeMayEvalToError` which does
some basic checks on the AST node to return never, always, or maybe.

Depending on this result, AstGen skips the errdefers, always includes
the errdefers, or emits a conditional branch to check whether the return
value is an error that Sema will have to evaluate.

Closes #8821
Unblocks #9047
2021-06-20 16:25:52 -07:00
LemonBoy
76102ea41f stage1: Store the specified code model in the LLVM module
This is needed for LTO builds to pick up the correct module.

Closes #9132
2021-06-20 16:25:22 -07:00
Andrew Kelley
74ca811a66 Merge pull request #9117 from greenfork/unify-compiler-error-printing
stage2: Unify compiler error printing
2021-06-17 20:28:54 -07:00
Vincent Rischmann
721ec8fa53 zig cc: improve linker args parsing
Handle linker args joined with a = like -Wl,-rpath=foo

Update existing args --major-os-version, --minor-os-version,
--major-subsystem-version and --minor-subsytem-version to work with the
new parsing.

Also handle -Wl,--script in addition to -Wl,-T
2021-06-17 20:28:37 -07:00
Andrew Kelley
dc392f49f8 stage1: fix zig0 help message
closes #9140
2021-06-17 20:28:37 -07:00
d18g
71ec89383b Fix lakemont CpuModel (#9099)
Lakemont has no x86, no MMX, no SSE and no way of handling any fp-math. In theory LLVM is able to implicitly use the soft-float emulation library calls to legalize any such operation but, given Zig's use of many non-standard features, sometimes we hit a weak spot in the X86 codegen backend.

Consider this as a work-around for this LLVM problem, fixing the problem in LLVM is not so high in my todo list as the target is pretty niche and Intel axed it in '19.

(Commit message by @LemonBoy)
2021-06-17 20:28:37 -07:00
Michael Dusan
4adbdcb587 netbsd: add more std.os.bits 2021-06-17 20:28:37 -07:00
Michael Dusan
162b92c93e netbsd: add args to limit number of PT_LOAD segs
NetBSD expects 2 PT_LOAD segments in a shared object, otherwise
ld.elf_so fails to load, emitting a general "not found" error.

Workaround issue by adding args `--no-rosegment` and `-znorelro`.

see #9109
2021-06-17 20:28:37 -07:00
Andrew Kelley
8be29674a9 fix RISC-V assembly CPU features
Previously, Zig did not properly communicate the target CPU features for
RISC-V to clang assembler, because Clang has a different way to pass CPU
features for C code and for assembly code. This commit makes Zig pass a
RISC-V -march flag in order to communicate CPU features to Clang when
compiling assembly files.
2021-06-17 20:28:37 -07:00
Björn Linse
52ead255a2 std: don't reference non-existant ComptimeStringHashMap type 2021-06-15 13:32:14 -07:00
Andrew Kelley
6f180131a5 ci: azure: update to newer msys2 release 2021-06-14 12:16:54 -07:00
Isaac Freund
4453f6a5ce std: fix auto hash of tagged union with void field 2021-06-14 12:16:36 -07:00
viri
7f6e7e3e5d std.windows: fix OVERLAPPED, add OVERLAPPED_ENTRY 2021-06-14 12:14:46 -07:00
LemonBoy
5c9eb94a2b std: Fix complex ldexp implementation
Two bugs in the implementation ported from musl made all the complex
functions relying on ldexp return incorrect results in some cases.

Spotted in #9047
2021-06-14 12:13:53 -07:00
Andrew Kelley
9c1e7de6c6 zig cc: recognize more pie flags
This is a bug fix.
2021-06-14 12:13:03 -07:00
codic12
54229fec33 c.zig: fix waitpid() definition 2021-06-11 14:50:48 -07:00
Andrew Kelley
264969a8c3 better awareness of unwind tables
* stage1 backend allows configuring the uwtables function attr
   via a flag rather than its own logic.
 * stage2 defaults to enabling uwtable attr when
   linking libunwind, or always on windows
 * stage2 makes link_eh_frame_hdr true automatically if uwtable
   attr is set to be on for zig functions
 * CLI: add -funwind-tables and -fno-unwind-tables to allow the user to
   override the defaults.
 * hook it up to `zig cc`

closes #9046
2021-06-11 10:31:48 -07:00
Veikka Tuominen
e3a74697f0 Merge pull request #8330 from kivikakk/single-limb-bigint-overflow
bigint add failures with aliasing
2021-06-11 10:31:08 -07:00
LemonBoy
a913311f3c std: Fix tanh for negative inputs
It turns out the code was not ported correctly from C and produced wrong
results for negative input values. As a bonus fix the NaN codepath by
adding yet another missing piece of code.

Spotted in #9047
2021-06-11 10:30:07 -07:00
Andrew Kelley
ec4c60c481 zig fmt 2021-06-11 10:28:42 -07:00
LemonBoy
29386f0d30 stage1: Fix handling of C ABI parameters split in multiple regs
Take into account the increased number of parameters when flattening a
structure into one or more SSE registers.

Fixes #9061
2021-06-10 10:22:08 -07:00
Frank Denis
80e1797faf aes 128-bit key expansion test - properly test the inverse round keys (#9065) 2021-06-10 10:22:03 -07:00
Jakub Konka
f677c24740 Re-enable multiple wasm32 vector tests
Fixes #5339
2021-06-10 10:21:13 -07:00
Andrew Kelley
6afdc3cc79 CLI: remove --verbose-ast and --verbose-tokenize
closes #9034

These options were listed under the
"Debug Options (Zig Compiler Development)" heading. Anything in this
section should be considered unstable and can be modified at any time
at any developer's discretion.
2021-06-10 10:20:59 -07:00
Andrew Kelley
c230258d9b native libc detection: respect spaces in CC env var
Zig has detection for when it is accidentally being called recursively
when trying to find the native libc installation. However it was not
working, resulting in a cryptic failure, because zig tried to execute
a command which had spaces in it rather than tokenizing it.

This improves the user experience of `zig cc` for systems that Zig
does not support cross-compiling for.

Closes #8960
2021-06-10 10:20:52 -07:00
Andrew Kelley
2d0dff6498 langref: link to 0.7.1 not 0.7.0 for the previous docs 2021-06-10 10:20:27 -07:00
Andrew Kelley
060cb0f277 langref: remove paragraph that mentions IRC
I want the language reference to be divorced from any particular
community. Also remove the call to action since the docs are
known to be incomplete and are not the current focus of the project.

Closes #9055
2021-06-10 10:20:16 -07:00
Filippo Casarin
05380a11a4 std.math.sqrt_int: fixed odd size integers types 2021-06-10 10:20:09 -07:00
viri
4a3ac16711 std.Progress: use *W functions on windows
Closes #534.
See: https://source.winehq.org/git/wine.git/blob/refs/heads/stable:/dlls/kernelbase/console.c#l520
2021-06-10 10:19:37 -07:00
Jakub Konka
51076f4e1d libc,macos: update and add missing libc headers 2021-06-10 10:10:24 -07:00
Matthew Borkowski
503b85a1b0 stage1: make @truncate to an integer type of different sign an error at comptime too 2021-06-08 12:27:22 -07:00
Dustin Taylor
0c25ff81a3 Limit Fixed Buffer Stream seekTo (#9023) 2021-06-08 12:27:22 -07:00
Matthew Borkowski
39c80942e7 stage1: fix render_const_value for printing const optional pointers 2021-06-08 22:24:55 +03:00
Andrew Kelley
bfc85211bb link: windows: look for more DLL import lib path names
When linking with -lfoo syntax, this indicates to Zig that the
dependency should either be provided by Zig, or it should be dynamically
provided by the system.

For windows-gnu targets, the search path was "foo.lib". Now it
additionally looks for "libfoo.dll.a".

Closes #7799
2021-06-07 22:31:32 -07:00
LemonBoy
7ca86936ca std: Add helpers to safely align pointers
Add two helpers to ensure people won't ignore some edge cases such as
pointers overflowing the address space.

Also fix #8924 to some degree, the amount of unchecked alignForward is
still scary.

Revert "tests: disable i386-linux-gnu -lc target due to CI failures"

This reverts commit 97a2f4e7ae.
2021-06-06 18:07:47 -07:00
LemonBoy
5c765b2ec4 std: Fix some BPF fn definitions
Cros-checked with bpf.h of kernel 5.12.9.
2021-06-06 18:02:52 -07:00
LemonBoy
a745a17aa9 build: Avoid using undefined variables
Closes #9013
Closes #8928
Closes #7991
2021-06-06 18:01:52 -07:00
LemonBoy
2681e1ffe0 stage1: Apply the same set of fn attributes everywhere
Make sure to propagate the target-specific attributes to internal
functions too.

Closes #8965
2021-06-06 18:01:47 -07:00
Sebastien Marie
27f6db66e3 openbsd: adjust dynamic linker path (#9010)
the dynamic linker on OpenBSD is at /usr/libexec/ld.so (and not /libexec/ld.so)
2021-06-06 18:01:40 -07:00
Michael Dusan
6d6ba1e998 test: re-enable dragonfly tests
Tests with LLVM assertions enabled are no longer failing.

closes #3563
2021-06-05 19:54:45 -07:00
Nicolas
c8ee445c86 Add zig_llvm-ar.cpp in build.zig
This was added in 0afb5b2ec6 8 days ago, but it seems it was only added in the cmake files and not build.zig
2021-06-05 19:54:33 -07:00
LemonBoy
072c3202c3 std: Better handing of POLLHUP in ChildProcess (#8988)
* std: Better handing of POLLHUP in ChildProcess

Upon hitting the EOF condition there are two main differences between
how Linux and the *BSD-derived systems behave: the former sets POLLHUP
and POLLIN and, after reading any residual data, only POLLHUP remains
set. The latter signal the EOF condition by setting both flags thus
requiring some extra checks to determine if the stream is "done".

DragonFly workaround/hack for POLLHUP is no longer required.

Closes #8969
2021-06-05 19:54:26 -07:00
LemonBoy
07852a4bc8 compiler-rt: Fix __floatunsitf signature
The function transforms an unsigned integer into a f128.

Closes #8996
2021-06-05 10:35:05 -07:00
Andrew Kelley
ae1871a028 start the 0.8.1 release branch 2021-06-04 11:30:34 -07:00
7088 changed files with 475973 additions and 888639 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:

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

View File

@@ -12,26 +12,10 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
if(NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/stage3" CACHE STRING
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE STRING
"Directory to install zig to" FORCE)
endif()
# CMake recognizes the CMAKE_PREFIX_PATH environment variable for some things,
# and also the CMAKE_PREFIX_PATH cache variable for other things. However, it
# does not relate these two things, i.e. if the environment variable is set,
# CMake does not populate the cache variable in a corresponding manner. Some
# package systems, such as Homebrew, set the environment variable but not the
# cache variable. Furthermore, the environment variable follows the system path
# separator, such as ':' on POSIX and ';' on Windows, but the cache variable
# follows CMake's array behavior, i.e. always ';' for a separator.
list(APPEND ZIG_CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
if(WIN32)
list(APPEND ZIG_CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
else()
string(REGEX REPLACE ":" ";" ZIG_CMAKE_PREFIX_PATH_STRING "$ENV{CMAKE_PREFIX_PATH}")
list(APPEND ZIG_CMAKE_PREFIX_PATH "${ZIG_CMAKE_PREFIX_PATH_STRING}")
endif()
set(CMAKE_USER_MAKE_RULES_OVERRIDE
${CMAKE_CURRENT_SOURCE_DIR}/cmake/c_flag_overrides.cmake)
set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX
@@ -41,13 +25,13 @@ project(zig C CXX)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(ZIG_VERSION_MAJOR 0)
set(ZIG_VERSION_MINOR 10)
set(ZIG_VERSION_PATCH 0)
set(ZIG_VERSION_MINOR 8)
set(ZIG_VERSION_PATCH 1)
set(ZIG_VERSION "" CACHE STRING "Override Zig version string. Default is to find out with git.")
if("${ZIG_VERSION}" STREQUAL "")
set(ZIG_VERSION "${ZIG_VERSION_MAJOR}.${ZIG_VERSION_MINOR}.${ZIG_VERSION_PATCH}")
find_program(GIT_EXE NAMES git NAMES_PER_DIR)
find_program(GIT_EXE NAMES git)
if(GIT_EXE)
execute_process(
COMMAND ${GIT_EXE} -C ${CMAKE_SOURCE_DIR} describe --match *.*.* --tags
@@ -79,22 +63,12 @@ if("${ZIG_VERSION}" STREQUAL "")
endif()
endif()
endif()
message(STATUS "Configuring zig version ${ZIG_VERSION}")
set(ZIG_NO_LIB off CACHE BOOL
"Disable copying lib/ files to install prefix during the build phase")
set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL "Deprecated. Use ZIG_NO_LIB")
if(ZIG_SKIP_INSTALL_LIB_FILES)
message(WARNING "ZIG_SKIP_INSTALL_LIB_FILES is deprecated. Use ZIG_NO_LIB instead.")
set(ZIG_NO_LIB ON)
endif()
message("Configuring zig version ${ZIG_VERSION}")
set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
set(ZIG_SHARED_LLVM off CACHE BOOL "Prefer linking against shared LLVM libraries")
set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
set(ZIG_STATIC_ZLIB off CACHE BOOL "Prefer linking against static zlib")
set(ZIG_STATIC_ZSTD off CACHE BOOL "Prefer linking against static zstd")
set(ZIG_PREFER_CLANG_CPP_DYLIB off CACHE BOOL "Try to link against -lclang-cpp")
set(ZIG_USE_CCACHE off CACHE BOOL "Use ccache if available")
if(CCACHE_PROGRAM AND ZIG_USE_CCACHE)
@@ -104,11 +78,6 @@ endif()
if(ZIG_STATIC)
set(ZIG_STATIC_LLVM ON)
set(ZIG_STATIC_ZLIB ON)
set(ZIG_STATIC_ZSTD ON)
endif()
if (ZIG_SHARED_LLVM AND ZIG_STATIC_LLVM)
message(SEND_ERROR "-DZIG_SHARED_LLVM and -DZIG_STATIC_LLVM cannot both be enabled simultaneously")
endif()
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_LIB_DIR_ESCAPED "${ZIG_LIBC_LIB_DIR}")
@@ -122,12 +91,7 @@ set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries
set(ZIG_EXECUTABLE "" CACHE STRING "(when cross compiling) path to already-built zig binary")
set(ZIG_SINGLE_THREADED off CACHE BOOL "limit the zig compiler to use only 1 thread")
set(ZIG_OMIT_STAGE2 off CACHE BOOL "omit the stage2 backend from stage1")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(ZIG_ENABLE_LOGGING ON CACHE BOOL "enable logging")
else()
set(ZIG_ENABLE_LOGGING OFF CACHE BOOL "enable logging")
endif()
set(ZIG_ENABLE_LOGGING off CACHE BOOL "enable logging")
if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")
set(ZIG_USE_LLVM_CONFIG ON CACHE BOOL "use llvm-config to find LLVM libraries")
@@ -135,28 +99,19 @@ else()
set(ZIG_USE_LLVM_CONFIG OFF CACHE BOOL "use llvm-config to find LLVM libraries")
endif()
find_package(llvm 15)
find_package(clang 15)
find_package(lld 15)
find_package(llvm)
find_package(clang)
find_package(lld)
if(ZIG_STATIC_ZLIB)
list(REMOVE_ITEM LLVM_LIBRARIES "-lz")
find_library(ZLIB NAMES libz.a libzlibstatic.a z zlib libz NAMES_PER_DIR)
find_library(ZLIB NAMES libz.a libzlibstatic.a z zlib libz)
list(APPEND LLVM_LIBRARIES "${ZLIB}")
endif()
if(ZIG_STATIC_ZSTD)
list(REMOVE_ITEM LLVM_LIBRARIES "-lzstd")
find_library(ZSTD NAMES libzstd.a libzstdstatic.a zstd NAMES_PER_DIR)
list(APPEND LLVM_LIBRARIES "${ZSTD}")
endif()
if(APPLE AND ZIG_STATIC)
list(REMOVE_ITEM LLVM_LIBRARIES "-lcurses")
find_library(CURSES NAMES libcurses.a libncurses.a NAMES_PER_DIR
PATHS
/usr/local/opt/ncurses/lib
/opt/homebrew/opt/ncurses/lib)
find_library(CURSES NAMES libcurses.a curses libcurses libncurses.a ncurses libncurses)
list(APPEND LLVM_LIBRARIES "${CURSES}")
endif()
@@ -179,19 +134,15 @@ include_directories(${CLANG_INCLUDE_DIRS})
# No patches have been applied to SoftFloat-3e
set(EMBEDDED_SOFTFLOAT_SOURCES
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/f128M_isSignalingNaN.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/extF80M_isSignalingNaN.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_commonNaNToF128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_commonNaNToExtF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_commonNaNToF16UI.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_commonNaNToF32UI.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_commonNaNToF64UI.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_f128MToCommonNaN.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_extF80MToCommonNaN.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_f16UIToCommonNaN.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_f32UIToCommonNaN.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_f64UIToCommonNaN.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_propagateNaNF128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_propagateNaNExtF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/s_propagateNaNF16UI.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/8086/softfloat_raiseFlags.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_add.c"
@@ -211,7 +162,6 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_f16.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_f32.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_f64.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_extF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_i32.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_i32_r_minMag.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_i64.c"
@@ -220,20 +170,6 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_ui32_r_minMag.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_ui64.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_to_ui64_r_minMag.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_add.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_div.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_eq.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_le.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_lt.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_mul.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_rem.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_roundToInt.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_sqrt.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_sub.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_to_f16.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_to_f32.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_to_f64.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/extF80M_to_f128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_add.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_div.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_eq.c"
@@ -244,12 +180,9 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_roundToInt.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_sqrt.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_sub.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_to_extF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_to_f128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_to_f64.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f32_to_extF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f32_to_f128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f64_to_extF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f64_to_f128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f64_to_f16.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/i32_to_f128M.c"
@@ -257,7 +190,6 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addCarryM.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addComplCarryM.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addF128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addExtF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addM.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addMagsF16.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addMagsF32.c"
@@ -268,14 +200,12 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_approxRecip_1Ks.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_compare128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_compare96M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_compareNonnormExtF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_countLeadingZeros16.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_countLeadingZeros32.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_countLeadingZeros64.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_countLeadingZeros8.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_eq128.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_invalidF128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_invalidExtF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_isNaNF128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_le128.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_lt128.c"
@@ -286,9 +216,7 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_mulAddF32.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_mulAddF64.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_negXM.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normExtF80SigM.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normRoundPackMToF128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normRoundPackMToExtF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normRoundPackToF16.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normRoundPackToF32.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_normRoundPackToF64.c"
@@ -299,7 +227,6 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_remStepMBy32.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundMToI64.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundMToUI64.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundPackMToExtF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundPackMToF128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundPackToF16.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_roundPackToF32.c"
@@ -328,25 +255,16 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_subMagsF32.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_subMagsF64.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_tryPropagateNaNF128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_tryPropagateNaNExtF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f16_mulAdd.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f128M_mulAdd.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/softfloat_state.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/ui32_to_f128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/ui64_to_f128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/ui32_to_extF80M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/ui64_to_extF80M.c"
)
add_library(embedded_softfloat STATIC ${EMBEDDED_SOFTFLOAT_SOURCES})
if(MSVC)
set(SOFTFLOAT_CFLAGS "/w")
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(SOFTFLOAT_CFLAGS "${SOFTFLOAT_CFLAGS} /O2")
endif()
set_target_properties(embedded_softfloat PROPERTIES
COMPILE_FLAGS ${SOFTFLOAT_CFLAGS}
COMPILE_FLAGS "/w /O2"
)
else()
set_target_properties(embedded_softfloat PROPERTIES
@@ -372,7 +290,7 @@ set(ZIG_CONFIG_H_OUT "${CMAKE_BINARY_DIR}/config.h")
set(ZIG_CONFIG_ZIG_OUT "${CMAKE_BINARY_DIR}/config.zig")
# This is our shim which will be replaced by stage1.zig.
set(ZIG1_SOURCES
set(ZIG0_SOURCES
"${CMAKE_SOURCE_DIR}/src/stage1/zig0.cpp"
)
@@ -383,6 +301,7 @@ set(STAGE1_SOURCES
"${CMAKE_SOURCE_DIR}/src/stage1/bigint.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/buffer.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/codegen.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/dump_analysis.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/errmsg.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/error.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/heap.cpp"
@@ -412,9 +331,9 @@ set(ZIG_CPP_SOURCES
# https://github.com/ziglang/zig/issues/6363
"${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp"
)
# Needed because we use cmake, not the zig build system, to build zig2.o.
# Needed because we use cmake, not the zig build system, to build zig1.o.
# This list is generated by building zig and then clearing the zig-cache directory,
# then manually running the build-obj command (see BUILD_ZIG2_ARGS), and then looking
# then manually running the build-obj command (see BUILD_ZIG1_ARGS), and then looking
# in the zig-cache directory for the compiler-generated list of zig file dependencies.
set(ZIG_STAGE2_SOURCES
"${ZIG_CONFIG_ZIG_OUT}"
@@ -439,12 +358,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/crypto/siphash.zig"
"${CMAKE_SOURCE_DIR}/lib/std/debug.zig"
"${CMAKE_SOURCE_DIR}/lib/std/dwarf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/dwarf/AT.zig"
"${CMAKE_SOURCE_DIR}/lib/std/dwarf/ATE.zig"
"${CMAKE_SOURCE_DIR}/lib/std/dwarf/FORM.zig"
"${CMAKE_SOURCE_DIR}/lib/std/dwarf/LANG.zig"
"${CMAKE_SOURCE_DIR}/lib/std/dwarf/OP.zig"
"${CMAKE_SOURCE_DIR}/lib/std/dwarf/TAG.zig"
"${CMAKE_SOURCE_DIR}/lib/std/dwarf_bits.zig"
"${CMAKE_SOURCE_DIR}/lib/std/elf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/event.zig"
"${CMAKE_SOURCE_DIR}/lib/std/event/batch.zig"
@@ -486,8 +400,9 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/math.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/big.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/big/int.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/float.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/floor.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/frexp.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/inf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/isinf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/isnan.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/ln.zig"
@@ -504,15 +419,18 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/meta/trait.zig"
"${CMAKE_SOURCE_DIR}/lib/std/multi_array_list.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/darwin.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/errno/generic.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno-generic.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/netlink.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/prctl.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/securebits.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/x86_64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/io_uring.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/posix_spawn.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/windows.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/bits.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/ntstatus.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/win32error.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Progress.zig"
@@ -520,180 +438,68 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/process.zig"
"${CMAKE_SOURCE_DIR}/lib/std/rand.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sort.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/absv.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/absvdi2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/absvsi2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/absvti2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/adddf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/addf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/addo.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/addsf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/addtf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/addxf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/arm.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/atomics.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/aulldiv.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/aullrem.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/bswap.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/ceil.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/clear_cache.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/cmp.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/cmpdf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/cmpsf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/cmptf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/cmpxf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/common.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/comparef.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/cos.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/count0bits.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/divdf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/divsf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/divtf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/divti3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/divxf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/emutls.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/exp.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/exp2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/extenddftf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/extenddfxf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/extendf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/extendhfsf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/extendhftf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/extendhfxf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/extendsfdf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/extendsftf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/extendsfxf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/extendxftf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fabs.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixdfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixdfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixdfti.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixhfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixhfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixhfti.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixsfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixsfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixsfti.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixtfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixtfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixtfti.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunsdfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunsdfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunsdfti.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunshfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunshfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunshfti.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunssfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunssfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunssfti.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunstfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunstfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunstfti.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunsxfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunsxfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixunsxfti.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixxfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixxfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fixxfti.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/float_to_int.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatdidf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatdihf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatdisf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatditf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatdixf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatsidf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatsihf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatsisf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatsitf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatsixf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floattidf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floattihf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floattisf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floattitf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floattixf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatundidf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatundihf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatundisf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatunditf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatundixf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatunsidf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatunsihf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatunsisf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatunsitf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatunsixf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatuntidf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatuntihf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatuntisf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatuntitf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floatuntixf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/floor.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fma.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fmax.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fmin.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/fmod.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/gedf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/gesf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/getf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/gexf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/int.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/int_to_float.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/log.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/log10.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/log2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/modti3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/muldf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/muldi3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/mulf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/mulo.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/mulsf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/multf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/multi3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/mulxf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/negXi2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/negv.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/os_version_check.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/parity.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/popcount.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/rem_pio2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/rem_pio2_large.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/rem_pio2f.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/round.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/shift.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/sin.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/sincos.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/sqrt.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/stack_probe.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/subo.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/subsf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/subdf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/subtf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/subxf3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/negsf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/negdf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/negtf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/negxf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/tan.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/trig.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/trunc.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/truncdfhf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/truncdfsf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/truncf.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/truncsfhf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/trunctfdf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/trunctfhf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/trunctfsf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/trunctfxf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/truncxfdf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/truncxfhf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/truncxfsf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/udivmod.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/udivmodti4.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/udivti3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/umodti3.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/unorddf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/unordsf2.zig"
"${CMAKE_SOURCE_DIR}/lib/compiler_rt/unordtf2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/addXf3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/atomics.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/clear_cache.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/clzsi2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/compareXf2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divdf3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divsf3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divtf3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divti3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/extendXfYf2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixdfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixdfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixdfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixint.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixsfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixsfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixsfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixtfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixtfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixtfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixuint.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunsdfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunsdfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunsdfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunssfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunssfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunssfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunstfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunstfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunstfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatXisf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatdidf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatditf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatsiXf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floattidf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floattitf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatundidf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatundisf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatunditf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatunsidf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatunsisf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatunsitf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatuntidf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatuntisf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatuntitf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/int.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/modti3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/mulXf3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/muldi3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/mulodi4.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/muloti4.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/multi3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/negXf2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/popcountdi2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/shift.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/stack_probe.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/truncXfYf2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/udivmod.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/udivmodti4.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/udivti3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/umodti3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/start.zig"
"${CMAKE_SOURCE_DIR}/lib/std/std.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target.zig"
@@ -709,79 +515,50 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/target/powerpc.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/riscv.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/sparc.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/s390x.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/systemz.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/wasm.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/x86.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/Futex.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/AutoResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/Mutex.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/ResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/StaticResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/time.zig"
"${CMAKE_SOURCE_DIR}/lib/std/treap.zig"
"${CMAKE_SOURCE_DIR}/lib/std/unicode.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/Ast.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/CrossTarget.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/c_builtins.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/ast.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/cross_target.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/parse.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/string_literal.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/system.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/system/NativePaths.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/system/NativeTargetInfo.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/system/x86.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/tokenizer.zig"
"${CMAKE_SOURCE_DIR}/src/Air.zig"
"${CMAKE_SOURCE_DIR}/src/AstGen.zig"
"${CMAKE_SOURCE_DIR}/src/Cache.zig"
"${CMAKE_SOURCE_DIR}/src/Compilation.zig"
"${CMAKE_SOURCE_DIR}/src/DepTokenizer.zig"
"${CMAKE_SOURCE_DIR}/src/Liveness.zig"
"${CMAKE_SOURCE_DIR}/src/Module.zig"
"${CMAKE_SOURCE_DIR}/src/Package.zig"
"${CMAKE_SOURCE_DIR}/src/RangeSet.zig"
"${CMAKE_SOURCE_DIR}/src/Sema.zig"
"${CMAKE_SOURCE_DIR}/src/ThreadPool.zig"
"${CMAKE_SOURCE_DIR}/src/TypedValue.zig"
"${CMAKE_SOURCE_DIR}/src/WaitGroup.zig"
"${CMAKE_SOURCE_DIR}/src/Zir.zig"
"${CMAKE_SOURCE_DIR}/src/arch/aarch64/CodeGen.zig"
"${CMAKE_SOURCE_DIR}/src/arch/aarch64/Emit.zig"
"${CMAKE_SOURCE_DIR}/src/arch/aarch64/Mir.zig"
"${CMAKE_SOURCE_DIR}/src/arch/aarch64/bits.zig"
"${CMAKE_SOURCE_DIR}/src/arch/aarch64/abi.zig"
"${CMAKE_SOURCE_DIR}/src/arch/arm/CodeGen.zig"
"${CMAKE_SOURCE_DIR}/src/arch/arm/Emit.zig"
"${CMAKE_SOURCE_DIR}/src/arch/arm/Mir.zig"
"${CMAKE_SOURCE_DIR}/src/arch/arm/bits.zig"
"${CMAKE_SOURCE_DIR}/src/arch/arm/abi.zig"
"${CMAKE_SOURCE_DIR}/src/arch/riscv64/CodeGen.zig"
"${CMAKE_SOURCE_DIR}/src/arch/riscv64/Emit.zig"
"${CMAKE_SOURCE_DIR}/src/arch/riscv64/Mir.zig"
"${CMAKE_SOURCE_DIR}/src/arch/riscv64/bits.zig"
"${CMAKE_SOURCE_DIR}/src/arch/riscv64/abi.zig"
"${CMAKE_SOURCE_DIR}/src/arch/sparc64/CodeGen.zig"
"${CMAKE_SOURCE_DIR}/src/arch/sparc64/Emit.zig"
"${CMAKE_SOURCE_DIR}/src/arch/sparc64/Mir.zig"
"${CMAKE_SOURCE_DIR}/src/arch/sparc64/bits.zig"
"${CMAKE_SOURCE_DIR}/src/arch/sparc64/abi.zig"
"${CMAKE_SOURCE_DIR}/src/arch/wasm/CodeGen.zig"
"${CMAKE_SOURCE_DIR}/src/arch/wasm/Emit.zig"
"${CMAKE_SOURCE_DIR}/src/arch/wasm/Mir.zig"
"${CMAKE_SOURCE_DIR}/src/arch/x86_64/CodeGen.zig"
"${CMAKE_SOURCE_DIR}/src/arch/x86_64/Emit.zig"
"${CMAKE_SOURCE_DIR}/src/arch/x86_64/Mir.zig"
"${CMAKE_SOURCE_DIR}/src/arch/x86_64/bits.zig"
"${CMAKE_SOURCE_DIR}/src/arch/x86_64/abi.zig"
"${CMAKE_SOURCE_DIR}/src/AstGen.zig"
"${CMAKE_SOURCE_DIR}/src/clang.zig"
"${CMAKE_SOURCE_DIR}/src/clang_options.zig"
"${CMAKE_SOURCE_DIR}/src/clang_options_data.zig"
"${CMAKE_SOURCE_DIR}/src/codegen.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/aarch64.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/arm.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/c.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/llvm.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/llvm/bindings.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/riscv64.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/wasm.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/x86_64.zig"
"${CMAKE_SOURCE_DIR}/src/glibc.zig"
"${CMAKE_SOURCE_DIR}/src/introspect.zig"
"${CMAKE_SOURCE_DIR}/src/air.zig"
"${CMAKE_SOURCE_DIR}/src/libc_installation.zig"
"${CMAKE_SOURCE_DIR}/src/libcxx.zig"
"${CMAKE_SOURCE_DIR}/src/libtsan.zig"
@@ -789,42 +566,30 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/link.zig"
"${CMAKE_SOURCE_DIR}/src/link/C.zig"
"${CMAKE_SOURCE_DIR}/src/link/Coff.zig"
"${CMAKE_SOURCE_DIR}/src/link/Coff/Atom.zig"
"${CMAKE_SOURCE_DIR}/src/link/Coff/Object.zig"
"${CMAKE_SOURCE_DIR}/src/link/Coff/lld.zig"
"${CMAKE_SOURCE_DIR}/src/link/Elf.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Archive.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Atom.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/CodeSignature.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/DebugSymbols.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/DwarfInfo.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Dylib.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Object.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Symbol.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Trie.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/ZldAtom.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Zld.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/bind.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/dead_strip.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/thunks.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/zld.zig"
"${CMAKE_SOURCE_DIR}/src/link/Plan9.zig"
"${CMAKE_SOURCE_DIR}/src/link/Plan9/aout.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/commands.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/reloc.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/reloc/aarch64.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/reloc/x86_64.zig"
"${CMAKE_SOURCE_DIR}/src/link/Wasm.zig"
"${CMAKE_SOURCE_DIR}/src/link/C/zig.h"
"${CMAKE_SOURCE_DIR}/src/link/msdos-stub.bin"
"${CMAKE_SOURCE_DIR}/src/link/strtab.zig"
"${CMAKE_SOURCE_DIR}/src/link/tapi.zig"
"${CMAKE_SOURCE_DIR}/src/link/tapi/Tokenizer.zig"
"${CMAKE_SOURCE_DIR}/src/link/tapi/parse.zig"
"${CMAKE_SOURCE_DIR}/src/link/tapi/parse/test.zig"
"${CMAKE_SOURCE_DIR}/src/link/tapi/yaml.zig"
"${CMAKE_SOURCE_DIR}/src/liveness.zig"
"${CMAKE_SOURCE_DIR}/src/main.zig"
"${CMAKE_SOURCE_DIR}/src/mingw.zig"
"${CMAKE_SOURCE_DIR}/src/musl.zig"
"${CMAKE_SOURCE_DIR}/src/print_air.zig"
"${CMAKE_SOURCE_DIR}/src/print_env.zig"
"${CMAKE_SOURCE_DIR}/src/print_targets.zig"
"${CMAKE_SOURCE_DIR}/src/print_zir.zig"
"${CMAKE_SOURCE_DIR}/src/register_manager.zig"
"${CMAKE_SOURCE_DIR}/src/stage1.zig"
"${CMAKE_SOURCE_DIR}/src/target.zig"
"${CMAKE_SOURCE_DIR}/src/tracy.zig"
@@ -834,6 +599,8 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/value.zig"
"${CMAKE_SOURCE_DIR}/src/wasi_libc.zig"
"${CMAKE_SOURCE_DIR}/src/windows_sdk.zig"
"${CMAKE_SOURCE_DIR}/src/Zir.zig"
"${CMAKE_SOURCE_DIR}/src/Sema.zig"
)
if(MSVC)
@@ -911,9 +678,7 @@ else()
endif()
if(MSVC)
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(OPTIMIZED_C_FLAGS "/O2")
endif()
set(OPTIMIZED_C_FLAGS "/O2")
else(MSVC)
set(OPTIMIZED_C_FLAGS "-std=c99 -O3")
endif(MSVC)
@@ -963,9 +728,6 @@ add_library(opt_c_util STATIC ${OPTIMIZED_C_SOURCES})
set_target_properties(opt_c_util PROPERTIES
COMPILE_FLAGS "${OPTIMIZED_C_FLAGS}"
)
target_include_directories(opt_c_util PRIVATE
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e-prebuilt"
)
add_library(zigstage1 STATIC ${STAGE1_SOURCES})
set_target_properties(zigstage1 PROPERTIES
@@ -990,118 +752,110 @@ if(MSVC OR MINGW)
endif()
if("${ZIG_EXECUTABLE}" STREQUAL "")
add_executable(zig1 ${ZIG1_SOURCES})
set_target_properties(zig1 PROPERTIES
add_executable(zig0 ${ZIG0_SOURCES})
set_target_properties(zig0 PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
LINK_FLAGS ${EXE_LDFLAGS}
)
target_link_libraries(zig1 zigstage1)
target_link_libraries(zig0 zigstage1)
endif()
if(MSVC)
set(ZIG2_OBJECT "${CMAKE_BINARY_DIR}/zig2.obj")
set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.obj")
else()
set(ZIG2_OBJECT "${CMAKE_BINARY_DIR}/zig2.o")
set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.o")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(ZIG_RELEASE_ARG "")
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
set(ZIG_RELEASE_ARG -Drelease)
set(ZIG1_RELEASE_ARG "")
else()
set(ZIG_RELEASE_ARG -Drelease -Dstrip)
endif()
if(ZIG_NO_LIB)
set(ZIG_NO_LIB_ARG "-Dno-lib")
else()
set(ZIG_NO_LIB_ARG "")
set(ZIG1_RELEASE_ARG -OReleaseFast --strip)
endif()
if(ZIG_SINGLE_THREADED)
set(ZIG_SINGLE_THREADED_ARG "-fsingle-threaded")
set(ZIG1_SINGLE_THREADED_ARG "--single-threaded")
else()
set(ZIG_SINGLE_THREADED_ARG "")
endif()
if(ZIG_STATIC)
set(ZIG_STATIC_ARG "-Duse-zig-libcxx")
else()
set(ZIG_STATIC_ARG "")
set(ZIG1_SINGLE_THREADED_ARG "")
endif()
set(BUILD_ZIG2_ARGS
set(BUILD_ZIG1_ARGS
"src/stage1.zig"
--name zig2
--zig-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-femit-bin=${ZIG2_OBJECT}"
-fcompiler-rt
${ZIG_SINGLE_THREADED_ARG}
-target "${ZIG_TARGET_TRIPLE}"
-mcpu "${ZIG_TARGET_MCPU}"
"-mcpu=${ZIG_TARGET_MCPU}"
--name zig1
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-femit-bin=${ZIG1_OBJECT}"
"${ZIG1_RELEASE_ARG}"
"${ZIG1_SINGLE_THREADED_ARG}"
-lc
--pkg-begin build_options "${ZIG_CONFIG_ZIG_OUT}"
--pkg-end
--pkg-begin compiler_rt "${CMAKE_SOURCE_DIR}/lib/compiler_rt.zig"
--pkg-begin compiler_rt "${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt.zig"
--pkg-end
)
if("${ZIG_EXECUTABLE}" STREQUAL "")
add_custom_command(
OUTPUT "${ZIG2_OBJECT}"
COMMAND zig1 ${BUILD_ZIG2_ARGS}
DEPENDS zig1 "${ZIG_STAGE2_SOURCES}"
COMMENT STATUS "Building stage2 object ${ZIG2_OBJECT}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT "${ZIG1_OBJECT}"
COMMAND zig0 ${BUILD_ZIG1_ARGS}
DEPENDS zig0 "${ZIG_STAGE2_SOURCES}"
COMMENT STATUS "Building self-hosted component ${ZIG1_OBJECT}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
set(ZIG_EXECUTABLE "${zig_BINARY_DIR}/zig")
if (WIN32)
set(ZIG_EXECUTABLE "${CMAKE_BINARY_DIR}/zig2.exe")
else()
set(ZIG_EXECUTABLE "${CMAKE_BINARY_DIR}/zig2")
set(ZIG_EXECUTABLE "${ZIG_EXECUTABLE}.exe")
endif()
else()
add_custom_command(
OUTPUT "${ZIG2_OBJECT}"
COMMAND "${ZIG_EXECUTABLE}" "build-obj" ${BUILD_ZIG2_ARGS}
DEPENDS ${ZIG_STAGE2_SOURCES}
COMMENT STATUS "Building stage2 component ${ZIG2_OBJECT}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT "${ZIG1_OBJECT}"
COMMAND "${ZIG_EXECUTABLE}" "build-obj" ${BUILD_ZIG1_ARGS}
DEPENDS ${ZIG_STAGE2_SOURCES}
COMMENT STATUS "Building self-hosted component ${ZIG1_OBJECT}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
endif()
# cmake won't let us configure an executable without C sources.
add_executable(zig2 "${CMAKE_SOURCE_DIR}/src/stage1/empty.cpp" "${ZIG2_OBJECT}")
add_executable(zig "${CMAKE_SOURCE_DIR}/src/stage1/empty.cpp" "${ZIG1_OBJECT}")
set_target_properties(zig2 PROPERTIES
set_target_properties(zig PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
LINK_FLAGS ${EXE_LDFLAGS}
)
target_link_libraries(zig2 zigstage1)
target_link_libraries(zig zigstage1)
if(MSVC)
target_link_libraries(zig2 ntdll.lib)
target_link_libraries(zig ntdll.lib)
elseif(MINGW)
target_link_libraries(zig2 ntdll)
target_link_libraries(zig ntdll)
endif()
set(ZIG_BUILD_ARGS
--zig-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-Dconfig_h=${ZIG_CONFIG_H_OUT}"
"-Denable-llvm"
"-Denable-stage1"
${ZIG_RELEASE_ARG}
${ZIG_STATIC_ARG}
${ZIG_NO_LIB_ARG}
${ZIG_SINGLE_THREADED_ARG}
"-Dtarget=${ZIG_TARGET_TRIPLE}"
"-Dcpu=${ZIG_TARGET_MCPU}"
"-Dversion-string=${ZIG_VERSION}"
)
install(TARGETS zig DESTINATION bin)
add_custom_target(stage3 ALL
COMMAND zig2 build compile ${ZIG_BUILD_ARGS}
DEPENDS zig2
COMMENT STATUS "Building stage3"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL
"Disable copying lib/ files to install prefix during the build phase")
install(CODE "set(ZIG_EXECUTABLE \"${ZIG_EXECUTABLE}\")")
install(CODE "set(ZIG_BUILD_ARGS \"${ZIG_BUILD_ARGS}\")")
install(CODE "set(CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\")")
install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")")
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/install.cmake")
if(NOT ZIG_SKIP_INSTALL_LIB_FILES)
set(ZIG_INSTALL_ARGS "build"
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-Dlib-files-only"
--prefix "${CMAKE_INSTALL_PREFIX}"
"-Dconfig_h=${ZIG_CONFIG_H_OUT}"
install
)
# CODE has no effect with Visual Studio build system generator, therefore
# when using Visual Studio build system generator we resort to running
# `zig build install` during the build phase.
if(MSVC)
add_custom_target(zig_install_lib_files ALL
COMMAND zig ${ZIG_INSTALL_ARGS}
DEPENDS zig
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
else()
get_target_property(zig_BINARY_DIR zig BINARY_DIR)
install(CODE "set(zig_EXE \"${ZIG_EXECUTABLE}\")")
install(CODE "set(ZIG_INSTALL_ARGS \"${ZIG_INSTALL_ARGS}\")")
install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")")
install(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.cmake)
endif()
endif()

View File

@@ -5,6 +5,7 @@
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
@@ -68,7 +69,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 +105,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 +116,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,7 +128,7 @@ 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.
@@ -143,7 +136,7 @@ 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
`-Denable-wasmtime` 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.

View File

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

View File

@@ -1,4 +1,4 @@
![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.
@@ -9,8 +9,8 @@ A general-purpose programming language and toolchain for maintaining
* [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)

729
build.zig

File diff suppressed because it is too large Load Diff

125
ci/azure/linux_script Executable file
View File

@@ -0,0 +1,125 @@
#!/bin/sh
set -x
set -e
sudo apt-get update -q
sudo apt-get install -y cmake s3cmd tidy
ZIGDIR="$(pwd)"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.1-dev.94+535615117"
PREFIX="$HOME/$CACHE_BASENAME"
MCPU="baseline"
JOBS="-j$(nproc)"
rm -rf $PREFIX
cd $HOME
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
QEMUBASE="qemu-linux-x86_64-5.2.0.1"
wget -nv "https://ziglang.org/deps/$QEMUBASE.tar.xz"
tar xf "$QEMUBASE.tar.xz"
export PATH="$(pwd)/$QEMUBASE/bin:$PATH"
# Bump to v0.23 once this issue is resolved:
# https://github.com/ziglang/zig/issues/8742
WASMTIME="wasmtime-v0.22.1-x86_64-linux"
wget -nv "https://github.com/bytecodealliance/wasmtime/releases/download/v0.22.1/$WASMTIME.tar.xz"
tar xf "$WASMTIME.tar.xz"
export PATH="$(pwd)/$WASMTIME:$PATH"
ZIG="$PREFIX/bin/zig"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
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="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-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
make $JOBS install
# 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
for step in test-toolchain test-std docs; do
release/bin/zig build $step -Denable-qemu -Denable-wasmtime
done
# Look for HTML errors.
tidy -qe ../zig-cache/langref.html
if [ "${BUILD_REASON}" != "PullRequest" ]; then
# Produce the experimental std lib documentation.
mkdir -p release/docs/std
release/bin/zig test ../lib/std/std.zig \
--override-lib-dir ../lib \
-femit-docs=release/docs/std \
-fno-emit-bin
mv ../LICENSE release/
mv ../zig-cache/langref.html release/docs/
# Remove the unnecessary bin dir in $prefix/bin/zig
mv release/bin/zig release/
rmdir release/bin
# Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig
mv release/lib/zig release/lib2
rmdir release/lib
mv release/lib2 release/lib
VERSION=$(release/zig version)
DIRNAME="zig-linux-$ARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd 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="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/$ARCH-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

131
ci/azure/macos_arm64_script Executable file
View File

@@ -0,0 +1,131 @@
#!/bin/sh
set -x
set -e
brew update && brew install s3cmd
ZIGDIR="$(pwd)"
HOST_ARCH="x86_64"
HOST_TARGET="$HOST_ARCH-macos-gnu"
HOST_MCPU="baseline"
HOST_CACHE_BASENAME="zig+llvm+lld+clang-$HOST_TARGET-0.8.0-dev.2703+c12704a33"
HOST_PREFIX="$HOME/$HOST_CACHE_BASENAME"
ARCH="aarch64"
TARGET="$ARCH-macos-gnu"
MCPU="apple_a14"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2703+c12704a33"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j2"
rm -rf $HOST_PREFIX $PREFIX
cd $HOME
wget -nv "https://ziglang.org/deps/$HOST_CACHE_BASENAME.tar.xz"
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$HOST_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
# Build host zig compiler in debug so that we can get the
# current version when packaging
ZIG="$HOST_PREFIX/bin/zig"
export CC="$ZIG cc -target $HOST_TARGET -mcpu=$HOST_MCPU"
export CXX="$ZIG c++ -target $HOST_TARGET -mcpu=$HOST_MCPU"
mkdir build.host
cd build.host
cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$HOST_PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$HOST_TARGET" \
-DZIG_TARGET_MCPU="$HOST_MCPU" \
-DZIG_STATIC=ON
unset CC
unset CXX
make $JOBS install
# Build zig compiler cross-compiled for arm64
cd $ZIGDIR
ZIG="$ZIGDIR/build.host/release/bin/zig"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_EXECUTABLE="$ZIG" \
-DZIG_STATIC=ON
unset CC
unset CXX
make $JOBS install
if [ "${BUILD_REASON}" != "PullRequest" ]; then
mv ../LICENSE release/
# We do not run test suite but still need langref.
mkdir -p release/docs
$ZIG run ../doc/docgen.zig -- $ZIG ../doc/langref.html.in release/docs/langref.html
# Produce the experimental std lib documentation.
mkdir -p release/docs/std
$ZIG test ../lib/std/std.zig \
--override-lib-dir ../lib \
-femit-docs=release/docs/std \
-fno-emit-bin
mv release/bin/zig release/
rmdir release/bin
VERSION=$(../build.host/release/bin/zig version)
DIRNAME="zig-macos-$ARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
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="macos-$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/$ARCH-macos-$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

@@ -3,13 +3,13 @@
set -x
set -e
brew update && brew install ncurses s3cmd
brew update && brew install s3cmd
ZIGDIR="$(pwd)"
ARCH="x86_64"
TARGET="$ARCH-macos-none"
TARGET="$ARCH-macos-gnu"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.10.0-dev.4560+828735ac0"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.1-dev.94+535615117"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j2"
@@ -34,7 +34,7 @@ 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" \
@@ -48,37 +48,26 @@ unset CXX
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
for step in test-toolchain test-std docs; do
release/bin/zig build $step
done
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 +91,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,7 +1,7 @@
jobs:
- job: BuildMacOS
pool:
vmImage: 'macOS-11'
vmImage: 'macOS-10.15'
timeoutInMinutes: 360
steps:
- task: DownloadSecureFile@1
@@ -10,157 +10,66 @@ jobs:
- script: ci/azure/macos_script
name: main
displayName: 'Build and test'
- job: BuildWindows
timeoutInMinutes: 360
- job: BuildMacOS_arm64
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: 'macOS-10.15'
timeoutInMinutes: 180
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/macos_arm64_script
name: main
displayName: 'Build'
- job: BuildLinux
pool:
vmImage: 'ubuntu-18.04'
timeoutInMinutes: 360
steps:
- task: DownloadSecureFile@1
inputs:
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/2021-06-04/msys2-base-x86_64-20210604.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
- BuildMacOS_arm64
- 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 -Suy --needed --noconfirm
pacman -S --needed --noconfirm wget p7zip python3-pip tar xz
pip install s3cmd
wget -nv "https://ziglang.org/deps/llvm%2bclang%2blld-12.0.1-rc1-x86_64-windows-msvc-release-mt.tar.xz"
tar xf llvm+clang+lld-12.0.1-rc1-x86_64-windows-msvc-release-mt.tar.xz

View File

@@ -0,0 +1,35 @@
@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-12.0.1-rc1-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
git.exe fetch --unshallow
git.exe fetch --tags
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 -DZIG_OMIT_STAGE2=ON || exit /b
msbuild /maxcpucount /p:Configuration=Release INSTALL.vcxproj || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-toolchain -Dskip-non-native -Dskip-stage2-tests || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-std -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,44 @@
---
kind: pipeline
type: docker
name: test-aarch64-linux-musl
platform:
os: linux
arch: arm64
steps:
- name: build
image: ziglang/static-base:llvm15-aarch64-3
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_build
- name: behavior
- name: test-1
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/test_linux_behavior
- ./ci/drone/linux_script_test 1
- name: std_Debug
- name: test-2
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/test_linux_std_Debug
- ./ci/drone/linux_script_test 2
- name: std_ReleaseSafe
- name: test-3
depends_on:
- build
image: ziglang/static-base:llvm15-aarch64-3
image: ziglang/static-base:llvm12-aarch64-5
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
- ./ci/drone/linux_script_test 3
- name: finalize
depends_on:
- build
- behavior
- std_Debug
- std_ReleaseSafe
- std_ReleaseFast
- std_ReleaseSmall
- misc
- cases
image: ziglang/static-base:llvm15-aarch64-3
- test-1
- test-2
- test-3
image: ziglang/static-base:llvm12-aarch64-5
environment:
SRHT_OAUTH_TOKEN:
from_secret: SRHT_OAUTH_TOKEN

22
ci/drone/linux_script_base Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/sh
# https://docs.drone.io/pipeline/docker/syntax/workspace/
#
# Drone automatically creates a temporary volume, known as your workspace,
# where it clones your repository. The workspace is the current working
# directory for each step in your pipeline.
#
# Because the workspace is a volume, filesystem changes are persisted between
# pipeline steps. In other words, individual steps can communicate and share
# state using the filesystem.
#
# Workspace volumes are ephemeral. They are created when the pipeline starts
# and destroyed after the pipeline completes.
set -x
set -e
TRIPLEARCH="$(uname -m)"
DISTDIR="$DRONE_WORKSPACE/dist"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"

View File

@@ -1,16 +1,10 @@
#!/bin/sh
set -x
set -e
ARCH="$(uname -m)"
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
. ./ci/drone/linux_script_base
PREFIX="/deps/local"
ZIG="$PREFIX/bin/zig"
TARGET="$ARCH-linux-musl"
TARGET="$TRIPLEARCH-linux-musl"
MCPU="baseline"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
@@ -19,6 +13,7 @@ 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 $@
@@ -29,8 +24,8 @@ cat <<'ENDFILE' >$PREFIX/bin/ranlib
/deps/local/bin/zig ranlib $@
ENDFILE
chmod +x "$PREFIX/bin/ar"
chmod +x "$PREFIX/bin/ranlib"
chmod +x $PREFIX/bin/ar
chmod +x $PREFIX/bin/ranlib
# Make the `zig version` number consistent.
# This will affect the cmake command below.
@@ -41,8 +36,8 @@ git fetch --tags
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX="$DISTDIR" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_AR="$PREFIX/bin/ar" \
-DCMAKE_RANLIB="$PREFIX/bin/ranlib" \
@@ -56,3 +51,9 @@ cmake .. \
unset CC
unset CXX
samu install
# 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="$DISTDIR/bin/zig"
samu install

View File

@@ -1,36 +1,28 @@
#!/bin/sh
set -x
set -e
ARCH="$(uname -m)"
INSTALL_PREFIX="$DRONE_WORKSPACE/stage3-release"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"
. ./ci/drone/linux_script_base
if [ -n "$DRONE_PULL_REQUEST" ]; then
exit 0
fi
apk update
apk add py3-pip perl-utils jq curl
pip3 install s3cmd
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/"
mv ../LICENSE "$DISTDIR/"
# docs are disabled due to: https://github.com/ziglang/zig/issues/8597
#mv ../zig-cache/langref.html "$DISTDIR/"
mv "$DISTDIR/bin/zig" "$DISTDIR/"
rmdir "$DISTDIR/bin"
GITBRANCH="$DRONE_BRANCH"
VERSION="$("$INSTALL_PREFIX/zig" version)"
DIRNAME="zig-linux-$ARCH-$VERSION"
VERSION="$("$DISTDIR/zig" version)"
DIRNAME="zig-linux-$TRIPLEARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv "$INSTALL_PREFIX" "$DIRNAME"
mv "$DISTDIR" "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
@@ -44,7 +36,7 @@ echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-linux-$VERSION.json"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$TRIPLEARCH-linux-$VERSION.json"
if [ "$GITBRANCH" = "master" ]; then
# avoid leaking oauth token
set +x

46
ci/drone/linux_script_test Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
. ./ci/drone/linux_script_base
# only release-fast builds of test suite due to: https://github.com/ziglang/zig/issues/8597
#
# Some test suite components will be missing because they do not support
# forcing -OReleaseFast
#
# see `zig build --help` for the full list of test-* components
case "$1" in
1)
steps="\
test-stage2 \
test-fmt \
test-behavior"
;;
2)
steps="test-std"
;;
3)
steps="\
test-compiler-rt \
test-minilibc \
test-compare-output \
test-translate-c \
test-run-translated-c"
;;
'')
echo "error: expecting test group argument"
exit 1
;;
*)
echo "error: unknown test group: $1"
exit 1
;;
esac
# only release-fast builds of test suite due to: https://github.com/ziglang/zig/issues/8597
./build/zig build \
-Drelease \
-Dskip-debug \
-Dskip-release-small \
-Dskip-release-safe \
-Dskip-non-native \
$steps

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,12 +4,10 @@ set -x
set -e
sudo pkg update -fq
sudo pkg install -y cmake py39-s3cmd wget curl jq samurai
sudo pkg install -y cmake py38-s3cmd wget curl jq samurai
ZIGDIR="$(pwd)"
TARGET="x86_64-freebsd-gnu"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.10.0-dev.4560+828735ac0"
CACHE_BASENAME="zig+llvm+lld+clang-x86_64-freebsd-gnu-0.8.0-dev.2703+c12704a33"
PREFIX="$HOME/$CACHE_BASENAME"
cd $HOME
@@ -31,62 +29,29 @@ 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
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$PREFIX \
"-DCMAKE_INSTALL_PREFIX=$(pwd)/release" \
-DZIG_STATIC=ON \
-DZIG_TARGET_TRIPLE=x86_64-freebsd-gnu \
-GNinja
samu 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/

737
ci/srht/index.html Normal file
View File

@@ -0,0 +1,737 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Releases ⚡ The Zig Programming Language</title>
<link rel="icon" href="/favicon.png">
<style>
body{
font-family: system-ui, -apple-system, Roboto, "Segoe UI", sans-serif;
line-height: 1.45;
margin-left: 0;
margin-right: 0;
}
p {
margin: 0.8em 0;
}
h1, h2, h3, h4 {
margin: 0.5em 0 0.5em;
line-height: 1.2;
font-weight: bold;
color: #666;
}
h1 a, h2 a, h3 a, h4 a {
text-decoration: none;
color: #666;
}
a.hdr {
visibility: hidden;
}
h1:hover > a.hdr, h2:hover > a.hdr, h3:hover > a.hdr, h4:hover > a.hdr, h5:hover > a.hdr {
visibility: visible;
}
h1 { font-size: 2.0em; }
h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; }
h4 { font-size: 1.0em; }
a {
color: #2A6286;
}
a:not(:hover) {
text-decoration: none;
}
th, td {
padding: 0.6em;
text-align: left;
white-space: nowrap;
}
td {
font-size: 0.96em;
}
th {
border-bottom: 2px solid #f2f3f3;
}
tr:nth-child(even) {
background: #f2f3f3;
}
.container {
margin: 0 auto;
position: relative;
max-width: 1000px;
}
#navbar {
background-color: #737475;
padding: 5px 0;
border-top: 4px solid #f7a41d;
margin-bottom: 30px;
}
#navbar .navbar-item, #navbar .navbar-item:visited {
color: white;
padding-right: 5px;
padding-left: 5px;
}
.code {
font-family: monospace;
font-size: 0.8em;
}
#header-image {
background-image: url(https://ziglang.org/img/zig-logo-dark.svg);
background-repeat: no-repeat;
width: 340px;
height: 90px;
display: block;
padding: 0;
margin: 0;
}
@media (prefers-color-scheme: dark) {
body{
background-color:#111;
color: #bbb;
}
a {
color: #88f;
}
table, th, td {
border-color: grey;
}
tr:nth-child(even) {
background: #1e1e1e;
}
h1 a, h2 a, h3 a, h4 a, h5 a {
color: #aaa;
}
#header-image {
background-image: url(https://ziglang.org/img/zig-logo-light.svg);
}
}
</style>
</head>
<body>
<div class="container">
<a href="/"><span id="header-image"></span></a>
</div>
<nav id="navbar">
<div class="container">
<a href="/download/" class="navbar-item">Download &amp; Documentation</a>
<a href="https://github.com/ziglang/zig" class="navbar-item">Source Code</a>
<a href="/news/" class="navbar-item">News</a>
<a href="https://github.com/ziglang/zig/wiki/Community" class="navbar-item">Join a Community</a>
<a href="/zsf/" class="navbar-item">
<svg style="color: #ea4aaa; vertical-align: middle;fill: currentColor; margin-right: 5px" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M9 2c-.97 0-1.69.42-2.2 1-.51.58-.78.92-.8 1-.02-.08-.28-.42-.8-1-.52-.58-1.17-1-2.2-1-1.632.086-2.954 1.333-3 3 0 .52.09 1.52.67 2.67C1.25 8.82 3.01 10.61 6 13c2.98-2.39 4.77-4.17 5.34-5.33C11.91 6.51 12 5.5 12 5c-.047-1.69-1.342-2.913-3-3z"></path></svg>Sponsor the Zig Software Foundation</a>
</div>
</nav>
<div class="container">
<h1>Releases</h1>
<p>You can also
<a href="https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager">install Zig from a package manager</a>.
</p>
<p>
There is a <a href="index.json">JSON version of this page</a>.
</p>
<h2 id="release-master">master</h2>
<ul>
<li>{{MASTER_DATE}}</li>
<li><a href="/documentation/master/">Language Reference</a></li>
<li><a href="/documentation/master/std/">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/builds/{{SRC_TARBALL}}">{{SRC_TARBALL}}</a></td>
<td>Source</td>
<td>{{SRC_BYTESIZE}}</td>
<td class="code">{{SRC_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_LINUX_TARBALL}}">{{X86_64_LINUX_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_LINUX_BYTESIZE}}</td>
<td class="code">{{X86_64_LINUX_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{AARCH64_LINUX_TARBALL}}">{{AARCH64_LINUX_TARBALL}}</a></td>
<td>Binary</td>
<td>{{AARCH64_LINUX_BYTESIZE}}</td>
<td class="code">{{AARCH64_LINUX_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_WINDOWS_TARBALL}}">{{X86_64_WINDOWS_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_WINDOWS_BYTESIZE}}</td>
<td class="code">{{X86_64_WINDOWS_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_MACOS_TARBALL}}">{{X86_64_MACOS_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_MACOS_BYTESIZE}}</td>
<td class="code">{{X86_64_MACOS_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{AARCH64_MACOS_TARBALL}}">{{AARCH64_MACOS_TARBALL}}</a></td>
<td>Binary</td>
<td>{{AARCH64_MACOS_BYTESIZE}}</td>
<td class="code">{{AARCH64_MACOS_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_FREEBSD_TARBALL}}">{{X86_64_FREEBSD_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_FREEBSD_BYTESIZE}}</td>
<td class="code">{{X86_64_FREEBSD_SHASUM}}</td>
</tr>
</tbody>
</table>
<h2 id="release-0.7.1">0.7.1</h2>
<ul>
<li>2020-12-13</li>
<li><a href="0.7.1/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.7.1/">Language Reference</a></li>
<li><a href="/documentation/0.7.1/std">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-0.7.1.tar.xz">zig-0.7.1.tar.xz</a></td>
<td>Source</td>
<td>11MiB</td>
<td class="code">2db3b944ab368d955b48743d9f7c963b8f96de1a441ba5a35e197237cc6dae44</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-bootstrap-0.7.1.tar.xz">zig-bootstrap-0.7.1.tar.xz</a></td>
<td>Source</td>
<td>39MiB</td>
<td class="code">040f27c1fae4b0cac0a2782aecdb691f6a2f8e89db6a6ed35024c31c304fd9b2</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-freebsd-x86_64-0.7.1.tar.xz">zig-freebsd-x86_64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">e73c1dca35791a3183fdd5ecde0443ebbe180942efceafe651886034fb8def09</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-aarch64-0.7.1.tar.xz">zig-linux-aarch64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>33MiB</td>
<td class="code">48ec90eba407e4587ddef7eecef25fec7e13587eb98e3b83c5f2f5fff2a5cbe7</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-armv7a-0.7.1.tar.xz">zig-linux-armv7a-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>35MiB</td>
<td class="code">5a0662e07b4c4968665e1f97558f8591f6facec45d2e0ff5715e661743107ceb</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-i386-0.7.1.tar.xz">zig-linux-i386-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">4882e052e5f83690bd0334bb4fc1702b5403cb3a3d2aa63fd7d6043d8afecba3</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-riscv64-0.7.1.tar.xz">zig-linux-riscv64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">187294bfd35983348c3fe042901b42e67e7e36ab7f77a5f969d21c0051f4d21f</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-x86_64-0.7.1.tar.xz">zig-linux-x86_64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>37MiB</td>
<td class="code">18c7b9b200600f8bcde1cd8d7f1f578cbc3676241ce36d771937ce19a8159b8d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-macos-x86_64-0.7.1.tar.xz">zig-macos-x86_64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>35MiB</td>
<td class="code">845cb17562978af0cf67e3993f4e33330525eaf01ead9386df9105111e3bc519</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-windows-i386-0.7.1.zip">zig-windows-i386-0.7.1.zip</a></td>
<td>Binary</td>
<td>52MiB</td>
<td class="code">a1b9a7421e13153e07fd2e2c93ff29aad64d83105b8fcdafa633dbe689caf1c0</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-windows-x86_64-0.7.1.zip">zig-windows-x86_64-0.7.1.zip</a></td>
<td>Binary</td>
<td>53MiB</td>
<td class="code">4818a8a65b4672bc52c0ae7f14d014e0eb8caf10f12c0745176820384cea296a</td>
</tr>
</tbody>
</table>
<h2 id="release-0.7.0">0.7.0</h2>
<ul>
<li>2020-11-08</li>
<li><a href="0.7.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.7.0/">Language Reference</a></li>
<li><a href="/documentation/0.7.0/std">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-0.7.0.tar.xz">zig-0.7.0.tar.xz</a></td>
<td>Source</td>
<td>11MiB</td>
<td class="code">0efd2cf6c3b05723db80e9cf193bc55150bba84ca41f855a90f53fc756445f83</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-bootstrap-0.7.0.tar.xz">zig-bootstrap-0.7.0.tar.xz</a></td>
<td>Source</td>
<td>39MiB</td>
<td class="code">f073beaf5c53c8c57c0d374cbfcb332ef92ad703173edba0d9e0f2ed28401b72</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-freebsd-x86_64-0.7.0.tar.xz">zig-freebsd-x86_64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>34MiB</td>
<td class="code">a0c926272ee4ae720034b4a6a1dc98399d76156dd84182554740f0ca8a41fc99</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-aarch64-0.7.0.tar.xz">zig-linux-aarch64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>32MiB</td>
<td class="code">f89933bac87d44be82325754ff88423020c81c7032a6fc41cfeb81e982eeab9b</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-armv7a-0.7.0.tar.xz">zig-linux-armv7a-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>34MiB</td>
<td class="code">011c267e25a96ee160505a560c441daa045359a9d50e13ab1bada9d75c95db2d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-i386-0.7.0.tar.xz">zig-linux-i386-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>37MiB</td>
<td class="code">4bb2072cd363bcb1cbeb4872ff5cbc1f683b02d0cc1f90c46e3ea7422ce53222</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-riscv64-0.7.0.tar.xz">zig-linux-riscv64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">40dff81faa6f232ac40abbf88b9371f3cc932b6e09c423b94387c9ea580cb7be</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-x86_64-0.7.0.tar.xz">zig-linux-x86_64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">e619b1c6094c095b932767f527aee2507f847ea981513ff8a08aab0fd730e0ac</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-macos-aarch64-0.7.0.tar.xz">zig-macos-aarch64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>33MiB</td>
<td class="code">338238035734db74ea4f30e500a4893bf741d38305c10952d5e39fa05bdb057d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-macos-x86_64-0.7.0.tar.xz">zig-macos-x86_64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>35MiB</td>
<td class="code">94063f9a311cbbf7a2e0a12295e09437182cf950f18cb0eb30ea9893f3677f24</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-windows-i386-0.7.0.zip">zig-windows-i386-0.7.0.zip</a></td>
<td>Binary</td>
<td>51MiB</td>
<td class="code">b1e520aacbfbd645ff3521b3eb4d44166d9a0288b8725e4b001f8b50a425eb2e</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-windows-x86_64-0.7.0.zip">zig-windows-x86_64-0.7.0.zip</a></td>
<td>Binary</td>
<td>52MiB</td>
<td class="code">965f56c0a36f9cda2125e3a348bc654f7f155e2804c3667d231775ec228f8553</td>
</tr>
</tbody>
</table>
<h2 id="release-0.6.0">0.6.0</h2>
<ul>
<li>2020-04-13</li>
<li><a href="0.6.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.6.0">Language Reference</a></li>
<li><a href="/documentation/0.6.0/std">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-0.6.0.tar.xz">zig-0.6.0.tar.xz</a></td>
<td>Source</td>
<td>9.9MiB</td>
<td class="code">5d167dc19354282dd35dd17b38e99e1763713b9be8a4ba9e9e69284e059e7204</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-bootstrap-0.6.0.tar.xz">zig-bootstrap-0.6.0.tar.xz</a></td>
<td>Source</td>
<td>36.7MiB</td>
<td class="code">5e0e4dc878b3dd0c1852a442b174f0732e8c07869a8fcd226b71a93b89b381ab</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-freebsd-x86_64-0.6.0.tar.xz">zig-freebsd-x86_64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">190ff79c1eb56805a315d7c7a51082e32f62926250c0702b36760c225e1634a3</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-aarch64-0.6.0.tar.xz">zig-linux-aarch64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">e7520efd42cfa02be48c2e430d08fe1f3cbb999d21d9f0d3ffd0febb976b2f41</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-armv6kz-0.6.0.tar.xz">zig-linux-armv6kz-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">36b6493b3fed43eb1f0000e765798ad31a6bb7d7fd3f553ac1c3761dbc919b82</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-armv7a-0.6.0.tar.xz">zig-linux-armv7a-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">946969abe357def95ca9cbbfcebfcf2d90cf967bcd3f48ee87662e32d91d8f35</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-i386-0.6.0.tar.xz">zig-linux-i386-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>43MiB</td>
<td class="code">a97a2f9ae21575743cdd763c1917d49400d83fc562ef64582b18bade43eb24ce</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-riscv64-0.6.0.tar.xz">zig-linux-riscv64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>41MiB</td>
<td class="code">68ddee43f7503c8ae5f26a921f3602c34719a02ed2241f528c0b8b888cc14b38</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-x86_64-0.6.0.tar.xz">zig-linux-x86_64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>43MiB</td>
<td class="code">08fd3c757963630645441c2772362e9c2294020c44f14fce1b89f45de0dc1253</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-macos-x86_64-0.6.0.tar.xz">zig-macos-x86_64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>41MiB</td>
<td class="code">17270360e87ddc49f737e760047b2fac49f1570a824a306119b1194ac4093895</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-windows-i386-0.6.0.zip">zig-windows-i386-0.6.0.zip</a></td>
<td>Binary</td>
<td>58MiB</td>
<td class="code">3b0a02618743e92175990dc6d1a787bb95ff62c4cda016f1c14c7786f575f8ca</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-windows-x86_64-0.6.0.zip">zig-windows-x86_64-0.6.0.zip</a></td>
<td>Binary</td>
<td>47MiB</td>
<td class="code">c3b897832523e1026e10b2d8d55d7f895185c0a27a63681f3a23219c3f1c38f4</td>
</tr>
</tbody>
</table>
<h2 id="release-0.5.0">0.5.0</h2>
<ul>
<li>2019-09-30</li>
<li><a href="0.5.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.5.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-0.5.0.tar.xz">zig-0.5.0.tar.xz</a></td>
<td>Source</td>
<td>10.4MiB</td>
<td class="code">55ae16960f152bcb9cf98b4f8570902d0e559a141abf927f0d3555b7cc838a31</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-linux-x86_64-0.5.0.tar.xz">zig-linux-x86_64-0.5.0.tar.xz</a></td>
<td>Binary</td>
<td>39.0MiB</td>
<td class="code">43e8f8a8b8556edd373ddf9c1ef3ca6cf852d4d09fe07d5736d12fefedd2b4f7</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-windows-x86_64-0.5.0.zip">zig-windows-x86_64-0.5.0.zip</a></td>
<td>Binary</td>
<td>42.8MiB</td>
<td class="code">58141323db8d84a5af62746be5f9140bc161ee760ef33dc91a887bf9ac021976</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-macos-x86_64-0.5.0.tar.xz">zig-macos-x86_64-0.5.0.tar.xz</a></td>
<td>Binary</td>
<td>36.1MiB</td>
<td class="code">28702cc05745c7c0bd450487d5f4091bf0a1ad279b35eb9a640ce3e3a15b300d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-freebsd-x86_64-0.5.0.tar.xz">zig-freebsd-x86_64-0.5.0.tar.xz</a></td>
<td>Binary</td>
<td>32.1MiB</td>
<td class="code">9e1f4d36c3d584c0aa01f20eb4cd0a0eef3eee5af23e483b8414de55feab6ab6</td>
</tr>
</tbody>
</table>
<h2 id="release-0.4.0">0.4.0</h2>
<ul>
<li>2019-04-08</li>
<li><a href="0.4.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.4.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-0.4.0.tar.xz">zig-0.4.0.tar.xz</a></td>
<td>Source</td>
<td>5.1MiB</td>
<td class="code">fec1f3f6b359a3d942e0a7f9157b3b30cde83927627a0e1ea95c54de3c526cfc</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-linux-x86_64-0.4.0.tar.xz">zig-linux-x86_64-0.4.0.tar.xz</a></td>
<td>Binary</td>
<td>31.4MiB</td>
<td class="code">fb1954e2fb556a01f8079a08130e88f70084e08978ff853bb2b1986d8c39d84e</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-windows-x86_64-0.4.0.zip">zig-windows-x86_64-0.4.0.zip</a></td>
<td>Binary</td>
<td>34.1MiB</td>
<td class="code">fbc3dd205e064c263063f69f600bedb18e3d0aa2efa747a63ef6cafb6d73f127</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-macos-x86_64-0.4.0.tar.xz">zig-macos-x86_64-0.4.0.tar.xz</a></td>
<td>Binary</td>
<td>29.4MiB</td>
<td class="code">67c932982484d017c5111e54af9f33f15e8e05c6bc5346a55e04052159c964a8</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-freebsd-x86_64-0.4.0.tar.xz">zig-freebsd-x86_64-0.4.0.tar.xz</a></td>
<td>Binary</td>
<td>26.0MiB</td>
<td class="code">3d557c91ac36d8262eb1733bb5f261c95944f9b635e43386e3d00a3272818c30</td>
</tr>
</tbody>
</table>
<h2 id="release-0.3.0">0.3.0</h2>
<ul>
<li>2018-09-28</li>
<li><a href="0.3.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.3.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-0.3.0.tar.xz">zig-0.3.0.tar.xz</a></td>
<td>Source</td>
<td>2.2MiB</td>
<td class="code">d70af604f3a8622f3393d93abb3e056bf60351e32d121e6fa4fe03d8d41e1f5a</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-linux-x86_64-0.3.0.tar.xz">zig-linux-x86_64-0.3.0.tar.xz</a></td>
<td>Binary</td>
<td>24.0MiB</td>
<td class="code">b378d0aae30cb54f28494e7bc4efbc9bfb6326f47bfb302e8b5287af777b2f3c</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-windows-x86_64-0.3.0.zip">zig-windows-x86_64-0.3.0.zip</a></td>
<td>Binary</td>
<td>21.5MiB</td>
<td class="code">bb568c03950958f8bb3472139c3ab5ed74547c8c694ab50f404c202faf51baf4</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-macos-x86_64-0.3.0.tar.xz">zig-macos-x86_64-0.3.0.tar.xz</a></td>
<td>Binary</td>
<td>22.6MiB</td>
<td class="code">19dec1f1943ab7be26823376d466f7e456143deb34e17502778a949034dc2e7e</td>
</tr>
</tbody>
</table>
<h2 id="release-0.2.0">0.2.0</h2>
<ul>
<li>2018-03-15</li>
<li><a href="0.2.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.2.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.2.0/zig-0.2.0.tar.xz">zig-0.2.0.tar.xz</a></td>
<td>Source</td>
<td>1.9MiB</td>
<td class="code">29c9beb172737f4d5019b88ceae829ae8bc6512fb4386cfbf895ae2b42aa6965</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.2.0/zig-linux-x86_64-0.2.0.tar.xz">zig-linux-x86_64-0.2.0.tar.xz</a></td>
<td>Binary</td>
<td>23.5MiB</td>
<td class="code">209c6fb745d42474c0a73d6f291c7ae3a38b6a1b6b641eea285a7f840cc1a890</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.2.0/zig-win64-0.2.0.zip">zig-win64-0.2.0.zip</a></td>
<td>Binary</td>
<td>20.6MiB</td>
<td class="code">4f8a2979941a1f081ec8e545cca0b72608c0db1c5a3fd377a94db40649dcd3d4</td>
</tr>
</tbody>
</table>
<h2 id="release-0.1.1">0.1.1</h2>
<ul>
<li>2017-10-17</li>
<li><a href="0.1.1/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.1.1">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.1.1/zig-0.1.1.tar.xz">zig-0.1.1.tar.xz</a></td>
<td>Source</td>
<td>1.62MiB</td>
<td class="code">ffca0cfb263485287e19cc997b08701fcd5f24b700345bcdc3dd8074f5a104e0</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.1.1/zig-win64-0.1.1.zip">zig-win64-0.1.1.zip</a></td>
<td>Binary</td>
<td>19.3MiB</td>
<td class="code">6fc88bef531af7e567fe30bf60da1487b86833cbee84c7a2f3e317030aa5b660</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

View File

@@ -40,280 +40,6 @@
"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/",

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:

View File

@@ -6,10 +6,15 @@ pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
const allocator = &arena.allocator;
const out_dir = "out";
try std.fs.cwd().makePath(out_dir);
{
const out_file = out_dir ++ path.sep_str ++ "index.html";
const in_file = "index.html";
try render(allocator, in_file, out_file, .html);
}
{
const out_file = out_dir ++ path.sep_str ++ "index.json";
const in_file = "index.json";
@@ -18,7 +23,7 @@ pub fn main() !void {
}
fn render(
allocator: mem.Allocator,
allocator: *mem.Allocator,
in_file: []const u8,
out_file: []const u8,
fmt: enum {
@@ -74,7 +79,7 @@ fn render(
try writer.writeAll(trimmed);
}
} else {
std.debug.print("line {d}: missing variable: {s}\n", .{ line, var_name });
std.debug.warn("line {d}: missing variable: {s}\n", .{ line, var_name });
try writer.writeAll("(missing)");
}
state = State.EndBrace;
@@ -86,7 +91,7 @@ fn render(
state = State.Start;
},
else => {
std.debug.print("line {d}: invalid byte: '0x{x}'", .{ line, byte });
std.debug.warn("line {d}: invalid byte: '0x{x}'", .{ line, byte });
std.process.exit(1);
},
},

View File

@@ -15,7 +15,6 @@ 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.
@@ -25,7 +24,6 @@ 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
@@ -48,7 +46,7 @@ wget "https://ziglang.org/builds/$NATIVE_TARBALL"
tar xf "$NATIVE_TARBALL"
ZIGDIR="$(pwd)/$(basename $NATIVE_TARBALL .tar.xz)"
ZIG="$ZIGDIR/zig"
LANGREF="$ZIGDIR/doc/langref.html"
LANGREF="$ZIGDIR/docs/langref.html"
SRCTARBALLDIR="zig-$VERSION"
export SRC_TARBALL="$SRCTARBALLDIR.tar.xz"
mv "$SRCDIR" "$SRCTARBALLDIR"
@@ -86,65 +84,29 @@ 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)"
export MASTER_DATE="$(date +%Y-%m-%d)"
export MASTER_VERSION="$VERSION"
# Create index.json and update the website repo.
cd "$SRCTARBALLDIR/ci/srht"
"$ZIG" run update-download-page.zig
CIDIR="$(pwd)"
# Create index.json and index.html and update the website repo.
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
git clone git@github.com:ziglang/www.ziglang.org.git
cd www.ziglang.org
WWWDIR="$(pwd)"
$S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536000, immutable" "$HOME/$SRC_TARBALL" s3://ziglang.org/builds/
cd "$WWWDIR"
cp "$CIDIR/out/index.json" data/releases.json
mkdir -p content/documentation/master/std
cp "$LANGREF" content/documentation/master/index.html
cp "$ZIGDIR/docs/std/index.html" content/documentation/master/std/index.html
cp "$ZIGDIR/docs/std/data.js" content/documentation/master/std/data.js
cp "$ZIGDIR/docs/std/main.js" content/documentation/master/std/main.js
git add data/releases.json
git commit -m "CI: update releases"
git add content/
git commit -m "CI: update releases and docs"
git push origin master

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/12/include
/usr/lib/llvm-12/include
/usr/lib/llvm-12.0/include
/usr/local/llvm120/include
/usr/local/llvm12/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-12.0
clang-cpp120
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/12/lib
/usr/lib/llvm/12/lib64
/usr/lib/llvm-12/lib
/usr/local/llvm120/lib
/usr/local/llvm12/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/12/lib
/usr/lib/llvm-12/lib
/usr/lib/llvm-12.0/lib
/usr/local/llvm120/lib
/usr/local/llvm12/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-12/include
/usr/local/llvm120/include
/usr/local/llvm12/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-12.0 lld120 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-12/lib
/usr/local/llvm120/lib
/usr/local/llvm12/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-12/lib
/usr/local/llvm120/lib
/usr/local/llvm12/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/12/include
/usr/lib/llvm-12/include
/usr/lib/llvm-12.0/include
/usr/local/llvm12/include
/usr/local/llvm120/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-12.0
LLVM-12
LLVM-120
LLVM
PATHS
${LLVM_LIBDIRS}
/usr/lib/llvm/12/lib
/usr/lib/llvm/12/lib64
/usr/lib/llvm-12/lib
/usr/local/llvm12/lib
/usr/local/llvm120/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-12 llvm-config-12.0 llvm-config120 llvm-config12 llvm-config
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-12.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 12)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
elseif(ZIG_USE_LLVM_CONFIG)
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-12 llvm-config-12.0 llvm-config120 llvm-config12 llvm-config
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-12.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 12)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 13)
message(FATAL_ERROR "expected LLVM 12.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-12 LLVM-12.0)
endif()
link_directories("${CMAKE_PREFIX_PATH}/lib")
link_directories("${LLVM_LIBDIRS}")
@@ -191,18 +177,24 @@ 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/12/lib
/usr/lib/llvm-12/lib
/usr/lib/llvm-12.0/lib
/usr/local/llvm120/lib
/usr/local/llvm12/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)
@@ -212,7 +204,6 @@ else()
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)
@@ -222,13 +213,7 @@ else()
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(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)
@@ -288,7 +273,6 @@ else()
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)
@@ -304,16 +288,16 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)
FIND_AND_ADD_LLVM_LIB(LLVMMCJIT)
FIND_AND_ADD_LLVM_LIB(LLVMJITLink)
FIND_AND_ADD_LLVM_LIB(LLVMOrcTargetProcess)
FIND_AND_ADD_LLVM_LIB(LLVMOrcShared)
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(LLVMSymbolize)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
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)
@@ -321,6 +305,7 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMCFGuard)
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
FIND_AND_ADD_LLVM_LIB(LLVMObjCARCOpts)
FIND_AND_ADD_LLVM_LIB(LLVMHelloNew)
FIND_AND_ADD_LLVM_LIB(LLVMipo)
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
@@ -332,6 +317,7 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMGlobalISel)
FIND_AND_ADD_LLVM_LIB(LLVMMIRParser)
FIND_AND_ADD_LLVM_LIB(LLVMAsmPrinter)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARF)
FIND_AND_ADD_LLVM_LIB(LLVMSelectionDAG)
FIND_AND_ADD_LLVM_LIB(LLVMCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMIRReader)
@@ -347,26 +333,19 @@ 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(LLVMDebugInfoMSF)
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(LLVMBinaryFormat)
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,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,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);
}

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(__eqxf2, .{ .name = "__eqxf2", .linkage = common.linkage });
@export(__nexf2, .{ .name = "__nexf2", .linkage = common.linkage });
@export(__lexf2, .{ .name = "__lexf2", .linkage = common.linkage });
@export(__cmpxf2, .{ .name = "__cmpxf2", .linkage = common.linkage });
@export(__ltxf2, .{ .name = "__ltxf2", .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 `__lexf2`, `__eqxf2`, `__nexf2`, `__cmpxf2`,
/// and `__ltxf2`.
fn __cmpxf2(a: f80, b: f80) callconv(.C) i32 {
return @enumToInt(comparef.cmp_f80(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 __lexf2(a: f80, b: f80) callconv(.C) i32 {
return __cmpxf2(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, __eqxf2 and __nexf2 are defined
/// to have the same return value.
fn __eqxf2(a: f80, b: f80) callconv(.C) i32 {
return __cmpxf2(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, __eqxf2 and __nexf2 are defined
/// to have the same return value.
fn __nexf2(a: f80, b: f80) callconv(.C) i32 {
return __cmpxf2(a, b);
}
/// "These functions return a value less than zero if neither argument is NaN, and a
/// is strictly less than b."
fn __ltxf2(a: f80, b: f80) callconv(.C) i32 {
return __cmpxf2(a, b);
}

View File

@@ -1,219 +0,0 @@
const std = @import("std");
const builtin = @import("builtin");
pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
pub const want_aeabi = switch (builtin.abi) {
.eabi,
.eabihf,
.musleabi,
.musleabihf,
.gnueabi,
.gnueabihf,
.android,
=> switch (builtin.cpu.arch) {
.arm, .armeb, .thumb, .thumbeb => true,
else => false,
},
else => false,
};
pub const want_ppc_abi = builtin.cpu.arch.isPPC() or builtin.cpu.arch.isPPC64();
// Libcalls that involve u128 on Windows x86-64 are expected by LLVM to use the
// calling convention of @Vector(2, u64), rather than what's standard.
pub const want_windows_v2u64_abi = builtin.os.tag == .windows and builtin.cpu.arch == .x86_64;
/// This governs whether to use these symbol names for f16/f32 conversions
/// rather than the standard names:
/// * __gnu_f2h_ieee
/// * __gnu_h2f_ieee
/// Known correct configurations:
/// x86_64-freestanding-none => true
/// x86_64-linux-none => true
/// x86_64-linux-gnu => true
/// x86_64-linux-musl => true
/// x86_64-linux-eabi => true
/// arm-linux-musleabihf => true
/// arm-linux-gnueabihf => true
/// arm-linux-eabihf => false
/// wasm32-wasi-musl => false
/// wasm32-freestanding-none => false
/// x86_64-windows-gnu => true
/// x86_64-windows-msvc => true
/// any-macos-any => false
pub const gnu_f16_abi = switch (builtin.cpu.arch) {
.wasm32,
.wasm64,
.riscv64,
.riscv32,
.x86_64,
=> false,
.i386 => true,
.arm, .armeb, .thumb, .thumbeb => switch (builtin.abi) {
.eabi, .eabihf => false,
else => true,
},
else => !builtin.os.tag.isDarwin(),
};
pub const want_sparc_abi = builtin.cpu.arch.isSPARC();
// Avoid dragging in the runtime safety mechanisms into this .o file,
// unless we're trying to test compiler-rt.
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
_ = error_return_trace;
if (builtin.is_test) {
@setCold(true);
std.debug.panic("{s}", .{msg});
} else {
unreachable;
}
}
/// AArch64 is the only ABI (at the moment) to support f16 arguments without the
/// need for extending them to wider fp types.
/// TODO remove this; do this type selection in the language rather than
/// here in compiler-rt.
pub const F16T = switch (builtin.cpu.arch) {
.aarch64, .aarch64_be, .aarch64_32 => f16,
.riscv64 => if (builtin.zig_backend == .stage1) u16 else f16,
.i386, .x86_64 => f16,
else => u16,
};
pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
switch (Z) {
u16 => {
// 16x16 --> 32 bit multiply
const product = @as(u32, a) * @as(u32, b);
hi.* = @intCast(u16, product >> 16);
lo.* = @truncate(u16, product);
},
u32 => {
// 32x32 --> 64 bit multiply
const product = @as(u64, a) * @as(u64, b);
hi.* = @truncate(u32, product >> 32);
lo.* = @truncate(u32, product);
},
u64 => {
const S = struct {
fn loWord(x: u64) u64 {
return @truncate(u32, x);
}
fn hiWord(x: u64) u64 {
return @truncate(u32, x >> 32);
}
};
// 64x64 -> 128 wide multiply for platforms that don't have such an operation;
// many 64-bit platforms have this operation, but they tend to have hardware
// floating-point, so we don't bother with a special case for them here.
// Each of the component 32x32 -> 64 products
const plolo: u64 = S.loWord(a) * S.loWord(b);
const plohi: u64 = S.loWord(a) * S.hiWord(b);
const philo: u64 = S.hiWord(a) * S.loWord(b);
const phihi: u64 = S.hiWord(a) * S.hiWord(b);
// Sum terms that contribute to lo in a way that allows us to get the carry
const r0: u64 = S.loWord(plolo);
const r1: u64 = S.hiWord(plolo) +% S.loWord(plohi) +% S.loWord(philo);
lo.* = r0 +% (r1 << 32);
// Sum terms contributing to hi with the carry from lo
hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;
},
u128 => {
const Word_LoMask = @as(u64, 0x00000000ffffffff);
const Word_HiMask = @as(u64, 0xffffffff00000000);
const Word_FullMask = @as(u64, 0xffffffffffffffff);
const S = struct {
fn Word_1(x: u128) u64 {
return @truncate(u32, x >> 96);
}
fn Word_2(x: u128) u64 {
return @truncate(u32, x >> 64);
}
fn Word_3(x: u128) u64 {
return @truncate(u32, x >> 32);
}
fn Word_4(x: u128) u64 {
return @truncate(u32, x);
}
};
// 128x128 -> 256 wide multiply for platforms that don't have such an operation;
// many 64-bit platforms have this operation, but they tend to have hardware
// floating-point, so we don't bother with a special case for them here.
const product11: u64 = S.Word_1(a) * S.Word_1(b);
const product12: u64 = S.Word_1(a) * S.Word_2(b);
const product13: u64 = S.Word_1(a) * S.Word_3(b);
const product14: u64 = S.Word_1(a) * S.Word_4(b);
const product21: u64 = S.Word_2(a) * S.Word_1(b);
const product22: u64 = S.Word_2(a) * S.Word_2(b);
const product23: u64 = S.Word_2(a) * S.Word_3(b);
const product24: u64 = S.Word_2(a) * S.Word_4(b);
const product31: u64 = S.Word_3(a) * S.Word_1(b);
const product32: u64 = S.Word_3(a) * S.Word_2(b);
const product33: u64 = S.Word_3(a) * S.Word_3(b);
const product34: u64 = S.Word_3(a) * S.Word_4(b);
const product41: u64 = S.Word_4(a) * S.Word_1(b);
const product42: u64 = S.Word_4(a) * S.Word_2(b);
const product43: u64 = S.Word_4(a) * S.Word_3(b);
const product44: u64 = S.Word_4(a) * S.Word_4(b);
const sum0: u128 = @as(u128, product44);
const sum1: u128 = @as(u128, product34) +%
@as(u128, product43);
const sum2: u128 = @as(u128, product24) +%
@as(u128, product33) +%
@as(u128, product42);
const sum3: u128 = @as(u128, product14) +%
@as(u128, product23) +%
@as(u128, product32) +%
@as(u128, product41);
const sum4: u128 = @as(u128, product13) +%
@as(u128, product22) +%
@as(u128, product31);
const sum5: u128 = @as(u128, product12) +%
@as(u128, product21);
const sum6: u128 = @as(u128, product11);
const r0: u128 = (sum0 & Word_FullMask) +%
((sum1 & Word_LoMask) << 32);
const r1: u128 = (sum0 >> 64) +%
((sum1 >> 32) & Word_FullMask) +%
(sum2 & Word_FullMask) +%
((sum3 << 32) & Word_HiMask);
lo.* = r0 +% (r1 << 64);
hi.* = (r1 >> 64) +%
(sum1 >> 96) +%
(sum2 >> 64) +%
(sum3 >> 32) +%
sum4 +%
(sum5 << 32) +%
(sum6 << 64);
},
else => @compileError("unsupported"),
}
}
pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeInfo(T).Float.bits)) i32 {
const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T);
const shift = @clz(significand.*) - @clz(integerBit);
significand.* <<= @intCast(std.math.Log2Int(Z), shift);
return @as(i32, 1) - shift;
}
pub inline fn fneg(a: anytype) @TypeOf(a) {
const F = @TypeOf(a);
const bits = @typeInfo(F).Float.bits;
const U = @Type(.{ .Int = .{
.signedness = .unsigned,
.bits = bits,
} });
const sign_bit_mask = @as(U, 1) << (bits - 1);
const negated = @bitCast(U, a) ^ sign_bit_mask;
return @bitCast(F, negated);
}

View File

@@ -1,109 +0,0 @@
// Ported from:
//
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/comparedf2_test.c
const std = @import("std");
const builtin = @import("builtin");
const is_test = builtin.is_test;
const __eqdf2 = @import("./cmpdf2.zig").__eqdf2;
const __ledf2 = @import("./cmpdf2.zig").__ledf2;
const __ltdf2 = @import("./cmpdf2.zig").__ltdf2;
const __nedf2 = @import("./cmpdf2.zig").__nedf2;
const __gedf2 = @import("./gedf2.zig").__gedf2;
const __gtdf2 = @import("./gedf2.zig").__gtdf2;
const __unorddf2 = @import("./unorddf2.zig").__unorddf2;
const TestVector = struct {
a: f64,
b: f64,
eqReference: c_int,
geReference: c_int,
gtReference: c_int,
leReference: c_int,
ltReference: c_int,
neReference: c_int,
unReference: c_int,
};
fn test__cmpdf2(vector: TestVector) bool {
if (__eqdf2(vector.a, vector.b) != vector.eqReference) {
return false;
}
if (__gedf2(vector.a, vector.b) != vector.geReference) {
return false;
}
if (__gtdf2(vector.a, vector.b) != vector.gtReference) {
return false;
}
if (__ledf2(vector.a, vector.b) != vector.leReference) {
return false;
}
if (__ltdf2(vector.a, vector.b) != vector.ltReference) {
return false;
}
if (__nedf2(vector.a, vector.b) != vector.neReference) {
return false;
}
if (__unorddf2(vector.a, vector.b) != vector.unReference) {
return false;
}
return true;
}
const arguments = [_]f64{
std.math.nan(f64),
-std.math.inf(f64),
-0x1.fffffffffffffp1023,
-0x1.0000000000001p0 - 0x1.0000000000000p0,
-0x1.fffffffffffffp-1,
-0x1.0000000000000p-1022,
-0x0.fffffffffffffp-1022,
-0x0.0000000000001p-1022,
-0.0,
0.0,
0x0.0000000000001p-1022,
0x0.fffffffffffffp-1022,
0x1.0000000000000p-1022,
0x1.fffffffffffffp-1,
0x1.0000000000000p0,
0x1.0000000000001p0,
0x1.fffffffffffffp1023,
std.math.inf(f64),
};
fn generateVector(comptime a: f64, comptime b: f64) TestVector {
const leResult = if (a < b) -1 else if (a == b) 0 else 1;
const geResult = if (a > b) 1 else if (a == b) 0 else -1;
const unResult = if (a != a or b != b) 1 else 0;
return TestVector{
.a = a,
.b = b,
.eqReference = leResult,
.geReference = geResult,
.gtReference = geResult,
.leReference = leResult,
.ltReference = leResult,
.neReference = leResult,
.unReference = unResult,
};
}
const test_vectors = init: {
@setEvalBranchQuota(10000);
var vectors: [arguments.len * arguments.len]TestVector = undefined;
for (arguments[0..]) |arg_i, i| {
for (arguments[0..]) |arg_j, j| {
vectors[(i * arguments.len) + j] = generateVector(arg_i, arg_j);
}
}
break :init vectors;
};
test "compare f64" {
for (test_vectors) |vector| {
try std.testing.expect(test__cmpdf2(vector));
}
}

View File

@@ -1,118 +0,0 @@
const std = @import("std");
pub const LE = enum(i32) {
Less = -1,
Equal = 0,
Greater = 1,
const Unordered: LE = .Greater;
};
pub const GE = enum(i32) {
Less = -1,
Equal = 0,
Greater = 1,
const Unordered: GE = .Less;
};
pub inline fn cmpf2(comptime T: type, comptime RT: type, a: T, b: T) RT {
const bits = @typeInfo(T).Float.bits;
const srep_t = std.meta.Int(.signed, bits);
const rep_t = std.meta.Int(.unsigned, bits);
const significandBits = std.math.floatMantissaBits(T);
const exponentBits = std.math.floatExponentBits(T);
const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
const absMask = signBit - 1;
const infT = comptime std.math.inf(T);
const infRep = @bitCast(rep_t, infT);
const aInt = @bitCast(srep_t, a);
const bInt = @bitCast(srep_t, b);
const aAbs = @bitCast(rep_t, aInt) & absMask;
const bAbs = @bitCast(rep_t, bInt) & absMask;
// If either a or b is NaN, they are unordered.
if (aAbs > infRep or bAbs > infRep) return RT.Unordered;
// If a and b are both zeros, they are equal.
if ((aAbs | bAbs) == 0) return .Equal;
// If at least one of a and b is positive, we get the same result comparing
// a and b as signed integers as we would with a floating-point compare.
if ((aInt & bInt) >= 0) {
if (aInt < bInt) {
return .Less;
} else if (aInt == bInt) {
return .Equal;
} else return .Greater;
} else {
// Otherwise, both are negative, so we need to flip the sense of the
// comparison to get the correct result. (This assumes a twos- or ones-
// complement integer representation; if integers are represented in a
// sign-magnitude representation, then this flip is incorrect).
if (aInt > bInt) {
return .Less;
} else if (aInt == bInt) {
return .Equal;
} else return .Greater;
}
}
pub inline fn cmp_f80(comptime RT: type, a: f80, b: f80) RT {
const a_rep = std.math.break_f80(a);
const b_rep = std.math.break_f80(b);
const sig_bits = std.math.floatMantissaBits(f80);
const int_bit = 0x8000000000000000;
const sign_bit = 0x8000;
const special_exp = 0x7FFF;
// If either a or b is NaN, they are unordered.
if ((a_rep.exp & special_exp == special_exp and a_rep.fraction ^ int_bit != 0) or
(b_rep.exp & special_exp == special_exp and b_rep.fraction ^ int_bit != 0))
return RT.Unordered;
// If a and b are both zeros, they are equal.
if ((a_rep.fraction | b_rep.fraction) | ((a_rep.exp | b_rep.exp) & special_exp) == 0)
return .Equal;
if (@boolToInt(a_rep.exp == b_rep.exp) & @boolToInt(a_rep.fraction == b_rep.fraction) != 0) {
return .Equal;
} else if (a_rep.exp & sign_bit != b_rep.exp & sign_bit) {
// signs are different
if (@bitCast(i16, a_rep.exp) < @bitCast(i16, b_rep.exp)) {
return .Less;
} else {
return .Greater;
}
} else {
const a_fraction = a_rep.fraction | (@as(u80, a_rep.exp) << sig_bits);
const b_fraction = b_rep.fraction | (@as(u80, b_rep.exp) << sig_bits);
if (a_fraction < b_fraction) {
return .Less;
} else {
return .Greater;
}
}
}
pub inline fn unordcmp(comptime T: type, a: T, b: T) i32 {
const rep_t = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
const significandBits = std.math.floatMantissaBits(T);
const exponentBits = std.math.floatExponentBits(T);
const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
const absMask = signBit - 1;
const infRep = @bitCast(rep_t, std.math.inf(T));
const aAbs: rep_t = @bitCast(rep_t, a) & absMask;
const bAbs: rep_t = @bitCast(rep_t, b) & absMask;
return @boolToInt(aAbs > infRep or bAbs > infRep);
}
test {
_ = @import("comparesf2_test.zig");
_ = @import("comparedf2_test.zig");
}

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