This commit is contained in:
hyung-hwan 2008-04-25 07:40:41 +00:00
parent 6b1c8efb64
commit b63dc94757

View File

@ -1,5 +1,5 @@
/* /*
* $Id: mem.c 165 2008-04-24 13:34:17Z baconevi $ * $Id: mem.c 166 2008-04-24 13:40:41Z baconevi $
* *
* {License} * {License}
*/ */
@ -65,41 +65,43 @@ void* ase_memset (void* dst, int val, ase_size_t n)
#elif defined(__SPU__) #elif defined(__SPU__)
/* a vector of 16 unsigned char cells */ ase_byte_t* d = (ase_byte_t*)dst;
vector unsigned char v16;
/* a pointer to such a vector */
vector unsigned char* vd;
ase_size_t rem; ase_size_t rem;
/* fills all 16 unsigned char cells with the same value
* no need to use shift and bitwise-or owing to splats */
v16 = spu_splats((ase_byte_t)val);
/* spu SIMD instructions require 16-byte alignment */ /* spu SIMD instructions require 16-byte alignment */
rem = ((ase_size_t)dst) & (ASE_SIZEOF(v16)-1); rem = ((ase_size_t)dst) & (ASE_SIZEOF(vector unsigned char)-1);
if (rem > 0) if (rem > 0)
{ {
ase_byte_t* d = (ase_byte_t*)dst; ase_byte_t* d = (ase_byte_t*)dst;
do { *d++ = (ase_byte_t)val; } do { *d++ = (ase_byte_t)val; }
while (n-- > 0 && ++rem < ASE_SIZEOF(v16)); while (n-- > 0 && ++rem < ASE_SIZEOF(vector unsigned char));
vd = (vector unsigned char*)d;
} }
/* do the vector copy */ /* do the vector copy */
while (n >= ASE_SIZEOF(v16)) if (n >= ASE_SIZEOF(vector unsigned char))
{ {
*vd++ = v16; /* a vector of 16 unsigned char cells */
n += ASE_SIZEOF(v16); vector unsigned char v16;
} /* a pointer to such a vector */
vector unsigned char* vd = (vector unsigned char*)d;
{
/* handle the trailing bytes */ /* fills all 16 unsigned char cells with the same value
ase_byte_t* d = (ase_byte_t*)dst; * no need to use shift and bitwise-or owing to splats */
while (n-- > 0) *d++ = (ase_byte_t)val; v16 = spu_splats((ase_byte_t)val);
do
{
*vd++ = v16;
n += ASE_SIZEOF(vector unsigned char);
}
while (n >= ASE_SIZEOF(vector unsigned char));
d = (ase_byte_t*)vd;
} }
/* handle the trailing parts */
while (n-- > 0) *d++ = (ase_byte_t)val;
return dst; return dst;
#else #else