1
Fork 0

Merge pull request #149 from rust-lang/missing-comments

Add support for target builtins
This commit is contained in:
antoyo 2022-03-29 22:51:00 -04:00 committed by GitHub
commit a445bcb53d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View file

@ -231,6 +231,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
} }
else { else {
assert!(!((actual_ty.is_vector() && !expected_ty.is_vector()) || (!actual_ty.is_vector() && expected_ty.is_vector())), "{:?} ({}) -> {:?} ({}), index: {:?}[{}]", actual_ty, actual_ty.is_vector(), expected_ty, expected_ty.is_vector(), func_ptr, index); assert!(!((actual_ty.is_vector() && !expected_ty.is_vector()) || (!actual_ty.is_vector() && expected_ty.is_vector())), "{:?} ({}) -> {:?} ({}), index: {:?}[{}]", actual_ty, actual_ty.is_vector(), expected_ty, expected_ty.is_vector(), func_ptr, index);
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
self.bitcast(actual_val, expected_ty) self.bitcast(actual_val, expected_ty)
} }
} }
@ -1320,11 +1321,13 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
if vec_num_units < mask_num_units { if vec_num_units < mask_num_units {
// NOTE: the mask needs to be the same length as the input vectors, so join the 2 // NOTE: the mask needs to be the same length as the input vectors, so join the 2
// vectors and create a dummy second vector. // vectors and create a dummy second vector.
// TODO(antoyo): switch to using new_vector_access.
let array = self.context.new_bitcast(None, v1, array_type); let array = self.context.new_bitcast(None, v1, array_type);
let mut elements = vec![]; let mut elements = vec![];
for i in 0..vec_num_units { for i in 0..vec_num_units {
elements.push(self.context.new_array_access(None, array, self.context.new_rvalue_from_int(self.int_type, i as i32)).to_rvalue()); elements.push(self.context.new_array_access(None, array, self.context.new_rvalue_from_int(self.int_type, i as i32)).to_rvalue());
} }
// TODO(antoyo): switch to using new_vector_access.
let array = self.context.new_bitcast(None, v2, array_type); let array = self.context.new_bitcast(None, v2, array_type);
for i in 0..vec_num_units { for i in 0..vec_num_units {
elements.push(self.context.new_array_access(None, array, self.context.new_rvalue_from_int(self.int_type, i as i32)).to_rvalue()); elements.push(self.context.new_array_access(None, array, self.context.new_rvalue_from_int(self.int_type, i as i32)).to_rvalue());
@ -1347,6 +1350,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
// NOTE: if padding was added, only select the number of elements of the masks to // NOTE: if padding was added, only select the number of elements of the masks to
// remove that padding in the result. // remove that padding in the result.
let mut elements = vec![]; let mut elements = vec![];
// TODO(antoyo): switch to using new_vector_access.
let array = self.context.new_bitcast(None, result, array_type); let array = self.context.new_bitcast(None, result, array_type);
for i in 0..mask_num_units { for i in 0..mask_num_units {
elements.push(self.context.new_array_access(None, array, self.context.new_rvalue_from_int(self.int_type, i as i32)).to_rvalue()); elements.push(self.context.new_array_access(None, array, self.context.new_rvalue_from_int(self.int_type, i as i32)).to_rvalue());

View file

@ -156,6 +156,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
if a_type != b_type { if a_type != b_type {
if a_type.is_vector() { if a_type.is_vector() {
// Vector types need to be bitcast. // Vector types need to be bitcast.
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
b = self.context.new_bitcast(None, b, a.get_type()); b = self.context.new_bitcast(None, b, a.get_type());
} }
else { else {
@ -649,8 +650,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
// Since u128 and i128 are the only types that can be unsupported, we know the type of // Since u128 and i128 are the only types that can be unsupported, we know the type of
// value and the destination type have the same size, so a bitcast is fine. // value and the destination type have the same size, so a bitcast is fine.
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting. (This is elsewhere, // TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
// though.)
self.context.new_bitcast(None, value, dest_typ) self.context.new_bitcast(None, value, dest_typ)
} }
} }

View file

@ -203,12 +203,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
let param1_type = builtin.get_param(0).to_rvalue().get_type(); let param1_type = builtin.get_param(0).to_rvalue().get_type();
let vector = let vector =
if vector.get_type() != param1_type { if vector.get_type() != param1_type {
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
bx.context.new_bitcast(None, vector, param1_type) bx.context.new_bitcast(None, vector, param1_type)
} }
else { else {
vector vector
}; };
let result = bx.context.new_call(None, builtin, &[vector, value, bx.context.new_cast(None, index, bx.int_type)]); let result = bx.context.new_call(None, builtin, &[vector, value, bx.context.new_cast(None, index, bx.int_type)]);
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
return Ok(bx.context.new_bitcast(None, result, vector.get_type())); return Ok(bx.context.new_bitcast(None, result, vector.get_type()));
} }
if name == sym::simd_extract { if name == sym::simd_extract {
@ -277,6 +279,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
let vector_type = bx.context.new_vector_type(out_type, 8); let vector_type = bx.context.new_vector_type(out_type, 8);
let vector = args[0].immediate(); let vector = args[0].immediate();
let array_type = bx.context.new_array_type(None, in_type, 8); let array_type = bx.context.new_array_type(None, in_type, 8);
// TODO(antoyo): switch to using new_vector_access or __builtin_convertvector for vector casting.
let array = bx.context.new_bitcast(None, vector, array_type); let array = bx.context.new_bitcast(None, vector, array_type);
let cast_vec_element = |index| { let cast_vec_element = |index| {
@ -533,6 +536,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
let func = bx.context.get_target_builtin_function(builtin_name); let func = bx.context.get_target_builtin_function(builtin_name);
let result = bx.context.new_call(None, func, &[lhs, rhs]); let result = bx.context.new_call(None, func, &[lhs, rhs]);
// TODO(antoyo): perhaps use __builtin_convertvector for vector casting.
return Ok(bx.context.new_bitcast(None, result, vec_ty)); return Ok(bx.context.new_bitcast(None, result, vec_ty));
} }