Re: generic strncpy - off-by-one error

Timothy Miller
2003-08-18T18:25:32Z

Peter Kjellerstedt wrote:

> For unaligned source or destination the "Multi copy & fill"
> would degenerate into "Multi byte fill". However, for
> architectures like ix86 and CRIS that can do unaligned long
> access, it would be a win to remove the UNALIGNED() check,
> and use long word copying all the time.

In fact, it's possible to do the copy even if the source and dest are
not aligned. It requires holding pieces of source in a register and
doing shifts. If the CPU is much faster than the memory, this can be a
huge win.

> Then whether using memset() or your filling is a win depends
> on the architecture and how many bytes needs to be filled.
> For a slow processor with little function call overhead (like
> CRIS), using memset seems to be a win almost immediately.
> However, for a fast processor like my P4, the call to memset
> is not a win until some 1500 bytes need to be filled.

What is in memset that isn't in the fill code I suggested?