Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-developers-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin-developers AT sources DOT redhat DOT com Date: Mon, 22 Oct 2001 20:31:22 -0400 From: Christopher Faylor To: cygwin-developers AT cygwin DOT com Subject: Re: miscfuncs.cc won't compile with --enable-debugging Message-ID: <20011022203122.A17641@redhat.com> Reply-To: cygwin-developers AT cygwin DOT com Mail-Followup-To: cygwin-developers AT cygwin DOT com References: <20011022202804 DOT 5132 DOT qmail AT lizard DOT curl DOT com> <025a01c15b58$bcf61ca0$0200a8c0 AT lifelesswks> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <025a01c15b58$bcf61ca0$0200a8c0@lifelesswks> User-Agent: Mutt/1.3.21i On Tue, Oct 23, 2001 at 10:22:01AM +1000, Robert Collins wrote: >In addition to Chris's comment, I'd like to point out that this function >should be as streamlined for speed as possible (it can potentially get >called a lot).. > >this: >__check_invalid_read_ptr_errno (const void *s, unsigned sz) >{ > if (s && !IsBadReadPtr ((void *) s, sz)) > return 0; > > set_errno (EFAULT); > return EFAULT; >} > >is probably better. (I've been doing a little code tuning research >recently. One thing that stood out was that if() tests should have the >most common branch as the {}, and drop through to the least common >branch. Good point. In this case, __check_invalid_read_ptr_errno is only called by write but it doesn't hurt to optimize things a little. I looked at the assembly code that results from inverting the test and it is suprisingly more compact. You may notice that this is a regparm() function. I've been sprinkling regparm() around many of the function declarations. This makes more efficient code, too, AFAICT. Using __stdcall results in having the callee pop the stack via a 'ret nn' rather than having the caller perform stack arithmetic. That seems to help some, too. It's not really needed for the cases where regparm is able to put all of the arguments in registers but I use it anyway whereever possible just in case I need to add a register later on. cgf