add memcpy intrinsic to mirror memmove

This commit is contained in:
Daniel Micay
2013-05-23 22:15:31 -04:00
parent 5ba5865e85
commit 7d2f836065
4 changed files with 58 additions and 1 deletions

View File

@@ -845,6 +845,26 @@ pub fn trans_intrinsic(ccx: @CrateContext,
T_ptr(T_nil()));
Store(bcx, morestack_addr, fcx.llretptr.get());
}
~"memcpy32" => {
let dst_ptr = get_param(decl, first_real_arg);
let src_ptr = get_param(decl, first_real_arg + 1);
let size = get_param(decl, first_real_arg + 2);
let align = C_i32(1);
let volatile = C_i1(false);
let llfn = *bcx.ccx().intrinsics.get(
&~"llvm.memcpy.p0i8.p0i8.i32");
Call(bcx, llfn, [dst_ptr, src_ptr, size, align, volatile]);
}
~"memcpy64" => {
let dst_ptr = get_param(decl, first_real_arg);
let src_ptr = get_param(decl, first_real_arg + 1);
let size = get_param(decl, first_real_arg + 2);
let align = C_i32(1);
let volatile = C_i1(false);
let llfn = *bcx.ccx().intrinsics.get(
&~"llvm.memcpy.p0i8.p0i8.i64");
Call(bcx, llfn, [dst_ptr, src_ptr, size, align, volatile]);
}
~"memmove32" => {
let dst_ptr = get_param(decl, first_real_arg);
let src_ptr = get_param(decl, first_real_arg + 1);

View File

@@ -135,7 +135,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
~"visit_tydesc" | ~"forget" | ~"frame_address" |
~"morestack_addr" => 0,
~"memmove32" | ~"memmove64" => 0,
~"memcpy32" | ~"memcpy64" | ~"memmove32" | ~"memmove64" => 0,
~"sqrtf32" | ~"sqrtf64" | ~"powif32" | ~"powif64" |
~"sinf32" | ~"sinf64" | ~"cosf32" | ~"cosf64" |

View File

@@ -3537,6 +3537,36 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
~"morestack_addr" => {
(0u, ~[], ty::mk_nil_ptr(ccx.tcx))
}
~"memcpy32" => {
(0,
~[
ty::mk_ptr(tcx, ty::mt {
ty: ty::mk_u8(),
mutbl: ast::m_mutbl
}),
ty::mk_ptr(tcx, ty::mt {
ty: ty::mk_u8(),
mutbl: ast::m_imm
}),
ty::mk_u32()
],
ty::mk_nil())
}
~"memcpy64" => {
(0,
~[
ty::mk_ptr(tcx, ty::mt {
ty: ty::mk_u8(),
mutbl: ast::m_mutbl
}),
ty::mk_ptr(tcx, ty::mt {
ty: ty::mk_u8(),
mutbl: ast::m_imm
}),
ty::mk_u64()
],
ty::mk_nil())
}
~"memmove32" => {
(0,
~[

View File

@@ -128,6 +128,13 @@ pub extern "rust-intrinsic" {
/// Get the address of the `__morestack` stack growth function.
pub fn morestack_addr() -> *();
/// Equivalent to the `llvm.memcpy.p0i8.0i8.i32` intrinsic.
#[cfg(not(stage0))]
pub fn memcpy32(dst: *mut u8, src: *u8, size: u32);
/// Equivalent to the `llvm.memcpy.p0i8.0i8.i64` intrinsic.
#[cfg(not(stage0))]
pub fn memcpy64(dst: *mut u8, src: *u8, size: u64);
/// Equivalent to the `llvm.memmove.p0i8.0i8.i32` intrinsic.
pub fn memmove32(dst: *mut u8, src: *u8, size: u32);
/// Equivalent to the `llvm.memmove.p0i8.0i8.i64` intrinsic.