simd_vector::Vector<T>
represents an immutable vector with a size that's automatically determined by your CPU architecture and is designed as a building block for vectorizing large algorithms.
- 📦 Built on Rust's
portable_simd
- 🚀 Automatic selection of optimal SIMD lane count based on hardware architecture
- 🔒 Type-safe operations with compile-time size checking
- ⚡ Zero-cost abstractions over hardware SIMD instructions
- 💪 Support for common numeric types (f32, f64, i8, i16, i32, i64, u8, u16, u32, u64)
- 🔄 Cross-platform support (x86_64, aarch64)
Add this to your Cargo.toml
:
[dependencies]
simd_vector = "0.1.0"
⚠️ Note: This crate requires a nightly Rust compiler due to the use ofportable_simd
.rustup override set nightly # Set nightly for this project # or rustup default nightly # Set nightly as your default toolchain
use simd_vector::Vector;
// Create vectors
let a = Vector::<f32>::new(1.0);
let b = Vector::<f32>::new(2.0);
// Basic arithmetic
let sum = a + b;
let diff = a - b;
let product = a * b;
let quotient = a / b;
// Reduction operations
let total = sum.reduce_sum();
// Element-wise operations
let abs_values = a.abs();
let min_values = Vector::min(a, b);
let max_values = Vector::max(a, b);
The number of lanes in a vector depends on both the data type and the target architecture.
Type | x86_64 (256-bit AVX) | aarch64 (128-bit NEON) | Other (128-bit) |
---|---|---|---|
f32 | 8 lanes | 4 lanes | 4 lanes |
f64 | 4 lanes | 2 lanes | 2 lanes |
i8 | 32 lanes | 16 lanes | 16 lanes |
i16 | 16 lanes | 8 lanes | 8 lanes |
i32 | 8 lanes | 4 lanes | 4 lanes |
i64 | 4 lanes | 2 lanes | 2 lanes |
u8 | 32 lanes | 16 lanes | 16 lanes |
u16 | 16 lanes | 8 lanes | 8 lanes |
u32 | 8 lanes | 4 lanes | 4 lanes |
u64 | 4 lanes | 2 lanes | 2 lanes |
- Fork the Repository: Start by forking the repository to your own GitHub account.
- Clone the Forked Repository: Clone the fork to your local machine.
- Create a New Branch: Always create a new branch for your changes.
- Make Your Changes: Implement your changes.
- Run Tests: Make sure to test your changes locally.
- Submit a Pull Request: Commit and push your changes, then create a pull request against the main branch.