Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target-cpu value? #22

Open
novacrazy opened this issue Nov 13, 2019 · 5 comments
Open

Add target-cpu value? #22

novacrazy opened this issue Nov 13, 2019 · 5 comments

Comments

@novacrazy
Copy link

I have an application that will be distributed for specific CPU models in order to take advantage of specific instructions and different techniques better suited for AMD or Intel.

It would be nice to have built parse RUSTFLAGS and store target-cpu so it could be included in the build information.

@lukaslueg
Copy link
Owner

Excuse my ignorance: Is target-cpu the more specific form of target_arch, which gives you one of these ?

@novacrazy
Copy link
Author

target-arch would just be x86_64 or similar, but target-cpu is for the specific CPU architecture being targeted.

Here is the current list given by rustc --print target-cpus:

    native         - Select the CPU of the current host (currently znver1).
    amdfam10
    athlon
    athlon-4
    athlon-fx
    athlon-mp
    athlon-tbird
    athlon-xp
    athlon64
    athlon64-sse3
    atom
    barcelona
    bdver1
    bdver2
    bdver3
    bdver4
    bonnell
    broadwell     
    btver1
    btver2
    c3
    c3-2
    cannonlake
    cascadelake
    cooperlake
    core-avx-i
    core-avx2
    core2
    corei7
    corei7-avx
    generic
    geode
    goldmont
    goldmont-plus
    haswell
    i386
    i486
    i586
    i686
    icelake-client
    icelake-server
    ivybridge
    k6
    k6-2
    k6-3
    k8
    k8-sse3       
    knl
    knm
    lakemont
    nehalem
    nocona
    opteron
    opteron-sse3
    penryn
    pentium
    pentium-m
    pentium-mmx
    pentium2
    pentium3
    pentium3m
    pentium4
    pentium4m
    pentiumpro
    prescott
    sandybridge
    silvermont
    skx
    skylake
    skylake-avx512
    slm
    tremont
    westmere
    winchip-c6
    winchip2
    x86-64
    yonah
    znver1
    znver2

Most Rust users seem totally unaware of this flag... but setting it to native or something specific enables a plethora of optimizations that can take advantage of SSE3+/AVX/etc. (by default Rust only uses SSE2 or lower for compatibility)

In my case, I set it to znver1 to target AMD Zen 1, or various generations of Intel chips for Intel builds, and my code can have specific optimizations for each platform.

I think it would be convenient to include target-cpu in built for this reason, so it can be very easily included in user-viewable build information, especially for remote instances.

@novacrazy
Copy link
Author

Likewise a list of target-features would be pretty handy, which can be found with rustc --print target-features

target-feature can actually be used in cfg expressions/attributes, which makes adding those possibly easier.

target-cpu is basically invisible from within Rust code, though, and the only way I know of finding it is to parse RUSTFLAGS during build.

@lukaslueg
Copy link
Owner

My natural inclination is to avoid having to parse RUSTFLAGS for obvious reasons, at least if this is the only solution. Maybe open an issue with Cargo, so target-cpu and target-features get their own env-var, visible from build scripts. This would do the heavy lifting of parsing RUSTFLAGS and sanitizing it. I'll take a look at what it takes to parse RUSTFLAGS, which will involve some code-copying...

@lukaslueg
Copy link
Owner

This depends on rust-lang/rust#44036

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants