Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S272164AbTHRQBV (ORCPT ); Mon, 18 Aug 2003 12:01:21 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S272165AbTHRQBV (ORCPT ); Mon, 18 Aug 2003 12:01:21 -0400 Received: from kinesis.swishmail.com ([209.10.110.86]:46093 "HELO kinesis.swishmail.com") by vger.kernel.org with SMTP id S272164AbTHRQBM (ORCPT ); Mon, 18 Aug 2003 12:01:12 -0400 Message-ID: <3F40FC02.3000506@techsource.com> Date: Mon, 18 Aug 2003 12:17:06 -0400 From: Timothy Miller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Daniel Forrest CC: Peter Kjellerstedt , "'Willy Tarreau'" , linux-kernel mailing list Subject: Re: generic strncpy - off-by-one error References: <20030816034129.A6301@rda07.lmcg.wisc.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1498 Lines: 48 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/