about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAntoni Boucher <bouanto@zoho.com>2024-09-07 20:02:24 -0400
committerAntoni Boucher <bouanto@zoho.com>2024-09-07 20:02:24 -0400
commit42d03f6633e3ebc939d3d04d7605301f99d22a54 (patch)
tree6c53bd4b76ca6bcf6df9a87b2e46b69b35a69ed1
parentbcc5a1c77e7453445040184b8879e9fb49f9adb0 (diff)
downloadrust-42d03f6633e3ebc939d3d04d7605301f99d22a54.tar.gz
rust-42d03f6633e3ebc939d3d04d7605301f99d22a54.zip
Add support for more SIMD intrinsics
-rw-r--r--build_system/src/build.rs1
-rw-r--r--src/intrinsic/simd.rs32
2 files changed, 23 insertions, 10 deletions
diff --git a/build_system/src/build.rs b/build_system/src/build.rs
index d96683afa35..d5d099fb14c 100644
--- a/build_system/src/build.rs
+++ b/build_system/src/build.rs
@@ -136,6 +136,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
         &"build",
         &"--target",
         &config.target,
+        // TODO: remove this feature?
         &"--features",
         &"std/compiler-builtins-no-f16-f128",
     ];
diff --git a/src/intrinsic/simd.rs b/src/intrinsic/simd.rs
index a0d8ff6346f..79b345982c6 100644
--- a/src/intrinsic/simd.rs
+++ b/src/intrinsic/simd.rs
@@ -739,11 +739,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
                 return Err(());
             }};
         }
-        let (elem_ty_str, elem_ty) = if let ty::Float(ref f) = *in_elem.kind() {
+        let (elem_ty_str, elem_ty, cast_type) = if let ty::Float(ref f) = *in_elem.kind() {
             let elem_ty = bx.cx.type_float_from_ty(*f);
             match f.bit_width() {
-                32 => ("f", elem_ty),
-                64 => ("", elem_ty),
+                16 => ("", elem_ty, Some(bx.cx.double_type)),
+                32 => ("f", elem_ty, None),
+                64 => ("", elem_ty, None),
                 _ => {
                     return_error!(InvalidMonomorphization::FloatingPointVector {
                         span,
@@ -787,17 +788,28 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
         for i in 0..in_len {
             let index = bx.context.new_rvalue_from_long(bx.ulong_type, i as i64);
             // we have to treat fpowi specially, since fpowi's second argument is always an i32
-            let arguments = if name == sym::simd_fpowi {
-                vec![
+            let mut arguments = vec![];
+            if name == sym::simd_fpowi {
+                arguments = vec![
                     bx.extract_element(args[0].immediate(), index).to_rvalue(),
                     args[1].immediate(),
-                ]
+                ];
             } else {
-                args.iter()
-                    .map(|arg| bx.extract_element(arg.immediate(), index).to_rvalue())
-                    .collect()
+                for arg in args {
+                    let mut element = bx.extract_element(arg.immediate(), index).to_rvalue();
+                    // FIXME: it would probably be better to not have casts here and use the proper
+                    // instructions.
+                    if let Some(typ) = cast_type {
+                        element = bx.context.new_cast(None, element, typ);
+                    }
+                    arguments.push(element);
+                }
             };
-            vector_elements.push(bx.context.new_call(None, function, &arguments));
+            let mut result = bx.context.new_call(None, function, &arguments);
+            if cast_type.is_some() {
+                result = bx.context.new_cast(None, result, elem_ty);
+            }
+            vector_elements.push(result);
         }
         let c = bx.context.new_rvalue_from_vector(None, vec_ty, &vector_elements);
         Ok(c)