You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently target-cpu is passed using rustcargs. However rustcargs are passed only to the final compiler target, not to its deps. This causes that when --native or --target-cpu is specified, only the last target is compiled with optimization for the current or specified processor. If cargo asm is called for test, example or bench than the library or binary itself is compiled without target-cpu as well.
This may not always be the case for inline functions. But for example library items with #[cfg(target_feature = "sse3")] won't be compiled when calling cargo asm --native for its test, example or bench on sse3-compatible processor.
RUSTFLAGS — A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast with cargo rustc, this is useful for passing a flag to all compiler instances.
From cargo asm --help
...
Available options:
...
--native Optimize for the CPU running the compiler
--target-cpu=CPU Optimize code for a specific CPU, see 'rustc --print target-cpus'
...
Example with cargo rustc -v
Pass target-cpu using rustcargs and pass target-cpu using RUSTFLAGS:
#[no_mangle]pubfnffi_has_sse3_than_2_else_1() -> u32{has_sse3_than_2_else_1()}#[cfg(target_feature = "sse3")]#[inline]pubfnhas_sse3_than_2_else_1() -> u32{2// Different numbers are used to avoid function merging}#[cfg(not(target_feature = "sse3"))]#[inline]pubfnhas_sse3_than_2_else_1() -> u32{1}
$ cargo asm --native --lib ffi_has_sse3_than_2_else_1
mov eax, 2 # lib compiled with target-cpu=native
ret
$ cargo asm --native --test test ffi_lib_has_sse3_then_2_else_1
mov eax, 1 # lib compiled without target-cpu=native
ret
$ cargo asm --native --test test ffi_test_has_sse3_then_4_else_3
mov eax, 4 # test compiled with target-cpu=native
ret
Possible solutions
Just mention in the help that native and target-cpu options may have no effect on dependencies or even crate library if called for its example or bench or test. But I'd say it's kind of expected that the --native and --target-cpu flags should affect dependencies as well.
Pass target-cpu using RUSTFLAGS.
Workaround
Don't use cargo asm --native or cargo asm --target-cpu=CPU, use RUSTFLAGS='-C target-cpu={CPU|native}' cargo asm instead.
The text was updated successfully, but these errors were encountered:
Summary
Currently
target-cpu
is passed usingrustc
args
. Howeverrustc
args
are passed only to the final compiler target, not to its deps. This causes that when--native
or--target-cpu
is specified, only the last target is compiled with optimization for the current or specified processor. Ifcargo asm
is called for test, example or bench than the library or binary itself is compiled withouttarget-cpu
as well.This may not always be the case for inline functions. But for example library items with
#[cfg(target_feature = "sse3")]
won't be compiled when callingcargo asm --native
for its test, example or bench on sse3-compatible processor.References
From
cargo rustc
description at https://doc.rust-lang.org/cargo/commands/cargo-rustc.html:From https://doc.rust-lang.org/cargo/reference/environment-variables.html
From
cargo asm --help
Example with
cargo rustc -v
Pass
target-cpu
usingrustc
args
and passtarget-cpu
usingRUSTFLAGS
:The first invocation compiles dependency.
The second invocation compiles library.
The final invocation compiles library example.
Example with
cargo asm --native
src/lib.rs
:tests/test.rs
:Possible solutions
Just mention in the help that
native
andtarget-cpu
options may have no effect on dependencies or even crate library if called for its example or bench or test. But I'd say it's kind of expected that the--native
and--target-cpu
flags should affect dependencies as well.Pass
target-cpu
usingRUSTFLAGS
.Workaround
Don't use
cargo asm --native
orcargo asm --target-cpu=CPU
, useRUSTFLAGS='-C target-cpu={CPU|native}' cargo asm
instead.The text was updated successfully, but these errors were encountered: