add memset32/memset64
This commit is contained in:
parent
2eaa5dbb60
commit
d9c0f0f188
@ -897,6 +897,32 @@ pub fn trans_intrinsic(ccx: @CrateContext,
|
||||
let llfn = *bcx.ccx().intrinsics.get(&~"llvm.memmove.p0i8.p0i8.i64");
|
||||
Call(bcx, llfn, [dst_ptr, src_ptr, Mul(bcx, size, count), align, volatile]);
|
||||
}
|
||||
~"memset32" => {
|
||||
let tp_ty = substs.tys[0];
|
||||
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
||||
let align = C_i32(machine::llalign_of_min(ccx, lltp_ty) as i32);
|
||||
let size = C_i32(machine::llsize_of_real(ccx, lltp_ty) as i32);
|
||||
|
||||
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), T_ptr(T_i8()));
|
||||
let val = get_param(decl, first_real_arg + 1);
|
||||
let count = get_param(decl, first_real_arg + 2);
|
||||
let volatile = C_i1(false);
|
||||
let llfn = *bcx.ccx().intrinsics.get(&~"llvm.memset.p0i8.i32");
|
||||
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align, volatile]);
|
||||
}
|
||||
~"memset64" => {
|
||||
let tp_ty = substs.tys[0];
|
||||
let lltp_ty = type_of::type_of(ccx, tp_ty);
|
||||
let align = C_i32(machine::llalign_of_min(ccx, lltp_ty) as i32);
|
||||
let size = C_i64(machine::llsize_of_real(ccx, lltp_ty) as i64);
|
||||
|
||||
let dst_ptr = PointerCast(bcx, get_param(decl, first_real_arg), T_ptr(T_i8()));
|
||||
let val = get_param(decl, first_real_arg + 1);
|
||||
let count = get_param(decl, first_real_arg + 2);
|
||||
let volatile = C_i1(false);
|
||||
let llfn = *bcx.ccx().intrinsics.get(&~"llvm.memset.p0i8.i64");
|
||||
Call(bcx, llfn, [dst_ptr, val, Mul(bcx, size, count), align, volatile]);
|
||||
}
|
||||
~"sqrtf32" => {
|
||||
let x = get_param(decl, first_real_arg);
|
||||
let sqrtf = *ccx.intrinsics.get(&~"llvm.sqrt.f32");
|
||||
|
@ -135,7 +135,8 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
|
||||
~"visit_tydesc" | ~"forget" | ~"frame_address" |
|
||||
~"morestack_addr" => 0,
|
||||
|
||||
~"memcpy32" | ~"memcpy64" | ~"memmove32" | ~"memmove64" => use_repr,
|
||||
~"memcpy32" | ~"memcpy64" | ~"memmove32" | ~"memmove64" |
|
||||
~"memset32" | ~"memset64" => use_repr,
|
||||
|
||||
~"sqrtf32" | ~"sqrtf64" | ~"powif32" | ~"powif64" |
|
||||
~"sinf32" | ~"sinf64" | ~"cosf32" | ~"cosf64" |
|
||||
|
@ -3597,6 +3597,30 @@ fn param(ccx: @mut CrateCtxt, n: uint) -> ty::t {
|
||||
],
|
||||
ty::mk_nil())
|
||||
}
|
||||
~"memset32" => {
|
||||
(1,
|
||||
~[
|
||||
ty::mk_ptr(tcx, ty::mt {
|
||||
ty: param(ccx, 0),
|
||||
mutbl: ast::m_mutbl
|
||||
}),
|
||||
ty::mk_u8(),
|
||||
ty::mk_u32()
|
||||
],
|
||||
ty::mk_nil())
|
||||
}
|
||||
~"memset64" => {
|
||||
(1,
|
||||
~[
|
||||
ty::mk_ptr(tcx, ty::mt {
|
||||
ty: param(ccx, 0),
|
||||
mutbl: ast::m_mutbl
|
||||
}),
|
||||
ty::mk_u8(),
|
||||
ty::mk_u64()
|
||||
],
|
||||
ty::mk_nil())
|
||||
}
|
||||
~"sqrtf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
|
||||
~"sqrtf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
|
||||
~"powif32" => {
|
||||
|
@ -19,6 +19,7 @@
|
||||
#[cfg(not(test))] use cmp::{Eq, Ord};
|
||||
use uint;
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub mod libc_ {
|
||||
use libc::c_void;
|
||||
use libc;
|
||||
@ -157,11 +158,26 @@ pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: u
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(stage0)]
|
||||
pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
|
||||
let n = count * sys::size_of::<T>();
|
||||
libc_::memset(dst as *mut c_void, c as libc::c_int, n as size_t);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_word_size = "32", not(stage0))]
|
||||
pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
|
||||
use unstable::intrinsics::memset32;
|
||||
memset32(dst, c, count as u32);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_word_size = "64", not(stage0))]
|
||||
pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
|
||||
use unstable::intrinsics::memset64;
|
||||
memset64(dst, c, count as u64);
|
||||
}
|
||||
|
||||
/**
|
||||
Transform a region pointer - &T - to an unsafe pointer - *T.
|
||||
This is safe, but is implemented with an unsafe block due to
|
||||
@ -603,4 +619,12 @@ fn test_ptr_array_each_null_ptr() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_memory() {
|
||||
let mut xs = [0u8, ..20];
|
||||
let ptr = vec::raw::to_mut_ptr(xs);
|
||||
unsafe { set_memory(ptr, 5u8, xs.len()); }
|
||||
assert_eq!(xs, [5u8, ..20]);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@
|
||||
with atomic types and is equivalent to Java's `volatile`.
|
||||
|
||||
*/
|
||||
|
||||
#[abi = "rust-intrinsic"]
|
||||
pub extern "rust-intrinsic" {
|
||||
|
||||
@ -152,6 +153,15 @@
|
||||
#[cfg(not(stage0))]
|
||||
pub fn memmove64<T>(dst: *mut T, src: *T, count: u64);
|
||||
|
||||
/// Equivalent to the `llvm.memset.p0i8.i32` intrinsic, with a size of
|
||||
/// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
|
||||
#[cfg(not(stage0))]
|
||||
pub fn memset32<T>(dst: *mut T, val: u8, count: u32);
|
||||
/// Equivalent to the `llvm.memset.p0i8.i64` intrinsic, with a size of
|
||||
/// `count` * `size_of::<T>()` and an alignment of `min_align_of::<T>()`
|
||||
#[cfg(not(stage0))]
|
||||
pub fn memset64<T>(dst: *mut T, val: u8, count: u64);
|
||||
|
||||
pub fn sqrtf32(x: f32) -> f32;
|
||||
pub fn sqrtf64(x: f64) -> f64;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user