Possible issue detecting SSE4.2 support


#1

I’m not sure if this is a Rust issue, an LLVM one or an ‘I don’t know how CPUs work’ issue. I’m on rustc 1.13.0-nightly (923bac459 2016-09-06) and if I run rustc --print cfg I get the following target_features:

target_feature="sse"
target_feature="sse2"

I believe this is incorrectly missing sse3, sse4.1 and sse4.2 (the feature I actually care about). If I dump cpuinfo I get something like:

processor    : 0
vendor_id    : GenuineIntel
cpu family    : 6
model        : 94
model name    : Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz

...

flags        :  ... sse sse2 ... ssse3 ... sse4_1 sse4_2 ...

...

Is this not meant to be supported in Rust yet, is there something I need to configure or am I misunderstanding something?


#2

Rustc is just printing which configuration it’s using. It changes according to options. Try rustc --print cfg -Ctarget-cpu=native


#3

The way I tend to actually turn these on with real builds is (for example):

RUSTFLAGS="-C target-feature=+ssse3" cargo build --release
RUSTFLAGS="-C target-cpu=native" cargo build --release

(I’m not aware of a better way currently.)


#4

You can use build.rustflags in cargo configuration files too


#5

Ahh I see, thanks all! So for an app I can set the target cpu in the cargo config and just rely on cfg conditions in a library.


#6

Could you be a bit more specific? Should we put those flags in the ~/.cargo/config file? like this?

[build.rustflags]
target-feature = "+ssse3"
target-cpu = "native"

or should they be added to the Cargo.toml file in the current project?


#7

@Razican they go in .cargo/config: http://doc.crates.io/config.html#configuration-keys


#8

In that link I cannot see target-feature = "+ssse3" or target-cpu = "native" variables, where should they go? into the [build] section? How can I know if they are being used?


#9

They go like this I believe:

[build]
rustflags = ["--target-feature=+ssse3", "--target-cpu=native"]

#10

I had to do:

[build]
rustflags = ["-C", "target-cpu=native"]

There’s an open issue for making rustflags nicer to use.