Rust-SIMD 你好世界

Rust-SIMD hello world

我找不到 Rust-SIMD 的工作示例。我能找到的最接近的是 this one。调整后变为:

#![feature(core)]
#![feature(portable_simd)]

use std::simd::f32x4;

fn main() {
    let x = f32x4(1.0, 1.0, 1.0, 1.0);
}

但是还是有货物投诉

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

建设中。

如何让这个简单的示例运行?

Cargo.toml:

[package]
name = "rust-simd"
version = "0.1.0"
edition = "2021"

[dependencies]

我已经开启了 nightlyrustup default nightly

std::simd构造SIMD向量的方法是type::from(array),例如f32x4::from([1.0, 1.0, 1.0, 1.0])。这个提到in the documentation.