1
Fork 0

Add support for more SIMD intrinsics

This commit is contained in:
Antoni Boucher 2024-09-07 20:02:24 -04:00
parent bcc5a1c77e
commit 42d03f6633
2 changed files with 23 additions and 10 deletions

View file

@ -136,6 +136,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
&"build", &"build",
&"--target", &"--target",
&config.target, &config.target,
// TODO: remove this feature?
&"--features", &"--features",
&"std/compiler-builtins-no-f16-f128", &"std/compiler-builtins-no-f16-f128",
]; ];

View file

@ -739,11 +739,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
return Err(()); 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); let elem_ty = bx.cx.type_float_from_ty(*f);
match f.bit_width() { match f.bit_width() {
32 => ("f", elem_ty), 16 => ("", elem_ty, Some(bx.cx.double_type)),
64 => ("", elem_ty), 32 => ("f", elem_ty, None),
64 => ("", elem_ty, None),
_ => { _ => {
return_error!(InvalidMonomorphization::FloatingPointVector { return_error!(InvalidMonomorphization::FloatingPointVector {
span, span,
@ -787,17 +788,28 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
for i in 0..in_len { for i in 0..in_len {
let index = bx.context.new_rvalue_from_long(bx.ulong_type, i as i64); 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 // we have to treat fpowi specially, since fpowi's second argument is always an i32
let arguments = if name == sym::simd_fpowi { let mut arguments = vec![];
vec![ if name == sym::simd_fpowi {
arguments = vec![
bx.extract_element(args[0].immediate(), index).to_rvalue(), bx.extract_element(args[0].immediate(), index).to_rvalue(),
args[1].immediate(), args[1].immediate(),
] ];
} else { } else {
args.iter() for arg in args {
.map(|arg| bx.extract_element(arg.immediate(), index).to_rvalue()) let mut element = bx.extract_element(arg.immediate(), index).to_rvalue();
.collect() // 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); let c = bx.context.new_rvalue_from_vector(None, vec_ty, &vector_elements);
Ok(c) Ok(c)