about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2021-04-29 03:34:28 +0000
committerJubilee Young <workingjubilee@gmail.com>2021-04-30 23:22:27 -0700
commit589fce03131225f9167b6b90c6382f40ea22edb6 (patch)
treea98d1282160da4bb96bbe3dd31aa7c0c676f18ff
parent98dad135268e0da590a162d24da6f7e2d8781648 (diff)
downloadrust-589fce03131225f9167b6b90c6382f40ea22edb6.tar.gz
rust-589fce03131225f9167b6b90c6382f40ea22edb6.zip
Attempt to workaround MIPS bug
-rw-r--r--crates/core_simd/src/masks/full_masks.rs13
-rw-r--r--crates/core_simd/tests/masks.rs4
2 files changed, 14 insertions, 3 deletions
diff --git a/crates/core_simd/src/masks/full_masks.rs b/crates/core_simd/src/masks/full_masks.rs
index bd52a25551e..f89bbefba63 100644
--- a/crates/core_simd/src/masks/full_masks.rs
+++ b/crates/core_simd/src/masks/full_masks.rs
@@ -112,7 +112,18 @@ macro_rules! define_mask {
                     // TODO remove the transmute when rustc is more flexible
                     assert_eq!(core::mem::size_of::<U::IntBitMask>(), core::mem::size_of::<U::BitMask>());
                     let mask: U::IntBitMask = crate::intrinsics::simd_bitmask(self.0);
-                    core::mem::transmute_copy(&mask)
+                    let mut bitmask: U::BitMask = core::mem::transmute_copy(&mask);
+
+                    // There is a bug where LLVM appears to implement this operation with the wrong
+                    // bit order.
+                    // TODO fix this in a better way
+                    if cfg!(any(target_arch = "mips", target_arch = "mips64")) {
+                        for x in bitmask.as_mut() {
+                            *x = x.reverse_bits();
+                        }
+                    }
+
+                    bitmask
                 }
             }
         }
diff --git a/crates/core_simd/tests/masks.rs b/crates/core_simd/tests/masks.rs
index 54427ec1ec0..7021d58aa54 100644
--- a/crates/core_simd/tests/masks.rs
+++ b/crates/core_simd/tests/masks.rs
@@ -70,10 +70,10 @@ macro_rules! test_mask_api {
             fn to_bitmask() {
                 let values = [
                     true, false, false, true, false, false, true, false,
-                    false, false, false, false, false, false, false, false,
+                    true, true, false, false, false, false, false, true,
                 ];
                 let mask = core_simd::$name::<16>::from_array(values);
-                assert_eq!(mask.to_bitmask(), [0b01001001, 0]);
+                assert_eq!(mask.to_bitmask(), [0b01001001, 0b10000011]);
             }
         }
     }