Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic features: Vec8f and Vec4f #1

Merged
merged 67 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
1091d2b
add CI
NamorNiradnug Dec 27, 2023
66a82b6
vec256f basic operations: load/store, add/sub/mul/div
NamorNiradnug Dec 28, 2023
e060153
change `Vec256::load`'s `addr` argument type to `*const [f32; 8]`
NamorNiradnug Dec 28, 2023
b95c33f
fix typo in sample test name
NamorNiradnug Dec 28, 2023
f6cb77b
implement vec-scalar operators; impl PartialEq; add docs
NamorNiradnug Jan 2, 2024
069133a
use aligned load instrinsic in `Vec256f::load_aligned`
NamorNiradnug Jan 2, 2024
f97a80b
add failing example for `Vec256f::load_aligned`
NamorNiradnug Jan 2, 2024
46d87d1
add `Vec256f::store_non_temporal`; conditional compilation; make intr…
NamorNiradnug Jan 3, 2024
8d975ad
add 32bit x86 CI; rename vec256f to vec8f; Vec4f
NamorNiradnug Jan 3, 2024
1b89978
impl missing functions for `Vec4f`; restrict `SIMDVector`'s requireme…
NamorNiradnug Jan 3, 2024
d0e2aab
fix typo in channel name in CI
NamorNiradnug Jan 3, 2024
7228adf
`Vec8f`: `join`, `split`, `low`, `high`
NamorNiradnug Jan 3, 2024
9c09aca
add missing docs for some of `Vec4f` traits
NamorNiradnug Jan 3, 2024
d8d5c5c
use `Example` header if there is only one example
NamorNiradnug Jan 3, 2024
8170aae
implement `load_partial`
NamorNiradnug Jan 3, 2024
73b5fb5
implement `sum` (aka `horizontal_add`)
NamorNiradnug Jan 3, 2024
0641ec1
fallback Vec8f implementation when AVX instructions are not available
NamorNiradnug Jan 4, 2024
35dc128
add AVX-only test
NamorNiradnug Jan 4, 2024
e2bfd80
return cargo config
NamorNiradnug Jan 4, 2024
c6ae591
update `Vec8f` description
NamorNiradnug Jan 4, 2024
44265c2
optimize Vecf to array convertions
NamorNiradnug Jan 4, 2024
b020583
add missing `inline` annotations; fix Vec4f::eq using AVX instruction
NamorNiradnug Jan 4, 2024
e8b25af
explicitly enable AVX target-feature in CI
NamorNiradnug Jan 4, 2024
76a11e2
move tests for vec4f under #[cfg(test)]
NamorNiradnug Jan 4, 2024
d3e5c0c
remove Into<VecXf> implementation for f32
NamorNiradnug Jan 4, 2024
d855245
mark VecXf type with `#[repr(transparent)]`
NamorNiradnug Jan 4, 2024
197f065
fix AVX-less build
NamorNiradnug Jan 4, 2024
dcc74a5
refactor load/store-like functions for VecXf
NamorNiradnug Jan 4, 2024
f43bf76
add more `store_`-functions
NamorNiradnug Jan 4, 2024
3423b01
fix AVX-less implementation of Vec8f
NamorNiradnug Jan 4, 2024
e9207df
formatting
NamorNiradnug Jan 4, 2024
b4819af
add missing `inline` attributes
NamorNiradnug Jan 5, 2024
b036d6c
`Vec8f`: use `#[repr(C)]` attribute for avx-less implementation
NamorNiradnug Jan 5, 2024
cddd688
formatting
NamorNiradnug Jan 5, 2024
91148da
impl `Sum` and `Product`
NamorNiradnug Jan 5, 2024
4637ec2
add dotproduct benchmark
NamorNiradnug Jan 5, 2024
745a0e8
remove unneeded doctest-compile option in CI/bench_32bits
NamorNiradnug Jan 5, 2024
f1ea628
speedup benchmarks; use `throughput`
NamorNiradnug Jan 5, 2024
2553968
use newer criterion version; use `bench_with_input`
NamorNiradnug Jan 5, 2024
c0962d1
add fields in Cargo.toml
NamorNiradnug Jan 5, 2024
fc38ba4
implement `extract` functions for VecXf
NamorNiradnug Jan 6, 2024
2512d6f
switch to nightly channel
NamorNiradnug Jan 6, 2024
b41d3c5
fix CI; remove benches from CI
NamorNiradnug Jan 6, 2024
90c5839
use `cfg_aliases` in `build.rs`
NamorNiradnug Jan 6, 2024
2511c1f
`extract_const`: hacks to check INDEX for validness on stable toolchain
NamorNiradnug Jan 6, 2024
9b6b677
fix panic messages in `store_prefix` and `store_checked`
NamorNiradnug Jan 6, 2024
afe3a27
remove underscores in `Vec8f` halfs names
NamorNiradnug Jan 6, 2024
621b3c0
replace `as_ptr` with `as_mut_ptr` in `store_prefix`
NamorNiradnug Jan 6, 2024
91ddc07
use pointer to f32 instead of [f32; N] in unsafe load/store functions
NamorNiradnug Jan 6, 2024
7357db8
test under Miri
NamorNiradnug Jan 6, 2024
b1072d7
fix Miri CI
NamorNiradnug Jan 6, 2024
9c29c59
impl `Index` for `&VecXf`
NamorNiradnug Jan 6, 2024
5e77f5b
formatting
NamorNiradnug Jan 6, 2024
9d99f44
impl `Index` and `IndexMut` for `VecXX`
NamorNiradnug Jan 6, 2024
7148d17
formatting
NamorNiradnug Jan 6, 2024
a7578c8
remove const_guard from deps; use `Examples` instead of `Exmaple` hea…
NamorNiradnug Jan 6, 2024
82d1634
move dotprod test into `tests/`
NamorNiradnug Jan 6, 2024
adfa2c3
fix several typos in docs
NamorNiradnug Jan 6, 2024
b67d5c1
split vecxf platform-specific implementations into separate modules
NamorNiradnug Jan 7, 2024
52f6dc4
replace `inline(always)` with `inline`
NamorNiradnug Jan 7, 2024
3a172c5
remove `Index[Mut]` implementations for `VecXf` as UB-prone
NamorNiradnug Jan 7, 2024
a25c13e
add `VecXf::extract_wrapping` method
NamorNiradnug Jan 7, 2024
1b4a100
use transmute instead of pointers casting; uncomment `Index[Mut]` imp…
NamorNiradnug Jan 7, 2024
8be47f2
bump version
NamorNiradnug Jan 7, 2024
2e73d68
remove unneeded `cfg` conditions from in `lib.rs`
NamorNiradnug Jan 7, 2024
ce8b9c2
replace check with clippy in CI
NamorNiradnug Jan 7, 2024
ed1c87b
CI: use `cache` for jobs using `cross`
NamorNiradnug Jan 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustflags = ["-C", "target-cpu=native"]
103 changes: 103 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# borrowed from https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md
on: [push, pull_request]

name: Continuous integration

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: check

check_32bits:
name: Check (32 bits; no AVX)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
target: i686-unknown-linux-gnu
- uses: actions-rs/cargo@v1
with:
use-cross: true
command: check
args: --target i686-unknown-linux-gnu -Zdoctest-xcompile
env:
RUSTFLAGS: -C target-feature=-avx,-avx2

test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: test

test_32bits:
name: Test Suite (32 bits; no AVX)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
target: i686-unknown-linux-gnu
- uses: actions-rs/cargo@v1
with:
use-cross: true
command: test
args: --target i686-unknown-linux-gnu -Zdoctest-xcompile
env:
RUSTFLAGS: -C target-feature=-avx,-avx2

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ authors = ["NamorNiradnug"]
name = "vector-rust-library"
version = "0.1.0"
edition = "2021"

[lib]
name = "vrl"

[dependencies]
paste = "1.0.14"
derive_more = "0.99.17"
16 changes: 16 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::env;

fn feature_shortcut(feature: &str) {
if env::var("CARGO_CFG_TARGET_FEATURE")
.map_or(false, |cfg| cfg.split(',').any(|f| f == feature))
{
println!("cargo:rustc-cfg={}", feature);
} else {
println!("cargo:rustc-cfg=no_{}", feature)
}
}

fn main() {
feature_shortcut("sse");
feature_shortcut("avx");
}
47 changes: 47 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};

/// Represents a packed vector containing [`ELEMENTS`](SIMDVector::ELEMENTS)
/// values of type [`Element`].
///
/// Converting [`Element`] to [`SIMDVector`] works as `broadcast`, i.e. assigns
/// the converting value to all elements of the vector.
///
/// [`Default::default`] initializes all elements of vector with zero.
///
/// All arithmetic operations ([`Neg`], [`Add`], etc) are applied vertically, i.e. "elementwise".
///
/// [`Element`]: Self::Element
pub trait SIMDVector
where
Self: From<Self::Underlying>
+ From<Self::Element>
+ Default
+ Neg<Output = Self>
+ Add<Self>
+ Add<Self::Element>
+ Sub<Self>
+ Sub<Self::Element>
+ Mul<Self>
+ Mul<Self::Element>
+ Div<Self>
+ Div<Self::Element>
+ AddAssign<Self>
+ AddAssign<Self::Element>
+ SubAssign<Self>
+ SubAssign<Self::Element>
+ MulAssign<Self>
+ MulAssign<Self::Element>
+ DivAssign<Self>
+ DivAssign<Self::Element>, // + [Self::Element; Self::ELEMENTS]
Self::Underlying: From<Self>,
Self::Element: Add<Self> + Sub<Self> + Mul<Self> + Div<Self>,
{
/// Underlying intrinsic type or tuple of types implementing [`SIMDVector`].
type Underlying;

/// Type of a single element of [`SIMDVector`].
type Element;

/// Number of elements in [`SIMDVector`].
const ELEMENTS: usize;
}
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Port (__NOT__ bindings) of Agner Fog's [Vector Class Library](https://github.com/vectorclass/version2) to Rust.
//! `vrl` stands for **V**ector **R**ust **L**ibrary.
//!
//! This is a library for using the SIMD (Single Instruction Multiple Data) instructions on modern
//! x86 and x86-64 CPUs.

mod common;
mod macros;

mod vec4f;
mod vec8f;

mod intrinsics {
#[cfg(target_arch = "x86_64")]
pub use core::arch::x86_64::*;

#[cfg(target_arch = "x86")]
pub use core::arch::x86::*;
}

#[cfg(any(sse, doc))]
pub use vec4f::Vec4f;

#[cfg(any(sse, doc))]
pub use vec8f::Vec8f;

pub use common::SIMDVector;
42 changes: 42 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
macro_rules! vec_overload_operator {
($vectype: ty, $op_trait: ident, $op_name: ident, $intrinsic: ident, $basic_impl_condition: meta) => {
#[cfg($basic_impl_condition)]
impl $op_trait for $vectype {
type Output = Self;
#[inline(always)]
fn $op_name(self, rhs: Self) -> Self::Output {
unsafe { $intrinsic(self.into(), rhs.into()).into() }
}
}

impl $op_trait<<$vectype as SIMDVector>::Element> for $vectype {
type Output = Self;
#[inline(always)]
fn $op_name(self, rhs: <$vectype as SIMDVector>::Element) -> Self::Output {
self.$op_name(Into::<Self>::into(rhs))
}
}

impl $op_trait<$vectype> for <$vectype as SIMDVector>::Element {
type Output = $vectype;
#[inline(always)]
fn $op_name(self, rhs: $vectype) -> Self::Output {
rhs.$op_name(self)
}
}

paste::paste! {
impl<T> [<$op_trait Assign>]<T> for $vectype
where
Self: $op_trait<T, Output = Self>,
{
#[inline(always)]
fn [<$op_name _assign>](&mut self, rhs: T) {
*self = self.$op_name(rhs);
}
}
}
};
}

pub(crate) use vec_overload_operator;
Loading
Loading