Add new #[target_feature = "..."] attribute.

This commit adds a new attribute that instructs the compiler to emit
target specific code for a single function. For example, the following
function is permitted to use instructions that are part of SSE 4.2:

    #[target_feature = "+sse4.2"]
    fn foo() { ... }

In particular, use of this attribute does not require setting the
-C target-feature or -C target-cpu options on rustc.

This attribute does not have any protections built into it. For example,
nothing stops one from calling the above `foo` function on hosts without
SSE 4.2 support. Doing so may result in a SIGILL.

This commit also expands the target feature whitelist to include lzcnt,
popcnt and sse4a. Namely, lzcnt and popcnt have their own CPUID bits,
but were introduced with SSE4.
This commit is contained in:
Andrew Gallant 2016-11-29 19:02:00 -05:00
parent 5de15be5ec
commit 80ef1dbf2d
5 changed files with 50 additions and 11 deletions

View file

@ -66,13 +66,13 @@ impl LLVMRustResult {
pub fn AddFunctionAttrStringValue(llfn: ValueRef,
idx: AttributePlace,
attr: &'static str,
value: &'static str) {
attr: &CStr,
value: &CStr) {
unsafe {
LLVMRustAddFunctionAttrStringValue(llfn,
idx.as_uint(),
attr.as_ptr() as *const _,
value.as_ptr() as *const _)
attr.as_ptr(),
value.as_ptr())
}
}