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

Update simd.rs to Rust 1.58 #414

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion c2rust-transpile/src/translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4589,7 +4589,7 @@ impl<'c> Translation<'c> {
.implicit_default_expr(inner, is_static)?
.map(|val| vec_expr(val, count)))
} else if let &CTypeKind::Vector(CQualTypeId { ctype, .. }, len) = resolved_ty {
self.implicit_vector_default(ctype, len, is_static)
self.implicit_vector_default(ctype, len, is_static).map_err(Into::into)
} else {
Err(format_err!("Unsupported default initializer: {:?}", resolved_ty).into())
}
Expand Down
39 changes: 14 additions & 25 deletions c2rust-transpile/src/translator/simd.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#![deny(missing_docs)]
//! This module provides translation for SIMD operations and expressions.

use super::*;
use failure::bail;

use crate::c_ast::BinOp::{Add, BitAnd, ShiftRight};
use crate::c_ast::CastKind::{BitCast, IntegralCast};
use crate::c_ast::CExprKind::{Binary, Call, Conditional, ExplicitCast, ImplicitCast, Literal};
use crate::c_ast::CLiteral::Integer;
use crate::c_ast::CTypeKind::{Char, Double, Float, Int, LongLong, Short};
use crate::c_ast::CastKind::{BitCast, IntegralCast};

/// As of rustc 1.29, rust is known to be missing some SIMD functions.
use super::*;

/// As of rustc 1.58, rust is known to be missing some SIMD functions.
/// See https://github.com/rust-lang-nursery/stdsimd/issues/579
static MISSING_SIMD_FUNCTIONS: [&str; 36] = [
static MISSING_SIMD_FUNCTIONS: &[&str] = &[
"_mm_and_si64",
"_mm_andnot_si64",
"_mm_cmpeq_pi16",
"_mm_cmpeq_pi32",
"_mm_cmpeq_pi8",
"_mm_cvtm64_si64",
"_mm_cvtph_ps",
"_mm_cvtsi32_si64",
"_mm_cvtsi64_m64",
"_mm_cvtsi64_si32",
"_mm_empty",
"_mm_free",
"_mm_loadu_si64",
"_mm_madd_pi16",
"_mm_malloc",
"_mm_mulhi_pi16",
Expand Down Expand Up @@ -173,12 +173,8 @@ impl<'c> Translation<'c> {
))?;
}

// The majority of x86/64 SIMD is stable, however there are still some
// bits that are behind a feature gate.
self.use_feature("stdsimd");

self.with_cur_file_item_store(|item_store| {
let std_or_core = if self.tcfg.emit_no_std { "core" } else { "std" }.to_string();
let std_or_core = if self.tcfg.emit_no_std { "core" } else { "std" };

// REVIEW: Also a linear lookup
if !SIMD_X86_64_ONLY.contains(&name) {
Expand All @@ -193,7 +189,7 @@ impl<'c> Translation<'c> {
.pub_();

item_store.add_use_with_attr(
vec![std_or_core.clone(), "arch".into(), "x86".into()],
vec![std_or_core.to_owned(), "arch".into(), "x86".into()],
name,
x86_attr,
);
Expand All @@ -212,7 +208,7 @@ impl<'c> Translation<'c> {
.pub_();

item_store.add_use_with_attr(
vec![std_or_core, "arch".into(), "x86_64".into()],
vec![std_or_core.to_owned(), "arch".into(), "x86_64".into()],
name,
x86_64_attr,
);
Expand Down Expand Up @@ -286,7 +282,7 @@ impl<'c> Translation<'c> {
ctype: CTypeId,
len: usize,
is_static: bool,
) -> Result<WithStmts<Box<Expr>>, TranslationError> {
) -> Result<WithStmts<Box<Expr>>, failure::Error> {
// NOTE: This is only for x86/_64, and so support for other architectures
// might need some sort of disambiguation to be exported
let (fn_name, bytes) = match (&self.ast_context[ctype].kind, len) {
Expand All @@ -296,17 +292,10 @@ impl<'c> Translation<'c> {
(Double, 4) => ("_mm256_setzero_pd", 32),
(Char, 16) | (Int, 4) | (LongLong, 2) => ("_mm_setzero_si128", 16),
(Char, 32) | (Int, 8) | (LongLong, 4) => ("_mm256_setzero_si256", 32),
(Char, 8) | (Int, 2) | (LongLong, 1) => {
// __m64 is still unstable as of rust 1.29
self.use_feature("stdsimd");

("_mm_setzero_si64", 8)
}
(kind, len) => Err(format_err!(
"Unsupported vector default initializer: {:?} x {}",
kind,
len
))?,
(Char, 8) | (Int, 2) | (LongLong, 1) =>
bail!("__m64 and MMX are no longer supported, due to removed upstream support. See https://github.com/immunant/c2rust/issues/369"),
(kind, len) =>
bail!("Unsupported vector default initializer: {:?} x {}", kind, len),
};

if is_static {
Expand Down