lkml.org 
[lkml]   [2003]   [Aug]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: generic strncpy - off-by-one error


Daniel Forrest wrote:
> On Sat, Aug 16, 2003 at 10:15:14AM +0200, Peter Kjellerstedt wrote:


> Shouldn't this be:
>
> while (tmp & (sizeof(long) - 1)) {
>
>
>> *tmp++ = '\0';
>> count--;
>> }

Oh, yeah! That's right. We need to check the address. Also need to
cast tmp to (int) or something (doesn't matter what it's cast to,
because we only care about the lower 2 or 3 bits).

Peter, please see if this makes any speed difference. But it definately
needs this fix.


Frankly, I'm surprised it works. In fact, it might not, but it's hard
to tell from the tests just benchmarks.


Also, if you're doing dense addressing on Alpha, and you do byte
accesses the addresses for char are byte addresses, but the code does
read-modify-write to memory for byte accesses, because in that mode, you
can only do 32-bit and 64-bit accesses. The performance increase could
be even greater for Alpha than for x86.


For Sparc, we might be able to do something with VIS instructions,
although I don't know what the setup overhead is. Sun's memcpy and
memset only use VIS when the size is greater than 512, because
otherwise, it's not worth it.


I don't know enough about PowerPC other than the proper use of the
"eieio" instruction. :)

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:47    [W:0.046 / U:1.472 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site