about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-02-19 14:38:00 +0100
committerGitHub <noreply@github.com>2024-02-19 14:38:00 +0100
commitba7404a2934041c95e540dfe6d74a8492e7c1896 (patch)
tree20c9269c41313c16150474fa1af80dd39fac5df3
parent2768789b20286104501a69f0078f5a088bcc3a6d (diff)
parentb886be124d5bcbc242cb1f6f6a29c9fbaa577272 (diff)
downloadrust-ba7404a2934041c95e540dfe6d74a8492e7c1896.tar.gz
rust-ba7404a2934041c95e540dfe6d74a8492e7c1896.zip
Merge pull request #1457 from uweigand/simd-endian
Fix simd_select_bitmask on big-endian systems
-rw-r--r--src/intrinsics/simd.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs
index ebdc744bcd8..a5490bd091b 100644
--- a/src/intrinsics/simd.rs
+++ b/src/intrinsics/simd.rs
@@ -853,7 +853,13 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
             };
 
             for lane in 0..lane_count {
-                let m_lane = fx.bcx.ins().ushr_imm(m, u64::from(lane) as i64);
+                // The bit order of the mask depends on the byte endianness, LSB-first for
+                // little endian and MSB-first for big endian.
+                let mask_lane = match fx.tcx.sess.target.endian {
+                    Endian::Big => lane_count - 1 - lane,
+                    Endian::Little => lane,
+                };
+                let m_lane = fx.bcx.ins().ushr_imm(m, u64::from(mask_lane) as i64);
                 let m_lane = fx.bcx.ins().band_imm(m_lane, 1);
                 let a_lane = a.value_lane(fx, lane).load_scalar(fx);
                 let b_lane = b.value_lane(fx, lane).load_scalar(fx);