Mercurial > projects > ldc
changeset 1480:b3ba2c6ff038
Use `llvm.memset` instead of `_d_array_init_i1` and `_d_array_init_i8`.
This exposes what's happening to LLVM, and memset is probably faster than the
runtime functions we were using anyway.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sun, 07 Jun 2009 13:57:59 +0200 |
parents | 4f7d50c744ed |
children | e0f03e11cdf8 |
files | gen/arrays.cpp gen/tollvm.cpp gen/tollvm.h runtime/internal/arrayInit.d |
diffstat | 4 files changed, 22 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/gen/arrays.cpp Sat Jun 06 20:16:13 2009 +0200 +++ b/gen/arrays.cpp Sun Jun 07 13:57:59 2009 +0200 @@ -112,15 +112,16 @@ switch (arrayelemty->ty) { case Tbool: - funcname = "_d_array_init_i1"; - break; + val = gIR->ir->CreateZExt(val, LLType::Int8Ty, ".bool"); + // fall through case Tvoid: case Tchar: case Tint8: case Tuns8: - funcname = "_d_array_init_i8"; - break; + Logger::println("Using memset for array init"); + DtoMemSet(ptr, val, dim); + return; case Twchar: case Tint16:
--- a/gen/tollvm.cpp Sat Jun 06 20:16:13 2009 +0200 +++ b/gen/tollvm.cpp Sun Jun 07 13:57:59 2009 +0200 @@ -411,7 +411,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoMemSetZero(LLValue* dst, LLValue* nbytes) +void DtoMemSet(LLValue* dst, LLValue* val, LLValue* nbytes) { dst = DtoBitCast(dst,getVoidPtrType()); @@ -419,7 +419,14 @@ llvm::Function* fn = llvm::Intrinsic::getDeclaration(gIR->module, llvm::Intrinsic::memset, &intTy, 1); - gIR->ir->CreateCall4(fn, dst, DtoConstUbyte(0), nbytes, DtoConstUint(0), ""); + gIR->ir->CreateCall4(fn, dst, val, nbytes, DtoConstUint(0), ""); +} + +////////////////////////////////////////////////////////////////////////////////////////// + +void DtoMemSetZero(LLValue* dst, LLValue* nbytes) +{ + DtoMemSet(dst, DtoConstUbyte(0), nbytes); } //////////////////////////////////////////////////////////////////////////////////////////
--- a/gen/tollvm.h Sat Jun 06 20:16:13 2009 +0200 +++ b/gen/tollvm.h Sun Jun 07 13:57:59 2009 +0200 @@ -112,6 +112,14 @@ /** * Generates a call to llvm.memset.i32 (or i64 depending on architecture). * @param dst Destination memory. + * @param val The value to set. + * @param nbytes Number of bytes to overwrite. + */ +void DtoMemSet(LLValue* dst, LLValue* val, LLValue* nbytes); + +/** + * Generates a call to llvm.memset.i32 (or i64 depending on architecture). + * @param dst Destination memory. * @param nbytes Number of bytes to overwrite. */ void DtoMemSetZero(LLValue* dst, LLValue* nbytes);
--- a/runtime/internal/arrayInit.d Sat Jun 06 20:16:13 2009 +0200 +++ b/runtime/internal/arrayInit.d Sun Jun 07 13:57:59 2009 +0200 @@ -12,22 +12,6 @@ // per-element array init routines -void _d_array_init_i1(bool* a, size_t n, bool v) -{ - auto p = a; - auto end = a+n; - while (p !is end) - *p++ = v; -} - -void _d_array_init_i8(ubyte* a, size_t n, ubyte v) -{ - auto p = a; - auto end = a+n; - while (p !is end) - *p++ = v; -} - void _d_array_init_i16(ushort* a, size_t n, ushort v) { auto p = a;