about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2023-07-27 23:04:14 -0400
committerCaleb Zulawski <caleb.zulawski@gmail.com>2023-07-27 23:04:14 -0400
commit3ea0e6e3fbdc0bdd84a5669efec7b38c21f84f8e (patch)
treebff3b409a7cf84a2db561dba1afacbc6d00e4ef7 /compiler/rustc_codegen_llvm/src
parent0eb5efc7ae7479367c3d4567465cb042df176e71 (diff)
downloadrust-3ea0e6e3fbdc0bdd84a5669efec7b38c21f84f8e.tar.gz
rust-3ea0e6e3fbdc0bdd84a5669efec7b38c21f84f8e.zip
Add simd_bswap intrinsic
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/intrinsic.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs
index 6df1b708ccd..c30cb6801da 100644
--- a/compiler/rustc_codegen_llvm/src/intrinsic.rs
+++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs
@@ -2074,6 +2074,28 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
         simd_neg: Int => neg, Float => fneg;
     }
 
+    if name == sym::simd_bswap {
+        let vec_ty = bx.cx.type_vector(
+            match *in_elem.kind() {
+                ty::Int(i) => bx.cx.type_int_from_ty(i),
+                ty::Uint(i) => bx.cx.type_uint_from_ty(i),
+                _ => return_error!(InvalidMonomorphization::UnsupportedOperation {
+                    span,
+                    name,
+                    in_ty,
+                    in_elem
+                }),
+            },
+            in_len as u64,
+        );
+        let llvm_intrinsic =
+            &format!("llvm.bswap.v{}i{}", in_len, in_elem.int_size_and_signed(bx.tcx()).0.bits(),);
+        let fn_ty = bx.type_func(&[vec_ty], vec_ty);
+        let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty);
+        let v = bx.call(fn_ty, None, None, f, &[args[0].immediate()], None);
+        return Ok(v);
+    }
+
     if name == sym::simd_arith_offset {
         // This also checks that the first operand is a ptr type.
         let pointee = in_elem.builtin_deref(true).unwrap_or_else(|| {