I couldn't find a working example for Rust-SIMD. The closest I can find is this one. After adjusting, it becomes:
#![feature(core)]
#![feature(portable_simd)]
use std::simd::f32x4;
fn main() {
let x = f32x4(1.0, 1.0, 1.0, 1.0);
}
But still cargo complains
error[E0423]: expected function, found type alias `f32x4`
--> src/main.rs:7:13
|
7 | let x = f32x4(1.0, 1.0, 1.0, 1.0);
| ^^^^^
|
= note: can't use a type alias as a constructor
during building.
How do I get this simple example working?
Cargo.toml
:
[package]
name = "rust-simd"
version = "0.1.0"
edition = "2021"
[dependencies]
I have nightly
switched on already: rustup default nightly
.
The way to construct a SIMD vector with std::simd
is type::from(array)
, for example f32x4::from([1.0, 1.0, 1.0, 1.0])
. This is mentioned in the documentation.