#floating point questions
7 messages in this thread
My turbo silver disk has a normal version and an FP version, the latter
of which crashes the machine if it can't find a FP. I want to know in
general whether calculations are automatically directed to the FP when
possible, or does the FP lie dormant in programs that are not written
specifically for it? If I pulled out the FP in my A3000, would, say,
Perfect sound be able to put an echo on a large sampled sound with the same
speed as it does now? For example, does a spreadsheet recalc get sent to
the FP at some point? If so, what are the criteria to redirect a task to
the FP? Is it possible to direct large calculations to the FP if they are
not directed there by default? Could redirecting these calulations be done
by a DOS application? Anyone who can shed some light on these questions
(and also answer why the sky in blue, since I've asked everything else)
would calm the curiosity caused by extreme ignorance.
—K.H.–Salt Lake City.—
Keir,
There is no simple answer to your questions, as different programmers
have dealt with this issue in different ways. For example, Impulse chose
to go the "direct" route as you've discovered. This means that their FP
version has been created with in-line floating-point instructions that go
straight to the hardware. When executing this instruction, the 680×0
processor generates an exception (since the instruction is not a generic
680×0 instruction). If there is a math coprocessor installed, then this
exception is trapped and the coprocessor executes the instruction. This is
all done via the "magic" of hardware. If there isn't a coprocessor
available to handle the exception, then the program will "crash".
Programmers do have other options available. First, they could assume
that there is no FP coprocessor available, and hard-code their floating
point calculations to use software emulation functions to do the calcs.
This will work on all 680×0 processors, but will not take advantage of the
coprocessor, even if it exists. For example, you could run the non-FP
version of Silver on any amiga, including the 3000 (assuming there were no
other bugs lurking in the program). It just wouldn't be as fast in FP
calculations (although Silver is a special case, as their non-FP version is
designed to rely more heavily on integer calculations).
Finally, there is a third way available which is the "recommended way"
(according to Commodore). Starting with WorkBench release 1.3, there is a
system library in the libs: directory (mathtrans.library) that provides
software functions to do the FP calculations. These functions are written
to take advantage of the FP coprocessor if it is present, and to use
software emulation if it is not present. The advantage here is that the
same program will work whether or not you have the coprocessor, and will
have a speed advantage if the processor is present. The disadvantage is
that using these functions will take longer than the inline FP
[ MORE ]
[ continuation ]
instructions.
As to why the sky is blue – you'll have to ask that in one of the IBM
forums. That's a marketing question! <grin>
Hope this helps…..
…BobR
and the best method of all is to utilize the Amiga's ability to tell you if
the 881 or 882 is there and let the program have BOTH types of code built
in, with the program directed to utilize FAST in-line 881/882 code sections
if the chip is there and to go use different code section if it isn't.
NeuroPro is written that way, but most programs have two completely
separate versions – one for 881/882 Amigas and one for those lacking the
math chip. Seems the reason most programmers go that way is that they
write in C (not assembler) and apparently (not positive about this)
something about the C compilers makes it uncomfortably difficult to write
one program which has both types of code in it and just branches according
to whether a coprocessor is present or not. FractalPro is written with two
completely different sets of math routines which aren't floating point at
all but which differ according to whether they are for a 68030/020 or just
a 68000/010. The whole thing is transparent to the user if you let the
Amiga tell what set of routines to use according to presence/absence of
various types of 68xxx. FractalPro runs at X speed on a stock Amiga and at
10 – 30 times X speed on those machines with accelerators. NeuroPro also
transparently just utilizes the fastest method it can – both are built in.
It's not that hard to do in assembler (assuming that assembler isn't that
hard to do, which if true would mean more assembly based programs rather
than C ones).
Daniel,
You're right, of course. Unfortunately, it is not possible to take that
approach in C directly. However, using the appropriate CBM
"math….library" is almost the same, as it is doing the same thing you're
doing (and is written in assembler). I haven't done any benchmarks
personally – I _never_ use FP code myself. With very few exceptions, FP
isn't really needed for most applications, and is significantly slower than
equivalent integer-based algorithms.
…BobR
Oh yeah! I can write that in… three notes and a few #defines. 🙂
What's a few function pointers? Hmm. Maybe you're right. The compilers
generate different code depending on the math mode. Watch for my upcoming
article on math libraries in the next Tech Journal.
WOW!
Ask a simple question around here and open up a can of worms who
themselves are in a heated debate, spurred by slef confidence. Ahh, the
joys of an active BBS. Thznx for all the input, it is obvious that the
matter is more complicated than I thought and seems still unresolved. I'll
keep posted
—-K.H.—-