PiR*_*cks 3 assembly inline-assembly rust
编译以下内联汇编:
#![feature(portable_simd)]
use std::simd::{i64x8, f64x8};
use std::arch::asm;
pub fn convert(a: i64x8) -> f64x8{
let converted: f64x8;
unsafe {
asm!(
"vcvtqq2pd {converted} {a}",
a = in(zmm_reg) a,
converted = out(zmm_reg) converted,
);
}
converted
}
Run Code Online (Sandbox Code Playgroud)
导致错误:
error: cannot use value of type `Simd<i64, 8>` for inline assembly
--> <source>:12:25
|
12 | a = in(zmm_reg) a,
| ^
|
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
error: cannot use value of type `Simd<f64, 8>` for inline assembly
--> <source>:13:34
|
13 | converted = out(zmm_reg) converted,
| ^^^^^^^^^
|
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
error: aborting due to 2 previous errors
Run Code Online (Sandbox Code Playgroud)
您将需要-C target-feature=+avx512f
编译以上内容。或者看看这个神螺栓
这对我来说没有多大意义,因为内联汇编文档明确指出f64x8
和i64x8
是可接受的输入类型zmm_reg
。
此外,错误消息指出 SIMD 向量是可接受的,但这就是我输入的内容。
如果相关的话,请复制到:
active toolchain
----------------
nightly-x86_64-unknown-linux-gnu (default)
rustc 1.68.0-nightly (afaf3e07a 2023-01-14)
Run Code Online (Sandbox Code Playgroud)
这是锈虫还是我做错了什么?
正如评论中提到的,编译器尚不支持在程序集中使用可移植的 simd 类型(相关问题)。请注意,并非所有可移植 simd 类型都可以发送到程序集,使用类型之类的事情f64x16
是完全合法的,但我不知道有任何支持的体系结构可以处理等效类型。作为解决方法,请使用特定于平台的向量类型,例如__m512i
或__m512d
。
#![feature(portable_simd)]
#![feature(stdsimd)]
use std::simd::{i64x8, f64x8};
use std::arch::asm;
use std::arch::x86_64::*;
pub fn convert(a: i64x8) -> f64x8{
let a = __mm512i::from(a);
let converted: __mm512d;
unsafe {
asm!(
"vcvtqq2pd {converted}, {a}",
a = in(zmm_reg) a,
converted = out(zmm_reg) converted,
);
}
converted.into()
}
Run Code Online (Sandbox Code Playgroud)
当然,如果您这样做,请尝试使用适当的 simd 内在函数而不是汇编(如果可能)编写代码,以帮助编译器优化您的代码。