forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#89167 - workingjubilee:use-simd, r=MarkSimula…
…crum pub use core::simd; A portable abstraction over SIMD has been a major pursuit in recent years for several programming languages. In Rust, `std::arch` offers explicit SIMD acceleration via compiler intrinsics, but it does so at the cost of having to individually maintain each and every single such API, and is almost completely `unsafe` to use. `core::simd` offers safe abstractions that are resolved to the appropriate SIMD instructions by LLVM during compilation, including scalar instructions if that is all that is available. `core::simd` is enabled by the `#![portable_simd]` nightly feature tracked in rust-lang#86656 and is introduced here by pulling in the https://github.com/rust-lang/portable-simd repository as a subtree. We built the repository out-of-tree to allow faster compilation and a stochastic test suite backed by the proptest crate to verify that different targets, features, and optimizations produce the same result, so that using this library does not introduce any surprises. As these tests are technically non-deterministic, and thus can introduce overly interesting Heisenbugs if included in the rustc CI, they are visible in the commit history of the subtree but do nothing here. Some tests **are** introduced via the documentation, but these use deterministic asserts. There are multiple unsolved problems with the library at the current moment, including a want for better documentation, technical issues with LLVM scalarizing and lowering to libm, room for improvement for the APIs, and so far I have not added the necessary plumbing for allowing the more experimental or libm-dependent APIs to be used. However, I thought it would be prudent to open this for review in its current condition, as it is both usable and it is likely I am going to learn something else needs to be fixed when bors tries this out. The major types are - `core::simd::Simd<T, N>` - `core::simd::Mask<T, N>` There is also the `LaneCount` struct, which, together with the SimdElement and SupportedLaneCount traits, limit the implementation's maximum support to vectors we know will actually compile and provide supporting logic for bitmasks. I'm hoping to simplify at least some of these out of the way as the compiler and library evolve.
- Loading branch information
Showing
89 changed files
with
7,631 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use core::simd::f32x4; | ||
|
||
#[test] | ||
fn testing() { | ||
let x = f32x4::from_array([1.0, 1.0, 1.0, 1.0]); | ||
let y = -x; | ||
|
||
let h = x * 0.5; | ||
|
||
let r = y.abs(); | ||
assert_eq!(x, r); | ||
assert_eq!(h, f32x4::splat(0.5)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
name: Blank Issue | ||
about: Create a blank issue. | ||
--- |
50 changes: 50 additions & 0 deletions
50
library/portable-simd/.github/ISSUE_TEMPLATE/bug_report.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
name: Bug Report | ||
about: Create a bug report for Rust. | ||
labels: C-bug | ||
--- | ||
<!-- | ||
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug, | ||
along with any information you feel relevant to replicating the bug. | ||
--> | ||
|
||
I tried this code: | ||
|
||
```rust | ||
<code> | ||
``` | ||
|
||
I expected to see this happen: *explanation* | ||
|
||
Instead, this happened: *explanation* | ||
|
||
### Meta | ||
|
||
`rustc --version --verbose`: | ||
``` | ||
<version> | ||
``` | ||
|
||
|
||
`crate version in Cargo.toml`: | ||
```toml | ||
[dependencies] | ||
stdsimd = | ||
``` | ||
<!-- If this specifies the repo at HEAD, please include the latest commit. --> | ||
|
||
|
||
<!-- | ||
If a backtrace is available, please include a backtrace in the code block by | ||
setting `RUST_BACKTRACE=1` in your environment. e.g. | ||
`RUST_BACKTRACE=1 cargo build`. | ||
--> | ||
<details><summary>Backtrace</summary> | ||
<p> | ||
|
||
``` | ||
<backtrace> | ||
``` | ||
|
||
</p> | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This only controls whether a tiny, hard-to-find "open a blank issue" link appears at the end of | ||
# the template list. | ||
blank_issues_enabled: true | ||
contact_links: | ||
- name: Intrinsic Support | ||
url: https://github.com/rust-lang/stdarch/issues | ||
about: Please direct issues about Rust's support for vendor intrinsics to core::arch | ||
- name: Internal Compiler Error | ||
url: https://github.com/rust-lang/rust/issues | ||
about: Please report ICEs to the rustc repository |
14 changes: 14 additions & 0 deletions
14
library/portable-simd/.github/ISSUE_TEMPLATE/feature_request.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
name: Feature Request | ||
about: Request an addition to the core::simd API | ||
labels: C-feature-request | ||
--- | ||
<!-- | ||
Hello! | ||
We are very interested in any feature requests you may have. | ||
However, please be aware that core::simd exists to address concerns with creating a portable SIMD API for Rust. | ||
Requests for extensions to compiler features, such as `target_feature`, binary versioning for SIMD APIs, or | ||
improving specific compilation issues in general should be discussed at https://internals.rust-lang.org/ | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Hello, welcome to `std::simd`! | ||
|
||
It seems this pull request template checklist was created while a lot of vector math ops were being implemented, and only really applies to ops. Feel free to delete everything here if it's not applicable, or ask for help if you're not sure what it means! | ||
|
||
For a given vector math operation on TxN, please add tests for interactions with: | ||
- [ ] `T::MAX` | ||
- [ ] `T::MIN` | ||
- [ ] -1 | ||
- [ ] 1 | ||
- [ ] 0 | ||
|
||
|
||
For a given vector math operation on TxN where T is a float, please add tests for test interactions with: | ||
- [ ] a really large number, larger than the mantissa | ||
- [ ] a really small "subnormal" number | ||
- [ ] NaN | ||
- [ ] Infinity | ||
- [ ] Negative Infinity |
Oops, something went wrong.