| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Cube root |
Quoting Mike Bilow to Patrick Annette in a message dated 12/19
MB> I think you misunderstood what I was talking about.
I've been known to do that at times
MB> the point. As long as you have a logarithm and an
MB> antilogarithm to the same base, that is all that matters.
^^^^^^^^^^^^^ there's the problem!
MB> Raising a number to a power in the FPU is a matter of three
MB> instructions if done properly, not counting the load and
MB> unload operations. I saw your assembly language post
MB> earlier, and there is a lot of housekeeping going on with
MB> regard to storing the control word and so on.
Yes, there's really no way to avoid some of these instructions. The
algorithm requires rounding-down (instead of the default
rounding-to-nearest) to separate the power of 2 into the next lowest
integer and a fraction < 1 (needed for FSCALE and F2XM1; see below).
That meant the control word had to be changed, then restored before
exiting. Housekeeping is essential so that the next time the FPU is
used it isn't in an abnormal state.
MB> Taking the
MB> logarithm to base 2 is one instruction, multiplying by the
MB> other number is one instruction,
FYL2X does both in a single instruction y * log2(x); very efficient.
MB> and then taking the
MB> antilogarithm to base 2 is one instruction.
Can you tell me what instruction that is? Unfortunately, Intel
FPUs (at least up to the '387) have *no* antilogarithm function to any
base! Someone posted here recently that he looked at the source code
for the C pow() function and (if I remember correctly) said it does the
same thing as the code I posted, calling an FPU procedure to calculate
y**x=exp(y*ln(x)).
Most of the code is for doing the exponential part of the function
(actually in raising 2 to an arbitrary non-integer power); and in that,
much of the complexity was needed to work around a documented limitation
of the FPU instructions for raising 2 to a power. FSCALE does integer
powers, and F2XM1 is supposed to be limited to fractional powers between
-1/2 and +1/2.
You may have seen some code posted by Russ Parks. It was much shorter,
because it assumed F2XM1 worked for powers < +1, which disagrees with
both my references (8087 and 80387). But it seems to work on my 486DX.
Intel either provided wrong information about F2XM1 or they
changed the limitation on the 486. If I can verify that his code works
on the '387 and higher the code will become much slimmer; but the
function has to work on any Intel system running OS/2, which means 387
or higher FPU. Time to get another expensive book!
Too bad the FPU isn't the kind of 'magic box' you envision, with a rich
instruction set, because I'm beginning to fear the hyperbolic
functions. Maybe I'll leave them out... Still, it's fun to get
down-and-dirty sometimes.
Patrick
___
X KWQ/2 1.2i X
--- Maximus/2 2.02
* Origin: OS/2 Online * Auburn, WA * 206-351-5998 * (1:343/212)SEEN-BY: 270/101 620/243 711/401 409 410 413 430 808 809 934 955 712/407 515 SEEN-BY: 712/517 628 713/888 800/1 7877/2809 @PATH: 343/212 800 1 138/103 3615/50 396/1 270/101 712/515 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.