Skip to content

Commit ba7404a

Browse files
authored
Merge pull request #1457 from uweigand/simd-endian
Fix simd_select_bitmask on big-endian systems
2 parents 2768789 + b886be1 commit ba7404a

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)