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

Whitelist pclmulqdq x86 feature flag #48126

Merged
merged 6 commits into from
Feb 15, 2018
Merged

Conversation

newpavlov
Copy link
Contributor

Relevant stdsimd issue.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

Thanks @newpavlov! From our discussion on rust-lang/stdarch#320 I think that we may want to rename this to pclmulqdq, though, as that's what Intel is calling it. This'll be the first of its kind doing that though so will require a little bit more effort unfortunately, but I think I can help guide you through what's necessary!

I think there may wish to be a few things we'd like to change as part of this:

  • First, I think we'll want to store and pass features as &'static str rather than &CStr. This'll basically involve removing the \0 from the end of all the features.
  • Next we'll want a function like target_feature_to_llvm_feature which requires a String. The mapping logic would then go in this function.
  • You'll want to call target_feature_to_llvm_feature from two locations:
    • Here when we ask LLVM if a feature is enabled.
    • And here where we build up the attribute we'll attach to the LLVM function in the IR.

And... I think that's it! I think it's fine to define target_feature_to_llvm_feature in a "naive" fashion that looks like:

pub fn target_feature_to_llvm_feature(s: &str) -> String {
    match s {
        "pclmulqdq" => "pclmul".to_string(),
        s => s.to_string()
    }
}

and we can continue to make it more robust as needed

@retep998
Copy link
Member

AMD also refers to it as PCLMULQDQ in their documentation.

@newpavlov
Copy link
Contributor Author

@alexcrichton
Thank you!

First, I think we'll want to store and pass features as &'static str rather than &CStr. This'll basically involve removing the \0 from the end of all the features.

If I understand correctly null termination is needed for calling LLVMRustHasFeature. We could convert null-less &'static str features to CString, but it will require an allocation. Cost should be quite negligible and removing null bytes from features lists looks nice, but I can't shake off "allocations are evil" feeling. :) So I would like to hear your opinion on this.

@alexcrichton
Copy link
Member

Ah yeah no need to worry about that, I can guarantee it won't show up in any profiles :)

@newpavlov newpavlov changed the title Whitelist pclmul x86 feature flag Whitelist pclmulqdq x86 feature flag Feb 11, 2018
@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Contributor

bors commented Feb 11, 2018

📌 Commit 7c6adb4 has been approved by alexcrichton

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Feb 11, 2018
.iter()
.filter(|feature| {
let llvm_feature = to_llvm_feature(feature);
let ptr = CString::new(llvm_feature).unwrap().as_ptr();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a dangling pointer. See temporary_cstring_as_ptr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you for noticing!

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 11, 2018

📌 Commit c2a31de has been approved by alexcrichton

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 12, 2018

Could we maybe just have a hashmap from rust feature name to llvm feature name, and if a feature is not in the hashmap, we just use the rust feature name as llvm's feature name ?

EDIT: Ah, I see you have a match statement, that looks good for me :)

kennytm added a commit to kennytm/rust that referenced this pull request Feb 12, 2018
…hitelist pclmulqdq x86 feature flag Relevant `stdsimd` [issue](rust-lang/stdarch#318).
@alexcrichton
Copy link
Member

@bors: rollup

bors added a commit that referenced this pull request Feb 12, 2018
Rollup of 8 pull requests

- Successful merges: #47846, #48033, #48087, #48114, #48126, #48130, #48133, #48151
- Failed merges:
kennytm added a commit to kennytm/rust that referenced this pull request Feb 13, 2018
Whitelist pclmulqdq x86 feature flag

Relevant `stdsimd` [issue](rust-lang/stdarch#318).
bors added a commit that referenced this pull request Feb 13, 2018
Rollup of 14 pull requests

- Successful merges: #47784, #47846, #48033, #48083, #48087, #48114, #48126, #48130, #48133, #48151, #48154, #48163, #48165, #48167
- Failed merges:
kennytm added a commit to kennytm/rust that referenced this pull request Feb 14, 2018
Whitelist pclmulqdq x86 feature flag

Relevant `stdsimd` [issue](rust-lang/stdarch#318).
bors added a commit that referenced this pull request Feb 14, 2018
bors added a commit that referenced this pull request Feb 15, 2018
bors added a commit that referenced this pull request Feb 15, 2018
@kennytm kennytm merged commit c2a31de into rust-lang:master Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants