mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
add simd_bswap and simd_bitreverse
This commit is contained in:
parent
31ea5181b6
commit
2903f1c322
@ -29,6 +29,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
|
||||
| "fsqrt"
|
||||
| "ctlz"
|
||||
| "cttz"
|
||||
| "bswap"
|
||||
| "bitreverse"
|
||||
=> {
|
||||
let [op] = check_arg_count(args)?;
|
||||
let (op, op_len) = this.operand_to_simd(op)?;
|
||||
@ -54,6 +56,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
|
||||
"trunc" => Op::Round(rustc_apfloat::Round::TowardZero),
|
||||
"ctlz" => Op::Numeric(sym::ctlz),
|
||||
"cttz" => Op::Numeric(sym::cttz),
|
||||
"bswap" => Op::Numeric(sym::bswap),
|
||||
"bitreverse" => Op::Numeric(sym::bitreverse),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
@ -116,6 +120,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
|
||||
let bits_out = match name {
|
||||
sym::ctlz => u128::from(bits.leading_zeros()).checked_sub(extra).unwrap(),
|
||||
sym::cttz => u128::from((bits << extra).trailing_zeros()).checked_sub(extra).unwrap(),
|
||||
sym::bswap => (bits << extra).swap_bytes(),
|
||||
sym::bitreverse => (bits << extra).reverse_bits(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
Scalar::from_uint(bits_out, size)
|
||||
|
@ -202,6 +202,19 @@ fn simd_ops_i32() {
|
||||
assert_eq!(b.trailing_zeros(), u32x4::from_array([0, 1, 0, 2]));
|
||||
assert_eq!(b.leading_ones(), u32x4::from_array([0, 0, 0, 30]));
|
||||
assert_eq!(b.trailing_ones(), u32x4::from_array([1, 0, 2, 0]));
|
||||
assert_eq!(
|
||||
b.swap_bytes(),
|
||||
i32x4::from_array([0x01000000, 0x02000000, 0x03000000, 0xfcffffffu32 as i32])
|
||||
);
|
||||
assert_eq!(
|
||||
b.reverse_bits(),
|
||||
i32x4::from_array([
|
||||
0x80000000u32 as i32,
|
||||
0x40000000,
|
||||
0xc0000000u32 as i32,
|
||||
0x3fffffffu32 as i32
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
fn simd_mask() {
|
||||
|
Loading…
Reference in New Issue
Block a user