mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-04 17:11:44 +03:00
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:
parent
1958e17734
commit
f79e40a491
4 changed files with 22 additions and 22 deletions
|
@ -112,15 +112,16 @@ void DtoArrayInit(Loc& loc, DValue* array, DValue* value)
|
|||
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:
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
@ -419,7 +419,14 @@ void DtoMemSetZero(LLValue* dst, LLValue* nbytes)
|
|||
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);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -109,6 +109,14 @@ LLValue* DtoAggrPair(LLValue* V1, LLValue* V2, const char* name = 0);
|
|||
LLValue* DtoAggrPaint(LLValue* aggr, const LLType* as);
|
||||
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).
|
||||
* @param dst Destination memory.
|
||||
|
|
|
@ -12,22 +12,6 @@ alias llvm_memcpy_i32 llvm_memcpy;
|
|||
|
||||
// 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue