Skip to content

Commit 340491b

Browse files
authored
Merge branch 'rust-lang:master' into dotprodexample
2 parents fd131cd + 0711e11 commit 340491b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+5105
-3022
lines changed

.github/workflows/ci.yml

Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,53 @@ env:
1111
RUSTUP_MAX_RETRIES: 10
1212

1313
jobs:
14+
rustfmt:
15+
name: "rustfmt"
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Setup Rust
21+
run: |
22+
rustup update nightly --no-self-update
23+
rustup default nightly
24+
rustup component add rustfmt
25+
- name: Run rustfmt
26+
run: cargo fmt --all -- --check
27+
28+
clippy:
29+
name: "clippy on ${{ matrix.target }}"
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
target:
35+
# We shouldn't really have any OS-specific code, so think of this as a list of architectures
36+
- x86_64-unknown-linux-gnu
37+
- i686-unknown-linux-gnu
38+
- i586-unknown-linux-gnu
39+
- aarch64-unknown-linux-gnu
40+
- armv7-unknown-linux-gnueabihf
41+
- mips-unknown-linux-gnu
42+
- mips64-unknown-linux-gnuabi64
43+
- powerpc-unknown-linux-gnu
44+
- powerpc64-unknown-linux-gnu
45+
- riscv64gc-unknown-linux-gnu
46+
- s390x-unknown-linux-gnu
47+
- sparc64-unknown-linux-gnu
48+
- wasm32-unknown-unknown
49+
50+
steps:
51+
- uses: actions/checkout@v2
52+
- name: Setup Rust
53+
run: |
54+
rustup update nightly --no-self-update
55+
rustup default nightly
56+
rustup target add ${{ matrix.target }}
57+
rustup component add clippy
58+
- name: Run Clippy
59+
run: cargo clippy --all-targets --target ${{ matrix.target }}
60+
1461
x86-tests:
1562
name: "${{ matrix.target_feature }} on ${{ matrix.target }}"
1663
runs-on: ${{ matrix.os }}
@@ -47,8 +94,7 @@ jobs:
4794
- { target: i586-pc-windows-msvc, target_feature: +sse2, os: windows-latest }
4895

4996
# Annoyingly, the x86_64-unknown-linux-gnu runner *almost* always has
50-
# avx512vl, but occasionally doesn't. As a result, we still run that
51-
# one under travis.
97+
# avx512vl, but occasionally doesn't. Maybe one day we can enable it.
5298

5399
steps:
54100
- uses: actions/checkout@v2
@@ -63,12 +109,12 @@ jobs:
63109
run: |
64110
case "${{ matrix.target_feature }}" in
65111
default)
66-
;;
112+
echo "RUSTFLAGS=-Dwarnings" >> $GITHUB_ENV;;
67113
native)
68-
echo "RUSTFLAGS=-Ctarget-cpu=native" >> $GITHUB_ENV
114+
echo "RUSTFLAGS=-Dwarnings -Ctarget-cpu=native" >> $GITHUB_ENV
69115
;;
70116
*)
71-
echo "RUSTFLAGS=-Ctarget-feature=${{ matrix.target_feature }}" >> $GITHUB_ENV
117+
echo "RUSTFLAGS=-Dwarnings -Ctarget-feature=${{ matrix.target_feature }}" >> $GITHUB_ENV
72118
;;
73119
esac
74120
@@ -94,6 +140,31 @@ jobs:
94140
- name: Test (release)
95141
run: cargo test --verbose --target=${{ matrix.target }} --release
96142

143+
wasm-tests:
144+
name: "wasm (firefox, ${{ matrix.name }})"
145+
runs-on: ubuntu-latest
146+
strategy:
147+
matrix:
148+
include:
149+
- { name: default, RUSTFLAGS: "" }
150+
- { name: simd128, RUSTFLAGS: "-C target-feature=+simd128" }
151+
steps:
152+
- uses: actions/checkout@v2
153+
- name: Setup Rust
154+
run: |
155+
rustup update nightly --no-self-update
156+
rustup default nightly
157+
- name: Install wasm-pack
158+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
159+
- name: Test (debug)
160+
run: wasm-pack test --firefox --headless crates/core_simd
161+
env:
162+
RUSTFLAGS: ${{ matrix.rustflags }}
163+
- name: Test (release)
164+
run: wasm-pack test --firefox --headless crates/core_simd --release
165+
env:
166+
RUSTFLAGS: ${{ matrix.rustflags }}
167+
97168
cross-tests:
98169
name: "${{ matrix.target }} (via cross)"
99170
runs-on: ubuntu-latest
@@ -116,12 +187,19 @@ jobs:
116187
# 32-bit arm has a few idiosyncracies like having subnormal flushing
117188
# to zero on by default. Ideally we'd set
118189
- armv7-unknown-linux-gnueabihf
190+
- aarch64-unknown-linux-gnu
119191
# Note: The issue above means neither of these mips targets will use
120192
# MSA (mips simd) but MIPS uses a nonstandard binary representation
121193
# for NaNs which makes it worth testing on despite that.
122194
- mips-unknown-linux-gnu
123195
- mips64-unknown-linux-gnuabi64
124196
- riscv64gc-unknown-linux-gnu
197+
# TODO this test works, but it appears to time out
198+
# - powerpc-unknown-linux-gnu
199+
# TODO this test is broken, but it appears to be a problem with QEMU, not us.
200+
# - powerpc64le-unknown-linux-gnu
201+
# TODO enable this once a new version of cross is released
202+
# - powerpc64-unknown-linux-gnu
125203

126204
steps:
127205
- uses: actions/checkout@v2
@@ -149,3 +227,34 @@ jobs:
149227
- name: Test (release)
150228
run: cross test --verbose --target=${{ matrix.target }} --release
151229

230+
features:
231+
name: "Check cargo features (${{ matrix.simd }} × ${{ matrix.features }})"
232+
runs-on: ubuntu-latest
233+
strategy:
234+
fail-fast: false
235+
matrix:
236+
simd:
237+
- ""
238+
- "avx512"
239+
features:
240+
- ""
241+
- "--features std"
242+
- "--features generic_const_exprs"
243+
- "--features std --features generic_const_exprs"
244+
245+
steps:
246+
- uses: actions/checkout@v2
247+
- name: Setup Rust
248+
run: |
249+
rustup update nightly --no-self-update
250+
rustup default nightly
251+
- name: Detect AVX512
252+
run: echo "CPU_FEATURE=$(lscpu | grep -o avx512[a-z]* | sed s/avx/+avx/ | tr '\n' ',' )" >> $GITHUB_ENV
253+
- name: Check build
254+
if: ${{ matrix.simd == '' }}
255+
run: RUSTFLAGS="-Dwarnings" cargo check --all-targets --no-default-features ${{ matrix.features }}
256+
- name: Check AVX
257+
if: ${{ matrix.simd == 'avx512' && contains(env.CPU_FEATURE, 'avx512') }}
258+
run: |
259+
echo "Found AVX features: $CPU_FEATURE"
260+
RUSTFLAGS="-Dwarnings -Ctarget-feature=$CPU_FEATURE" cargo check --all-targets --no-default-features ${{ matrix.features }}

.travis.yml

Lines changed: 0 additions & 82 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SIMD can be quite complex, and even a "simple" issue can be huge. If an issue is
1515

1616
## CI
1717

18-
We currently have 2 CI matrices through Travis CI and GitHub Actions that will automatically build and test your change in order to verify that `std::simd`'s portable API is, in fact, portable. If your change builds locally, but does not build on either, this is likely due to a platform-specific concern that your code has not addressed. Please consult the build logs and address the error, or ask for help if you need it.
18+
We currently use GitHub Actions which will automatically build and test your change in order to verify that `std::simd`'s portable API is, in fact, portable. If your change builds locally, but does not build in CI, this is likely due to a platform-specific concern that your code has not addressed. Please consult the build logs and address the error, or ask for help if you need it.
1919

2020
## Beyond stdsimd
2121

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
members = [
44
"crates/core_simd",
5+
"crates/std_float",
56
"crates/test_helpers",
67
]

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# stdsimd - Rust's standard library portable SIMD API
2-
[![Build Status](https://travis-ci.com/rust-lang/stdsimd.svg?branch=master)](https://travis-ci.com/rust-lang/stdsimd)
1+
# The Rust standard library's portable SIMD API
2+
![Build Status](https://github.com/rust-lang/portable-simd/actions/workflows/ci.yml/badge.svg?branch=master)
33

44
Code repository for the [Portable SIMD Project Group](https://github.com/rust-lang/project-portable-simd).
55
Please refer to [CONTRIBUTING.md](./CONTRIBUTING.md) for our contributing guidelines.
@@ -12,6 +12,40 @@ We can also be found on [Zulip][zulip-project-portable-simd].
1212

1313
If you are interested in support for a specific architecture, you may want [stdarch] instead.
1414

15+
## Hello World
16+
17+
Now we're gonna dip our toes into this world with a small SIMD "Hello, World!" example. Make sure your compiler is up to date and using `nightly`. We can do that by running
18+
19+
```bash
20+
rustup update -- nightly
21+
```
22+
23+
or by setting up `rustup default nightly` or else with `cargo +nightly {build,test,run}`. After updating, run
24+
```bash
25+
cargo new hellosimd
26+
```
27+
to create a new crate. Edit `hellosimd/Cargo.toml` to be
28+
```toml
29+
[package]
30+
name = "hellosimd"
31+
version = "0.1.0"
32+
edition = "2018"
33+
[dependencies]
34+
core_simd = { git = "https://github.com/rust-lang/portable-simd" }
35+
```
36+
37+
and finally write this in `src/main.rs`:
38+
```rust
39+
use core_simd::*;
40+
fn main() {
41+
let a = f32x4::splat(10.0);
42+
let b = f32x4::from_array([1.0, 2.0, 3.0, 4.0]);
43+
println!("{:?}", a + b);
44+
}
45+
```
46+
47+
Explanation: We import all the bindings from the crate with the first line. Then, we construct our SIMD vectors with methods like `splat` or `from_array`. Finally, we can use operators on them like `+` and the appropriate SIMD instructions will be carried out. When we run `cargo run` you should get `[11.0, 12.0, 13.0, 14.0]`.
48+
1549
## Code Organization
1650

1751
Currently the crate is organized so that each element type is a file, and then the 64-bit, 128-bit, 256-bit, and 512-bit vectors using those types are contained in said file.
@@ -32,4 +66,4 @@ The `mask` types are "truthy" values, but they use the number of bits in their n
3266
[simd-guide]: ./beginners-guide.md
3367
[zulip-project-portable-simd]: https://rust-lang.zulipchat.com/#narrow/stream/257879-project-portable-simd
3468
[stdarch]: https://github.com/rust-lang/stdarch
35-
[docs]: https://rust-lang.github.io/stdsimd/core_simd
69+
[docs]: https://rust-lang.github.io/portable-simd/core_simd

beginners-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SIMD has a few special vocabulary terms you should know:
3333

3434
* **Vertical:** When an operation is "vertical", each lane processes individually without regard to the other lanes in the same vector. For example, a "vertical add" between two vectors would add lane 0 in `a` with lane 0 in `b`, with the total in lane 0 of `out`, and then the same thing for lanes 1, 2, etc. Most SIMD operations are vertical operations, so if your problem is a vertical problem then you can probably solve it with SIMD.
3535

36-
* **Horizontal:** When an operation is "horizontal", the lanes within a single vector interact in some way. A "horizontal add" might add up lane 0 of `a` with lane 1 of `a`, with the total in lane 0 of `out`.
36+
* **Reducing/Reduce:** When an operation is "reducing" (functions named `reduce_*`), the lanes within a single vector are merged using some operation such as addition, returning the merged value as a scalar. For instance, a reducing add would return the sum of all the lanes' values.
3737

3838
* **Target Feature:** Rust calls a CPU architecture extension a `target_feature`. Proper SIMD requires various CPU extensions to be enabled (details below). Don't confuse this with `feature`, which is a Cargo crate concept.
3939

@@ -83,4 +83,4 @@ Fortunately, most SIMD types have a fairly predictable size. `i32x4` is bit-equi
8383
However, this is not the same as alignment. Computer architectures generally prefer aligned accesses, especially when moving data between memory and vector registers, and while some support specialized operations that can bend the rules to help with this, unaligned access is still typically slow, or even undefined behavior. In addition, different architectures can require different alignments when interacting with their native SIMD types. For this reason, any `#[repr(simd)]` type has a non-portable alignment. If it is necessary to directly interact with the alignment of these types, it should be via [`mem::align_of`].
8484

8585
[`mem::transmute`]: https://doc.rust-lang.org/core/mem/fn.transmute.html
86-
[`mem::align_of`]: https://doc.rust-lang.org/core/mem/fn.align_of.html
86+
[`mem::align_of`]: https://doc.rust-lang.org/core/mem/fn.align_of.html

crates/core_simd/Cargo.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
[package]
22
name = "core_simd"
33
version = "0.1.0"
4-
authors = ["Caleb Zulawski <[email protected]>"]
5-
edition = "2018"
6-
homepage = "https://github.com/rust-lang/stdsimd"
7-
repository = "https://github.com/rust-lang/stdsimd"
4+
edition = "2021"
5+
homepage = "https://github.com/rust-lang/portable-simd"
6+
repository = "https://github.com/rust-lang/portable-simd"
87
keywords = ["core", "simd", "intrinsics"]
98
categories = ["hardware-support", "no-std"]
109
license = "MIT OR Apache-2.0"
1110

1211
[features]
13-
default = ["std"]
12+
default = []
1413
std = []
14+
generic_const_exprs = []
1515

1616
[target.'cfg(target_arch = "wasm32")'.dev-dependencies.wasm-bindgen]
1717
version = "0.2"
@@ -26,3 +26,6 @@ features = ["alloc"]
2626

2727
[dev-dependencies.test_helpers]
2828
path = "../test_helpers"
29+
30+
[dev-dependencies]
31+
std_float = { path = "../std_float/", features = ["as_crate"] }

0 commit comments

Comments
 (0)