-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Dellvmize some intrinsics (use u32
instead of Self
in some integer intrinsics)
#124003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ceead1b
e4a854e
7ce867f
c2046c4
4b6bbcb
c0b5cc9
468179c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,7 +173,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
let ty = instance_args.type_at(0); | ||
let layout = self.layout_of(ty)?; | ||
let val = self.read_scalar(&args[0])?; | ||
let out_val = self.numeric_intrinsic(intrinsic_name, val, layout)?; | ||
|
||
let out_val = self.numeric_intrinsic(intrinsic_name, val, layout, dest.layout)?; | ||
self.write_scalar(out_val, dest)?; | ||
} | ||
sym::saturating_add | sym::saturating_sub => { | ||
|
@@ -200,21 +201,24 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
sym::rotate_left | sym::rotate_right => { | ||
// rotate_left: (X << (S % BW)) | (X >> ((BW - S) % BW)) | ||
// rotate_right: (X << ((BW - S) % BW)) | (X >> (S % BW)) | ||
let layout = self.layout_of(instance_args.type_at(0))?; | ||
let layout_val = self.layout_of(instance_args.type_at(0))?; | ||
let val = self.read_scalar(&args[0])?; | ||
let val_bits = val.to_bits(layout.size)?; | ||
let val_bits = val.to_bits(layout_val.size)?; | ||
|
||
let layout_raw_shift = self.layout_of(self.tcx.types.u32)?; | ||
let raw_shift = self.read_scalar(&args[1])?; | ||
let raw_shift_bits = raw_shift.to_bits(layout.size)?; | ||
let width_bits = u128::from(layout.size.bits()); | ||
let raw_shift_bits = raw_shift.to_bits(layout_raw_shift.size)?; | ||
|
||
let width_bits = u128::from(layout_val.size.bits()); | ||
let shift_bits = raw_shift_bits % width_bits; | ||
let inv_shift_bits = (width_bits - shift_bits) % width_bits; | ||
let result_bits = if intrinsic_name == sym::rotate_left { | ||
(val_bits << shift_bits) | (val_bits >> inv_shift_bits) | ||
} else { | ||
(val_bits >> shift_bits) | (val_bits << inv_shift_bits) | ||
}; | ||
let truncated_bits = self.truncate(result_bits, layout); | ||
let result = Scalar::from_uint(truncated_bits, layout.size); | ||
let truncated_bits = self.truncate(result_bits, layout_val); | ||
let result = Scalar::from_uint(truncated_bits, layout_val.size); | ||
self.write_scalar(result, dest)?; | ||
} | ||
sym::copy => { | ||
|
@@ -472,6 +476,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
name: Symbol, | ||
val: Scalar<M::Provenance>, | ||
layout: TyAndLayout<'tcx>, | ||
ret_layout: TyAndLayout<'tcx>, | ||
) -> InterpResult<'tcx, Scalar<M::Provenance>> { | ||
assert!(layout.ty.is_integral(), "invalid type for numeric intrinsic: {}", layout.ty); | ||
let bits = val.to_bits(layout.size)?; | ||
|
@@ -483,11 +488,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
} | ||
sym::ctlz | sym::ctlz_nonzero => u128::from(bits.leading_zeros()) - extra, | ||
sym::cttz | sym::cttz_nonzero => u128::from((bits << extra).trailing_zeros()) - extra, | ||
sym::bswap => (bits << extra).swap_bytes(), | ||
sym::bitreverse => (bits << extra).reverse_bits(), | ||
sym::bswap => { | ||
assert_eq!(layout, ret_layout); | ||
(bits << extra).swap_bytes() | ||
} | ||
sym::bitreverse => { | ||
assert_eq!(layout, ret_layout); | ||
(bits << extra).reverse_bits() | ||
} | ||
_ => bug!("not a numeric intrinsic: {}", name), | ||
}; | ||
Ok(Scalar::from_uint(bits_out, layout.size)) | ||
Ok(Scalar::from_uint(bits_out, ret_layout.size)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it can ICE when bswap/bitrevere is called with a too small ret_layout. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would that happen though? The intrinsics are defined like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's an extremely non-local invariant. This function here should make sense on its own without worrying about what happens in the standard library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add an assertion that for bswap/bitreverse, the two layouts are the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is true in general with intrinsics, we implicitly depend on their signature in a lot of ways. Either way, I added an assertion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the interpreter and Miri we always have local assertions for these things. |
||
} | ||
|
||
pub fn exact_div( | ||
|
Uh oh!
There was an error while loading. Please reload this page.