Re: Sharing code between largely identical functions
- From: Jerry Coffin <spamtrap@xxxxxxxxxx>
- Date: Thu, 13 Apr 2006 23:23:12 -0600
In article <443047FA.30006@xxxxxxxxx>,
spamtrap@xxxxxxxxxx says...
[ ... ]
In case anyone is interested, these functions are simple
(so called BLAS) functions from linear algebra.
One pair is: norm and norm squared of a vector where the
only difference is a square root at the end in the more
common norm case which is bypassed by the other one. The
first function might be considered redundant since the
same result could be achieved by following the call to
the second function with a square root call outside the
function; however, I do not want to upset the much more
common case for the benefit of the less common one, which
is good design in my opinion.
The obvious answer in this case would be to just write it
as two functions. The first function implements the non-
normalized version. The second calls the first, then does
the square root.
At least to me, it seems pretty obvious that this is
cleaner. Given the work CPU designers have put into
optimizing function calls, on any reasonably recent CPU,
it's almost certain to be faster as well.
The other pair is one that renders a vector unit norm but
discards the norm where its companion optionally returns
the (square of the) original norm "by value".
The norm, conforming to __cdecl, is returned in FPU ST(0),
so the only difference is that the function which does not
return the norm pops the FPU stack whereas the other does
not (its caller will do that somewhere after using or
copying the value).
This sounds like it could (and almost certainly should)
be implemented essentially the same way as above -- the
version that does the pop becomes almost completely
trivial, just calling the other one and then doing a fpop
before returning.
--
Later,
Jerry.
The universe is a figment of its own imagination.
.
- References:
- Sharing code between largely identical functions
- From: Jentje Goslinga
- Re: Sharing code between largely identical functions
- From: Eman
- Re: Sharing code between largely identical functions
- From: Jentje Goslinga
- Sharing code between largely identical functions
- Prev by Date: Re: Efficient scather-gather-copy
- Next by Date: Re: Efficient scather-gather-copy
- Previous by thread: Re: Sharing code between largely identical functions
- Next by thread: Re: Sharing code between largely identical functions
- Index(es):
Relevant Pages
|