Skip to content

Commit 42d03f6

Browse files
committed
Add support for more SIMD intrinsics
1 parent bcc5a1c commit 42d03f6

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

build_system/src/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
136136
&"build",
137137
&"--target",
138138
&config.target,
139+
// TODO: remove this feature?
139140
&"--features",
140141
&"std/compiler-builtins-no-f16-f128",
141142
];

src/intrinsic/simd.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -739,11 +739,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
739739
return Err(());
740740
}};
741741
}
742-
let (elem_ty_str, elem_ty) = if let ty::Float(ref f) = *in_elem.kind() {
742+
let (elem_ty_str, elem_ty, cast_type) = if let ty::Float(ref f) = *in_elem.kind() {
743743
let elem_ty = bx.cx.type_float_from_ty(*f);
744744
match f.bit_width() {
745-
32 => ("f", elem_ty),
746-
64 => ("", elem_ty),
745+
16 => ("", elem_ty, Some(bx.cx.double_type)),
746+
32 => ("f", elem_ty, None),
747+
64 => ("", elem_ty, None),
747748
_ => {
748749
return_error!(InvalidMonomorphization::FloatingPointVector {
749750
span,
@@ -787,17 +788,28 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
787788
for i in 0..in_len {
788789
let index = bx.context.new_rvalue_from_long(bx.ulong_type, i as i64);
789790
// we have to treat fpowi specially, since fpowi's second argument is always an i32
790-
let arguments = if name == sym::simd_fpowi {
791-
vec![
791+
let mut arguments = vec![];
792+
if name == sym::simd_fpowi {
793+
arguments = vec![
792794
bx.extract_element(args[0].immediate(), index).to_rvalue(),
793795
args[1].immediate(),
794-
]
796+
];
795797
} else {
796-
args.iter()
797-
.map(|arg| bx.extract_element(arg.immediate(), index).to_rvalue())
798-
.collect()
798+
for arg in args {
799+
let mut element = bx.extract_element(arg.immediate(), index).to_rvalue();
800+
// FIXME: it would probably be better to not have casts here and use the proper
801+
// instructions.
802+
if let Some(typ) = cast_type {
803+
element = bx.context.new_cast(None, element, typ);
804+
}
805+
arguments.push(element);
806+
}
799807
};
800-
vector_elements.push(bx.context.new_call(None, function, &arguments));
808+
let mut result = bx.context.new_call(None, function, &arguments);
809+
if cast_type.is_some() {
810+
result = bx.context.new_cast(None, result, elem_ty);
811+
}
812+
vector_elements.push(result);
801813
}
802814
let c = bx.context.new_rvalue_from_vector(None, vec_ty, &vector_elements);
803815
Ok(c)

0 commit comments

Comments
 (0)