about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-01-17 15:51:45 -0800
committerNiko Matsakis <niko@alum.mit.edu>2012-01-17 20:21:09 -0800
commit31b25d81eb9efb392a0bd3b55d1387ff7724d0fe (patch)
tree39af743bbbbe05b8056ff879167bde6bfd1d12fc
parent7bc2930cfaa1f4f5bf883b4df23b09cbb6fe6e27 (diff)
use 64-bit memset on 64-bit platforms. Fixes #1546. Fixes #843.
Actually, we don't "fix" #843 so much as close it: as with memmove,
we simply use an alignment of 1 with dynamically sized types.
-rw-r--r--src/comp/middle/trans.rs34
1 files changed, 12 insertions, 22 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index c9591340d9f..f709ddb56bd 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -1944,24 +1944,6 @@ fn call_memmove(cx: @block_ctxt, dst: ValueRef, src: ValueRef,
     ret rslt(cx, ret_val);
 }
 
-fn call_bzero(cx: @block_ctxt, dst: ValueRef, n_bytes: ValueRef,
-              align_bytes: ValueRef) -> result {
-    // FIXME: switch to the 64-bit variant when on such a platform.
-    let ccx = bcx_ccx(cx);
-    let i = ccx.intrinsics;
-    assert (i.contains_key("llvm.memset.p0i8.i32"));
-    let memset = i.get("llvm.memset.p0i8.i32");
-    let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8()));
-    let size = IntCast(cx, n_bytes, T_i32());
-    let align =
-        if lib::llvm::llvm::LLVMIsConstant(align_bytes) == True {
-            IntCast(cx, align_bytes, T_i32())
-        } else { IntCast(cx, C_int(ccx, 0), T_i32()) };
-    let volatile = C_bool(false);
-    ret rslt(cx,
-             Call(cx, memset, [dst_ptr, C_u8(0u), size, align, volatile]));
-}
-
 fn memmove_ty(bcx: @block_ctxt, dst: ValueRef, src: ValueRef, t: ty::t) ->
     @block_ctxt {
     let ccx = bcx_ccx(bcx);
@@ -3985,10 +3967,18 @@ fn zero_alloca(cx: @block_ctxt, llptr: ValueRef, t: ty::t)
         let llty = type_of(ccx, sp, t);
         Store(bcx, C_null(llty), llptr);
     } else {
-        let llsz = size_of(bcx, t);
-        // FIXME passing in the align here is correct, but causes issue #843
-        // let llalign = align_of(llsz.bcx, t);
-        bcx = call_bzero(llsz.bcx, llptr, llsz.val, C_int(ccx, 0)).bcx;
+        let key = alt ccx.sess.targ_cfg.arch {
+          session::arch_x86. | session::arch_arm. { "llvm.memset.p0i8.i32" }
+          session::arch_x86_64. { "llvm.memset.p0i8.i64" }
+        };
+        let i = ccx.intrinsics;
+        let memset = i.get(key);
+        let dst_ptr = PointerCast(cx, llptr, T_ptr(T_i8()));
+        let size = size_of(cx, t);
+        bcx = size.bcx;
+        let align = C_i32(1i32); // cannot use computed value here.
+        let volatile = C_bool(false);
+        Call(cx, memset, [dst_ptr, C_u8(0u), size.val, align, volatile]);
     }
     ret bcx;
 }