about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2015-07-29 22:18:39 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2015-07-29 22:18:39 +0200
commit21be09448b21c25570f28ddd597f3d30ccc6fabf (patch)
tree27bd67e2f8d59e33b8e4e4169a65b6e822cc1a19 /src
parent26f4ebe7a0b166cbfb04f6e8df16cb799f81058b (diff)
downloadrust-21be09448b21c25570f28ddd597f3d30ccc6fabf.tar.gz
rust-21be09448b21c25570f28ddd597f3d30ccc6fabf.zip
Improve code emitted for inserting padding before unsized field.
Hat-tip to eddyb for the appropriate bit-trickery here.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trans/trans/glue.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/librustc_trans/trans/glue.rs b/src/librustc_trans/trans/glue.rs
index 91b20f0b9de..18fedda4919 100644
--- a/src/librustc_trans/trans/glue.rs
+++ b/src/librustc_trans/trans/glue.rs
@@ -475,21 +475,13 @@ pub fn size_and_align_of_dst<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, t: Ty<'tcx>, in
             //
             //   `size + ((size & (align-1)) ? align : 0)`
             //
-            // Currently I am emulating the above via:
+            // emulated via the semi-standard fast bit trick:
             //
-            //   `size + ((size & (align-1)) * align-(size & (align-1)))`
-            //
-            // because I am not sure which is cheaper between a branch
-            // or a multiply.
-
-            let mask = Sub(bcx, align, C_uint(bcx.ccx(), 1_u64), dbloc);
-            let lowbits = And(bcx, size, mask, DebugLoc::None);
-            let nonzero = ICmp(bcx, llvm::IntNE, lowbits, C_uint(bcx.ccx(), 0_u64), dbloc);
-            let add_size = Mul(bcx,
-                               ZExt(bcx, nonzero, Type::i64(bcx.ccx())),
-                               Sub(bcx, align, lowbits, dbloc),
-                               dbloc);
-            let size = Add(bcx, size, add_size, dbloc);
+            //   `(size + (align-1)) & !align`
+
+            let addend = Sub(bcx, align, C_uint(bcx.ccx(), 1_u64), dbloc);
+            let size = And(
+                bcx, Add(bcx, size, addend, dbloc), Neg(bcx, align, dbloc), dbloc);
 
             (size, align)
         }