Compare commits
116 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
783cb980ab | ||
|
|
cf0e453cc9 | ||
|
|
9d2e5bbcb4 | ||
|
|
a42c712934 | ||
|
|
1bbf731e7e | ||
|
|
a6de0b4136 | ||
|
|
5df9f15843 | ||
|
|
4797fdb3db | ||
|
|
74c17aa8c5 | ||
|
|
465b90c1fa | ||
|
|
00664dbdce | ||
|
|
c9bc8b9d0c | ||
|
|
fd4c98cbb7 | ||
|
|
21236c0151 | ||
|
|
ea70a983ba | ||
|
|
235d56cb82 | ||
|
|
b4c0396d3c | ||
|
|
97692cb4fe | ||
|
|
d9c808e3ff | ||
|
|
1f09584d05 | ||
|
|
cad2e8da9d | ||
|
|
b124d04e6a | ||
|
|
a7eea0813f | ||
|
|
85c1db9222 | ||
|
|
40e37d4324 | ||
|
|
1ec0261518 | ||
|
|
5c13a4e54a | ||
|
|
c2de3bdc12 | ||
|
|
ad95eecf37 | ||
|
|
83b2785a43 | ||
|
|
e2104ecc2d | ||
|
|
05fefc0d3f | ||
|
|
01ff3684dc | ||
|
|
48c8948f49 | ||
|
|
f385419259 | ||
|
|
96a703ee6d | ||
|
|
32997a2fb0 | ||
|
|
a1d0c77539 | ||
|
|
2ce5f84c2f | ||
|
|
05265160ae | ||
|
|
52de625df9 | ||
|
|
cdde9d8885 | ||
|
|
ff802cc996 | ||
|
|
0ac43154eb | ||
|
|
401d091fb4 | ||
|
|
b1f52ca7f2 | ||
|
|
02cb3841a6 | ||
|
|
7c13bec7cb | ||
|
|
7add370371 | ||
|
|
d15a0ec7b2 | ||
|
|
0858d7b0df | ||
|
|
a4c8bd8fd4 | ||
|
|
7099dff7ea | ||
|
|
6bf19e32e7 | ||
|
|
c8b8f0ea13 | ||
|
|
d2445764a9 | ||
|
|
a9b7d8fa07 | ||
|
|
57ac835a03 | ||
|
|
3c907e51d1 | ||
|
|
791e38da8c | ||
|
|
1a61a9d4bf | ||
|
|
8f346d9a4b | ||
|
|
a7c2cfe16d | ||
|
|
0a4a99ec87 | ||
|
|
be2adff087 | ||
|
|
a6222d1d4b | ||
|
|
f09f960ce4 | ||
|
|
288b8b535f | ||
|
|
36b8f5d194 | ||
|
|
41d57b051f | ||
|
|
24d4bfb666 | ||
|
|
06a75c16ff | ||
|
|
8af016c5be | ||
|
|
a05ae01b4f | ||
|
|
1344706b47 | ||
|
|
72980388ca | ||
|
|
c6c25a1c09 | ||
|
|
3f134cfe5e | ||
|
|
e814f71052 | ||
|
|
50269f2315 | ||
|
|
8af0a1987b | ||
|
|
b498d26376 | ||
|
|
d3f1a4edce | ||
|
|
1add7c616f | ||
|
|
5f9a664de9 | ||
|
|
1c8cd268be | ||
|
|
eea4cd2924 | ||
|
|
4d44a813de | ||
|
|
51ffb0548d | ||
|
|
5b42704ea7 | ||
|
|
c8b6e407ba | ||
|
|
9e1e91dafc | ||
|
|
6624f9cd5c | ||
|
|
7d0c461b77 | ||
|
|
2d280825cd | ||
|
|
10617593f8 | ||
|
|
10b1001a12 | ||
|
|
eaa1db2002 | ||
|
|
1aec406311 | ||
|
|
b6350a2b3f | ||
|
|
8c62733927 | ||
|
|
aa6fc29744 | ||
|
|
01a927a0cb | ||
|
|
7d3c5f207a | ||
|
|
0405698696 | ||
|
|
73455eaf42 | ||
|
|
85665386c6 | ||
|
|
2c0caa8533 | ||
|
|
904c513a1e | ||
|
|
0e2eb6eb65 | ||
|
|
c2c3177d82 | ||
|
|
a28c244afb | ||
|
|
97ec177953 | ||
|
|
810c03f426 | ||
|
|
0f4b893d6d | ||
|
|
61507d95d8 |
8
.builds/freebsd.yml
Normal file
8
.builds/freebsd.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
image: freebsd/latest
|
||||
secrets:
|
||||
- 51bfddf5-86a6-4e01-8576-358c72a4a0a4
|
||||
- 5cfede76-914e-4071-893e-e5e2e6ae3cea
|
||||
sources:
|
||||
- https://github.com/ziglang/zig
|
||||
tasks:
|
||||
- build: cd zig && ./ci/srht/freebsd_script
|
||||
13
.gitattributes
vendored
13
.gitattributes
vendored
@@ -3,10 +3,9 @@
|
||||
langref.html.in text eol=lf
|
||||
deps/SoftFloat-3e/*.txt text eol=crlf
|
||||
|
||||
deps/** linguist-vendored
|
||||
lib/include/** linguist-vendored
|
||||
lib/libc/** linguist-vendored
|
||||
lib/libcxx/** linguist-vendored
|
||||
lib/libcxxabi/** linguist-vendored
|
||||
lib/libunwind/** linguist-vendored
|
||||
lib/tsan/** linguist-vendored
|
||||
deps/* linguist-vendored
|
||||
lib/include/* linguist-vendored
|
||||
lib/libc/* linguist-vendored
|
||||
lib/libcxx/* linguist-vendored
|
||||
lib/libcxxabi/* linguist-vendored
|
||||
lib/libunwind/* linguist-vendored
|
||||
|
||||
4
.github/CODEOWNERS
vendored
4
.github/CODEOWNERS
vendored
@@ -1,4 +0,0 @@
|
||||
# Autodoc
|
||||
/src/Autodoc.zig @kristoff-it
|
||||
/src/autodoc/* @kristoff-it
|
||||
/lib/docs/* @kristoff-it
|
||||
12
.github/ISSUE_TEMPLATE/autodoc-issue.md
vendored
12
.github/ISSUE_TEMPLATE/autodoc-issue.md
vendored
@@ -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.
|
||||
33
.github/ISSUE_TEMPLATE/bug.yml
vendored
33
.github/ISSUE_TEMPLATE/bug.yml
vendored
@@ -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
|
||||
7
.github/ISSUE_TEMPLATE/config.yml
vendored
7
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -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
|
||||
47
.github/workflows/ci.yaml
vendored
47
.github/workflows/ci.yaml
vendored
@@ -1,47 +0,0 @@
|
||||
name: ci
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 0.10.x
|
||||
concurrency:
|
||||
# Cancels pending runs when a PR gets updated.
|
||||
group: ${{ github.head_ref || github.run_id }}-${{ github.actor }}
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
x86_64-linux-debug:
|
||||
runs-on: [self-hosted, Linux, x86_64]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Build and Test
|
||||
run: sh ci/x86_64-linux-debug.sh
|
||||
x86_64-linux-release:
|
||||
runs-on: [self-hosted, Linux, x86_64]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Build and Test
|
||||
run: sh ci/x86_64-linux-release.sh
|
||||
aarch64-linux-debug:
|
||||
runs-on: [self-hosted, Linux, aarch64]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Build and Test
|
||||
run: sh ci/aarch64-linux-debug.sh
|
||||
aarch64-linux-release:
|
||||
runs-on: [self-hosted, Linux, aarch64]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Build and Test
|
||||
run: sh ci/aarch64-linux-release.sh
|
||||
x86_64-macos:
|
||||
runs-on: "macos-11"
|
||||
env:
|
||||
ARCH: "x86_64"
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Build and Test
|
||||
run: ci/x86_64-macos.sh
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -10,9 +10,6 @@
|
||||
# -andrewrk
|
||||
|
||||
zig-cache/
|
||||
zig-out/
|
||||
/release/
|
||||
/debug/
|
||||
/build/
|
||||
/build-*/
|
||||
/docgen_tmp/
|
||||
|
||||
702
CMakeLists.txt
702
CMakeLists.txt
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@ a link. There is no concept of "official" or "unofficial", however, each
|
||||
gathering place has its own moderators and rules.
|
||||
|
||||
This is Andrew Kelley speaking. At least for now, I'm the moderator of the
|
||||
ziglang organization GitHub repositories and the #zig IRC channel on Libera.chat.
|
||||
ziglang organization GitHub repositories and the #zig IRC channel on Freenode.
|
||||
**This document contains the rules that govern these two spaces only**.
|
||||
|
||||
The rules here are strict. This space is for focused, on topic, technical work
|
||||
@@ -5,11 +5,9 @@
|
||||
One of the best ways you can contribute to Zig is to start using it for a
|
||||
personal project. Here are some great examples:
|
||||
|
||||
* [Oxid](https://github.com/dbandstra/oxid) - arcade style game
|
||||
* [TM35-Metronome](https://github.com/TM35-Metronome) - tools for modifying and randomizing Pokémon games
|
||||
* [River](https://github.com/ifreund/river/) - a dynamic tiling wayland compositor
|
||||
|
||||
More examples can be found on the
|
||||
[Community Projects Wiki](https://github.com/ziglang/zig/wiki/Community-Projects).
|
||||
* [trOS](https://github.com/sjdh02/trOS) - tiny aarch64 baremetal OS thingy
|
||||
|
||||
Without fail, these projects lead to discovering bugs and helping flesh out use
|
||||
cases, which lead to further design iterations of Zig. Importantly, each issue
|
||||
@@ -53,8 +51,7 @@ knowledge of Zig internals.**
|
||||
|
||||
### Editing Source Code
|
||||
|
||||
First, build the Stage 1 compiler as described in
|
||||
[Building Zig From Source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source).
|
||||
First, build the Stage 1 compiler as described in [Building from Source](README.md#Building-from-Source).
|
||||
|
||||
Zig locates lib files relative to executable path by searching up the
|
||||
filesystem tree for a sub-path of `lib/zig/std/std.zig` or `lib/std/std.zig`.
|
||||
@@ -68,7 +65,7 @@ test and debug from a git working tree.
|
||||
- `make` is typically sufficient to build zig during development iterations.
|
||||
- `make install` performs a build __and__ install.
|
||||
- `msbuild -p:Configuration=Release INSTALL.vcxproj` on Windows performs a
|
||||
build and install. To avoid install, pass cmake option `-DZIG_NO_LIB=ON`.
|
||||
build and install. To avoid install, pass cmake option `-DZIG_SKIP_INSTALL_LIB_FILES=ON`.
|
||||
|
||||
To test changes, do the following from the build directory:
|
||||
|
||||
@@ -104,17 +101,9 @@ When making changes to the compiler source code, the most helpful test step to
|
||||
run is `test-behavior`. When editing documentation it is `docs`. You can find
|
||||
this information and more in the `--help` menu.
|
||||
|
||||
#### Testing Changes to std lib
|
||||
|
||||
To quickly test a change to a file in the standard library, you can run zig test and specify a custom lib directory with the follow command-line argument.
|
||||
|
||||
```bash
|
||||
./build/zig test lib/std/fmt.zig --zig-lib-dir lib --main-pkg-path lib/std
|
||||
```
|
||||
|
||||
#### Testing Non-Native Architectures with QEMU
|
||||
|
||||
The Linux CI server additionally has qemu installed and sets `-fqemu`.
|
||||
The Linux CI server additionally has qemu installed and sets `-Denable-qemu`.
|
||||
This provides test coverage for, e.g. aarch64 even on x86_64 machines. It's
|
||||
recommended for Linux users to install qemu and enable this testing option
|
||||
when editing the standard library or anything related to a non-native
|
||||
@@ -123,7 +112,7 @@ architecture.
|
||||
##### glibc
|
||||
|
||||
Testing foreign architectures with dynamically linked glibc is one step trickier.
|
||||
This requires enabling `--glibc-runtimes /path/to/glibc/multi/install/glibcs`.
|
||||
This requires enabling `-Denable-foreign-glibc=/path/to/glibc/multi/install/glibcs`.
|
||||
This path is obtained by building glibc for multiple architectures. This
|
||||
process for me took an entire day to complete and takes up 65 GiB on my hard
|
||||
drive. The CI server does not provide this test coverage. Instructions for
|
||||
@@ -135,19 +124,11 @@ It's understood that most contributors will not have these tests enabled.
|
||||
|
||||
#### Testing Windows from a Linux Machine with Wine
|
||||
|
||||
When developing on Linux, another option is available to you: `-fwine`.
|
||||
When developing on Linux, another option is available to you: `-Denable-wine`.
|
||||
This will enable running behavior tests and std lib tests with Wine. It's
|
||||
recommended for Linux users to install Wine and enable this testing option
|
||||
when editing the standard library or anything Windows-related.
|
||||
|
||||
#### Testing WebAssembly using wasmtime
|
||||
|
||||
If you have [wasmtime](https://wasmtime.dev/) installed, take advantage of the
|
||||
`-fwasmtime` flag which will enable running WASI behavior tests and std
|
||||
lib tests. It's recommended for all users to install wasmtime and enable this
|
||||
testing option when editing the standard library and especially anything
|
||||
WebAssembly-related.
|
||||
|
||||
#### Improving Translate-C
|
||||
|
||||
Please read the [Editing Source Code](#editing-source-code) section as a
|
||||
@@ -171,7 +152,7 @@ The relevant tests for this feature are:
|
||||
same, and that the program exits cleanly. This kind of test coverage is preferred, when
|
||||
possible, because it makes sure that the resulting Zig code is actually viable.
|
||||
|
||||
* `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
|
||||
* `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
|
||||
which checks that the relevant macros in `test/stage1/behavior/translate_c_macros.h`.
|
||||
have the correct values. Macros have to be tested separately since they are expanded by
|
||||
Clang in `run_translated_c` tests.
|
||||
@@ -192,21 +173,21 @@ repo, we maintain a C API on top of Clang's C++ API:
|
||||
Clang's C++ API changes. This one file necessarily does include Clang's C++ headers, which
|
||||
makes it the slowest-to-compile source file in all of Zig's codebase.
|
||||
|
||||
* `src/clang.zig` - the Zig equivalent of `src/zig_clang.h`. This is a manually
|
||||
* `src-self-hosted/clang.zig` - the Zig equivalent of `src/zig_clang.h`. This is a manually
|
||||
maintained list of types and functions that are ABI-compatible with the Clang C API we
|
||||
maintain. In theory this could be generated by running translate-c on `src/zig_clang.h`,
|
||||
but that would introduce a dependency cycle, since we are using this file to implement
|
||||
translate-c.
|
||||
|
||||
Finally, the actual source code for the translate-c feature is
|
||||
`src/translate_c.zig`. This code uses the Clang C API exposed by
|
||||
`src/clang.zig`, and produces Zig AST.
|
||||
`src-self-hosted/translate_c.zig`. This code uses the Clang C API exposed by
|
||||
`src-self-hosted/clang.zig`, and produces Zig AST.
|
||||
|
||||
The steps for contributing to translate-c look like this:
|
||||
|
||||
1. Identify a test case you want to improve. Add it as a run-translated-c test
|
||||
case (usually preferable), or as a translate-c test case.
|
||||
|
||||
2. Edit `src/translate_c.zig` to improve the behavior.
|
||||
2. Edit `src-self-hosted/translate_c.zig` to improve the behavior.
|
||||
|
||||
3. Run the relevant tests: `./zig build test-run-translated-c test-translate-c`
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
The MIT License (Expat)
|
||||
|
||||
Copyright (c) 2015-2023, Zig contributors
|
||||
Copyright (c) 2015 Andrew Kelley
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
104
README.md
104
README.md
@@ -1,25 +1,111 @@
|
||||

|
||||

|
||||
|
||||
A general-purpose programming language and toolchain for maintaining
|
||||
**robust**, **optimal**, and **reusable** software.
|
||||
|
||||
## Resources
|
||||
|
||||
* [Introduction](https://ziglang.org/learn/#introduction)
|
||||
* [Introduction](https://ziglang.org/#Introduction)
|
||||
* [Download & Documentation](https://ziglang.org/download)
|
||||
* [Chapter 0 - Getting Started | ZigLearn.org](https://ziglearn.org/)
|
||||
* [Community](https://github.com/ziglang/zig/wiki/Community)
|
||||
* [Contributing](https://github.com/ziglang/zig/blob/master/.github/CONTRIBUTING.md)
|
||||
* [Code of Conduct](https://github.com/ziglang/zig/blob/master/.github/CODE_OF_CONDUCT.md)
|
||||
* [Contributing](https://github.com/ziglang/zig/blob/master/CONTRIBUTING.md)
|
||||
* [Code of Conduct](https://github.com/ziglang/zig/blob/master/CODE_OF_CONDUCT.md)
|
||||
* [Frequently Asked Questions](https://github.com/ziglang/zig/wiki/FAQ)
|
||||
* [Community Projects](https://github.com/ziglang/zig/wiki/Community-Projects)
|
||||
|
||||
## Installation
|
||||
## Building from Source
|
||||
|
||||
* [download a pre-built binary](https://ziglang.org/download/)
|
||||
* [install from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
|
||||
* [build from source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source)
|
||||
* [bootstrap zig for any target](https://github.com/ziglang/zig-bootstrap)
|
||||
[](https://dev.azure.com/ziglang/zig/_build/latest?definitionId=1&branchName=master)
|
||||
|
||||
Note that you can
|
||||
[download a binary of the master branch](https://ziglang.org/download/#release-master) or
|
||||
[install Zig from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager).
|
||||
|
||||
### Stage 1: Build Zig from C++ Source Code
|
||||
|
||||
This step must be repeated when you make changes to any of the C++ source code.
|
||||
|
||||
#### Dependencies
|
||||
|
||||
##### POSIX
|
||||
|
||||
* cmake >= 2.8.5
|
||||
* gcc >= 5.0.0 or clang >= 3.6.0
|
||||
* LLVM, Clang, LLD development libraries == 11.x, compiled with the same gcc or clang version above
|
||||
- Use the system package manager, or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#posix).
|
||||
|
||||
##### Windows
|
||||
|
||||
* cmake >= 3.15.3
|
||||
* Microsoft Visual Studio. Supported versions:
|
||||
- 2017 (version 15.8)
|
||||
- 2019 (version 16)
|
||||
* LLVM, Clang, LLD development libraries == 11.x
|
||||
- Use the [pre-built binaries](https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows) or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#windows).
|
||||
|
||||
#### Instructions
|
||||
|
||||
##### POSIX
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make install
|
||||
```
|
||||
|
||||
Need help? [Troubleshooting Build Issues](https://github.com/ziglang/zig/wiki/Troubleshooting-Build-Issues)
|
||||
|
||||
##### MacOS
|
||||
|
||||
```
|
||||
brew install cmake llvm
|
||||
brew outdated llvm || brew upgrade llvm
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix llvm)
|
||||
make install
|
||||
```
|
||||
|
||||
##### Windows
|
||||
|
||||
See https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows
|
||||
|
||||
### Stage 2: Build Self-Hosted Zig from Zig Source Code
|
||||
|
||||
Now we use the stage1 binary:
|
||||
|
||||
```
|
||||
zig build --prefix $(pwd)/stage2 -Denable-llvm
|
||||
```
|
||||
|
||||
This produces `stage2/bin/zig` which can be used for testing and development.
|
||||
Once it is feature complete, it will be used to build stage 3 - the final compiler
|
||||
binary.
|
||||
|
||||
### Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler
|
||||
|
||||
*Note: Stage 2 compiler is not yet able to build Stage 3. Building Stage 3 is
|
||||
not yet supported.*
|
||||
|
||||
Once the self-hosted compiler can build itself, this will be the actual
|
||||
compiler binary that we will install to the system. Until then, users should
|
||||
use stage 1.
|
||||
|
||||
#### Debug / Development Build
|
||||
|
||||
```
|
||||
stage2/bin/zig build
|
||||
```
|
||||
|
||||
This produces `zig-cache/bin/zig`.
|
||||
|
||||
#### Release / Install Build
|
||||
|
||||
```
|
||||
stage2/bin/zig build install -Drelease
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Requires cmake ninja-build
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
ARCH="$(uname -m)"
|
||||
TARGET="$ARCH-linux-musl"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.11.0-dev.971+19056cb68"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
export PATH="$HOME/deps/wasmtime-v2.0.2-$ARCH-linux:$PATH"
|
||||
|
||||
# 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
|
||||
|
||||
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
|
||||
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
|
||||
|
||||
rm -rf build-debug
|
||||
mkdir build-debug
|
||||
cd build-debug
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-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
|
||||
|
||||
echo "Looking for non-conforming code formatting..."
|
||||
stage3-debug/bin/zig fmt --check .. \
|
||||
--exclude ../test/cases/ \
|
||||
--exclude ../build-debug
|
||||
|
||||
# simultaneously test building self-hosted without LLVM and with 32-bit arm
|
||||
stage3-debug/bin/zig build -Dtarget=arm-linux-musleabihf
|
||||
|
||||
stage3-debug/bin/zig build test docs \
|
||||
-fwasmtime \
|
||||
-Dstatic-llvm \
|
||||
-Dtarget=native-native-musl \
|
||||
--search-prefix "$PREFIX" \
|
||||
--zig-lib-dir "$(pwd)/../lib"
|
||||
|
||||
# Look for HTML errors.
|
||||
tidy --drop-empty-elements no -qe "$ZIG_LOCAL_CACHE_DIR/langref.html"
|
||||
|
||||
# Produce the experimental std lib documentation.
|
||||
stage3-debug/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
|
||||
@@ -1,71 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Requires cmake ninja-build
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
ARCH="$(uname -m)"
|
||||
TARGET="$ARCH-linux-musl"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.11.0-dev.971+19056cb68"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
export PATH="$HOME/deps/wasmtime-v2.0.2-$ARCH-linux:$PATH"
|
||||
|
||||
# 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
|
||||
|
||||
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
|
||||
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
|
||||
|
||||
rm -rf build-release
|
||||
mkdir build-release
|
||||
cd build-release
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-release" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-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
|
||||
|
||||
echo "Looking for non-conforming code formatting..."
|
||||
stage3-release/bin/zig fmt --check .. \
|
||||
--exclude ../test/cases/ \
|
||||
--exclude ../build-release
|
||||
|
||||
# simultaneously test building self-hosted without LLVM and with 32-bit arm
|
||||
stage3-release/bin/zig build -Dtarget=arm-linux-musleabihf
|
||||
|
||||
stage3-release/bin/zig build test docs \
|
||||
-fwasmtime \
|
||||
-Dstatic-llvm \
|
||||
-Dtarget=native-native-musl \
|
||||
--search-prefix "$PREFIX" \
|
||||
--zig-lib-dir "$(pwd)/../lib"
|
||||
|
||||
# Look for HTML errors.
|
||||
tidy --drop-empty-elements no -qe "$ZIG_LOCAL_CACHE_DIR/langref.html"
|
||||
|
||||
# Produce the experimental std lib documentation.
|
||||
stage3-release/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
|
||||
@@ -1,70 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Script assumes the presence of the following:
|
||||
# s3cmd
|
||||
|
||||
ZIGDIR="$(pwd)"
|
||||
TARGET="$ARCH-macos-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.11.0-dev.534+b0b1cc356-1"
|
||||
PREFIX="$HOME/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
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
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache"
|
||||
|
||||
PATH="$HOME/local/bin:$PATH" cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-release" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_C_COMPILER="$ZIG;cc;-target;$TARGET;-mcpu=$MCPU" \
|
||||
-DCMAKE_CXX_COMPILER="$ZIG;c++;-target;$TARGET;-mcpu=$MCPU" \
|
||||
-DZIG_TARGET_TRIPLE="$TARGET" \
|
||||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON \
|
||||
-GNinja
|
||||
|
||||
$HOME/local/bin/ninja install
|
||||
|
||||
stage3-release/bin/zig build test docs \
|
||||
--zig-lib-dir "$(pwd)/../lib" \
|
||||
-Denable-macos-sdk \
|
||||
-Dstatic-llvm \
|
||||
-Dskip-non-native \
|
||||
--search-prefix "$PREFIX"
|
||||
|
||||
# Produce the experimental std lib documentation.
|
||||
stage3-release/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
|
||||
|
||||
# Ensure that stage3 and stage4 are byte-for-byte identical.
|
||||
stage3-release/bin/zig build \
|
||||
--prefix stage4-release \
|
||||
-Denable-llvm \
|
||||
-Dno-lib \
|
||||
-Drelease \
|
||||
-Dstrip \
|
||||
-Dtarget=$TARGET \
|
||||
-Duse-zig-libcxx \
|
||||
-Dversion-string="$(stage3-release/bin/zig version)"
|
||||
|
||||
# diff returns an error code if the files differ.
|
||||
echo "If the following command fails, it means nondeterminism has been"
|
||||
echo "introduced, making stage3 and stage4 no longer byte-for-byte identical."
|
||||
diff stage3-release/bin/zig stage4-release/bin/zig
|
||||
87
ci/azure/linux_script
Executable file
87
ci/azure/linux_script
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
BUILDDIR="$(pwd)"
|
||||
|
||||
sudo sh -c 'echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list'
|
||||
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
|
||||
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
||||
|
||||
sudo apt-get remove -y llvm-*
|
||||
sudo rm -rf /usr/local/*
|
||||
|
||||
# Some APT mirrors can be flaky, retry the download instead of failing right
|
||||
# away.
|
||||
APT_MAX_RETRY=3
|
||||
|
||||
for i in $(seq 1 "$APT_MAX_RETRY"); do
|
||||
sudo apt-get update -q
|
||||
sudo apt-get install -y \
|
||||
libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd \
|
||||
gcc-7 g++-7 ninja-build tidy \
|
||||
&& break
|
||||
if [ "$i" -eq "$APT_MAX_RETRY" ]; then
|
||||
echo 'apt-get failed, giving up...'
|
||||
exit 1
|
||||
fi
|
||||
echo 'apt-get failed, retrying...'
|
||||
sleep 5s
|
||||
done
|
||||
|
||||
QEMUBASE="qemu-linux-x86_64-5.1.0"
|
||||
wget https://ziglang.org/deps/$QEMUBASE.tar.xz
|
||||
tar xf $QEMUBASE.tar.xz
|
||||
PATH=$PWD/$QEMUBASE/bin:$PATH
|
||||
|
||||
WASMTIME="wasmtime-v0.20.0-x86_64-linux"
|
||||
wget https://github.com/bytecodealliance/wasmtime/releases/download/v0.20.0/$WASMTIME.tar.xz
|
||||
tar xf $WASMTIME.tar.xz
|
||||
PATH=$PWD/$WASMTIME:$PATH
|
||||
|
||||
# Make the `zig version` number consistent.
|
||||
# This will affect the cmake command below.
|
||||
git config core.abbrev 9
|
||||
|
||||
export CC=gcc-7
|
||||
export CXX=g++-7
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja
|
||||
ninja install
|
||||
./zig build test -Denable-qemu -Denable-wasmtime
|
||||
|
||||
# look for HTML errors
|
||||
tidy -qe ../zig-cache/langref.html
|
||||
|
||||
VERSION="$(./zig version)"
|
||||
|
||||
if [ "${BUILD_REASON}" != "PullRequest" ]; then
|
||||
ARTIFACTSDIR="$BUILDDIR/artifacts"
|
||||
mkdir "$ARTIFACTSDIR"
|
||||
docker run -i --mount type=bind,source="$ARTIFACTSDIR",target=/z ziglang/static-base:llvm11-x86_64-1 -j2 $BUILD_SOURCEVERSION
|
||||
TARBALL="$(ls $ARTIFACTSDIR)"
|
||||
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
|
||||
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$ARTIFACTSDIR/$TARBALL" s3://ziglang.org/builds/
|
||||
|
||||
SHASUM=$(sha256sum $ARTIFACTSDIR/$TARBALL | cut '-d ' -f1)
|
||||
BYTESIZE=$(wc -c < $ARTIFACTSDIR/$TARBALL)
|
||||
|
||||
JSONFILE="linux-$GITBRANCH.json"
|
||||
touch $JSONFILE
|
||||
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
|
||||
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
|
||||
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
|
||||
|
||||
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
|
||||
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/x86_64-linux-$VERSION.json"
|
||||
|
||||
# `set -x` causes these variables to be mangled.
|
||||
# See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html
|
||||
set +x
|
||||
echo "##vso[task.setvariable variable=tarball;isOutput=true]$TARBALL"
|
||||
echo "##vso[task.setvariable variable=shasum;isOutput=true]$SHASUM"
|
||||
echo "##vso[task.setvariable variable=bytesize;isOutput=true]$BYTESIZE"
|
||||
echo "##vso[task.setvariable variable=version;isOutput=true]$VERSION"
|
||||
fi
|
||||
91
ci/azure/macos_script
Executable file
91
ci/azure/macos_script
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
brew install s3cmd
|
||||
|
||||
ZIGDIR="$(pwd)"
|
||||
ARCH="x86_64"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$ARCH-macos-gnu-0.6.0+1c9ef63a"
|
||||
PREFIX="$HOME/$CACHE_BASENAME"
|
||||
JOBS="-j2"
|
||||
|
||||
rm -rf $PREFIX
|
||||
cd $HOME
|
||||
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
|
||||
tar xf "$CACHE_BASENAME.tar.xz"
|
||||
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
NATIVE_LIBC_TXT="$HOME/native_libc.txt"
|
||||
$ZIG libc > "$NATIVE_LIBC_TXT"
|
||||
export ZIG_LIBC="$NATIVE_LIBC_TXT"
|
||||
export CC="$ZIG cc"
|
||||
export CXX="$ZIG c++"
|
||||
|
||||
cd $ZIGDIR
|
||||
|
||||
# Make the `zig version` number consistent.
|
||||
# This will affect the cmake command below.
|
||||
git config core.abbrev 9
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DZIG_TARGET_TRIPLE="$ARCH-native-gnu" \
|
||||
-DZIG_TARGET_MCPU="baseline" \
|
||||
-DZIG_STATIC=ON
|
||||
|
||||
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
|
||||
# so that installation and testing do not get affected by them.
|
||||
unset CC
|
||||
unset CXX
|
||||
unset ZIG_LIBC
|
||||
|
||||
make $JOBS install
|
||||
|
||||
# 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
|
||||
|
||||
release/bin/zig build test
|
||||
|
||||
if [ "${BUILD_REASON}" != "PullRequest" ]; then
|
||||
mv ../LICENSE release/
|
||||
mv ../zig-cache/langref.html release/
|
||||
mv release/bin/zig release/
|
||||
rmdir release/bin
|
||||
|
||||
VERSION=$(release/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
|
||||
12
ci/azure/on_master_success
Executable file
12
ci/azure/on_master_success
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
# We do not set -x because this would leak the oauth access token.
|
||||
set +x
|
||||
|
||||
set -e
|
||||
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y curl jq
|
||||
|
||||
OAUTH_TOKEN="$(cat "$DOWNLOADSECUREFILE_SECUREFILEPATH")"
|
||||
./ci/srht/on_master_success "$VERSION" "$OAUTH_TOKEN"
|
||||
70
ci/azure/pipelines.yml
Normal file
70
ci/azure/pipelines.yml
Normal file
@@ -0,0 +1,70 @@
|
||||
jobs:
|
||||
- job: BuildMacOS
|
||||
pool:
|
||||
vmImage: 'macOS-10.15'
|
||||
|
||||
timeoutInMinutes: 360
|
||||
|
||||
steps:
|
||||
- task: DownloadSecureFile@1
|
||||
inputs:
|
||||
secureFile: s3cfg
|
||||
- script: ci/azure/macos_script
|
||||
name: main
|
||||
displayName: 'Build and test'
|
||||
- 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/2020-09-03/msys2-base-x86_64-20200903.sfx.exe", "sfx.exe")
|
||||
.\sfx.exe -y -o\
|
||||
del sfx.exe
|
||||
displayName: Download/Extract/Install MSYS2
|
||||
- script: |
|
||||
@REM install updated filesystem package first without dependency checking
|
||||
@REM because of: https://github.com/msys2/MSYS2-packages/issues/2021
|
||||
%CD:~0,2%\msys64\usr\bin\bash -lc "pacman --noconfirm -Sydd filesystem"
|
||||
displayName: Workaround filesystem dash MSYS2 dependency issue
|
||||
- script: |
|
||||
%CD:~0,2%\msys64\usr\bin\bash -lc "pacman --noconfirm -Syuu"
|
||||
%CD:~0,2%\msys64\usr\bin\bash -lc "pacman --noconfirm -Syuu"
|
||||
displayName: Update MSYS2
|
||||
- task: DownloadSecureFile@1
|
||||
inputs:
|
||||
secureFile: s3cfg
|
||||
- script: ci/azure/windows_msvc_script.bat
|
||||
name: main
|
||||
displayName: 'Build and test'
|
||||
- job: OnMasterSuccess
|
||||
dependsOn:
|
||||
- BuildMacOS
|
||||
- BuildLinux
|
||||
- BuildWindows
|
||||
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
|
||||
strategy:
|
||||
maxParallel: 1
|
||||
pool:
|
||||
vmImage: 'ubuntu-18.04'
|
||||
variables:
|
||||
version: $[ dependencies.BuildLinux.outputs['main.version'] ]
|
||||
steps:
|
||||
- task: DownloadSecureFile@1
|
||||
inputs:
|
||||
secureFile: oauth_token
|
||||
- script: ci/azure/on_master_success
|
||||
displayName: 'master branch success hook'
|
||||
11
ci/azure/windows_msvc_install
Normal file
11
ci/azure/windows_msvc_install
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
pacman -Su --needed --noconfirm
|
||||
pacman -S --needed --noconfirm wget p7zip python3-pip tar xz
|
||||
|
||||
pip install s3cmd
|
||||
wget -nv "https://ziglang.org/deps/llvm%2bclang%2blld-11.0.0-x86_64-windows-msvc-release-mt.tar.xz"
|
||||
tar xf llvm+clang+lld-11.0.0-x86_64-windows-msvc-release-mt.tar.xz
|
||||
44
ci/azure/windows_msvc_script.bat
Normal file
44
ci/azure/windows_msvc_script.bat
Normal file
@@ -0,0 +1,44 @@
|
||||
@echo on
|
||||
SET "SRCROOT=%cd%"
|
||||
SET "PREVPATH=%PATH%"
|
||||
SET "PREVMSYSEM=%MSYSTEM%"
|
||||
|
||||
set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
|
||||
SET "MSYSTEM=MINGW64"
|
||||
bash -lc "cd ${SRCROOT} && ci/azure/windows_msvc_install" || exit /b
|
||||
SET "PATH=%PREVPATH%"
|
||||
SET "MSYSTEM=%PREVMSYSTEM%"
|
||||
|
||||
SET "ZIGBUILDDIR=%SRCROOT%\build"
|
||||
SET "ZIGINSTALLDIR=%ZIGBUILDDIR%\dist"
|
||||
SET "ZIGPREFIXPATH=%SRCROOT%\llvm+clang+lld-11.0.0-x86_64-windows-msvc-release-mt"
|
||||
|
||||
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
|
||||
|
||||
REM Make the `zig version` number consistent.
|
||||
REM This will affect the cmake command below.
|
||||
git.exe config core.abbrev 9
|
||||
|
||||
mkdir %ZIGBUILDDIR%
|
||||
cd %ZIGBUILDDIR%
|
||||
cmake.exe .. -Thost=x64 -G"Visual Studio 16 2019" -A x64 "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release || exit /b
|
||||
msbuild /maxcpucount /p:Configuration=Release INSTALL.vcxproj || exit /b
|
||||
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-behavior -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-stage2 -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-fmt -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-std -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-compiler-rt -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-compare-output -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-standalone -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-stack-traces -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-cli -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-asm-link -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-runtime-safety -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-translate-c -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build test-run-translated-c -Dskip-non-native || exit /b
|
||||
"%ZIGINSTALLDIR%\bin\zig.exe" build docs || exit /b
|
||||
|
||||
set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
|
||||
SET "MSYSTEM=MINGW64"
|
||||
bash -lc "cd ${SRCROOT} && ci/azure/windows_upload" || exit /b
|
||||
41
ci/azure/windows_upload
Executable file
41
ci/azure/windows_upload
Executable 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
|
||||
19
ci/drone/drone.yml
Normal file
19
ci/drone/drone.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
kind: pipeline
|
||||
name: test-aarch64-linux-musl
|
||||
|
||||
platform:
|
||||
arch: arm64
|
||||
|
||||
steps:
|
||||
- name: build-and-test
|
||||
image: ziglang/static-base:llvm11-aarch64-1
|
||||
environment:
|
||||
SRHT_OAUTH_TOKEN:
|
||||
from_secret: SRHT_OAUTH_TOKEN
|
||||
AWS_ACCESS_KEY_ID:
|
||||
from_secret: AWS_ACCESS_KEY_ID
|
||||
AWS_SECRET_ACCESS_KEY:
|
||||
from_secret: AWS_SECRET_ACCESS_KEY
|
||||
commands:
|
||||
- ./ci/drone/linux_script
|
||||
58
ci/drone/linux_script
Executable file
58
ci/drone/linux_script
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
TRIPLEARCH="$(uname -m)"
|
||||
BUILDDIR="$(pwd)"
|
||||
DISTDIR="$(pwd)/dist"
|
||||
|
||||
apk update
|
||||
apk add py3-pip xz perl-utils jq curl samurai
|
||||
pip3 install s3cmd
|
||||
|
||||
# Make the `zig version` number consistent.
|
||||
# This will affect the cmake command below.
|
||||
git config core.abbrev 9
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=$DISTDIR" -DZIG_STATIC=ON -DCMAKE_PREFIX_PATH=/deps/local -GNinja
|
||||
|
||||
samu install
|
||||
./zig build test -Dskip-release -Dskip-non-native
|
||||
|
||||
if [ -z "$DRONE_PULL_REQUEST" ]; then
|
||||
mv ../LICENSE "$DISTDIR/"
|
||||
mv ../zig-cache/langref.html "$DISTDIR/"
|
||||
mv "$DISTDIR/bin/zig" "$DISTDIR/"
|
||||
rmdir "$DISTDIR/bin"
|
||||
|
||||
GITBRANCH="$DRONE_BRANCH"
|
||||
VERSION="$("$DISTDIR/zig" version)"
|
||||
DIRNAME="zig-linux-$TRIPLEARCH-$VERSION"
|
||||
TARBALL="$DIRNAME.tar.xz"
|
||||
mv "$DISTDIR" "$DIRNAME"
|
||||
tar cfJ "$TARBALL" "$DIRNAME"
|
||||
|
||||
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
|
||||
|
||||
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
|
||||
BYTESIZE=$(wc -c < $TARBALL)
|
||||
|
||||
JSONFILE="$TRIPLEARCH-linux-$GITBRANCH.json"
|
||||
touch $JSONFILE
|
||||
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
|
||||
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
|
||||
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
|
||||
|
||||
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
|
||||
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$TRIPLEARCH-linux-$VERSION.json"
|
||||
if [ "$GITBRANCH" = "master" ]; then
|
||||
# avoid leaking oauth token
|
||||
set +x
|
||||
|
||||
cd "$BUILDDIR"
|
||||
./ci/srht/on_master_success "$VERSION" "$SRHT_OAUTH_TOKEN"
|
||||
fi
|
||||
fi
|
||||
72
ci/srht/freebsd_script
Executable file
72
ci/srht/freebsd_script
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
sudo pkg update -fq
|
||||
sudo pkg install -y cmake py27-s3cmd wget curl jq
|
||||
|
||||
ZIGDIR="$(pwd)"
|
||||
CACHE_BASENAME="llvm+clang+lld-11.0.0-x86_64-freebsd-release"
|
||||
PREFIX="$HOME/$CACHE_BASENAME"
|
||||
JOBS="-j$(sysctl -n hw.ncpu)"
|
||||
|
||||
cd $HOME
|
||||
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
|
||||
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
|
||||
|
||||
# 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
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PREFIX "-DCMAKE_INSTALL_PREFIX=$(pwd)/release" -DZIG_STATIC=ON
|
||||
make $JOBS install
|
||||
|
||||
# Here we skip some tests to save time.
|
||||
release/bin/zig build test -Dskip-compile-errors -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-freebsd-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="freebsd-$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-freebsd-$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
|
||||
39
ci/srht/on_master_success
Executable file
39
ci/srht/on_master_success
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script must run on a lot of different platforms.
|
||||
# It assumes that the following things are installed:
|
||||
# * curl
|
||||
# * jq
|
||||
# * cat
|
||||
|
||||
# We do not set -x because this would leak the oauth access token.
|
||||
set +x
|
||||
|
||||
set -e
|
||||
|
||||
VERSION="$1"
|
||||
OAUTH_TOKEN="$2"
|
||||
YML_FILE="tmp.yml"
|
||||
|
||||
cat <<EOF >"$YML_FILE"
|
||||
image: alpine/latest
|
||||
packages:
|
||||
- py3-pip
|
||||
- curl
|
||||
- jq
|
||||
- xz
|
||||
secrets:
|
||||
- 51bfddf5-86a6-4e01-8576-358c72a4a0a4
|
||||
sources:
|
||||
- https://github.com/ziglang/zig
|
||||
tasks:
|
||||
- build: cd zig && ./ci/srht/update_download_page $VERSION
|
||||
EOF
|
||||
|
||||
jq <$YML_FILE -sR '{
|
||||
"manifest": .,
|
||||
}' | curl \
|
||||
-H Authorization:"token $OAUTH_TOKEN" \
|
||||
-H Content-Type:application/json \
|
||||
-X POST \
|
||||
-d @- "https://builds.hut.lavatech.top/api/jobs"
|
||||
80
ci/srht/update_download_page
Executable file
80
ci/srht/update_download_page
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
VERSION="$1"
|
||||
SRCDIR="$(pwd)"
|
||||
NATIVE_TARBALL="zig-linux-$(uname -m)-$VERSION.tar.xz"
|
||||
|
||||
# Check for all the builds being completed. It's expected that this script is run several times
|
||||
# before they are all complete.
|
||||
AARCH64_LINUX_JSON_URL="https://ziglang.org/builds/aarch64-linux-$VERSION.json"
|
||||
X86_64_LINUX_JSON_URL="https://ziglang.org/builds/x86_64-linux-$VERSION.json"
|
||||
X86_64_WINDOWS_JSON_URL="https://ziglang.org/builds/x86_64-windows-$VERSION.json"
|
||||
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"
|
||||
|
||||
# If any of these fail, it's not really this job failing; rather we have detected
|
||||
# that this job will be called again later when other jobs have completed.
|
||||
curl --fail -I "$AARCH64_LINUX_JSON_URL" >/dev/null || exit 0
|
||||
curl --fail -I "$X86_64_LINUX_JSON_URL" >/dev/null || exit 0
|
||||
curl --fail -I "$X86_64_WINDOWS_JSON_URL" >/dev/null || exit 0
|
||||
curl --fail -I "$X86_64_MACOS_JSON_URL" >/dev/null || exit 0
|
||||
curl --fail -I "$X86_64_FREEBSD_JSON_URL" >/dev/null || exit 0
|
||||
|
||||
# Without --user, this gave me:
|
||||
# ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied
|
||||
pip3 install s3cmd --user
|
||||
S3CMD="$HOME/.local/bin/s3cmd"
|
||||
|
||||
rm -rf .git
|
||||
|
||||
cd "$HOME"
|
||||
wget "https://ziglang.org/builds/$NATIVE_TARBALL"
|
||||
tar xf "$NATIVE_TARBALL"
|
||||
ZIGDIR=$(basename $NATIVE_TARBALL .tar.xz)
|
||||
ZIG="$ZIGDIR/zig"
|
||||
LANGREF="$ZIGDIR/langref.html"
|
||||
SRCTARBALLDIR="zig-$VERSION"
|
||||
export SRC_TARBALL="$SRCTARBALLDIR.tar.xz"
|
||||
mv "$SRCDIR" "$SRCTARBALLDIR"
|
||||
tar cfJ "$SRC_TARBALL" "$SRCTARBALLDIR"
|
||||
export SRC_SHASUM=$(sha256sum $SRC_TARBALL | cut '-d ' -f1)
|
||||
export SRC_BYTESIZE=$(wc -c < $SRC_TARBALL)
|
||||
|
||||
X86_64_WINDOWS_JSON=$(curl --fail "$X86_64_WINDOWS_JSON_URL" || exit 1)
|
||||
export X86_64_WINDOWS_TARBALL="$(echo "$X86_64_WINDOWS_JSON" | jq .tarball -r)"
|
||||
export X86_64_WINDOWS_BYTESIZE="$(echo "$X86_64_WINDOWS_JSON" | jq .size -r)"
|
||||
export X86_64_WINDOWS_SHASUM="$(echo "$X86_64_WINDOWS_JSON" | jq .shasum -r)"
|
||||
|
||||
X86_64_MACOS_JSON=$(curl --fail "$X86_64_MACOS_JSON_URL" || exit 1)
|
||||
export X86_64_MACOS_TARBALL="$(echo "$X86_64_MACOS_JSON" | jq .tarball -r)"
|
||||
export X86_64_MACOS_BYTESIZE="$(echo "$X86_64_MACOS_JSON" | jq .size -r)"
|
||||
export X86_64_MACOS_SHASUM="$(echo "$X86_64_MACOS_JSON" | jq .shasum -r)"
|
||||
|
||||
X86_64_LINUX_JSON=$(curl --fail "$X86_64_LINUX_JSON_URL" || exit 1)
|
||||
export X86_64_LINUX_TARBALL="$(echo "$X86_64_LINUX_JSON" | jq .tarball -r)"
|
||||
export X86_64_LINUX_BYTESIZE="$(echo "$X86_64_LINUX_JSON" | jq .size -r)"
|
||||
export X86_64_LINUX_SHASUM="$(echo "$X86_64_LINUX_JSON" | jq .shasum -r)"
|
||||
|
||||
AARCH64_LINUX_JSON=$(curl --fail "$AARCH64_LINUX_JSON_URL" || exit 1)
|
||||
export AARCH64_LINUX_TARBALL="$(echo "$AARCH64_LINUX_JSON" | jq .tarball -r)"
|
||||
export AARCH64_LINUX_BYTESIZE="$(echo "$AARCH64_LINUX_JSON" | jq .size -r)"
|
||||
export AARCH64_LINUX_SHASUM="$(echo "$AARCH64_LINUX_JSON" | jq .shasum -r)"
|
||||
|
||||
X86_64_FREEBSD_JSON=$(curl --fail "$X86_64_FREEBSD_JSON_URL" || exit 1)
|
||||
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)"
|
||||
|
||||
git clone https://github.com/ziglang/www.ziglang.org --depth 1
|
||||
cd www.ziglang.org
|
||||
export MASTER_DATE="$(date +%Y-%m-%d)"
|
||||
export MASTER_VERSION="$VERSION"
|
||||
"../$ZIG" run update-download-page.zig
|
||||
|
||||
$S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536000, immutable" "../$SRC_TARBALL" s3://ziglang.org/builds/
|
||||
$S3CMD put -P --no-mime-magic "../$LANGREF" s3://ziglang.org/documentation/master/index.html --add-header="Cache-Control: max-age=0, must-revalidate"
|
||||
$S3CMD put -P --no-mime-magic www/download/index.html s3://ziglang.org/download/index.html --add-header="Cache-Control: max-age=0, must-revalidate"
|
||||
$S3CMD put -P --no-mime-magic www/download/index.json s3://ziglang.org/download/index.json --add-header="Cache-Control: max-age=0, must-revalidate"
|
||||
@@ -1,72 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Requires cmake ninja-build
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
ARCH="$(uname -m)"
|
||||
TARGET="$ARCH-linux-musl"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.11.0-dev.971+19056cb68"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
export PATH="$HOME/deps/wasmtime-v2.0.2-$ARCH-linux:$HOME/deps/qemu-linux-x86_64-6.1.0.1/bin:$PATH"
|
||||
|
||||
# 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
|
||||
|
||||
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
|
||||
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
|
||||
|
||||
rm -rf build-debug
|
||||
mkdir build-debug
|
||||
cd build-debug
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-debug" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-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
|
||||
|
||||
echo "Looking for non-conforming code formatting..."
|
||||
stage3-debug/bin/zig fmt --check .. \
|
||||
--exclude ../test/cases/ \
|
||||
--exclude ../build-debug
|
||||
|
||||
# simultaneously test building self-hosted without LLVM and with 32-bit arm
|
||||
stage3-debug/bin/zig build -Dtarget=arm-linux-musleabihf
|
||||
|
||||
stage3-debug/bin/zig build test docs \
|
||||
-fqemu \
|
||||
-fwasmtime \
|
||||
-Dstatic-llvm \
|
||||
-Dtarget=native-native-musl \
|
||||
--search-prefix "$PREFIX" \
|
||||
--zig-lib-dir "$(pwd)/../lib"
|
||||
|
||||
# Look for HTML errors.
|
||||
tidy --drop-empty-elements no -qe "$ZIG_LOCAL_CACHE_DIR/langref.html"
|
||||
|
||||
# Produce the experimental std lib documentation.
|
||||
stage3-debug/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
|
||||
@@ -1,73 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Requires cmake ninja-build
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
ARCH="$(uname -m)"
|
||||
TARGET="$ARCH-linux-musl"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.11.0-dev.971+19056cb68"
|
||||
PREFIX="$HOME/deps/$CACHE_BASENAME"
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
export PATH="$HOME/deps/wasmtime-v2.0.2-$ARCH-linux:$HOME/deps/qemu-linux-x86_64-6.1.0.1/bin:$PATH"
|
||||
|
||||
# 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
|
||||
|
||||
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
|
||||
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
|
||||
|
||||
rm -rf build-release
|
||||
mkdir build-release
|
||||
cd build-release
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-release" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-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
|
||||
|
||||
echo "Looking for non-conforming code formatting..."
|
||||
stage3-release/bin/zig fmt --check .. \
|
||||
--exclude ../test/cases/ \
|
||||
--exclude ../build-debug \
|
||||
--exclude ../build-release
|
||||
|
||||
# simultaneously test building self-hosted without LLVM and with 32-bit arm
|
||||
stage3-release/bin/zig build -Dtarget=arm-linux-musleabihf
|
||||
|
||||
stage3-release/bin/zig build test docs \
|
||||
-fqemu \
|
||||
-fwasmtime \
|
||||
-Dstatic-llvm \
|
||||
-Dtarget=native-native-musl \
|
||||
--search-prefix "$PREFIX" \
|
||||
--zig-lib-dir "$(pwd)/../lib"
|
||||
|
||||
# Look for HTML errors.
|
||||
tidy --drop-empty-elements no -qe "$ZIG_LOCAL_CACHE_DIR/langref.html"
|
||||
|
||||
# Produce the experimental std lib documentation.
|
||||
stage3-release/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
|
||||
@@ -1,62 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Script assumes the presence of the following:
|
||||
# s3cmd
|
||||
|
||||
ZIGDIR="$(pwd)"
|
||||
TARGET="$ARCH-macos-none"
|
||||
MCPU="baseline"
|
||||
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.11.0-dev.534+b0b1cc356"
|
||||
PREFIX="$HOME/$CACHE_BASENAME"
|
||||
JOBS="-j3"
|
||||
|
||||
rm -rf $PREFIX
|
||||
cd $HOME
|
||||
|
||||
curl -L -O "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
|
||||
tar xf "$CACHE_BASENAME.tar.xz"
|
||||
|
||||
ZIG="$PREFIX/bin/zig"
|
||||
|
||||
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
|
||||
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
# Override the cache directories because they won't actually help other CI runs
|
||||
# which will be testing alternate versions of zig, and ultimately would just
|
||||
# fill up space on the hard drive for no reason.
|
||||
export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache"
|
||||
export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache"
|
||||
|
||||
cmake .. \
|
||||
-DCMAKE_INSTALL_PREFIX="stage3-release" \
|
||||
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_C_COMPILER="$ZIG;cc;-target;$TARGET;-mcpu=$MCPU" \
|
||||
-DCMAKE_CXX_COMPILER="$ZIG;c++;-target;$TARGET;-mcpu=$MCPU" \
|
||||
-DZIG_TARGET_TRIPLE="$TARGET" \
|
||||
-DZIG_TARGET_MCPU="$MCPU" \
|
||||
-DZIG_STATIC=ON
|
||||
|
||||
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"
|
||||
|
||||
# Produce the experimental std lib documentation.
|
||||
stage3-release/bin/zig test ../lib/std/std.zig -femit-docs -fno-emit-bin --zig-lib-dir ../lib
|
||||
@@ -8,33 +8,45 @@
|
||||
# CLANG_LIBDIRS
|
||||
|
||||
find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
|
||||
HINTS ${LLVM_INCLUDE_DIRS}
|
||||
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
|
||||
NO_SYSTEM_ENVIRONMENT_PATH
|
||||
NO_CMAKE_SYSTEM_PATH
|
||||
PATHS
|
||||
/usr/lib/llvm/11/include
|
||||
/usr/lib/llvm-11/include
|
||||
/usr/lib/llvm-11.0/include
|
||||
/usr/local/llvm110/include
|
||||
/usr/local/llvm11/include
|
||||
/mingw64/include
|
||||
)
|
||||
|
||||
if(${LLVM_LINK_MODE} STREQUAL "shared")
|
||||
if(ZIG_PREFER_CLANG_CPP_DYLIB)
|
||||
find_library(CLANG_LIBRARIES
|
||||
NAMES
|
||||
libclang-cpp.so.15
|
||||
clang-cpp-15.0
|
||||
clang-cpp150
|
||||
clang-cpp-11.0
|
||||
clang-cpp110
|
||||
clang-cpp
|
||||
NAMES_PER_DIR
|
||||
HINTS "${LLVM_LIBDIRS}"
|
||||
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
|
||||
NO_SYSTEM_ENVIRONMENT_PATH
|
||||
NO_CMAKE_SYSTEM_PATH
|
||||
PATHS
|
||||
${CLANG_LIBDIRS}
|
||||
/usr/lib/llvm/11/lib
|
||||
/usr/lib/llvm/11/lib64
|
||||
/usr/lib/llvm-11/lib
|
||||
/usr/local/llvm110/lib
|
||||
/usr/local/llvm11/lib
|
||||
)
|
||||
else()
|
||||
endif()
|
||||
|
||||
if(NOT CLANG_LIBRARIES)
|
||||
macro(FIND_AND_ADD_CLANG_LIB _libname_)
|
||||
string(TOUPPER ${_libname_} _prettylibname_)
|
||||
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} NAMES_PER_DIR
|
||||
HINTS "${LLVM_LIBDIRS}"
|
||||
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
|
||||
NO_SYSTEM_ENVIRONMENT_PATH
|
||||
NO_CMAKE_SYSTEM_PATH
|
||||
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_}
|
||||
PATHS
|
||||
${CLANG_LIBDIRS}
|
||||
/usr/lib/llvm/11/lib
|
||||
/usr/lib/llvm-11/lib
|
||||
/usr/lib/llvm-11.0/lib
|
||||
/usr/local/llvm110/lib
|
||||
/usr/local/llvm11/lib
|
||||
/mingw64/lib
|
||||
/c/msys64/mingw64/lib
|
||||
c:\\msys64\\mingw64\\lib
|
||||
)
|
||||
if(CLANG_${_prettylibname_}_LIB)
|
||||
set(CLANG_LIBRARIES ${CLANG_LIBRARIES} ${CLANG_${_prettylibname_}_LIB})
|
||||
@@ -64,8 +76,6 @@ else()
|
||||
FIND_AND_ADD_CLANG_LIB(clangCrossTU)
|
||||
FIND_AND_ADD_CLANG_LIB(clangIndex)
|
||||
FIND_AND_ADD_CLANG_LIB(clangToolingCore)
|
||||
FIND_AND_ADD_CLANG_LIB(clangExtractAPI)
|
||||
FIND_AND_ADD_CLANG_LIB(clangSupport)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
@@ -7,51 +7,46 @@
|
||||
# LLD_LIBRARIES
|
||||
|
||||
find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
|
||||
HINTS ${LLVM_INCLUDE_DIRS}
|
||||
PATHS
|
||||
/usr/lib/llvm-15/include
|
||||
/usr/local/llvm150/include
|
||||
/usr/local/llvm15/include
|
||||
/usr/local/opt/llvm@15/include
|
||||
/opt/homebrew/opt/llvm@15/include
|
||||
/usr/lib/llvm-11/include
|
||||
/usr/local/llvm110/include
|
||||
/usr/local/llvm11/include
|
||||
/mingw64/include)
|
||||
|
||||
find_library(LLD_LIBRARY NAMES lld-15.0 lld150 lld NAMES_PER_DIR
|
||||
HINTS ${LLVM_LIBDIRS}
|
||||
find_library(LLD_LIBRARY NAMES lld-11.0 lld110 lld
|
||||
PATHS
|
||||
/usr/lib/llvm-15/lib
|
||||
/usr/local/llvm150/lib
|
||||
/usr/local/llvm15/lib
|
||||
/usr/local/opt/llvm@15/lib
|
||||
/opt/homebrew/opt/llvm@15/lib
|
||||
/usr/lib/llvm-11/lib
|
||||
/usr/local/llvm110/lib
|
||||
/usr/local/llvm11/lib
|
||||
)
|
||||
if(EXISTS ${LLD_LIBRARY})
|
||||
set(LLD_LIBRARIES ${LLD_LIBRARY})
|
||||
else()
|
||||
macro(FIND_AND_ADD_LLD_LIB _libname_)
|
||||
string(TOUPPER ${_libname_} _prettylibname_)
|
||||
find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_} NAMES_PER_DIR
|
||||
HINTS ${LLVM_LIBDIRS}
|
||||
find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_}
|
||||
PATHS
|
||||
${LLD_LIBDIRS}
|
||||
/usr/lib/llvm-15/lib
|
||||
/usr/local/llvm150/lib
|
||||
/usr/local/llvm15/lib
|
||||
/usr/local/opt/llvm@15/lib
|
||||
/opt/homebrew/opt/llvm@15/lib
|
||||
/usr/lib/llvm-11/lib
|
||||
/usr/local/llvm110/lib
|
||||
/usr/local/llvm11/lib
|
||||
/mingw64/lib
|
||||
/c/msys64/mingw64/lib
|
||||
c:/msys64/mingw64/lib)
|
||||
if(LLD_${_prettylibname_}_LIB)
|
||||
set(LLD_LIBRARIES ${LLD_LIBRARIES} ${LLD_${_prettylibname_}_LIB})
|
||||
if(LLD_${_prettylibname_}_LIB)
|
||||
set(LLD_LIBRARIES ${LLD_LIBRARIES} ${LLD_${_prettylibname_}_LIB})
|
||||
endif()
|
||||
endmacro(FIND_AND_ADD_LLD_LIB)
|
||||
|
||||
FIND_AND_ADD_LLD_LIB(lldDriver)
|
||||
FIND_AND_ADD_LLD_LIB(lldMinGW)
|
||||
FIND_AND_ADD_LLD_LIB(lldELF)
|
||||
FIND_AND_ADD_LLD_LIB(lldCOFF)
|
||||
FIND_AND_ADD_LLD_LIB(lldWasm)
|
||||
FIND_AND_ADD_LLD_LIB(lldMachO)
|
||||
FIND_AND_ADD_LLD_LIB(lldWasm)
|
||||
FIND_AND_ADD_LLD_LIB(lldReaderWriter)
|
||||
FIND_AND_ADD_LLD_LIB(lldCore)
|
||||
FIND_AND_ADD_LLD_LIB(lldYAML)
|
||||
FIND_AND_ADD_LLD_LIB(lldCommon)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -6,139 +6,150 @@
|
||||
# LLVM_INCLUDE_DIRS
|
||||
# LLVM_LIBRARIES
|
||||
# LLVM_LIBDIRS
|
||||
# LLVM_LINK_MODE
|
||||
|
||||
find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h
|
||||
PATHS
|
||||
/usr/lib/llvm/11/include
|
||||
/usr/lib/llvm-11/include
|
||||
/usr/lib/llvm-11.0/include
|
||||
/usr/local/llvm11/include
|
||||
/usr/local/llvm110/include
|
||||
/mingw64/include
|
||||
)
|
||||
|
||||
if(ZIG_USE_LLVM_CONFIG)
|
||||
set(LLVM_CONFIG_ERROR_MESSAGES "")
|
||||
while(1)
|
||||
unset(LLVM_CONFIG_EXE CACHE)
|
||||
find_program(LLVM_CONFIG_EXE
|
||||
NAMES llvm-config-15 llvm-config-15.0 llvm-config150 llvm-config15 llvm-config NAMES_PER_DIR
|
||||
PATHS
|
||||
"/mingw64/bin"
|
||||
"/c/msys64/mingw64/bin"
|
||||
"c:/msys64/mingw64/bin"
|
||||
"C:/Libraries/llvm-15.0.0/bin")
|
||||
if(ZIG_PREFER_CLANG_CPP_DYLIB)
|
||||
find_library(LLVM_LIBRARIES
|
||||
NAMES
|
||||
LLVM-11.0
|
||||
LLVM-11
|
||||
LLVM-110
|
||||
LLVM
|
||||
PATHS
|
||||
${LLVM_LIBDIRS}
|
||||
/usr/lib/llvm/11/lib
|
||||
/usr/lib/llvm/11/lib64
|
||||
/usr/lib/llvm-11/lib
|
||||
/usr/local/llvm11/lib
|
||||
/usr/local/llvm110/lib
|
||||
)
|
||||
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
if (NOT LLVM_CONFIG_ERROR_MESSAGES STREQUAL "")
|
||||
list(JOIN LLVM_CONFIG_ERROR_MESSAGES "\n" LLVM_CONFIG_ERROR_MESSAGE)
|
||||
message(FATAL_ERROR ${LLVM_CONFIG_ERROR_MESSAGE})
|
||||
else()
|
||||
message(FATAL_ERROR "unable to find llvm-config")
|
||||
endif()
|
||||
endif()
|
||||
find_program(LLVM_CONFIG_EXE
|
||||
NAMES llvm-config-11 llvm-config-11.0 llvm-config110 llvm-config11 llvm-config
|
||||
PATHS
|
||||
"/mingw64/bin"
|
||||
"/c/msys64/mingw64/bin"
|
||||
"c:/msys64/mingw64/bin"
|
||||
"C:/Libraries/llvm-11.0.0/bin")
|
||||
|
||||
# Check that this LLVM is the right version
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --version
|
||||
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
message(FATAL_ERROR "unable to find llvm-config")
|
||||
endif()
|
||||
|
||||
get_filename_component(LLVM_CONFIG_DIR "${LLVM_CONFIG_EXE}" DIRECTORY)
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 15 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 16 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 16)
|
||||
# Save the error message, in case this is the last llvm-config we find
|
||||
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "expected LLVM 15.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
message(FATAL_ERROR "unable to find llvm-config")
|
||||
endif()
|
||||
|
||||
# Ignore this directory and try the search again
|
||||
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
|
||||
continue()
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --version
|
||||
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
# Check that this LLVM supports linking as a shared/static library, if requested
|
||||
if (ZIG_SHARED_LLVM OR ZIG_STATIC_LLVM)
|
||||
if (ZIG_SHARED_LLVM)
|
||||
set(STATIC_OR_SHARED_LINK "--link-shared")
|
||||
elseif (ZIG_STATIC_LLVM)
|
||||
set(STATIC_OR_SHARED_LINK "--link-static")
|
||||
endif()
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 11)
|
||||
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 12)
|
||||
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 12)
|
||||
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
elseif(("${ZIG_TARGET_TRIPLE}" STREQUAL "native") OR ZIG_PREFER_LLVM_CONFIG)
|
||||
find_program(LLVM_CONFIG_EXE
|
||||
NAMES llvm-config-11 llvm-config-11.0 llvm-config110 llvm-config11 llvm-config
|
||||
PATHS
|
||||
"/mingw64/bin"
|
||||
"/c/msys64/mingw64/bin"
|
||||
"c:/msys64/mingw64/bin"
|
||||
"C:/Libraries/llvm-11.0.0/bin")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --libs ${STATIC_OR_SHARED_LINK}
|
||||
OUTPUT_QUIET
|
||||
ERROR_VARIABLE LLVM_CONFIG_ERROR
|
||||
ERROR_STRIP_TRAILING_WHITESPACE)
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
message(FATAL_ERROR "unable to find llvm-config")
|
||||
endif()
|
||||
|
||||
if (LLVM_CONFIG_ERROR)
|
||||
# Save the error message, in case this is the last llvm-config we find
|
||||
if (ZIG_SHARED_LLVM)
|
||||
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 15.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
|
||||
else()
|
||||
list(APPEND LLVM_CONFIG_ERROR_MESSAGES "LLVM 15.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
|
||||
endif()
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
message(FATAL_ERROR "unable to find llvm-config")
|
||||
endif()
|
||||
|
||||
# Ignore this directory and try the search again
|
||||
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
|
||||
continue()
|
||||
endif()
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --version
|
||||
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --targets-built
|
||||
OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 11)
|
||||
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 12)
|
||||
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 12)
|
||||
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
|
||||
set(ZIG_LLVM_REQUIRED_TARGETS "AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;Mips;MSP430;NVPTX;PowerPC;RISCV;Sparc;SystemZ;VE;WebAssembly;X86;XCore")
|
||||
|
||||
set(ZIG_LLVM_REQUIRED_TARGETS_ENABLED TRUE)
|
||||
foreach(TARGET_NAME IN LISTS ZIG_LLVM_REQUIRED_TARGETS)
|
||||
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}")
|
||||
set(ZIG_LLVM_REQUIRED_TARGETS_ENABLED FALSE)
|
||||
break()
|
||||
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()
|
||||
endforeach()
|
||||
if (NOT ZIG_LLVM_REQUIRED_TARGETS_ENABLED)
|
||||
continue()
|
||||
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("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
|
||||
@@ -146,32 +157,17 @@ if(ZIG_USE_LLVM_CONFIG)
|
||||
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --shared-mode
|
||||
OUTPUT_VARIABLE LLVM_LINK_MODE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
endif()
|
||||
|
||||
if (${LLVM_LINK_MODE} STREQUAL "shared")
|
||||
# We always ask for the system libs corresponding to static linking,
|
||||
# since on some distros LLD is only available as a static library
|
||||
# and we need these libraries to link it successfully
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --system-libs --link-static
|
||||
OUTPUT_VARIABLE LLVM_STATIC_SYSTEM_LIBS_SPACES
|
||||
ERROR_QUIET # Some installations have no static libs, we just ignore the failure
|
||||
COMMAND ${LLVM_CONFIG_EXE} --libdir
|
||||
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_STATIC_SYSTEM_LIBS "${LLVM_STATIC_SYSTEM_LIBS_SPACES}")
|
||||
|
||||
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS} ${LLVM_STATIC_SYSTEM_LIBS})
|
||||
else()
|
||||
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
|
||||
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --includedir
|
||||
OUTPUT_VARIABLE LLVM_INCLUDE_DIRS_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_INCLUDE_DIRS "${LLVM_INCLUDE_DIRS_SPACES}")
|
||||
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
|
||||
|
||||
if(NOT LLVM_LIBRARIES)
|
||||
find_library(LLVM_LIBRARIES NAMES LLVM LLVM-11 LLVM-11.0)
|
||||
endif()
|
||||
|
||||
link_directories("${CMAKE_PREFIX_PATH}/lib")
|
||||
link_directories("${LLVM_LIBDIRS}")
|
||||
@@ -181,75 +177,95 @@ else()
|
||||
|
||||
macro(FIND_AND_ADD_LLVM_LIB _libname_)
|
||||
string(TOUPPER ${_libname_} _prettylibname_)
|
||||
find_library(LLVM_${_prettylibname_}_LIB
|
||||
NAMES ${_libname_} NAMES_PER_DIR)
|
||||
find_library(LLVM_${_prettylibname_}_LIB NAMES ${_libname_}
|
||||
PATHS
|
||||
${LLVM_LIBDIRS}
|
||||
/usr/lib/llvm/11/lib
|
||||
/usr/lib/llvm-11/lib
|
||||
/usr/lib/llvm-11.0/lib
|
||||
/usr/local/llvm110/lib
|
||||
/usr/local/llvm11/lib
|
||||
/mingw64/lib
|
||||
/c/msys64/mingw64/lib
|
||||
c:\\msys64\\mingw64\\lib)
|
||||
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_${_prettylibname_}_LIB})
|
||||
endmacro(FIND_AND_ADD_LLVM_LIB)
|
||||
|
||||
set(LLVM_LINK_MODE "static")
|
||||
|
||||
# This list can be re-generated with `llvm-config --libfiles` and then
|
||||
# reformatting using your favorite text editor. Note we do not execute
|
||||
# `llvm-config` here because we are cross compiling.
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWindowsManifest)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWindowsDriver)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMXRay)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLibDriver)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDlltoolDriver)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMCoverage)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWindowsManifest)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSymbolize)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMOrcError)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMJITLink)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMCA)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLTO)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMObjCARCOpts)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLineEditor)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLibDriver)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMInterpreter)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFuzzMutate)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMCJIT)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMExecutionEngine)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMRuntimeDyld)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinker)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDlltoolDriver)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMOption)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMCoverage)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMXCoreCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMXCoreInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMX86TargetMCA)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMX86Disassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMX86AsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMX86CodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMX86AsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMX86Desc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMX86Info)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyUtils)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMVEDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMVEAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMVECodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMVEDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMVEInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSystemZDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSystemZAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSystemZCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSystemZAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSystemZDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSystemZInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSparcDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSparcAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSparcCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSparcAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSparcDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSparcInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMRISCVDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMRISCVAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMRISCVCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMRISCVAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMRISCVDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMRISCVUtils)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMRISCVInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Disassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMSP430AsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMSP430CodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMSP430AsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Desc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Info)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMipsDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMipsAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMipsCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMipsAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMipsDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMipsInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLanaiDisassembler)
|
||||
@@ -263,72 +279,44 @@ else()
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMHexagonDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMHexagonInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBPFDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBPFAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBPFCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBPFAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBPFDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBPFInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAVRDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAVRAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAVRCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAVRAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAVRDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAVRInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMARMDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMARMAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMARMCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMARMAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMARMDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMARMUtils)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMARMInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUTargetMCA)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMIRParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMipo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMIRReader)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUDesc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUUtils)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUInfo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Disassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64AsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64CodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Desc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Utils)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Info)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMCJIT)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMJITLink)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMInterpreter)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMExecutionEngine)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMRuntimeDyld)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMOrcTargetProcess)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMOrcShared)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDWP)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMOption)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMObjCopy)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMCA)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMCDisassembler)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLTO)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64CodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMCFGuard)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMObjCARCOpts)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMipo)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenACC)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinker)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMGlobalISel)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMIRParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAsmPrinter)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSelectionDAG)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAsmPrinter)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARF)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMCodeGen)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMIRReader)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMInterfaceStub)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFileCheck)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFuzzMutate)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMTarget)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMScalarOpts)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMInstCombine)
|
||||
@@ -337,26 +325,23 @@ else()
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBitWriter)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAnalysis)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMProfileData)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSymbolize)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoMSF)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARF)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMObject)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMTextAPI)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMCParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMC)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoCodeView)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBitReader)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMFuzzerCLI)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMCore)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMRemarks)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBitstreamReader)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64AsmParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMCParser)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Desc)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMMC)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoCodeView)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoMSF)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBinaryFormat)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Utils)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Info)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSupport)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDemangle)
|
||||
|
||||
get_filename_component(LLVM_LIBDIRS "${LLVM_LLVMCORE_LIB}" DIRECTORY)
|
||||
find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
@@ -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("::")
|
||||
|
||||
30
deps/SoftFloat-3e-prebuilt/platform.h
vendored
30
deps/SoftFloat-3e-prebuilt/platform.h
vendored
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
|
||||
1090
doc/docgen.zig
1090
doc/docgen.zig
File diff suppressed because it is too large
Load Diff
5216
doc/langref.html.in
5216
doc/langref.html.in
File diff suppressed because it is too large
Load Diff
@@ -1,354 +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, "--debug-compile-errors")) {
|
||||
builder.debug_compile_errors = true;
|
||||
} 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
555
lib/c.zig
@@ -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."),
|
||||
}
|
||||
}
|
||||
@@ -1,224 +0,0 @@
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub const panic = @import("compiler_rt/common.zig").panic;
|
||||
|
||||
comptime {
|
||||
_ = @import("compiler_rt/atomics.zig");
|
||||
|
||||
// macOS has these functions inside libSystem.
|
||||
if (builtin.cpu.arch.isAARCH64() and !builtin.os.tag.isDarwin()) {
|
||||
_ = @import("compiler_rt/aarch64_outline_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");
|
||||
}
|
||||
@@ -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"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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");
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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.*);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
const __ashldi3 = @import("shift.zig").__ashldi3;
|
||||
const testing = @import("std").testing;
|
||||
|
||||
fn test__ashldi3(a: i64, b: i32, expected: u64) !void {
|
||||
const x = __ashldi3(a, b);
|
||||
try testing.expectEqual(@bitCast(i64, expected), x);
|
||||
}
|
||||
|
||||
test "ashldi3" {
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
|
||||
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);
|
||||
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);
|
||||
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
|
||||
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
|
||||
try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
const __ashlti3 = @import("shift.zig").__ashlti3;
|
||||
const testing = @import("std").testing;
|
||||
|
||||
fn test__ashlti3(a: i128, b: i32, expected: i128) !void {
|
||||
const x = __ashlti3(a, b);
|
||||
try testing.expectEqual(expected, x);
|
||||
}
|
||||
|
||||
test "ashlti3" {
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642BFDB97530ECA8642A)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C857FB72EA61D950C854)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xEDCBA9876543215FEDCBA98765432150)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x876543215FEDCBA98765432150000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x0ECA8642BFDB97530ECA8642A0000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x1D950C857FB72EA61D950C8540000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x3B2A190AFF6E5D4C3B2A190A80000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x76543215FEDCBA987654321500000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xECA8642BFDB97530ECA8642A00000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xD950C857FB72EA61D950C85400000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xB2A190AFF6E5D4C3B2A190A800000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x6543215FEDCBA9876543215000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x5FEDCBA9876543215000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xBFDB97530ECA8642A000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x7FB72EA61D950C854000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190A8000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFEDCBA98765432150000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642A0000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C8540000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190A80000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xEDCBA987654321500000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x87654321500000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x0ECA8642A00000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x1D950C85400000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x3B2A190A800000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x76543215000000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xECA8642A000000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xD950C854000000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xB2A190A8000000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x65432150000000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x50000000000000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xA0000000000000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x40000000000000000000000000000000)));
|
||||
try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x80000000000000000000000000000000)));
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
const __ashrdi3 = @import("shift.zig").__ashrdi3;
|
||||
const testing = @import("std").testing;
|
||||
|
||||
fn test__ashrdi3(a: i64, b: i32, expected: u64) !void {
|
||||
const x = __ashrdi3(a, b);
|
||||
try testing.expectEqual(@bitCast(i64, expected), x);
|
||||
}
|
||||
|
||||
test "ashrdi3" {
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
|
||||
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
|
||||
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
|
||||
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
|
||||
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
|
||||
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
|
||||
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
|
||||
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
|
||||
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
|
||||
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
|
||||
try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
const __ashrti3 = @import("shift.zig").__ashrti3;
|
||||
const testing = @import("std").testing;
|
||||
|
||||
fn test__ashrti3(a: i128, b: i32, expected: i128) !void {
|
||||
const x = __ashrti3(a, b);
|
||||
try testing.expectEqual(expected, x);
|
||||
}
|
||||
|
||||
test "ashrti3" {
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFFB72EA61D950C857FB72EA61D950C85)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xFFDB97530ECA8642BFDB97530ECA8642)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xFFEDCBA9876543215FEDCBA987654321)));
|
||||
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0xFFFFFFFFEDCBA9876543215FEDCBA987)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFB72EA61D950C857FB72EA61)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFDB97530ECA8642BFDB97530)));
|
||||
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98)));
|
||||
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFB72EA61D950C857FB72EA6)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFDB97530ECA8642BFDB9753)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9)));
|
||||
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B)));
|
||||
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215)));
|
||||
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321)));
|
||||
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530)));
|
||||
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98)));
|
||||
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9)));
|
||||
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
|
||||
try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
|
||||
}
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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))));
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -1,308 +0,0 @@
|
||||
const builtin = @import("builtin");
|
||||
const clz = @import("count0bits.zig");
|
||||
const testing = @import("std").testing;
|
||||
|
||||
fn test__clzsi2(a: u32, expected: i32) !void {
|
||||
// stage1 and stage2 diverge on function pointer semantics
|
||||
switch (builtin.zig_backend) {
|
||||
.stage1 => {
|
||||
// Use of `var` here is working around a stage1 bug.
|
||||
var nakedClzsi2 = clz.__clzsi2;
|
||||
var actualClzsi2 = @ptrCast(fn (a: i32) callconv(.C) i32, nakedClzsi2);
|
||||
var x = @bitCast(i32, a);
|
||||
var result = actualClzsi2(x);
|
||||
try testing.expectEqual(expected, result);
|
||||
},
|
||||
else => {
|
||||
const nakedClzsi2 = clz.__clzsi2;
|
||||
const actualClzsi2 = @ptrCast(*const fn (a: i32) callconv(.C) i32, &nakedClzsi2);
|
||||
const x = @bitCast(i32, a);
|
||||
const result = actualClzsi2(x);
|
||||
try testing.expectEqual(expected, result);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
test "clzsi2" {
|
||||
try test__clzsi2(0x00800000, 8);
|
||||
try test__clzsi2(0x01000000, 7);
|
||||
try test__clzsi2(0x02000000, 6);
|
||||
try test__clzsi2(0x03000000, 6);
|
||||
try test__clzsi2(0x04000000, 5);
|
||||
try test__clzsi2(0x05000000, 5);
|
||||
try test__clzsi2(0x06000000, 5);
|
||||
try test__clzsi2(0x07000000, 5);
|
||||
try test__clzsi2(0x08000000, 4);
|
||||
try test__clzsi2(0x09000000, 4);
|
||||
try test__clzsi2(0x0A000000, 4);
|
||||
try test__clzsi2(0x0B000000, 4);
|
||||
try test__clzsi2(0x0C000000, 4);
|
||||
try test__clzsi2(0x0D000000, 4);
|
||||
try test__clzsi2(0x0E000000, 4);
|
||||
try test__clzsi2(0x0F000000, 4);
|
||||
try test__clzsi2(0x10000000, 3);
|
||||
try test__clzsi2(0x11000000, 3);
|
||||
try test__clzsi2(0x12000000, 3);
|
||||
try test__clzsi2(0x13000000, 3);
|
||||
try test__clzsi2(0x14000000, 3);
|
||||
try test__clzsi2(0x15000000, 3);
|
||||
try test__clzsi2(0x16000000, 3);
|
||||
try test__clzsi2(0x17000000, 3);
|
||||
try test__clzsi2(0x18000000, 3);
|
||||
try test__clzsi2(0x19000000, 3);
|
||||
try test__clzsi2(0x1A000000, 3);
|
||||
try test__clzsi2(0x1B000000, 3);
|
||||
try test__clzsi2(0x1C000000, 3);
|
||||
try test__clzsi2(0x1D000000, 3);
|
||||
try test__clzsi2(0x1E000000, 3);
|
||||
try test__clzsi2(0x1F000000, 3);
|
||||
try test__clzsi2(0x20000000, 2);
|
||||
try test__clzsi2(0x21000000, 2);
|
||||
try test__clzsi2(0x22000000, 2);
|
||||
try test__clzsi2(0x23000000, 2);
|
||||
try test__clzsi2(0x24000000, 2);
|
||||
try test__clzsi2(0x25000000, 2);
|
||||
try test__clzsi2(0x26000000, 2);
|
||||
try test__clzsi2(0x27000000, 2);
|
||||
try test__clzsi2(0x28000000, 2);
|
||||
try test__clzsi2(0x29000000, 2);
|
||||
try test__clzsi2(0x2A000000, 2);
|
||||
try test__clzsi2(0x2B000000, 2);
|
||||
try test__clzsi2(0x2C000000, 2);
|
||||
try test__clzsi2(0x2D000000, 2);
|
||||
try test__clzsi2(0x2E000000, 2);
|
||||
try test__clzsi2(0x2F000000, 2);
|
||||
try test__clzsi2(0x30000000, 2);
|
||||
try test__clzsi2(0x31000000, 2);
|
||||
try test__clzsi2(0x32000000, 2);
|
||||
try test__clzsi2(0x33000000, 2);
|
||||
try test__clzsi2(0x34000000, 2);
|
||||
try test__clzsi2(0x35000000, 2);
|
||||
try test__clzsi2(0x36000000, 2);
|
||||
try test__clzsi2(0x37000000, 2);
|
||||
try test__clzsi2(0x38000000, 2);
|
||||
try test__clzsi2(0x39000000, 2);
|
||||
try test__clzsi2(0x3A000000, 2);
|
||||
try test__clzsi2(0x3B000000, 2);
|
||||
try test__clzsi2(0x3C000000, 2);
|
||||
try test__clzsi2(0x3D000000, 2);
|
||||
try test__clzsi2(0x3E000000, 2);
|
||||
try test__clzsi2(0x3F000000, 2);
|
||||
try test__clzsi2(0x40000000, 1);
|
||||
try test__clzsi2(0x41000000, 1);
|
||||
try test__clzsi2(0x42000000, 1);
|
||||
try test__clzsi2(0x43000000, 1);
|
||||
try test__clzsi2(0x44000000, 1);
|
||||
try test__clzsi2(0x45000000, 1);
|
||||
try test__clzsi2(0x46000000, 1);
|
||||
try test__clzsi2(0x47000000, 1);
|
||||
try test__clzsi2(0x48000000, 1);
|
||||
try test__clzsi2(0x49000000, 1);
|
||||
try test__clzsi2(0x4A000000, 1);
|
||||
try test__clzsi2(0x4B000000, 1);
|
||||
try test__clzsi2(0x4C000000, 1);
|
||||
try test__clzsi2(0x4D000000, 1);
|
||||
try test__clzsi2(0x4E000000, 1);
|
||||
try test__clzsi2(0x4F000000, 1);
|
||||
try test__clzsi2(0x50000000, 1);
|
||||
try test__clzsi2(0x51000000, 1);
|
||||
try test__clzsi2(0x52000000, 1);
|
||||
try test__clzsi2(0x53000000, 1);
|
||||
try test__clzsi2(0x54000000, 1);
|
||||
try test__clzsi2(0x55000000, 1);
|
||||
try test__clzsi2(0x56000000, 1);
|
||||
try test__clzsi2(0x57000000, 1);
|
||||
try test__clzsi2(0x58000000, 1);
|
||||
try test__clzsi2(0x59000000, 1);
|
||||
try test__clzsi2(0x5A000000, 1);
|
||||
try test__clzsi2(0x5B000000, 1);
|
||||
try test__clzsi2(0x5C000000, 1);
|
||||
try test__clzsi2(0x5D000000, 1);
|
||||
try test__clzsi2(0x5E000000, 1);
|
||||
try test__clzsi2(0x5F000000, 1);
|
||||
try test__clzsi2(0x60000000, 1);
|
||||
try test__clzsi2(0x61000000, 1);
|
||||
try test__clzsi2(0x62000000, 1);
|
||||
try test__clzsi2(0x63000000, 1);
|
||||
try test__clzsi2(0x64000000, 1);
|
||||
try test__clzsi2(0x65000000, 1);
|
||||
try test__clzsi2(0x66000000, 1);
|
||||
try test__clzsi2(0x67000000, 1);
|
||||
try test__clzsi2(0x68000000, 1);
|
||||
try test__clzsi2(0x69000000, 1);
|
||||
try test__clzsi2(0x6A000000, 1);
|
||||
try test__clzsi2(0x6B000000, 1);
|
||||
try test__clzsi2(0x6C000000, 1);
|
||||
try test__clzsi2(0x6D000000, 1);
|
||||
try test__clzsi2(0x6E000000, 1);
|
||||
try test__clzsi2(0x6F000000, 1);
|
||||
try test__clzsi2(0x70000000, 1);
|
||||
try test__clzsi2(0x71000000, 1);
|
||||
try test__clzsi2(0x72000000, 1);
|
||||
try test__clzsi2(0x73000000, 1);
|
||||
try test__clzsi2(0x74000000, 1);
|
||||
try test__clzsi2(0x75000000, 1);
|
||||
try test__clzsi2(0x76000000, 1);
|
||||
try test__clzsi2(0x77000000, 1);
|
||||
try test__clzsi2(0x78000000, 1);
|
||||
try test__clzsi2(0x79000000, 1);
|
||||
try test__clzsi2(0x7A000000, 1);
|
||||
try test__clzsi2(0x7B000000, 1);
|
||||
try test__clzsi2(0x7C000000, 1);
|
||||
try test__clzsi2(0x7D000000, 1);
|
||||
try test__clzsi2(0x7E000000, 1);
|
||||
try test__clzsi2(0x7F000000, 1);
|
||||
try test__clzsi2(0x80000000, 0);
|
||||
try test__clzsi2(0x81000000, 0);
|
||||
try test__clzsi2(0x82000000, 0);
|
||||
try test__clzsi2(0x83000000, 0);
|
||||
try test__clzsi2(0x84000000, 0);
|
||||
try test__clzsi2(0x85000000, 0);
|
||||
try test__clzsi2(0x86000000, 0);
|
||||
try test__clzsi2(0x87000000, 0);
|
||||
try test__clzsi2(0x88000000, 0);
|
||||
try test__clzsi2(0x89000000, 0);
|
||||
try test__clzsi2(0x8A000000, 0);
|
||||
try test__clzsi2(0x8B000000, 0);
|
||||
try test__clzsi2(0x8C000000, 0);
|
||||
try test__clzsi2(0x8D000000, 0);
|
||||
try test__clzsi2(0x8E000000, 0);
|
||||
try test__clzsi2(0x8F000000, 0);
|
||||
try test__clzsi2(0x90000000, 0);
|
||||
try test__clzsi2(0x91000000, 0);
|
||||
try test__clzsi2(0x92000000, 0);
|
||||
try test__clzsi2(0x93000000, 0);
|
||||
try test__clzsi2(0x94000000, 0);
|
||||
try test__clzsi2(0x95000000, 0);
|
||||
try test__clzsi2(0x96000000, 0);
|
||||
try test__clzsi2(0x97000000, 0);
|
||||
try test__clzsi2(0x98000000, 0);
|
||||
try test__clzsi2(0x99000000, 0);
|
||||
try test__clzsi2(0x9A000000, 0);
|
||||
try test__clzsi2(0x9B000000, 0);
|
||||
try test__clzsi2(0x9C000000, 0);
|
||||
try test__clzsi2(0x9D000000, 0);
|
||||
try test__clzsi2(0x9E000000, 0);
|
||||
try test__clzsi2(0x9F000000, 0);
|
||||
try test__clzsi2(0xA0000000, 0);
|
||||
try test__clzsi2(0xA1000000, 0);
|
||||
try test__clzsi2(0xA2000000, 0);
|
||||
try test__clzsi2(0xA3000000, 0);
|
||||
try test__clzsi2(0xA4000000, 0);
|
||||
try test__clzsi2(0xA5000000, 0);
|
||||
try test__clzsi2(0xA6000000, 0);
|
||||
try test__clzsi2(0xA7000000, 0);
|
||||
try test__clzsi2(0xA8000000, 0);
|
||||
try test__clzsi2(0xA9000000, 0);
|
||||
try test__clzsi2(0xAA000000, 0);
|
||||
try test__clzsi2(0xAB000000, 0);
|
||||
try test__clzsi2(0xAC000000, 0);
|
||||
try test__clzsi2(0xAD000000, 0);
|
||||
try test__clzsi2(0xAE000000, 0);
|
||||
try test__clzsi2(0xAF000000, 0);
|
||||
try test__clzsi2(0xB0000000, 0);
|
||||
try test__clzsi2(0xB1000000, 0);
|
||||
try test__clzsi2(0xB2000000, 0);
|
||||
try test__clzsi2(0xB3000000, 0);
|
||||
try test__clzsi2(0xB4000000, 0);
|
||||
try test__clzsi2(0xB5000000, 0);
|
||||
try test__clzsi2(0xB6000000, 0);
|
||||
try test__clzsi2(0xB7000000, 0);
|
||||
try test__clzsi2(0xB8000000, 0);
|
||||
try test__clzsi2(0xB9000000, 0);
|
||||
try test__clzsi2(0xBA000000, 0);
|
||||
try test__clzsi2(0xBB000000, 0);
|
||||
try test__clzsi2(0xBC000000, 0);
|
||||
try test__clzsi2(0xBD000000, 0);
|
||||
try test__clzsi2(0xBE000000, 0);
|
||||
try test__clzsi2(0xBF000000, 0);
|
||||
try test__clzsi2(0xC0000000, 0);
|
||||
try test__clzsi2(0xC1000000, 0);
|
||||
try test__clzsi2(0xC2000000, 0);
|
||||
try test__clzsi2(0xC3000000, 0);
|
||||
try test__clzsi2(0xC4000000, 0);
|
||||
try test__clzsi2(0xC5000000, 0);
|
||||
try test__clzsi2(0xC6000000, 0);
|
||||
try test__clzsi2(0xC7000000, 0);
|
||||
try test__clzsi2(0xC8000000, 0);
|
||||
try test__clzsi2(0xC9000000, 0);
|
||||
try test__clzsi2(0xCA000000, 0);
|
||||
try test__clzsi2(0xCB000000, 0);
|
||||
try test__clzsi2(0xCC000000, 0);
|
||||
try test__clzsi2(0xCD000000, 0);
|
||||
try test__clzsi2(0xCE000000, 0);
|
||||
try test__clzsi2(0xCF000000, 0);
|
||||
try test__clzsi2(0xD0000000, 0);
|
||||
try test__clzsi2(0xD1000000, 0);
|
||||
try test__clzsi2(0xD2000000, 0);
|
||||
try test__clzsi2(0xD3000000, 0);
|
||||
try test__clzsi2(0xD4000000, 0);
|
||||
try test__clzsi2(0xD5000000, 0);
|
||||
try test__clzsi2(0xD6000000, 0);
|
||||
try test__clzsi2(0xD7000000, 0);
|
||||
try test__clzsi2(0xD8000000, 0);
|
||||
try test__clzsi2(0xD9000000, 0);
|
||||
try test__clzsi2(0xDA000000, 0);
|
||||
try test__clzsi2(0xDB000000, 0);
|
||||
try test__clzsi2(0xDC000000, 0);
|
||||
try test__clzsi2(0xDD000000, 0);
|
||||
try test__clzsi2(0xDE000000, 0);
|
||||
try test__clzsi2(0xDF000000, 0);
|
||||
try test__clzsi2(0xE0000000, 0);
|
||||
try test__clzsi2(0xE1000000, 0);
|
||||
try test__clzsi2(0xE2000000, 0);
|
||||
try test__clzsi2(0xE3000000, 0);
|
||||
try test__clzsi2(0xE4000000, 0);
|
||||
try test__clzsi2(0xE5000000, 0);
|
||||
try test__clzsi2(0xE6000000, 0);
|
||||
try test__clzsi2(0xE7000000, 0);
|
||||
try test__clzsi2(0xE8000000, 0);
|
||||
try test__clzsi2(0xE9000000, 0);
|
||||
try test__clzsi2(0xEA000000, 0);
|
||||
try test__clzsi2(0xEB000000, 0);
|
||||
try test__clzsi2(0xEC000000, 0);
|
||||
try test__clzsi2(0xED000000, 0);
|
||||
try test__clzsi2(0xEE000000, 0);
|
||||
try test__clzsi2(0xEF000000, 0);
|
||||
try test__clzsi2(0xF0000000, 0);
|
||||
try test__clzsi2(0xF1000000, 0);
|
||||
try test__clzsi2(0xF2000000, 0);
|
||||
try test__clzsi2(0xF3000000, 0);
|
||||
try test__clzsi2(0xF4000000, 0);
|
||||
try test__clzsi2(0xF5000000, 0);
|
||||
try test__clzsi2(0xF6000000, 0);
|
||||
try test__clzsi2(0xF7000000, 0);
|
||||
try test__clzsi2(0xF8000000, 0);
|
||||
try test__clzsi2(0xF9000000, 0);
|
||||
try test__clzsi2(0xFA000000, 0);
|
||||
try test__clzsi2(0xFB000000, 0);
|
||||
try test__clzsi2(0xFC000000, 0);
|
||||
try test__clzsi2(0xFD000000, 0);
|
||||
try test__clzsi2(0xFE000000, 0);
|
||||
try test__clzsi2(0xFF000000, 0);
|
||||
// arm and thumb1 assume input a != 0
|
||||
//try test__clzsi2(0x00000000, 32);
|
||||
try test__clzsi2(0x00000001, 31);
|
||||
try test__clzsi2(0x00000002, 30);
|
||||
try test__clzsi2(0x00000004, 29);
|
||||
try test__clzsi2(0x00000008, 28);
|
||||
try test__clzsi2(0x00000010, 27);
|
||||
try test__clzsi2(0x00000020, 26);
|
||||
try test__clzsi2(0x00000040, 25);
|
||||
try test__clzsi2(0x00000080, 24);
|
||||
try test__clzsi2(0x00000100, 23);
|
||||
try test__clzsi2(0x00000200, 22);
|
||||
try test__clzsi2(0x00000400, 21);
|
||||
try test__clzsi2(0x00000800, 20);
|
||||
try test__clzsi2(0x00001000, 19);
|
||||
try test__clzsi2(0x00002000, 18);
|
||||
try test__clzsi2(0x00004000, 17);
|
||||
try test__clzsi2(0x00008000, 16);
|
||||
try test__clzsi2(0x00010000, 15);
|
||||
try test__clzsi2(0x00020000, 14);
|
||||
try test__clzsi2(0x00040000, 13);
|
||||
try test__clzsi2(0x00080000, 12);
|
||||
try test__clzsi2(0x00100000, 11);
|
||||
try test__clzsi2(0x00200000, 10);
|
||||
try test__clzsi2(0x00400000, 9);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
// Ported from:
|
||||
//
|
||||
// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/test/builtins/Unit/comparesf2_test.c
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const is_test = builtin.is_test;
|
||||
|
||||
const __eqsf2 = @import("./cmpsf2.zig").__eqsf2;
|
||||
const __lesf2 = @import("./cmpsf2.zig").__lesf2;
|
||||
const __ltsf2 = @import("./cmpsf2.zig").__ltsf2;
|
||||
const __nesf2 = @import("./cmpsf2.zig").__nesf2;
|
||||
|
||||
const __gesf2 = @import("./gesf2.zig").__gesf2;
|
||||
const __gtsf2 = @import("./gesf2.zig").__gtsf2;
|
||||
|
||||
const __unordsf2 = @import("./unordsf2.zig").__unordsf2;
|
||||
|
||||
const TestVector = struct {
|
||||
a: f32,
|
||||
b: f32,
|
||||
eqReference: c_int,
|
||||
geReference: c_int,
|
||||
gtReference: c_int,
|
||||
leReference: c_int,
|
||||
ltReference: c_int,
|
||||
neReference: c_int,
|
||||
unReference: c_int,
|
||||
};
|
||||
|
||||
fn test__cmpsf2(vector: TestVector) bool {
|
||||
if (__eqsf2(vector.a, vector.b) != vector.eqReference) {
|
||||
return false;
|
||||
}
|
||||
if (__gesf2(vector.a, vector.b) != vector.geReference) {
|
||||
return false;
|
||||
}
|
||||
if (__gtsf2(vector.a, vector.b) != vector.gtReference) {
|
||||
return false;
|
||||
}
|
||||
if (__lesf2(vector.a, vector.b) != vector.leReference) {
|
||||
return false;
|
||||
}
|
||||
if (__ltsf2(vector.a, vector.b) != vector.ltReference) {
|
||||
return false;
|
||||
}
|
||||
if (__nesf2(vector.a, vector.b) != vector.neReference) {
|
||||
return false;
|
||||
}
|
||||
if (__unordsf2(vector.a, vector.b) != vector.unReference) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const arguments = [_]f32{
|
||||
std.math.nan(f32),
|
||||
-std.math.inf(f32),
|
||||
-0x1.fffffep127,
|
||||
-0x1.000002p0 - 0x1.000000p0,
|
||||
-0x1.fffffep-1,
|
||||
-0x1.000000p-126,
|
||||
-0x0.fffffep-126,
|
||||
-0x0.000002p-126,
|
||||
-0.0,
|
||||
0.0,
|
||||
0x0.000002p-126,
|
||||
0x0.fffffep-126,
|
||||
0x1.000000p-126,
|
||||
0x1.fffffep-1,
|
||||
0x1.000000p0,
|
||||
0x1.000002p0,
|
||||
0x1.fffffep127,
|
||||
std.math.inf(f32),
|
||||
};
|
||||
|
||||
fn generateVector(comptime a: f32, comptime b: f32) 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 f32" {
|
||||
for (test_vectors) |vector| {
|
||||
try std.testing.expect(test__cmpsf2(vector));
|
||||
}
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
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;
|
||||
|
||||
const trig = @import("trig.zig");
|
||||
const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
|
||||
const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
|
||||
|
||||
comptime {
|
||||
@export(__cosh, .{ .name = "__cosh", .linkage = common.linkage });
|
||||
@export(cosf, .{ .name = "cosf", .linkage = common.linkage });
|
||||
@export(cos, .{ .name = "cos", .linkage = common.linkage });
|
||||
@export(__cosx, .{ .name = "__cosx", .linkage = common.linkage });
|
||||
if (common.want_ppc_abi) {
|
||||
@export(cosq, .{ .name = "cosf128", .linkage = common.linkage });
|
||||
}
|
||||
@export(cosq, .{ .name = "cosq", .linkage = common.linkage });
|
||||
@export(cosl, .{ .name = "cosl", .linkage = common.linkage });
|
||||
}
|
||||
|
||||
pub fn __cosh(a: f16) callconv(.C) f16 {
|
||||
// TODO: more efficient implementation
|
||||
return @floatCast(f16, cosf(a));
|
||||
}
|
||||
|
||||
pub fn cosf(x: f32) callconv(.C) f32 {
|
||||
// Small multiples of pi/2 rounded to double precision.
|
||||
const c1pio2: f64 = 1.0 * math.pi / 2.0; // 0x3FF921FB, 0x54442D18
|
||||
const c2pio2: f64 = 2.0 * math.pi / 2.0; // 0x400921FB, 0x54442D18
|
||||
const c3pio2: f64 = 3.0 * math.pi / 2.0; // 0x4012D97C, 0x7F3321D2
|
||||
const c4pio2: f64 = 4.0 * math.pi / 2.0; // 0x401921FB, 0x54442D18
|
||||
|
||||
var ix = @bitCast(u32, x);
|
||||
const sign = ix >> 31 != 0;
|
||||
ix &= 0x7fffffff;
|
||||
|
||||
if (ix <= 0x3f490fda) { // |x| ~<= pi/4
|
||||
if (ix < 0x39800000) { // |x| < 2**-12
|
||||
// raise inexact if x != 0
|
||||
math.doNotOptimizeAway(x + 0x1p120);
|
||||
return 1.0;
|
||||
}
|
||||
return trig.__cosdf(x);
|
||||
}
|
||||
if (ix <= 0x407b53d1) { // |x| ~<= 5*pi/4
|
||||
if (ix > 0x4016cbe3) { // |x| ~> 3*pi/4
|
||||
return -trig.__cosdf(if (sign) x + c2pio2 else x - c2pio2);
|
||||
} else {
|
||||
if (sign) {
|
||||
return trig.__sindf(x + c1pio2);
|
||||
} else {
|
||||
return trig.__sindf(c1pio2 - x);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ix <= 0x40e231d5) { // |x| ~<= 9*pi/4
|
||||
if (ix > 0x40afeddf) { // |x| ~> 7*pi/4
|
||||
return trig.__cosdf(if (sign) x + c4pio2 else x - c4pio2);
|
||||
} else {
|
||||
if (sign) {
|
||||
return trig.__sindf(-x - c3pio2);
|
||||
} else {
|
||||
return trig.__sindf(x - c3pio2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cos(Inf or NaN) is NaN
|
||||
if (ix >= 0x7f800000) {
|
||||
return x - x;
|
||||
}
|
||||
|
||||
var y: f64 = undefined;
|
||||
const n = rem_pio2f(x, &y);
|
||||
return switch (n & 3) {
|
||||
0 => trig.__cosdf(y),
|
||||
1 => trig.__sindf(-y),
|
||||
2 => -trig.__cosdf(y),
|
||||
else => trig.__sindf(y),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn cos(x: f64) callconv(.C) f64 {
|
||||
var ix = @bitCast(u64, x) >> 32;
|
||||
ix &= 0x7fffffff;
|
||||
|
||||
// |x| ~< pi/4
|
||||
if (ix <= 0x3fe921fb) {
|
||||
if (ix < 0x3e46a09e) { // |x| < 2**-27 * sqrt(2)
|
||||
// raise inexact if x!=0
|
||||
math.doNotOptimizeAway(x + 0x1p120);
|
||||
return 1.0;
|
||||
}
|
||||
return trig.__cos(x, 0);
|
||||
}
|
||||
|
||||
// cos(Inf or NaN) is NaN
|
||||
if (ix >= 0x7ff00000) {
|
||||
return x - x;
|
||||
}
|
||||
|
||||
var y: [2]f64 = undefined;
|
||||
const n = rem_pio2(x, &y);
|
||||
return switch (n & 3) {
|
||||
0 => trig.__cos(y[0], y[1]),
|
||||
1 => -trig.__sin(y[0], y[1], 1),
|
||||
2 => -trig.__cos(y[0], y[1]),
|
||||
else => trig.__sin(y[0], y[1], 1),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn __cosx(a: f80) callconv(.C) f80 {
|
||||
// TODO: more efficient implementation
|
||||
return @floatCast(f80, cosq(a));
|
||||
}
|
||||
|
||||
pub fn cosq(a: f128) callconv(.C) f128 {
|
||||
// TODO: more correct implementation
|
||||
return cos(@floatCast(f64, a));
|
||||
}
|
||||
|
||||
pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {
|
||||
switch (@typeInfo(c_longdouble).Float.bits) {
|
||||
16 => return __cosh(x),
|
||||
32 => return cosf(x),
|
||||
64 => return cos(x),
|
||||
80 => return __cosx(x),
|
||||
128 => return cosq(x),
|
||||
else => @compileError("unreachable"),
|
||||
}
|
||||
}
|
||||
|
||||
test "cos32" {
|
||||
const epsilon = 0.00001;
|
||||
|
||||
try expect(math.approxEqAbs(f32, cosf(0.0), 1.0, epsilon));
|
||||
try expect(math.approxEqAbs(f32, cosf(0.2), 0.980067, epsilon));
|
||||
try expect(math.approxEqAbs(f32, cosf(0.8923), 0.627623, epsilon));
|
||||
try expect(math.approxEqAbs(f32, cosf(1.5), 0.070737, epsilon));
|
||||
try expect(math.approxEqAbs(f32, cosf(-1.5), 0.070737, epsilon));
|
||||
try expect(math.approxEqAbs(f32, cosf(37.45), 0.969132, epsilon));
|
||||
try expect(math.approxEqAbs(f32, cosf(89.123), 0.400798, epsilon));
|
||||
}
|
||||
|
||||
test "cos64" {
|
||||
const epsilon = 0.000001;
|
||||
|
||||
try expect(math.approxEqAbs(f64, cos(0.0), 1.0, epsilon));
|
||||
try expect(math.approxEqAbs(f64, cos(0.2), 0.980067, epsilon));
|
||||
try expect(math.approxEqAbs(f64, cos(0.8923), 0.627623, epsilon));
|
||||
try expect(math.approxEqAbs(f64, cos(1.5), 0.070737, epsilon));
|
||||
try expect(math.approxEqAbs(f64, cos(-1.5), 0.070737, epsilon));
|
||||
try expect(math.approxEqAbs(f64, cos(37.45), 0.969132, epsilon));
|
||||
try expect(math.approxEqAbs(f64, cos(89.123), 0.40080, epsilon));
|
||||
}
|
||||
|
||||
test "cos32.special" {
|
||||
try expect(math.isNan(cosf(math.inf(f32))));
|
||||
try expect(math.isNan(cosf(-math.inf(f32))));
|
||||
try expect(math.isNan(cosf(math.nan(f32))));
|
||||
}
|
||||
|
||||
test "cos64.special" {
|
||||
try expect(math.isNan(cos(math.inf(f64))));
|
||||
try expect(math.isNan(cos(-math.inf(f64))));
|
||||
try expect(math.isNan(cos(math.nan(f64))));
|
||||
}
|
||||
@@ -1,254 +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(__clzsi2, .{ .name = "__clzsi2", .linkage = common.linkage });
|
||||
@export(__clzdi2, .{ .name = "__clzdi2", .linkage = common.linkage });
|
||||
@export(__clzti2, .{ .name = "__clzti2", .linkage = common.linkage });
|
||||
@export(__ctzsi2, .{ .name = "__ctzsi2", .linkage = common.linkage });
|
||||
@export(__ctzdi2, .{ .name = "__ctzdi2", .linkage = common.linkage });
|
||||
@export(__ctzti2, .{ .name = "__ctzti2", .linkage = common.linkage });
|
||||
@export(__ffssi2, .{ .name = "__ffssi2", .linkage = common.linkage });
|
||||
@export(__ffsdi2, .{ .name = "__ffsdi2", .linkage = common.linkage });
|
||||
@export(__ffsti2, .{ .name = "__ffsti2", .linkage = common.linkage });
|
||||
}
|
||||
|
||||
// clz - count leading zeroes
|
||||
// - clzXi2 for unoptimized little and big endian
|
||||
// - __clzsi2_thumb1: assume a != 0
|
||||
// - __clzsi2_arm32: assume a != 0
|
||||
|
||||
// ctz - count trailing zeroes
|
||||
// - ctzXi2 for unoptimized little and big endian
|
||||
|
||||
// ffs - find first set
|
||||
// * ffs = (a == 0) => 0, (a != 0) => ctz + 1
|
||||
// * dont pay for `if (x == 0) return shift;` inside ctz
|
||||
// - ffsXi2 for unoptimized little and big endian
|
||||
|
||||
inline fn clzXi2(comptime T: type, a: T) i32 {
|
||||
var x = switch (@bitSizeOf(T)) {
|
||||
32 => @bitCast(u32, a),
|
||||
64 => @bitCast(u64, a),
|
||||
128 => @bitCast(u128, a),
|
||||
else => unreachable,
|
||||
};
|
||||
var n: T = @bitSizeOf(T);
|
||||
// Count first bit set using binary search, from Hacker's Delight
|
||||
var y: @TypeOf(x) = 0;
|
||||
comptime var shift: u8 = @bitSizeOf(T);
|
||||
inline while (shift > 0) {
|
||||
shift = shift >> 1;
|
||||
y = x >> shift;
|
||||
if (y != 0) {
|
||||
n = n - shift;
|
||||
x = y;
|
||||
}
|
||||
}
|
||||
return @intCast(i32, n - @bitCast(T, x));
|
||||
}
|
||||
|
||||
fn __clzsi2_thumb1() callconv(.Naked) void {
|
||||
@setRuntimeSafety(false);
|
||||
|
||||
// Similar to the generic version with the last two rounds replaced by a LUT
|
||||
asm volatile (
|
||||
\\ movs r1, #32
|
||||
\\ lsrs r2, r0, #16
|
||||
\\ beq 1f
|
||||
\\ subs r1, #16
|
||||
\\ movs r0, r2
|
||||
\\ 1:
|
||||
\\ lsrs r2, r0, #8
|
||||
\\ beq 1f
|
||||
\\ subs r1, #8
|
||||
\\ movs r0, r2
|
||||
\\ 1:
|
||||
\\ lsrs r2, r0, #4
|
||||
\\ beq 1f
|
||||
\\ subs r1, #4
|
||||
\\ movs r0, r2
|
||||
\\ 1:
|
||||
\\ ldr r3, =LUT
|
||||
\\ ldrb r0, [r3, r0]
|
||||
\\ subs r0, r1, r0
|
||||
\\ bx lr
|
||||
\\ .p2align 2
|
||||
\\ // Number of bits set in the 0-15 range
|
||||
\\ LUT:
|
||||
\\ .byte 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4
|
||||
);
|
||||
|
||||
unreachable;
|
||||
}
|
||||
|
||||
fn __clzsi2_arm32() callconv(.Naked) void {
|
||||
@setRuntimeSafety(false);
|
||||
|
||||
asm volatile (
|
||||
\\ // Assumption: n != 0
|
||||
\\ // r0: n
|
||||
\\ // r1: count of leading zeros in n + 1
|
||||
\\ // r2: scratch register for shifted r0
|
||||
\\ mov r1, #1
|
||||
\\
|
||||
\\ // Basic block:
|
||||
\\ // if ((r0 >> SHIFT) == 0)
|
||||
\\ // r1 += SHIFT;
|
||||
\\ // else
|
||||
\\ // r0 >>= SHIFT;
|
||||
\\ // for descending powers of two as SHIFT.
|
||||
\\ lsrs r2, r0, #16
|
||||
\\ movne r0, r2
|
||||
\\ addeq r1, #16
|
||||
\\
|
||||
\\ lsrs r2, r0, #8
|
||||
\\ movne r0, r2
|
||||
\\ addeq r1, #8
|
||||
\\
|
||||
\\ lsrs r2, r0, #4
|
||||
\\ movne r0, r2
|
||||
\\ addeq r1, #4
|
||||
\\
|
||||
\\ lsrs r2, r0, #2
|
||||
\\ movne r0, r2
|
||||
\\ addeq r1, #2
|
||||
\\
|
||||
\\ // The basic block invariants at this point are (r0 >> 2) == 0 and
|
||||
\\ // r0 != 0. This means 1 <= r0 <= 3 and 0 <= (r0 >> 1) <= 1.
|
||||
\\ //
|
||||
\\ // r0 | (r0 >> 1) == 0 | (r0 >> 1) == 1 | -(r0 >> 1) | 1 - (r0 >> 1)f
|
||||
\\ // ---+----------------+----------------+------------+--------------
|
||||
\\ // 1 | 1 | 0 | 0 | 1
|
||||
\\ // 2 | 0 | 1 | -1 | 0
|
||||
\\ // 3 | 0 | 1 | -1 | 0
|
||||
\\ //
|
||||
\\ // The r1's initial value of 1 compensates for the 1 here.
|
||||
\\ sub r0, r1, r0, lsr #1
|
||||
\\ bx lr
|
||||
);
|
||||
|
||||
unreachable;
|
||||
}
|
||||
|
||||
fn clzsi2_generic(a: i32) callconv(.C) i32 {
|
||||
return clzXi2(i32, a);
|
||||
}
|
||||
|
||||
pub const __clzsi2 = switch (builtin.cpu.arch) {
|
||||
.arm, .armeb, .thumb, .thumbeb => impl: {
|
||||
const use_thumb1 =
|
||||
(builtin.cpu.arch.isThumb() or
|
||||
std.Target.arm.featureSetHas(builtin.cpu.features, .noarm)) and
|
||||
!std.Target.arm.featureSetHas(builtin.cpu.features, .thumb2);
|
||||
|
||||
if (use_thumb1) {
|
||||
break :impl __clzsi2_thumb1;
|
||||
}
|
||||
// From here on we're either targeting Thumb2 or ARM.
|
||||
else if (!builtin.cpu.arch.isThumb()) {
|
||||
break :impl __clzsi2_arm32;
|
||||
}
|
||||
// Use the generic implementation otherwise.
|
||||
else break :impl clzsi2_generic;
|
||||
},
|
||||
else => clzsi2_generic,
|
||||
};
|
||||
|
||||
pub fn __clzdi2(a: i64) callconv(.C) i32 {
|
||||
return clzXi2(i64, a);
|
||||
}
|
||||
|
||||
pub fn __clzti2(a: i128) callconv(.C) i32 {
|
||||
return clzXi2(i128, a);
|
||||
}
|
||||
|
||||
inline fn ctzXi2(comptime T: type, a: T) i32 {
|
||||
var x = switch (@bitSizeOf(T)) {
|
||||
32 => @bitCast(u32, a),
|
||||
64 => @bitCast(u64, a),
|
||||
128 => @bitCast(u128, a),
|
||||
else => unreachable,
|
||||
};
|
||||
var n: T = 1;
|
||||
// Number of trailing zeroes as binary search, from Hacker's Delight
|
||||
var mask: @TypeOf(x) = std.math.maxInt(@TypeOf(x));
|
||||
comptime var shift = @bitSizeOf(T);
|
||||
if (x == 0) return shift;
|
||||
inline while (shift > 1) {
|
||||
shift = shift >> 1;
|
||||
mask = mask >> shift;
|
||||
if ((x & mask) == 0) {
|
||||
n = n + shift;
|
||||
x = x >> shift;
|
||||
}
|
||||
}
|
||||
return @intCast(i32, n - @bitCast(T, (x & 1)));
|
||||
}
|
||||
|
||||
pub fn __ctzsi2(a: i32) callconv(.C) i32 {
|
||||
return ctzXi2(i32, a);
|
||||
}
|
||||
|
||||
pub fn __ctzdi2(a: i64) callconv(.C) i32 {
|
||||
return ctzXi2(i64, a);
|
||||
}
|
||||
|
||||
pub fn __ctzti2(a: i128) callconv(.C) i32 {
|
||||
return ctzXi2(i128, a);
|
||||
}
|
||||
|
||||
inline fn ffsXi2(comptime T: type, a: T) i32 {
|
||||
var x = switch (@bitSizeOf(T)) {
|
||||
32 => @bitCast(u32, a),
|
||||
64 => @bitCast(u64, a),
|
||||
128 => @bitCast(u128, a),
|
||||
else => unreachable,
|
||||
};
|
||||
var n: T = 1;
|
||||
// adapted from Number of trailing zeroes (see ctzXi2)
|
||||
var mask: @TypeOf(x) = std.math.maxInt(@TypeOf(x));
|
||||
comptime var shift = @bitSizeOf(T);
|
||||
// In contrast to ctz return 0
|
||||
if (x == 0) return 0;
|
||||
inline while (shift > 1) {
|
||||
shift = shift >> 1;
|
||||
mask = mask >> shift;
|
||||
if ((x & mask) == 0) {
|
||||
n = n + shift;
|
||||
x = x >> shift;
|
||||
}
|
||||
}
|
||||
// return ctz + 1
|
||||
return @intCast(i32, n - @bitCast(T, (x & 1))) + @as(i32, 1);
|
||||
}
|
||||
|
||||
pub fn __ffssi2(a: i32) callconv(.C) i32 {
|
||||
return ffsXi2(i32, a);
|
||||
}
|
||||
|
||||
pub fn __ffsdi2(a: i64) callconv(.C) i32 {
|
||||
return ffsXi2(i64, a);
|
||||
}
|
||||
|
||||
pub fn __ffsti2(a: i128) callconv(.C) i32 {
|
||||
return ffsXi2(i128, a);
|
||||
}
|
||||
|
||||
test {
|
||||
_ = @import("clzsi2_test.zig");
|
||||
_ = @import("clzdi2_test.zig");
|
||||
_ = @import("clzti2_test.zig");
|
||||
|
||||
_ = @import("ctzsi2_test.zig");
|
||||
_ = @import("ctzdi2_test.zig");
|
||||
_ = @import("ctzti2_test.zig");
|
||||
|
||||
_ = @import("ffssi2_test.zig");
|
||||
_ = @import("ffsdi2_test.zig");
|
||||
_ = @import("ffsti2_test.zig");
|
||||
}
|
||||
@@ -1,325 +0,0 @@
|
||||
const ctz = @import("count0bits.zig");
|
||||
const testing = @import("std").testing;
|
||||
|
||||
fn test__ctzdi2(a: u64, expected: i32) !void {
|
||||
var x = @bitCast(i64, a);
|
||||
var result = ctz.__ctzdi2(x);
|
||||
try testing.expectEqual(expected, result);
|
||||
}
|
||||
|
||||
test "ctzdi2" {
|
||||
try test__ctzdi2(0x00000000_00000001, 0);
|
||||
try test__ctzdi2(0x00000000_00000002, 1);
|
||||
try test__ctzdi2(0x00000000_00000003, 0);
|
||||
try test__ctzdi2(0x00000000_00000004, 2);
|
||||
try test__ctzdi2(0x00000000_00000005, 0);
|
||||
try test__ctzdi2(0x00000000_00000006, 1);
|
||||
try test__ctzdi2(0x00000000_00000007, 0);
|
||||
try test__ctzdi2(0x00000000_00000008, 3);
|
||||
try test__ctzdi2(0x00000000_00000009, 0);
|
||||
try test__ctzdi2(0x00000000_0000000A, 1);
|
||||
try test__ctzdi2(0x00000000_0000000B, 0);
|
||||
try test__ctzdi2(0x00000000_0000000C, 2);
|
||||
try test__ctzdi2(0x00000000_0000000D, 0);
|
||||
try test__ctzdi2(0x00000000_0000000E, 1);
|
||||
try test__ctzdi2(0x00000000_0000000F, 0);
|
||||
try test__ctzdi2(0x00000000_00000010, 4);
|
||||
try test__ctzdi2(0x00000000_00000011, 0);
|
||||
try test__ctzdi2(0x00000000_00000012, 1);
|
||||
try test__ctzdi2(0x00000000_00000013, 0);
|
||||
try test__ctzdi2(0x00000000_00000014, 2);
|
||||
try test__ctzdi2(0x00000000_00000015, 0);
|
||||
try test__ctzdi2(0x00000000_00000016, 1);
|
||||
try test__ctzdi2(0x00000000_00000017, 0);
|
||||
try test__ctzdi2(0x00000000_00000018, 3);
|
||||
try test__ctzdi2(0x00000000_00000019, 0);
|
||||
try test__ctzdi2(0x00000000_0000001A, 1);
|
||||
try test__ctzdi2(0x00000000_0000001B, 0);
|
||||
try test__ctzdi2(0x00000000_0000001C, 2);
|
||||
try test__ctzdi2(0x00000000_0000001D, 0);
|
||||
try test__ctzdi2(0x00000000_0000001E, 1);
|
||||
try test__ctzdi2(0x00000000_0000001F, 0);
|
||||
try test__ctzdi2(0x00000000_00000020, 5);
|
||||
try test__ctzdi2(0x00000000_00000021, 0);
|
||||
try test__ctzdi2(0x00000000_00000022, 1);
|
||||
try test__ctzdi2(0x00000000_00000023, 0);
|
||||
try test__ctzdi2(0x00000000_00000024, 2);
|
||||
try test__ctzdi2(0x00000000_00000025, 0);
|
||||
try test__ctzdi2(0x00000000_00000026, 1);
|
||||
try test__ctzdi2(0x00000000_00000027, 0);
|
||||
try test__ctzdi2(0x00000000_00000028, 3);
|
||||
try test__ctzdi2(0x00000000_00000029, 0);
|
||||
try test__ctzdi2(0x00000000_0000002A, 1);
|
||||
try test__ctzdi2(0x00000000_0000002B, 0);
|
||||
try test__ctzdi2(0x00000000_0000002C, 2);
|
||||
try test__ctzdi2(0x00000000_0000002D, 0);
|
||||
try test__ctzdi2(0x00000000_0000002E, 1);
|
||||
try test__ctzdi2(0x00000000_0000002F, 0);
|
||||
try test__ctzdi2(0x00000000_00000030, 4);
|
||||
try test__ctzdi2(0x00000000_00000031, 0);
|
||||
try test__ctzdi2(0x00000000_00000032, 1);
|
||||
try test__ctzdi2(0x00000000_00000033, 0);
|
||||
try test__ctzdi2(0x00000000_00000034, 2);
|
||||
try test__ctzdi2(0x00000000_00000035, 0);
|
||||
try test__ctzdi2(0x00000000_00000036, 1);
|
||||
try test__ctzdi2(0x00000000_00000037, 0);
|
||||
try test__ctzdi2(0x00000000_00000038, 3);
|
||||
try test__ctzdi2(0x00000000_00000039, 0);
|
||||
try test__ctzdi2(0x00000000_0000003A, 1);
|
||||
try test__ctzdi2(0x00000000_0000003B, 0);
|
||||
try test__ctzdi2(0x00000000_0000003C, 2);
|
||||
try test__ctzdi2(0x00000000_0000003D, 0);
|
||||
try test__ctzdi2(0x00000000_0000003E, 1);
|
||||
try test__ctzdi2(0x00000000_0000003F, 0);
|
||||
try test__ctzdi2(0x00000000_00000040, 6);
|
||||
try test__ctzdi2(0x00000000_00000041, 0);
|
||||
try test__ctzdi2(0x00000000_00000042, 1);
|
||||
try test__ctzdi2(0x00000000_00000043, 0);
|
||||
try test__ctzdi2(0x00000000_00000044, 2);
|
||||
try test__ctzdi2(0x00000000_00000045, 0);
|
||||
try test__ctzdi2(0x00000000_00000046, 1);
|
||||
try test__ctzdi2(0x00000000_00000047, 0);
|
||||
try test__ctzdi2(0x00000000_00000048, 3);
|
||||
try test__ctzdi2(0x00000000_00000049, 0);
|
||||
try test__ctzdi2(0x00000000_0000004A, 1);
|
||||
try test__ctzdi2(0x00000000_0000004B, 0);
|
||||
try test__ctzdi2(0x00000000_0000004C, 2);
|
||||
try test__ctzdi2(0x00000000_0000004D, 0);
|
||||
try test__ctzdi2(0x00000000_0000004E, 1);
|
||||
try test__ctzdi2(0x00000000_0000004F, 0);
|
||||
try test__ctzdi2(0x00000000_00000050, 4);
|
||||
try test__ctzdi2(0x00000000_00000051, 0);
|
||||
try test__ctzdi2(0x00000000_00000052, 1);
|
||||
try test__ctzdi2(0x00000000_00000053, 0);
|
||||
try test__ctzdi2(0x00000000_00000054, 2);
|
||||
try test__ctzdi2(0x00000000_00000055, 0);
|
||||
try test__ctzdi2(0x00000000_00000056, 1);
|
||||
try test__ctzdi2(0x00000000_00000057, 0);
|
||||
try test__ctzdi2(0x00000000_00000058, 3);
|
||||
try test__ctzdi2(0x00000000_00000059, 0);
|
||||
try test__ctzdi2(0x00000000_0000005A, 1);
|
||||
try test__ctzdi2(0x00000000_0000005B, 0);
|
||||
try test__ctzdi2(0x00000000_0000005C, 2);
|
||||
try test__ctzdi2(0x00000000_0000005D, 0);
|
||||
try test__ctzdi2(0x00000000_0000005E, 1);
|
||||
try test__ctzdi2(0x00000000_0000005F, 0);
|
||||
try test__ctzdi2(0x00000000_00000060, 5);
|
||||
try test__ctzdi2(0x00000000_00000061, 0);
|
||||
try test__ctzdi2(0x00000000_00000062, 1);
|
||||
try test__ctzdi2(0x00000000_00000063, 0);
|
||||
try test__ctzdi2(0x00000000_00000064, 2);
|
||||
try test__ctzdi2(0x00000000_00000065, 0);
|
||||
try test__ctzdi2(0x00000000_00000066, 1);
|
||||
try test__ctzdi2(0x00000000_00000067, 0);
|
||||
try test__ctzdi2(0x00000000_00000068, 3);
|
||||
try test__ctzdi2(0x00000000_00000069, 0);
|
||||
try test__ctzdi2(0x00000000_0000006A, 1);
|
||||
try test__ctzdi2(0x00000000_0000006B, 0);
|
||||
try test__ctzdi2(0x00000000_0000006C, 2);
|
||||
try test__ctzdi2(0x00000000_0000006D, 0);
|
||||
try test__ctzdi2(0x00000000_0000006E, 1);
|
||||
try test__ctzdi2(0x00000000_0000006F, 0);
|
||||
try test__ctzdi2(0x00000000_00000070, 4);
|
||||
try test__ctzdi2(0x00000000_00000071, 0);
|
||||
try test__ctzdi2(0x00000000_00000072, 1);
|
||||
try test__ctzdi2(0x00000000_00000073, 0);
|
||||
try test__ctzdi2(0x00000000_00000074, 2);
|
||||
try test__ctzdi2(0x00000000_00000075, 0);
|
||||
try test__ctzdi2(0x00000000_00000076, 1);
|
||||
try test__ctzdi2(0x00000000_00000077, 0);
|
||||
try test__ctzdi2(0x00000000_00000078, 3);
|
||||
try test__ctzdi2(0x00000000_00000079, 0);
|
||||
try test__ctzdi2(0x00000000_0000007A, 1);
|
||||
try test__ctzdi2(0x00000000_0000007B, 0);
|
||||
try test__ctzdi2(0x00000000_0000007C, 2);
|
||||
try test__ctzdi2(0x00000000_0000007D, 0);
|
||||
try test__ctzdi2(0x00000000_0000007E, 1);
|
||||
try test__ctzdi2(0x00000000_0000007F, 0);
|
||||
try test__ctzdi2(0x00000000_00000080, 7);
|
||||
try test__ctzdi2(0x00000000_00000081, 0);
|
||||
try test__ctzdi2(0x00000000_00000082, 1);
|
||||
try test__ctzdi2(0x00000000_00000083, 0);
|
||||
try test__ctzdi2(0x00000000_00000084, 2);
|
||||
try test__ctzdi2(0x00000000_00000085, 0);
|
||||
try test__ctzdi2(0x00000000_00000086, 1);
|
||||
try test__ctzdi2(0x00000000_00000087, 0);
|
||||
try test__ctzdi2(0x00000000_00000088, 3);
|
||||
try test__ctzdi2(0x00000000_00000089, 0);
|
||||
try test__ctzdi2(0x00000000_0000008A, 1);
|
||||
try test__ctzdi2(0x00000000_0000008B, 0);
|
||||
try test__ctzdi2(0x00000000_0000008C, 2);
|
||||
try test__ctzdi2(0x00000000_0000008D, 0);
|
||||
try test__ctzdi2(0x00000000_0000008E, 1);
|
||||
try test__ctzdi2(0x00000000_0000008F, 0);
|
||||
try test__ctzdi2(0x00000000_00000090, 4);
|
||||
try test__ctzdi2(0x00000000_00000091, 0);
|
||||
try test__ctzdi2(0x00000000_00000092, 1);
|
||||
try test__ctzdi2(0x00000000_00000093, 0);
|
||||
try test__ctzdi2(0x00000000_00000094, 2);
|
||||
try test__ctzdi2(0x00000000_00000095, 0);
|
||||
try test__ctzdi2(0x00000000_00000096, 1);
|
||||
try test__ctzdi2(0x00000000_00000097, 0);
|
||||
try test__ctzdi2(0x00000000_00000098, 3);
|
||||
try test__ctzdi2(0x00000000_00000099, 0);
|
||||
try test__ctzdi2(0x00000000_0000009A, 1);
|
||||
try test__ctzdi2(0x00000000_0000009B, 0);
|
||||
try test__ctzdi2(0x00000000_0000009C, 2);
|
||||
try test__ctzdi2(0x00000000_0000009D, 0);
|
||||
try test__ctzdi2(0x00000000_0000009E, 1);
|
||||
try test__ctzdi2(0x00000000_0000009F, 0);
|
||||
try test__ctzdi2(0x00000000_000000A0, 5);
|
||||
try test__ctzdi2(0x00000000_000000A1, 0);
|
||||
try test__ctzdi2(0x00000000_000000A2, 1);
|
||||
try test__ctzdi2(0x00000000_000000A3, 0);
|
||||
try test__ctzdi2(0x00000000_000000A4, 2);
|
||||
try test__ctzdi2(0x00000000_000000A5, 0);
|
||||
try test__ctzdi2(0x00000000_000000A6, 1);
|
||||
try test__ctzdi2(0x00000000_000000A7, 0);
|
||||
try test__ctzdi2(0x00000000_000000A8, 3);
|
||||
try test__ctzdi2(0x00000000_000000A9, 0);
|
||||
try test__ctzdi2(0x00000000_000000AA, 1);
|
||||
try test__ctzdi2(0x00000000_000000AB, 0);
|
||||
try test__ctzdi2(0x00000000_000000AC, 2);
|
||||
try test__ctzdi2(0x00000000_000000AD, 0);
|
||||
try test__ctzdi2(0x00000000_000000AE, 1);
|
||||
try test__ctzdi2(0x00000000_000000AF, 0);
|
||||
try test__ctzdi2(0x00000000_000000B0, 4);
|
||||
try test__ctzdi2(0x00000000_000000B1, 0);
|
||||
try test__ctzdi2(0x00000000_000000B2, 1);
|
||||
try test__ctzdi2(0x00000000_000000B3, 0);
|
||||
try test__ctzdi2(0x00000000_000000B4, 2);
|
||||
try test__ctzdi2(0x00000000_000000B5, 0);
|
||||
try test__ctzdi2(0x00000000_000000B6, 1);
|
||||
try test__ctzdi2(0x00000000_000000B7, 0);
|
||||
try test__ctzdi2(0x00000000_000000B8, 3);
|
||||
try test__ctzdi2(0x00000000_000000B9, 0);
|
||||
try test__ctzdi2(0x00000000_000000BA, 1);
|
||||
try test__ctzdi2(0x00000000_000000BB, 0);
|
||||
try test__ctzdi2(0x00000000_000000BC, 2);
|
||||
try test__ctzdi2(0x00000000_000000BD, 0);
|
||||
try test__ctzdi2(0x00000000_000000BE, 1);
|
||||
try test__ctzdi2(0x00000000_000000BF, 0);
|
||||
try test__ctzdi2(0x00000000_000000C0, 6);
|
||||
try test__ctzdi2(0x00000000_000000C1, 0);
|
||||
try test__ctzdi2(0x00000000_000000C2, 1);
|
||||
try test__ctzdi2(0x00000000_000000C3, 0);
|
||||
try test__ctzdi2(0x00000000_000000C4, 2);
|
||||
try test__ctzdi2(0x00000000_000000C5, 0);
|
||||
try test__ctzdi2(0x00000000_000000C6, 1);
|
||||
try test__ctzdi2(0x00000000_000000C7, 0);
|
||||
try test__ctzdi2(0x00000000_000000C8, 3);
|
||||
try test__ctzdi2(0x00000000_000000C9, 0);
|
||||
try test__ctzdi2(0x00000000_000000CA, 1);
|
||||
try test__ctzdi2(0x00000000_000000CB, 0);
|
||||
try test__ctzdi2(0x00000000_000000CC, 2);
|
||||
try test__ctzdi2(0x00000000_000000CD, 0);
|
||||
try test__ctzdi2(0x00000000_000000CE, 1);
|
||||
try test__ctzdi2(0x00000000_000000CF, 0);
|
||||
try test__ctzdi2(0x00000000_000000D0, 4);
|
||||
try test__ctzdi2(0x00000000_000000D1, 0);
|
||||
try test__ctzdi2(0x00000000_000000D2, 1);
|
||||
try test__ctzdi2(0x00000000_000000D3, 0);
|
||||
try test__ctzdi2(0x00000000_000000D4, 2);
|
||||
try test__ctzdi2(0x00000000_000000D5, 0);
|
||||
try test__ctzdi2(0x00000000_000000D6, 1);
|
||||
try test__ctzdi2(0x00000000_000000D7, 0);
|
||||
try test__ctzdi2(0x00000000_000000D8, 3);
|
||||
try test__ctzdi2(0x00000000_000000D9, 0);
|
||||
try test__ctzdi2(0x00000000_000000DA, 1);
|
||||
try test__ctzdi2(0x00000000_000000DB, 0);
|
||||
try test__ctzdi2(0x00000000_000000DC, 2);
|
||||
try test__ctzdi2(0x00000000_000000DD, 0);
|
||||
try test__ctzdi2(0x00000000_000000DE, 1);
|
||||
try test__ctzdi2(0x00000000_000000DF, 0);
|
||||
try test__ctzdi2(0x00000000_000000E0, 5);
|
||||
try test__ctzdi2(0x00000000_000000E1, 0);
|
||||
try test__ctzdi2(0x00000000_000000E2, 1);
|
||||
try test__ctzdi2(0x00000000_000000E3, 0);
|
||||
try test__ctzdi2(0x00000000_000000E4, 2);
|
||||
try test__ctzdi2(0x00000000_000000E5, 0);
|
||||
try test__ctzdi2(0x00000000_000000E6, 1);
|
||||
try test__ctzdi2(0x00000000_000000E7, 0);
|
||||
try test__ctzdi2(0x00000000_000000E8, 3);
|
||||
try test__ctzdi2(0x00000000_000000E9, 0);
|
||||
try test__ctzdi2(0x00000000_000000EA, 1);
|
||||
try test__ctzdi2(0x00000000_000000EB, 0);
|
||||
try test__ctzdi2(0x00000000_000000EC, 2);
|
||||
try test__ctzdi2(0x00000000_000000ED, 0);
|
||||
try test__ctzdi2(0x00000000_000000EE, 1);
|
||||
try test__ctzdi2(0x00000000_000000EF, 0);
|
||||
try test__ctzdi2(0x00000000_000000F0, 4);
|
||||
try test__ctzdi2(0x00000000_000000F1, 0);
|
||||
try test__ctzdi2(0x00000000_000000F2, 1);
|
||||
try test__ctzdi2(0x00000000_000000F3, 0);
|
||||
try test__ctzdi2(0x00000000_000000F4, 2);
|
||||
try test__ctzdi2(0x00000000_000000F5, 0);
|
||||
try test__ctzdi2(0x00000000_000000F6, 1);
|
||||
try test__ctzdi2(0x00000000_000000F7, 0);
|
||||
try test__ctzdi2(0x00000000_000000F8, 3);
|
||||
try test__ctzdi2(0x00000000_000000F9, 0);
|
||||
try test__ctzdi2(0x00000000_000000FA, 1);
|
||||
try test__ctzdi2(0x00000000_000000FB, 0);
|
||||
try test__ctzdi2(0x00000000_000000FC, 2);
|
||||
try test__ctzdi2(0x00000000_000000FD, 0);
|
||||
try test__ctzdi2(0x00000000_000000FE, 1);
|
||||
try test__ctzdi2(0x00000000_000000FF, 0);
|
||||
|
||||
try test__ctzdi2(0x00000000_00000000, 64);
|
||||
try test__ctzdi2(0x80000000_00000000, 63);
|
||||
try test__ctzdi2(0x40000000_00000000, 62);
|
||||
try test__ctzdi2(0x20000000_00000000, 61);
|
||||
try test__ctzdi2(0x10000000_00000000, 60);
|
||||
try test__ctzdi2(0x08000000_00000000, 59);
|
||||
try test__ctzdi2(0x04000000_00000000, 58);
|
||||
try test__ctzdi2(0x02000000_00000000, 57);
|
||||
try test__ctzdi2(0x01000000_00000000, 56);
|
||||
try test__ctzdi2(0x00800000_00000000, 55);
|
||||
try test__ctzdi2(0x00400000_00000000, 54);
|
||||
try test__ctzdi2(0x00200000_00000000, 53);
|
||||
try test__ctzdi2(0x00100000_00000000, 52);
|
||||
try test__ctzdi2(0x00080000_00000000, 51);
|
||||
try test__ctzdi2(0x00040000_00000000, 50);
|
||||
try test__ctzdi2(0x00020000_00000000, 49);
|
||||
try test__ctzdi2(0x00010000_00000000, 48);
|
||||
try test__ctzdi2(0x00008000_00000000, 47);
|
||||
try test__ctzdi2(0x00004000_00000000, 46);
|
||||
try test__ctzdi2(0x00002000_00000000, 45);
|
||||
try test__ctzdi2(0x00001000_00000000, 44);
|
||||
try test__ctzdi2(0x00000800_00000000, 43);
|
||||
try test__ctzdi2(0x00000400_00000000, 42);
|
||||
try test__ctzdi2(0x00000200_00000000, 41);
|
||||
try test__ctzdi2(0x00000100_00000000, 40);
|
||||
try test__ctzdi2(0x00000080_00000000, 39);
|
||||
try test__ctzdi2(0x00000040_00000000, 38);
|
||||
try test__ctzdi2(0x00000020_00000000, 37);
|
||||
try test__ctzdi2(0x00000010_00000000, 36);
|
||||
try test__ctzdi2(0x00000008_00000000, 35);
|
||||
try test__ctzdi2(0x00000004_00000000, 34);
|
||||
try test__ctzdi2(0x00000002_00000000, 33);
|
||||
try test__ctzdi2(0x00000001_00000000, 32);
|
||||
|
||||
try test__ctzdi2(0x00000000_80000000, 31);
|
||||
try test__ctzdi2(0x00000000_40000000, 30);
|
||||
try test__ctzdi2(0x00000000_20000000, 29);
|
||||
try test__ctzdi2(0x00000000_10000000, 28);
|
||||
try test__ctzdi2(0x00000000_08000000, 27);
|
||||
try test__ctzdi2(0x00000000_04000000, 26);
|
||||
try test__ctzdi2(0x00000000_02000000, 25);
|
||||
try test__ctzdi2(0x00000000_01000000, 24);
|
||||
try test__ctzdi2(0x00000000_00800000, 23);
|
||||
try test__ctzdi2(0x00000000_00400000, 22);
|
||||
try test__ctzdi2(0x00000000_00200000, 21);
|
||||
try test__ctzdi2(0x00000000_00100000, 20);
|
||||
try test__ctzdi2(0x00000000_00080000, 19);
|
||||
try test__ctzdi2(0x00000000_00040000, 18);
|
||||
try test__ctzdi2(0x00000000_00020000, 17);
|
||||
try test__ctzdi2(0x00000000_00010000, 16);
|
||||
try test__ctzdi2(0x00000000_00008000, 15);
|
||||
try test__ctzdi2(0x00000000_00004000, 14);
|
||||
try test__ctzdi2(0x00000000_00002000, 13);
|
||||
try test__ctzdi2(0x00000000_00001000, 12);
|
||||
try test__ctzdi2(0x00000000_00000800, 11);
|
||||
try test__ctzdi2(0x00000000_00000400, 10);
|
||||
try test__ctzdi2(0x00000000_00000200, 9);
|
||||
try test__ctzdi2(0x00000000_00000100, 8);
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
const ctz = @import("count0bits.zig");
|
||||
const testing = @import("std").testing;
|
||||
|
||||
fn test__ctzsi2(a: u32, expected: i32) !void {
|
||||
var x = @bitCast(i32, a);
|
||||
var result = ctz.__ctzsi2(x);
|
||||
try testing.expectEqual(expected, result);
|
||||
}
|
||||
|
||||
test "ctzsi2" {
|
||||
try test__ctzsi2(0x00000001, 0);
|
||||
try test__ctzsi2(0x00000002, 1);
|
||||
try test__ctzsi2(0x00000003, 0);
|
||||
try test__ctzsi2(0x00000004, 2);
|
||||
try test__ctzsi2(0x00000005, 0);
|
||||
try test__ctzsi2(0x00000006, 1);
|
||||
try test__ctzsi2(0x00000007, 0);
|
||||
try test__ctzsi2(0x00000008, 3);
|
||||
try test__ctzsi2(0x00000009, 0);
|
||||
try test__ctzsi2(0x0000000A, 1);
|
||||
try test__ctzsi2(0x0000000B, 0);
|
||||
try test__ctzsi2(0x0000000C, 2);
|
||||
try test__ctzsi2(0x0000000D, 0);
|
||||
try test__ctzsi2(0x0000000E, 1);
|
||||
try test__ctzsi2(0x0000000F, 0);
|
||||
try test__ctzsi2(0x00000010, 4);
|
||||
try test__ctzsi2(0x00000011, 0);
|
||||
try test__ctzsi2(0x00000012, 1);
|
||||
try test__ctzsi2(0x00000013, 0);
|
||||
try test__ctzsi2(0x00000014, 2);
|
||||
try test__ctzsi2(0x00000015, 0);
|
||||
try test__ctzsi2(0x00000016, 1);
|
||||
try test__ctzsi2(0x00000017, 0);
|
||||
try test__ctzsi2(0x00000018, 3);
|
||||
try test__ctzsi2(0x00000019, 0);
|
||||
try test__ctzsi2(0x0000001A, 1);
|
||||
try test__ctzsi2(0x0000001B, 0);
|
||||
try test__ctzsi2(0x0000001C, 2);
|
||||
try test__ctzsi2(0x0000001D, 0);
|
||||
try test__ctzsi2(0x0000001E, 1);
|
||||
try test__ctzsi2(0x0000001F, 0);
|
||||
try test__ctzsi2(0x00000020, 5);
|
||||
try test__ctzsi2(0x00000021, 0);
|
||||
try test__ctzsi2(0x00000022, 1);
|
||||
try test__ctzsi2(0x00000023, 0);
|
||||
try test__ctzsi2(0x00000024, 2);
|
||||
try test__ctzsi2(0x00000025, 0);
|
||||
try test__ctzsi2(0x00000026, 1);
|
||||
try test__ctzsi2(0x00000027, 0);
|
||||
try test__ctzsi2(0x00000028, 3);
|
||||
try test__ctzsi2(0x00000029, 0);
|
||||
try test__ctzsi2(0x0000002A, 1);
|
||||
try test__ctzsi2(0x0000002B, 0);
|
||||
try test__ctzsi2(0x0000002C, 2);
|
||||
try test__ctzsi2(0x0000002D, 0);
|
||||
try test__ctzsi2(0x0000002E, 1);
|
||||
try test__ctzsi2(0x0000002F, 0);
|
||||
try test__ctzsi2(0x00000030, 4);
|
||||
try test__ctzsi2(0x00000031, 0);
|
||||
try test__ctzsi2(0x00000032, 1);
|
||||
try test__ctzsi2(0x00000033, 0);
|
||||
try test__ctzsi2(0x00000034, 2);
|
||||
try test__ctzsi2(0x00000035, 0);
|
||||
try test__ctzsi2(0x00000036, 1);
|
||||
try test__ctzsi2(0x00000037, 0);
|
||||
try test__ctzsi2(0x00000038, 3);
|
||||
try test__ctzsi2(0x00000039, 0);
|
||||
try test__ctzsi2(0x0000003A, 1);
|
||||
try test__ctzsi2(0x0000003B, 0);
|
||||
try test__ctzsi2(0x0000003C, 2);
|
||||
try test__ctzsi2(0x0000003D, 0);
|
||||
try test__ctzsi2(0x0000003E, 1);
|
||||
try test__ctzsi2(0x0000003F, 0);
|
||||
try test__ctzsi2(0x00000040, 6);
|
||||
try test__ctzsi2(0x00000041, 0);
|
||||
try test__ctzsi2(0x00000042, 1);
|
||||
try test__ctzsi2(0x00000043, 0);
|
||||
try test__ctzsi2(0x00000044, 2);
|
||||
try test__ctzsi2(0x00000045, 0);
|
||||
try test__ctzsi2(0x00000046, 1);
|
||||
try test__ctzsi2(0x00000047, 0);
|
||||
try test__ctzsi2(0x00000048, 3);
|
||||
try test__ctzsi2(0x00000049, 0);
|
||||
try test__ctzsi2(0x0000004A, 1);
|
||||
try test__ctzsi2(0x0000004B, 0);
|
||||
try test__ctzsi2(0x0000004C, 2);
|
||||
try test__ctzsi2(0x0000004D, 0);
|
||||
try test__ctzsi2(0x0000004E, 1);
|
||||
try test__ctzsi2(0x0000004F, 0);
|
||||
try test__ctzsi2(0x00000050, 4);
|
||||
try test__ctzsi2(0x00000051, 0);
|
||||
try test__ctzsi2(0x00000052, 1);
|
||||
try test__ctzsi2(0x00000053, 0);
|
||||
try test__ctzsi2(0x00000054, 2);
|
||||
try test__ctzsi2(0x00000055, 0);
|
||||
try test__ctzsi2(0x00000056, 1);
|
||||
try test__ctzsi2(0x00000057, 0);
|
||||
try test__ctzsi2(0x00000058, 3);
|
||||
try test__ctzsi2(0x00000059, 0);
|
||||
try test__ctzsi2(0x0000005A, 1);
|
||||
try test__ctzsi2(0x0000005B, 0);
|
||||
try test__ctzsi2(0x0000005C, 2);
|
||||
try test__ctzsi2(0x0000005D, 0);
|
||||
try test__ctzsi2(0x0000005E, 1);
|
||||
try test__ctzsi2(0x0000005F, 0);
|
||||
try test__ctzsi2(0x00000060, 5);
|
||||
try test__ctzsi2(0x00000061, 0);
|
||||
try test__ctzsi2(0x00000062, 1);
|
||||
try test__ctzsi2(0x00000063, 0);
|
||||
try test__ctzsi2(0x00000064, 2);
|
||||
try test__ctzsi2(0x00000065, 0);
|
||||
try test__ctzsi2(0x00000066, 1);
|
||||
try test__ctzsi2(0x00000067, 0);
|
||||
try test__ctzsi2(0x00000068, 3);
|
||||
try test__ctzsi2(0x00000069, 0);
|
||||
try test__ctzsi2(0x0000006A, 1);
|
||||
try test__ctzsi2(0x0000006B, 0);
|
||||
try test__ctzsi2(0x0000006C, 2);
|
||||
try test__ctzsi2(0x0000006D, 0);
|
||||
try test__ctzsi2(0x0000006E, 1);
|
||||
try test__ctzsi2(0x0000006F, 0);
|
||||
try test__ctzsi2(0x00000070, 4);
|
||||
try test__ctzsi2(0x00000071, 0);
|
||||
try test__ctzsi2(0x00000072, 1);
|
||||
try test__ctzsi2(0x00000073, 0);
|
||||
try test__ctzsi2(0x00000074, 2);
|
||||
try test__ctzsi2(0x00000075, 0);
|
||||
try test__ctzsi2(0x00000076, 1);
|
||||
try test__ctzsi2(0x00000077, 0);
|
||||
try test__ctzsi2(0x00000078, 3);
|
||||
try test__ctzsi2(0x00000079, 0);
|
||||
try test__ctzsi2(0x0000007A, 1);
|
||||
try test__ctzsi2(0x0000007B, 0);
|
||||
try test__ctzsi2(0x0000007C, 2);
|
||||
try test__ctzsi2(0x0000007D, 0);
|
||||
try test__ctzsi2(0x0000007E, 1);
|
||||
try test__ctzsi2(0x0000007F, 0);
|
||||
try test__ctzsi2(0x00000080, 7);
|
||||
try test__ctzsi2(0x00000081, 0);
|
||||
try test__ctzsi2(0x00000082, 1);
|
||||
try test__ctzsi2(0x00000083, 0);
|
||||
try test__ctzsi2(0x00000084, 2);
|
||||
try test__ctzsi2(0x00000085, 0);
|
||||
try test__ctzsi2(0x00000086, 1);
|
||||
try test__ctzsi2(0x00000087, 0);
|
||||
try test__ctzsi2(0x00000088, 3);
|
||||
try test__ctzsi2(0x00000089, 0);
|
||||
try test__ctzsi2(0x0000008A, 1);
|
||||
try test__ctzsi2(0x0000008B, 0);
|
||||
try test__ctzsi2(0x0000008C, 2);
|
||||
try test__ctzsi2(0x0000008D, 0);
|
||||
try test__ctzsi2(0x0000008E, 1);
|
||||
try test__ctzsi2(0x0000008F, 0);
|
||||
try test__ctzsi2(0x00000090, 4);
|
||||
try test__ctzsi2(0x00000091, 0);
|
||||
try test__ctzsi2(0x00000092, 1);
|
||||
try test__ctzsi2(0x00000093, 0);
|
||||
try test__ctzsi2(0x00000094, 2);
|
||||
try test__ctzsi2(0x00000095, 0);
|
||||
try test__ctzsi2(0x00000096, 1);
|
||||
try test__ctzsi2(0x00000097, 0);
|
||||
try test__ctzsi2(0x00000098, 3);
|
||||
try test__ctzsi2(0x00000099, 0);
|
||||
try test__ctzsi2(0x0000009A, 1);
|
||||
try test__ctzsi2(0x0000009B, 0);
|
||||
try test__ctzsi2(0x0000009C, 2);
|
||||
try test__ctzsi2(0x0000009D, 0);
|
||||
try test__ctzsi2(0x0000009E, 1);
|
||||
try test__ctzsi2(0x0000009F, 0);
|
||||
try test__ctzsi2(0x000000A0, 5);
|
||||
try test__ctzsi2(0x000000A1, 0);
|
||||
try test__ctzsi2(0x000000A2, 1);
|
||||
try test__ctzsi2(0x000000A3, 0);
|
||||
try test__ctzsi2(0x000000A4, 2);
|
||||
try test__ctzsi2(0x000000A5, 0);
|
||||
try test__ctzsi2(0x000000A6, 1);
|
||||
try test__ctzsi2(0x000000A7, 0);
|
||||
try test__ctzsi2(0x000000A8, 3);
|
||||
try test__ctzsi2(0x000000A9, 0);
|
||||
try test__ctzsi2(0x000000AA, 1);
|
||||
try test__ctzsi2(0x000000AB, 0);
|
||||
try test__ctzsi2(0x000000AC, 2);
|
||||
try test__ctzsi2(0x000000AD, 0);
|
||||
try test__ctzsi2(0x000000AE, 1);
|
||||
try test__ctzsi2(0x000000AF, 0);
|
||||
try test__ctzsi2(0x000000B0, 4);
|
||||
try test__ctzsi2(0x000000B1, 0);
|
||||
try test__ctzsi2(0x000000B2, 1);
|
||||
try test__ctzsi2(0x000000B3, 0);
|
||||
try test__ctzsi2(0x000000B4, 2);
|
||||
try test__ctzsi2(0x000000B5, 0);
|
||||
try test__ctzsi2(0x000000B6, 1);
|
||||
try test__ctzsi2(0x000000B7, 0);
|
||||
try test__ctzsi2(0x000000B8, 3);
|
||||
try test__ctzsi2(0x000000B9, 0);
|
||||
try test__ctzsi2(0x000000BA, 1);
|
||||
try test__ctzsi2(0x000000BB, 0);
|
||||
try test__ctzsi2(0x000000BC, 2);
|
||||
try test__ctzsi2(0x000000BD, 0);
|
||||
try test__ctzsi2(0x000000BE, 1);
|
||||
try test__ctzsi2(0x000000BF, 0);
|
||||
try test__ctzsi2(0x000000C0, 6);
|
||||
try test__ctzsi2(0x000000C1, 0);
|
||||
try test__ctzsi2(0x000000C2, 1);
|
||||
try test__ctzsi2(0x000000C3, 0);
|
||||
try test__ctzsi2(0x000000C4, 2);
|
||||
try test__ctzsi2(0x000000C5, 0);
|
||||
try test__ctzsi2(0x000000C6, 1);
|
||||
try test__ctzsi2(0x000000C7, 0);
|
||||
try test__ctzsi2(0x000000C8, 3);
|
||||
try test__ctzsi2(0x000000C9, 0);
|
||||
try test__ctzsi2(0x000000CA, 1);
|
||||
try test__ctzsi2(0x000000CB, 0);
|
||||
try test__ctzsi2(0x000000CC, 2);
|
||||
try test__ctzsi2(0x000000CD, 0);
|
||||
try test__ctzsi2(0x000000CE, 1);
|
||||
try test__ctzsi2(0x000000CF, 0);
|
||||
try test__ctzsi2(0x000000D0, 4);
|
||||
try test__ctzsi2(0x000000D1, 0);
|
||||
try test__ctzsi2(0x000000D2, 1);
|
||||
try test__ctzsi2(0x000000D3, 0);
|
||||
try test__ctzsi2(0x000000D4, 2);
|
||||
try test__ctzsi2(0x000000D5, 0);
|
||||
try test__ctzsi2(0x000000D6, 1);
|
||||
try test__ctzsi2(0x000000D7, 0);
|
||||
try test__ctzsi2(0x000000D8, 3);
|
||||
try test__ctzsi2(0x000000D9, 0);
|
||||
try test__ctzsi2(0x000000DA, 1);
|
||||
try test__ctzsi2(0x000000DB, 0);
|
||||
try test__ctzsi2(0x000000DC, 2);
|
||||
try test__ctzsi2(0x000000DD, 0);
|
||||
try test__ctzsi2(0x000000DE, 1);
|
||||
try test__ctzsi2(0x000000DF, 0);
|
||||
try test__ctzsi2(0x000000E0, 5);
|
||||
try test__ctzsi2(0x000000E1, 0);
|
||||
try test__ctzsi2(0x000000E2, 1);
|
||||
try test__ctzsi2(0x000000E3, 0);
|
||||
try test__ctzsi2(0x000000E4, 2);
|
||||
try test__ctzsi2(0x000000E5, 0);
|
||||
try test__ctzsi2(0x000000E6, 1);
|
||||
try test__ctzsi2(0x000000E7, 0);
|
||||
try test__ctzsi2(0x000000E8, 3);
|
||||
try test__ctzsi2(0x000000E9, 0);
|
||||
try test__ctzsi2(0x000000EA, 1);
|
||||
try test__ctzsi2(0x000000EB, 0);
|
||||
try test__ctzsi2(0x000000EC, 2);
|
||||
try test__ctzsi2(0x000000ED, 0);
|
||||
try test__ctzsi2(0x000000EE, 1);
|
||||
try test__ctzsi2(0x000000EF, 0);
|
||||
try test__ctzsi2(0x000000F0, 4);
|
||||
try test__ctzsi2(0x000000F1, 0);
|
||||
try test__ctzsi2(0x000000F2, 1);
|
||||
try test__ctzsi2(0x000000F3, 0);
|
||||
try test__ctzsi2(0x000000F4, 2);
|
||||
try test__ctzsi2(0x000000F5, 0);
|
||||
try test__ctzsi2(0x000000F6, 1);
|
||||
try test__ctzsi2(0x000000F7, 0);
|
||||
try test__ctzsi2(0x000000F8, 3);
|
||||
try test__ctzsi2(0x000000F9, 0);
|
||||
try test__ctzsi2(0x000000FA, 1);
|
||||
try test__ctzsi2(0x000000FB, 0);
|
||||
try test__ctzsi2(0x000000FC, 2);
|
||||
try test__ctzsi2(0x000000FD, 0);
|
||||
try test__ctzsi2(0x000000FE, 1);
|
||||
try test__ctzsi2(0x000000FF, 0);
|
||||
|
||||
try test__ctzsi2(0x00000000, 32);
|
||||
try test__ctzsi2(0x80000000, 31);
|
||||
try test__ctzsi2(0x40000000, 30);
|
||||
try test__ctzsi2(0x20000000, 29);
|
||||
try test__ctzsi2(0x10000000, 28);
|
||||
try test__ctzsi2(0x08000000, 27);
|
||||
try test__ctzsi2(0x04000000, 26);
|
||||
try test__ctzsi2(0x02000000, 25);
|
||||
try test__ctzsi2(0x01000000, 24);
|
||||
try test__ctzsi2(0x00800000, 23);
|
||||
try test__ctzsi2(0x00400000, 22);
|
||||
try test__ctzsi2(0x00200000, 21);
|
||||
try test__ctzsi2(0x00100000, 20);
|
||||
try test__ctzsi2(0x00080000, 19);
|
||||
try test__ctzsi2(0x00040000, 18);
|
||||
try test__ctzsi2(0x00020000, 17);
|
||||
try test__ctzsi2(0x00010000, 16);
|
||||
try test__ctzsi2(0x00008000, 15);
|
||||
try test__ctzsi2(0x00004000, 14);
|
||||
try test__ctzsi2(0x00002000, 13);
|
||||
try test__ctzsi2(0x00001000, 12);
|
||||
try test__ctzsi2(0x00000800, 11);
|
||||
try test__ctzsi2(0x00000400, 10);
|
||||
try test__ctzsi2(0x00000200, 9);
|
||||
try test__ctzsi2(0x00000100, 8);
|
||||
}
|
||||
@@ -1,391 +0,0 @@
|
||||
const ctz = @import("count0bits.zig");
|
||||
const testing = @import("std").testing;
|
||||
|
||||
fn test__ctzti2(a: u128, expected: i32) !void {
|
||||
var x = @bitCast(i128, a);
|
||||
var result = ctz.__ctzti2(x);
|
||||
try testing.expectEqual(expected, result);
|
||||
}
|
||||
|
||||
test "ctzti2" {
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000001, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000002, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000003, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000004, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000005, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000006, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000007, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000008, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000009, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000000A, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000000B, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000000C, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000000D, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000000E, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000000F, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000010, 4);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000011, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000012, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000013, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000014, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000015, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000016, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000017, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000018, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000019, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000001A, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000001B, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000001C, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000001D, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000001E, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000001F, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000020, 5);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000021, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000022, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000023, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000024, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000025, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000026, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000027, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000028, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000029, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000002A, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000002B, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000002C, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000002D, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000002E, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000002F, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000030, 4);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000031, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000032, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000033, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000034, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000035, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000036, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000037, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000038, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000039, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000003A, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000003B, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000003C, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000003D, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000003E, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000003F, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000040, 6);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000041, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000042, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000043, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000044, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000045, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000046, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000047, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000048, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000049, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000004A, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000004B, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000004C, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000004D, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000004E, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000004F, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000050, 4);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000051, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000052, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000053, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000054, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000055, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000056, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000057, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000058, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000059, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000005A, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000005B, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000005C, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000005D, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000005E, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000005F, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000060, 5);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000061, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000062, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000063, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000064, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000065, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000066, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000067, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000068, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000069, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000006A, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000006B, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000006C, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000006D, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000006E, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000006F, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000070, 4);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000071, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000072, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000073, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000074, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000075, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000076, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000077, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000078, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000079, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000007A, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000007B, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000007C, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000007D, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000007E, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000007F, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000080, 7);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000081, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000082, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000083, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000084, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000085, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000086, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000087, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000088, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000089, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000008A, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000008B, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000008C, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000008D, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000008E, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000008F, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000090, 4);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000091, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000092, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000093, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000094, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000095, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000096, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000097, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000098, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000099, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000009A, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000009B, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000009C, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000009D, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000009E, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_0000009F, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000A0, 5);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000A1, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000A2, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000A3, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000A4, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000A5, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000A6, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000A7, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000A8, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000A9, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000AA, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000AB, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000AC, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000AD, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000AE, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000AF, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000B0, 4);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000B1, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000B2, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000B3, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000B4, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000B5, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000B6, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000B7, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000B8, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000B9, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000BA, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000BB, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000BC, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000BD, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000BE, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000BF, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000C0, 6);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000C1, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000C2, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000C3, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000C4, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000C5, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000C6, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000C7, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000C8, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000C9, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000CA, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000CB, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000CC, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000CD, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000CE, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000CF, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000D0, 4);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000D1, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000D2, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000D3, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000D4, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000D5, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000D6, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000D7, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000D8, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000D9, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000DA, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000DB, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000DC, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000DD, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000DE, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000DF, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000E0, 5);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000E1, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000E2, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000E3, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000E4, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000E5, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000E6, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000E7, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000E8, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000E9, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000EA, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000EB, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000EC, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000ED, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000EE, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000EF, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000F0, 4);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000F1, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000F2, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000F3, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000F4, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000F5, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000F6, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000F7, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000F8, 3);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000F9, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000FA, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000FB, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000FC, 2);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000FD, 0);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000FE, 1);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_000000FF, 0);
|
||||
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000000, 128);
|
||||
try test__ctzti2(0x80000000_00000000_00000000_00000000, 127);
|
||||
try test__ctzti2(0x40000000_00000000_00000000_00000000, 126);
|
||||
try test__ctzti2(0x20000000_00000000_00000000_00000000, 125);
|
||||
try test__ctzti2(0x10000000_00000000_00000000_00000000, 124);
|
||||
try test__ctzti2(0x08000000_00000000_00000000_00000000, 123);
|
||||
try test__ctzti2(0x04000000_00000000_00000000_00000000, 122);
|
||||
try test__ctzti2(0x02000000_00000000_00000000_00000000, 121);
|
||||
try test__ctzti2(0x01000000_00000000_00000000_00000000, 120);
|
||||
try test__ctzti2(0x00800000_00000000_00000000_00000000, 119);
|
||||
try test__ctzti2(0x00400000_00000000_00000000_00000000, 118);
|
||||
try test__ctzti2(0x00200000_00000000_00000000_00000000, 117);
|
||||
try test__ctzti2(0x00100000_00000000_00000000_00000000, 116);
|
||||
try test__ctzti2(0x00080000_00000000_00000000_00000000, 115);
|
||||
try test__ctzti2(0x00040000_00000000_00000000_00000000, 114);
|
||||
try test__ctzti2(0x00020000_00000000_00000000_00000000, 113);
|
||||
try test__ctzti2(0x00010000_00000000_00000000_00000000, 112);
|
||||
try test__ctzti2(0x00008000_00000000_00000000_00000000, 111);
|
||||
try test__ctzti2(0x00004000_00000000_00000000_00000000, 110);
|
||||
try test__ctzti2(0x00002000_00000000_00000000_00000000, 109);
|
||||
try test__ctzti2(0x00001000_00000000_00000000_00000000, 108);
|
||||
try test__ctzti2(0x00000800_00000000_00000000_00000000, 107);
|
||||
try test__ctzti2(0x00000400_00000000_00000000_00000000, 106);
|
||||
try test__ctzti2(0x00000200_00000000_00000000_00000000, 105);
|
||||
try test__ctzti2(0x00000100_00000000_00000000_00000000, 104);
|
||||
try test__ctzti2(0x00000080_00000000_00000000_00000000, 103);
|
||||
try test__ctzti2(0x00000040_00000000_00000000_00000000, 102);
|
||||
try test__ctzti2(0x00000020_00000000_00000000_00000000, 101);
|
||||
try test__ctzti2(0x00000010_00000000_00000000_00000000, 100);
|
||||
try test__ctzti2(0x00000008_00000000_00000000_00000000, 99);
|
||||
try test__ctzti2(0x00000004_00000000_00000000_00000000, 98);
|
||||
try test__ctzti2(0x00000002_00000000_00000000_00000000, 97);
|
||||
try test__ctzti2(0x00000001_00000000_00000000_00000000, 96);
|
||||
|
||||
try test__ctzti2(0x00000000_80000000_00000000_00000000, 95);
|
||||
try test__ctzti2(0x00000000_40000000_00000000_00000000, 94);
|
||||
try test__ctzti2(0x00000000_20000000_00000000_00000000, 93);
|
||||
try test__ctzti2(0x00000000_10000000_00000000_00000000, 92);
|
||||
try test__ctzti2(0x00000000_08000000_00000000_00000000, 91);
|
||||
try test__ctzti2(0x00000000_04000000_00000000_00000000, 90);
|
||||
try test__ctzti2(0x00000000_02000000_00000000_00000000, 89);
|
||||
try test__ctzti2(0x00000000_01000000_00000000_00000000, 88);
|
||||
try test__ctzti2(0x00000000_00800000_00000000_00000000, 87);
|
||||
try test__ctzti2(0x00000000_00400000_00000000_00000000, 86);
|
||||
try test__ctzti2(0x00000000_00200000_00000000_00000000, 85);
|
||||
try test__ctzti2(0x00000000_00100000_00000000_00000000, 84);
|
||||
try test__ctzti2(0x00000000_00080000_00000000_00000000, 83);
|
||||
try test__ctzti2(0x00000000_00040000_00000000_00000000, 82);
|
||||
try test__ctzti2(0x00000000_00020000_00000000_00000000, 81);
|
||||
try test__ctzti2(0x00000000_00010000_00000000_00000000, 80);
|
||||
try test__ctzti2(0x00000000_00008000_00000000_00000000, 79);
|
||||
try test__ctzti2(0x00000000_00004000_00000000_00000000, 78);
|
||||
try test__ctzti2(0x00000000_00002000_00000000_00000000, 77);
|
||||
try test__ctzti2(0x00000000_00001000_00000000_00000000, 76);
|
||||
try test__ctzti2(0x00000000_00000800_00000000_00000000, 75);
|
||||
try test__ctzti2(0x00000000_00000400_00000000_00000000, 74);
|
||||
try test__ctzti2(0x00000000_00000200_00000000_00000000, 73);
|
||||
try test__ctzti2(0x00000000_00000100_00000000_00000000, 72);
|
||||
try test__ctzti2(0x00000000_00000080_00000000_00000000, 71);
|
||||
try test__ctzti2(0x00000000_00000040_00000000_00000000, 70);
|
||||
try test__ctzti2(0x00000000_00000020_00000000_00000000, 69);
|
||||
try test__ctzti2(0x00000000_00000010_00000000_00000000, 68);
|
||||
try test__ctzti2(0x00000000_00000008_00000000_00000000, 67);
|
||||
try test__ctzti2(0x00000000_00000004_00000000_00000000, 66);
|
||||
try test__ctzti2(0x00000000_00000002_00000000_00000000, 65);
|
||||
try test__ctzti2(0x00000000_00000001_00000000_00000000, 64);
|
||||
|
||||
try test__ctzti2(0x00000000_00000000_80000000_00000000, 63);
|
||||
try test__ctzti2(0x00000000_00000000_40000000_00000000, 62);
|
||||
try test__ctzti2(0x00000000_00000000_20000000_00000000, 61);
|
||||
try test__ctzti2(0x00000000_00000000_10000000_00000000, 60);
|
||||
try test__ctzti2(0x00000000_00000000_08000000_00000000, 59);
|
||||
try test__ctzti2(0x00000000_00000000_04000000_00000000, 58);
|
||||
try test__ctzti2(0x00000000_00000000_02000000_00000000, 57);
|
||||
try test__ctzti2(0x00000000_00000000_01000000_00000000, 56);
|
||||
try test__ctzti2(0x00000000_00000000_00800000_00000000, 55);
|
||||
try test__ctzti2(0x00000000_00000000_00400000_00000000, 54);
|
||||
try test__ctzti2(0x00000000_00000000_00200000_00000000, 53);
|
||||
try test__ctzti2(0x00000000_00000000_00100000_00000000, 52);
|
||||
try test__ctzti2(0x00000000_00000000_00080000_00000000, 51);
|
||||
try test__ctzti2(0x00000000_00000000_00040000_00000000, 50);
|
||||
try test__ctzti2(0x00000000_00000000_00020000_00000000, 49);
|
||||
try test__ctzti2(0x00000000_00000000_00010000_00000000, 48);
|
||||
try test__ctzti2(0x00000000_00000000_00008000_00000000, 47);
|
||||
try test__ctzti2(0x00000000_00000000_00004000_00000000, 46);
|
||||
try test__ctzti2(0x00000000_00000000_00002000_00000000, 45);
|
||||
try test__ctzti2(0x00000000_00000000_00001000_00000000, 44);
|
||||
try test__ctzti2(0x00000000_00000000_00000800_00000000, 43);
|
||||
try test__ctzti2(0x00000000_00000000_00000400_00000000, 42);
|
||||
try test__ctzti2(0x00000000_00000000_00000200_00000000, 41);
|
||||
try test__ctzti2(0x00000000_00000000_00000100_00000000, 40);
|
||||
try test__ctzti2(0x00000000_00000000_00000080_00000000, 39);
|
||||
try test__ctzti2(0x00000000_00000000_00000040_00000000, 38);
|
||||
try test__ctzti2(0x00000000_00000000_00000020_00000000, 37);
|
||||
try test__ctzti2(0x00000000_00000000_00000010_00000000, 36);
|
||||
try test__ctzti2(0x00000000_00000000_00000008_00000000, 35);
|
||||
try test__ctzti2(0x00000000_00000000_00000004_00000000, 34);
|
||||
try test__ctzti2(0x00000000_00000000_00000002_00000000, 33);
|
||||
try test__ctzti2(0x00000000_00000000_00000001_00000000, 32);
|
||||
|
||||
try test__ctzti2(0x00000000_00000000_00000000_80000000, 31);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_40000000, 30);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_20000000, 29);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_10000000, 28);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_08000000, 27);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_04000000, 26);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_02000000, 25);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_01000000, 24);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00800000, 23);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00400000, 22);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00200000, 21);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00100000, 20);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00080000, 19);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00040000, 18);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00020000, 17);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00010000, 16);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00008000, 15);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00004000, 14);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00002000, 13);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00001000, 12);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000800, 11);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000400, 10);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000200, 9);
|
||||
try test__ctzti2(0x00000000_00000000_00000000_00000100, 8);
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
const std = @import("std");
|
||||
const isNan = std.math.isNan;
|
||||
const isInf = std.math.isInf;
|
||||
const scalbn = std.math.scalbn;
|
||||
const ilogb = std.math.ilogb;
|
||||
const max = std.math.max;
|
||||
const fabs = std.math.fabs;
|
||||
const maxInt = std.math.maxInt;
|
||||
const minInt = std.math.minInt;
|
||||
const isFinite = std.math.isFinite;
|
||||
const copysign = std.math.copysign;
|
||||
const Complex = @import("mulc3.zig").Complex;
|
||||
|
||||
/// Implementation based on Annex G of C17 Standard (N2176)
|
||||
pub inline fn divc3(comptime T: type, a: T, b: T, c_in: T, d_in: T) Complex(T) {
|
||||
var c = c_in;
|
||||
var d = d_in;
|
||||
|
||||
// logbw used to prevent under/over-flow
|
||||
const logbw = ilogb(max(fabs(c), fabs(d)));
|
||||
const logbw_finite = logbw != maxInt(i32) and logbw != minInt(i32);
|
||||
const ilogbw = if (logbw_finite) b: {
|
||||
c = scalbn(c, -logbw);
|
||||
d = scalbn(d, -logbw);
|
||||
break :b logbw;
|
||||
} else 0;
|
||||
const denom = c * c + d * d;
|
||||
const result = Complex(T){
|
||||
.real = scalbn((a * c + b * d) / denom, -ilogbw),
|
||||
.imag = scalbn((b * c - a * d) / denom, -ilogbw),
|
||||
};
|
||||
|
||||
// Recover infinities and zeros that computed as NaN+iNaN;
|
||||
// the only cases are non-zero/zero, infinite/finite, and finite/infinite, ...
|
||||
if (isNan(result.real) and isNan(result.imag)) {
|
||||
const zero: T = 0.0;
|
||||
const one: T = 1.0;
|
||||
|
||||
if ((denom == 0.0) and (!isNan(a) or !isNan(b))) {
|
||||
return .{
|
||||
.real = copysign(std.math.inf(T), c) * a,
|
||||
.imag = copysign(std.math.inf(T), c) * b,
|
||||
};
|
||||
} else if ((isInf(a) or isInf(b)) and isFinite(c) and isFinite(d)) {
|
||||
const boxed_a = copysign(if (isInf(a)) one else zero, a);
|
||||
const boxed_b = copysign(if (isInf(b)) one else zero, b);
|
||||
return .{
|
||||
.real = std.math.inf(T) * (boxed_a * c - boxed_b * d),
|
||||
.imag = std.math.inf(T) * (boxed_b * c - boxed_a * d),
|
||||
};
|
||||
} else if (logbw == maxInt(i32) and isFinite(a) and isFinite(b)) {
|
||||
const boxed_c = copysign(if (isInf(c)) one else zero, c);
|
||||
const boxed_d = copysign(if (isInf(d)) one else zero, d);
|
||||
return .{
|
||||
.real = 0.0 * (a * boxed_c + b * boxed_d),
|
||||
.imag = 0.0 * (b * boxed_c - a * boxed_d),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
const std = @import("std");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
const Complex = @import("./mulc3.zig").Complex;
|
||||
const __divhc3 = @import("./divhc3.zig").__divhc3;
|
||||
const __divsc3 = @import("./divsc3.zig").__divsc3;
|
||||
const __divdc3 = @import("./divdc3.zig").__divdc3;
|
||||
const __divxc3 = @import("./divxc3.zig").__divxc3;
|
||||
const __divtc3 = @import("./divtc3.zig").__divtc3;
|
||||
|
||||
test {
|
||||
try testDiv(f16, __divhc3);
|
||||
try testDiv(f32, __divsc3);
|
||||
try testDiv(f64, __divdc3);
|
||||
try testDiv(f80, __divxc3);
|
||||
try testDiv(f128, __divtc3);
|
||||
}
|
||||
|
||||
fn testDiv(comptime T: type, comptime f: fn (T, T, T, T) callconv(.C) Complex(T)) !void {
|
||||
{
|
||||
var a: T = 1.0;
|
||||
var b: T = 0.0;
|
||||
var c: T = -1.0;
|
||||
var d: T = 0.0;
|
||||
|
||||
const result = f(a, b, c, d);
|
||||
try expect(result.real == -1.0);
|
||||
try expect(result.imag == 0.0);
|
||||
}
|
||||
{
|
||||
var a: T = 1.0;
|
||||
var b: T = 0.0;
|
||||
var c: T = -4.0;
|
||||
var d: T = 0.0;
|
||||
|
||||
const result = f(a, b, c, d);
|
||||
try expect(result.real == -0.25);
|
||||
try expect(result.imag == 0.0);
|
||||
}
|
||||
{
|
||||
// if the first operand is an infinity and the second operand is a finite number, then the
|
||||
// result of the / operator is an infinity;
|
||||
var a: T = -math.inf(T);
|
||||
var b: T = 0.0;
|
||||
var c: T = -4.0;
|
||||
var d: T = 1.0;
|
||||
|
||||
const result = f(a, b, c, d);
|
||||
try expect(result.real == math.inf(T));
|
||||
try expect(result.imag == math.inf(T));
|
||||
}
|
||||
{
|
||||
// if the first operand is a finite number and the second operand is an infinity, then the
|
||||
// result of the / operator is a zero;
|
||||
var a: T = 17.2;
|
||||
var b: T = 0.0;
|
||||
var c: T = -math.inf(T);
|
||||
var d: T = 0.0;
|
||||
|
||||
const result = f(a, b, c, d);
|
||||
try expect(result.real == -0.0);
|
||||
try expect(result.imag == 0.0);
|
||||
}
|
||||
{
|
||||
// if the first operand is a nonzero finite number or an infinity and the second operand is
|
||||
// a zero, then the result of the / operator is an infinity
|
||||
var a: T = 1.1;
|
||||
var b: T = 0.1;
|
||||
var c: T = 0.0;
|
||||
var d: T = 0.0;
|
||||
|
||||
const result = f(a, b, c, d);
|
||||
try expect(result.real == math.inf(T));
|
||||
try expect(result.imag == math.inf(T));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
const common = @import("./common.zig");
|
||||
const divc3 = @import("./divc3.zig");
|
||||
const Complex = @import("./mulc3.zig").Complex;
|
||||
|
||||
comptime {
|
||||
@export(__divdc3, .{ .name = "__divdc3", .linkage = common.linkage });
|
||||
}
|
||||
|
||||
pub fn __divdc3(a: f64, b: f64, c: f64, d: f64) callconv(.C) Complex(f64) {
|
||||
return divc3.divc3(f64, a, b, c, d);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user