Skip to content

Commit b886be1

Browse files
committed
Fix simd_select_bitmask on big-endian systems
The mask input for simd_select_bitmask depends on the host byteorder in the same way as the mask output of simd_bitmask does. Fix the implementation to work on both big- and little-endian systems.
1 parent e4584e8 commit b886be1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/intrinsics/simd.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,13 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
853853
};
854854

855855
for lane in 0..lane_count {
856-
let m_lane = fx.bcx.ins().ushr_imm(m, u64::from(lane) as i64);
856+
// The bit order of the mask depends on the byte endianness, LSB-first for
857+
// little endian and MSB-first for big endian.
858+
let mask_lane = match fx.tcx.sess.target.endian {
859+
Endian::Big => lane_count - 1 - lane,
860+
Endian::Little => lane,
861+
};
862+
let m_lane = fx.bcx.ins().ushr_imm(m, u64::from(mask_lane) as i64);
857863
let m_lane = fx.bcx.ins().band_imm(m_lane, 1);
858864
let a_lane = a.value_lane(fx, lane).load_scalar(fx);
859865
let b_lane = b.value_lane(fx, lane).load_scalar(fx);

0 commit comments

Comments
 (0)