Skip to content

Commit

Permalink
Merge branch 'main' into u8widen
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokathor authored Aug 12, 2024
2 parents 292cfc4 + d00b0be commit 5a0ec89
Show file tree
Hide file tree
Showing 25 changed files with 354 additions and 116 deletions.
30 changes: 14 additions & 16 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,36 @@ jobs:
matrix:
rust:
# x86 without sse/sse2 on by default
- { target: i586-pc-windows-msvc, toolchain: 1.56.0, os: windows-latest }
- { target: i586-pc-windows-msvc, toolchain: "1.61", os: windows-latest }
- { target: i586-pc-windows-msvc, toolchain: stable, os: windows-latest }
- { target: i586-pc-windows-msvc, toolchain: beta, os: windows-latest }
- { target: i586-pc-windows-msvc, toolchain: nightly, os: windows-latest }
# x86
- { target: i686-pc-windows-msvc, toolchain: 1.56.0, os: windows-latest }
- { target: i686-pc-windows-msvc, toolchain: "1.61", os: windows-latest }
- { target: i686-pc-windows-msvc, toolchain: stable, os: windows-latest }
- { target: i686-pc-windows-msvc, toolchain: beta, os: windows-latest }
- { target: i686-pc-windows-msvc, toolchain: nightly, os: windows-latest }
# x86_64
- { target: x86_64-pc-windows-msvc, toolchain: 1.56.0, os: windows-latest }
- { target: x86_64-pc-windows-msvc, toolchain: "1.61", os: windows-latest }
- { target: x86_64-pc-windows-msvc, toolchain: stable, os: windows-latest }
- { target: x86_64-pc-windows-msvc, toolchain: beta, os: windows-latest }
- { target: x86_64-pc-windows-msvc, toolchain: nightly, os: windows-latest }
# aarch64
- { target: aarch64-apple-darwin, toolchain: "1.61", os: macos-latest }
- { target: aarch64-apple-darwin, toolchain: stable, os: macos-latest }
- { target: aarch64-apple-darwin, toolchain: beta, os: macos-latest }
- { target: aarch64-apple-darwin, toolchain: nightly, os: macos-latest }
# wasm32
- { target: wasm32-wasi, toolchain: 1.56.0, os: ubuntu-latest, wasmtime: v5.0.0 }
- { target: wasm32-wasi, toolchain: "1.61", os: ubuntu-latest, wasmtime: v5.0.0 }
- { target: wasm32-wasi, toolchain: stable, os: ubuntu-latest, wasmtime: v5.0.0 }
- { target: wasm32-wasi, toolchain: beta, os: ubuntu-latest, wasmtime: v5.0.0 }
- { target: wasm32-wasi, toolchain: nightly, os: ubuntu-latest, wasmtime: v5.0.0 }
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust.toolchain }}
target: ${{ matrix.rust.target }}
profile: minimal
default: true

- name: Install wasmtime
if: matrix.rust.target == 'wasm32-wasi'
Expand All @@ -49,12 +52,10 @@ jobs:
run: cargo build --target ${{ matrix.rust.target }}

- name: Test with default CPU features + No Default Cargo Features
if: matrix.rust.target == 'i586-pc-windows-msvc' || matrix.rust.target == 'i686-pc-windows-msvc' || matrix.rust.target == 'x86_64-pc-windows-msvc' || matrix.rust.target == 'wasm32-wasi'
env:
CARGO_TARGET_WASM32_WASI_RUNNER: wasmtime run --wasm-features all --dir .
run: cargo test --target ${{ matrix.rust.target }} --no-default-features
- name: Test with default CPU features + All Cargo Features
if: matrix.rust.target == 'i586-pc-windows-msvc' || matrix.rust.target == 'i686-pc-windows-msvc' || matrix.rust.target == 'x86_64-pc-windows-msvc' || matrix.rust.target == 'wasm32-wasi'
env:
CARGO_TARGET_WASM32_WASI_RUNNER: wasmtime run --wasm-features all --dir .
run: cargo test --target ${{ matrix.rust.target }} --all-features
Expand All @@ -63,19 +64,17 @@ jobs:
run: mv .cargo-ci .cargo

- name: Test with 'native' CPU features + No Default Cargo Features
if: matrix.rust.target == 'i586-pc-windows-msvc' || matrix.rust.target == 'i686-pc-windows-msvc' || matrix.rust.target == 'x86_64-pc-windows-msvc' || matrix.rust.target == 'wasm32-wasi'
run: cargo test --target ${{ matrix.rust.target }} --no-default-features

- name: Test with 'native' CPU features + All Cargo Features
if: matrix.rust.target == 'i586-pc-windows-msvc' || matrix.rust.target == 'i686-pc-windows-msvc' || matrix.rust.target == 'x86_64-pc-windows-msvc' || matrix.rust.target == 'wasm32-wasi'
run: cargo test --target ${{ matrix.rust.target }} --all-features

cross_compile_aarch64:
runs-on: ubuntu-latest

strategy:
matrix:
rust: [1.59,stable,nightly]
rust: ["1.60", stable, nightly]
features: ["", "std"]

steps:
Expand All @@ -85,12 +84,11 @@ jobs:
sudo apt-get install qemu binfmt-support qemu-user-static gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
- name: Installing Rust toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
override: true
toolchain: ${{ matrix.rust }}
target: aarch64-unknown-linux-musl
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: build
run: >
cargo build --verbose --no-default-features --target aarch64-unknown-linux-musl --features "$FEATURES"
Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "wide"
description = "A crate to help you go wide."
version = "0.7.25"
version = "0.7.26"
authors = ["Lokathor <zefria@gmail.com>"]
repository = "https://github.com/Lokathor/wide"
readme = "README.md"
Expand All @@ -10,8 +10,9 @@ categories = ["data-structures", "hardware-support"]
edition = "2018"
license = "Zlib OR Apache-2.0 OR MIT"

# minimum version supported with WASM and all intrinsics for safe_arch (also first version to support this config option)
rust-version = "1.56"
# Aarch64 needs 1.59 while others need 1.56
# When updating, also update CI workflows and the badge in the README.
rust-version = "1.61"

[features]
default = ["std"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![License:Zlib](https://img.shields.io/badge/License-Zlib-brightgreen.svg)](https://opensource.org/licenses/Zlib)
![Minimum Rust Version](https://img.shields.io/badge/Min%20Rust-1.52-green.svg)
![Minimum Rust Version](https://img.shields.io/badge/Min%20Rust-1.61-green.svg)
[![crates.io](https://img.shields.io/crates/v/wide.svg)](https://crates.io/crates/wide)
[![docs.rs](https://docs.rs/wide/badge.svg)](https://docs.rs/wide/)

Expand Down
30 changes: 25 additions & 5 deletions src/f32x4_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pick! {
if #[cfg(target_feature="sse")] {
#[derive(Default, Clone, Copy, PartialEq)]
#[repr(C, align(16))]
pub struct f32x4 { sse: m128 }
pub struct f32x4 { pub(crate) sse: m128 }
} else if #[cfg(target_feature="simd128")] {
use core::arch::wasm32::*;

#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct f32x4 { simd: v128 }
pub struct f32x4 { pub(crate) simd: v128 }

impl Default for f32x4 {
fn default() -> Self {
Expand All @@ -27,7 +27,7 @@ pick! {
use core::arch::aarch64::*;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct f32x4 { neon : float32x4_t }
pub struct f32x4 { pub(crate) neon : float32x4_t }

impl Default for f32x4 {
#[inline]
Expand All @@ -48,7 +48,7 @@ pick! {
} else {
#[derive(Default, Clone, Copy, PartialEq)]
#[repr(C, align(16))]
pub struct f32x4 { arr: [f32;4] }
pub struct f32x4 { pub(crate) arr: [f32;4] }
}
}

Expand Down Expand Up @@ -1305,7 +1305,7 @@ impl f32x4 {
cast::<_, f32x4>(c)
}

/// Calculate the exponent of a packed f32x4
/// Calculate the exponent of a packed `f32x4`
#[inline]
#[must_use]
#[allow(non_upper_case_globals)]
Expand Down Expand Up @@ -1578,4 +1578,24 @@ impl f32x4 {
pub fn as_array_mut(&mut self) -> &mut [f32; 4] {
cast_mut(self)
}

#[inline]
pub fn from_i32x4(v: i32x4) -> Self {
pick! {
if #[cfg(target_feature="sse2")] {
Self { sse: convert_to_m128_from_i32_m128i(v.sse) }
} else if #[cfg(target_feature="simd128")] {
Self { simd: f32x4_convert_i32x4(v.simd) }
} else if #[cfg(all(target_feature="neon",target_arch="aarch64"))] {
Self { neon: unsafe { vcvtq_f32_s32(v.neon) }}
} else {
Self { arr: [
v.as_array_ref()[0] as f32,
v.as_array_ref()[1] as f32,
v.as_array_ref()[2] as f32,
v.as_array_ref()[3] as f32,
] }
}
}
}
}
24 changes: 22 additions & 2 deletions src/f32x8_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ impl f32x8 {
cast::<_, f32x8>(c)
}

/// Calculate the exponent of a packed f32x8
/// Calculate the exponent of a packed `f32x8`
#[inline]
#[must_use]
#[allow(non_upper_case_globals)]
Expand Down Expand Up @@ -1330,7 +1330,7 @@ impl f32x8 {
Self::pow_f32x8(self, f32x8::splat(y))
}

/// Transpose matrix of 8x8 f32 matrix. Currently only accelerated on AVX.
/// Transpose matrix of 8x8 `f32` matrix. Currently only accelerated on AVX.
#[must_use]
#[inline]
pub fn transpose(data: [f32x8; 8]) -> [f32x8; 8] {
Expand Down Expand Up @@ -1418,6 +1418,26 @@ impl f32x8 {
pub fn as_array_mut(&mut self) -> &mut [f32; 8] {
cast_mut(self)
}

#[inline]
pub fn from_i32x8(v: i32x8) -> Self {
pick! {
if #[cfg(target_feature="avx2")] {
Self { avx: convert_to_m256_from_i32_m256i(v.avx2) }
} else {
Self::new([
v.as_array_ref()[0] as f32,
v.as_array_ref()[1] as f32,
v.as_array_ref()[2] as f32,
v.as_array_ref()[3] as f32,
v.as_array_ref()[4] as f32,
v.as_array_ref()[5] as f32,
v.as_array_ref()[6] as f32,
v.as_array_ref()[7] as f32,
])
}
}
}
}

impl Not for f32x8 {
Expand Down
37 changes: 32 additions & 5 deletions src/f64x2_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pick! {
if #[cfg(target_feature="sse2")] {
#[derive(Default, Clone, Copy, PartialEq)]
#[repr(C, align(16))]
pub struct f64x2 { sse: m128d }
pub struct f64x2 { pub(crate) sse: m128d }
} else if #[cfg(target_feature="simd128")] {
use core::arch::wasm32::*;

#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct f64x2 { simd: v128 }
pub struct f64x2 { pub(crate) simd: v128 }

impl Default for f64x2 {
fn default() -> Self {
Expand All @@ -27,7 +27,7 @@ pick! {
use core::arch::aarch64::*;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct f64x2 { neon : float64x2_t }
pub struct f64x2 { pub(crate) neon: float64x2_t }

impl Default for f64x2 {
#[inline]
Expand All @@ -51,7 +51,7 @@ pick! {
} else {
#[derive(Default, Clone, Copy, PartialEq)]
#[repr(C, align(16))]
pub struct f64x2 { arr: [f64;2] }
pub struct f64x2 { pub(crate) arr: [f64;2] }
}
}

Expand Down Expand Up @@ -1304,7 +1304,7 @@ impl f64x2 {
cast::<_, f64x2>(c)
}

/// Calculate the exponent of a packed f64x2
/// Calculate the exponent of a packed `f64x2`
#[inline]
#[must_use]
#[allow(non_upper_case_globals)]
Expand Down Expand Up @@ -1608,6 +1608,33 @@ impl f64x2 {
pub fn as_array_mut(&mut self) -> &mut [f64; 2] {
cast_mut(self)
}

/// Converts the lower two `i32` lanes to two `f64` lanes (and dropping the higher two `i32` lanes)
#[inline]
pub fn from_i32x4_lower2(v: i32x4) -> Self {
pick! {
if #[cfg(target_feature="sse2")] {
Self { sse: convert_to_m128d_from_lower2_i32_m128i(v.sse) }
} else if #[cfg(target_feature="simd128")] {
Self { simd: f64x2_convert_low_i32x4(v.simd)}
} else if #[cfg(all(target_feature="neon",target_arch="aarch64"))] {
Self { neon: unsafe { vcvtq_f64_s64(vmovl_s32(vget_low_s32(v.neon))) }}
} else {
Self { arr: [
v.as_array_ref()[0] as f64,
v.as_array_ref()[1] as f64,
]}
}
}
}
}

impl From<i32x4> for f64x2 {
/// Converts the lower two `i32` lanes to two `f64` lanes (and dropping the higher two `i32` lanes)
#[inline]
fn from(v: i32x4) -> Self {
Self::from_i32x4_lower2(v)
}
}

impl Not for f64x2 {
Expand Down
29 changes: 26 additions & 3 deletions src/f64x4_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ pick! {
if #[cfg(target_feature="avx")] {
#[derive(Default, Clone, Copy, PartialEq)]
#[repr(C, align(32))]
pub struct f64x4 { avx: m256d }
pub struct f64x4 { pub(crate) avx: m256d }
} else {
#[derive(Default, Clone, Copy, PartialEq)]
#[repr(C, align(32))]
pub struct f64x4 { a : f64x2, b : f64x2 }
pub struct f64x4 { pub(crate) a: f64x2, pub(crate) b: f64x2 }
}
}

Expand Down Expand Up @@ -1174,7 +1174,7 @@ impl f64x4 {
cast::<_, f64x4>(c)
}

/// Calculate the exponent of a packed f64x4
/// Calculate the exponent of a packed `f64x4`
#[inline]
#[must_use]
#[allow(non_upper_case_globals)]
Expand Down Expand Up @@ -1473,6 +1473,29 @@ impl f64x4 {
pub fn as_array_mut(&mut self) -> &mut [f64; 4] {
cast_mut(self)
}

#[inline]
pub fn from_i32x4(v: i32x4) -> Self {
pick! {
if #[cfg(target_feature="avx")] {
Self { avx: convert_to_m256d_from_i32_m128i(v.sse) }
} else {
Self::new([
v.as_array_ref()[0] as f64,
v.as_array_ref()[1] as f64,
v.as_array_ref()[2] as f64,
v.as_array_ref()[3] as f64,
])
}
}
}
}

impl From<i32x4> for f64x4 {
#[inline]
fn from(v: i32x4) -> Self {
Self::from_i32x4(v)
}
}

impl Not for f64x4 {
Expand Down
Loading

0 comments on commit 5a0ec89

Please sign in to comment.