about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-01-16 20:23:09 +0000
committerbors <bors@rust-lang.org>2017-01-16 20:23:09 +0000
commit45b273af4a48e9625749286049326abe4fce064c (patch)
treed54cc9fa83e94efce59003079f2d92da5977b953
parent2d0baa71b94e15ac43532987777959edbaee098d (diff)
parentc032bbf95ef733e2316008639ca39492df735ce6 (diff)
downloadrust-45b273af4a48e9625749286049326abe4fce064c.tar.gz
rust-45b273af4a48e9625749286049326abe4fce064c.zip
Auto merge of #39094 - nagisa:i128-fix-endianness, r=eddyb
(Shot at) Fix endian bugs in i128 intrinsic impls

Attempt to fix the endianness issues on big-endian machines such as power pc. Could not test if it actually makes stuff work on the powerpc, because setting up cross-compiler for ppc seems to be nigh-impossible on arch.
-rw-r--r--src/libcompiler_builtins/lib.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/libcompiler_builtins/lib.rs b/src/libcompiler_builtins/lib.rs
index 1bc9b660001..662d7422f5f 100644
--- a/src/libcompiler_builtins/lib.rs
+++ b/src/libcompiler_builtins/lib.rs
@@ -392,7 +392,7 @@ pub mod reimpls {
             self.wrapping_shr(32) as i32
         }
         fn from_parts(low: u32, high: i32) -> i64 {
-            low as i64 | (high as i64).wrapping_shl(32)
+            u64::from_parts(low, high as u32) as i64
         }
     }
     #[cfg(not(stage0))]
@@ -404,11 +404,10 @@ pub mod reimpls {
             self as u64
         }
         fn high(self) -> u64 {
-            unsafe { *(&self as *const u128 as *const u64).offset(1) }
+            self.wrapping_shr(64) as u64
         }
         fn from_parts(low: u64, high: u64) -> u128 {
-            #[repr(C, packed)] struct Parts(u64, u64);
-            unsafe { ::core::mem::transmute(Parts(low, high)) }
+            (high as u128).wrapping_shl(64) | low as u128
         }
     }
     #[cfg(not(stage0))]
@@ -420,7 +419,7 @@ pub mod reimpls {
             self as u64
         }
         fn high(self) -> i64 {
-            unsafe { *(&self as *const i128 as *const i64).offset(1) }
+            self.wrapping_shr(64) as i64
         }
         fn from_parts(low: u64, high: i64) -> i128 {
             u128::from_parts(low, high as u64) as i128