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.
This commit is contained in:
Frits van Bommel 2009-06-07 13:57:59 +02:00
parent 1958e17734
commit f79e40a491
4 changed files with 22 additions and 22 deletions

View file

@ -112,15 +112,16 @@ void DtoArrayInit(Loc& loc, DValue* array, DValue* value)
switch (arrayelemty->ty) switch (arrayelemty->ty)
{ {
case Tbool: case Tbool:
funcname = "_d_array_init_i1"; val = gIR->ir->CreateZExt(val, LLType::Int8Ty, ".bool");
break; // fall through
case Tvoid: case Tvoid:
case Tchar: case Tchar:
case Tint8: case Tint8:
case Tuns8: case Tuns8:
funcname = "_d_array_init_i8"; Logger::println("Using memset for array init");
break; DtoMemSet(ptr, val, dim);
return;
case Twchar: case Twchar:
case Tint16: case Tint16:

View file

@ -411,7 +411,7 @@ LLConstant* DtoGEPi(LLConstant* ptr, unsigned i0, unsigned i1)
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
void DtoMemSetZero(LLValue* dst, LLValue* nbytes) void DtoMemSet(LLValue* dst, LLValue* val, LLValue* nbytes)
{ {
dst = DtoBitCast(dst,getVoidPtrType()); dst = DtoBitCast(dst,getVoidPtrType());
@ -419,7 +419,14 @@ void DtoMemSetZero(LLValue* dst, LLValue* nbytes)
llvm::Function* fn = llvm::Intrinsic::getDeclaration(gIR->module, llvm::Function* fn = llvm::Intrinsic::getDeclaration(gIR->module,
llvm::Intrinsic::memset, &intTy, 1); 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);
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////

View file

@ -109,6 +109,14 @@ LLValue* DtoAggrPair(LLValue* V1, LLValue* V2, const char* name = 0);
LLValue* DtoAggrPaint(LLValue* aggr, const LLType* as); LLValue* DtoAggrPaint(LLValue* aggr, const LLType* as);
LLValue* DtoAggrPairSwap(LLValue* aggr); LLValue* DtoAggrPairSwap(LLValue* aggr);
/**
* 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). * Generates a call to llvm.memset.i32 (or i64 depending on architecture).
* @param dst Destination memory. * @param dst Destination memory.

View file

@ -12,22 +12,6 @@ alias llvm_memcpy_i32 llvm_memcpy;
// per-element array init routines // 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) void _d_array_init_i16(ushort* a, size_t n, ushort v)
{ {
auto p = a; auto p = a;