Mail Archives: cygwin-developers/2001/10/22/20:30:23
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
- Raw text -