[comp.sys.mac.programmer] Mixing Sane And 881

Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) (03/05/90)

Can anyone tell me how to mix code so that it will be able to take best
advantage of the math system available. That is, if an FPU (881/2) is
available to use it; otherwise use SANE; or if the user wants to use
SANE via the math chip? I know it is possible (there are benchmarks that
let the user decide how to do math), but I can not figure out how to do
it. I would be working in either Pascal or C (rather avoid Assembly) in
the MPW environment. I have tried just having parts of code compiled for
881 direct and other compiled normally, but you can not seem to mix
them. THe linker did not like it. Worse, FPU code requires 68020 code
and it does not seem possible to mix 68020 and 68000 code together. I am
obviously missing something and it is probably simple. HELP! Thanks in
advance...
 
BTW, figuring out what is available is no problem.


--  

	Ken Knight at The Black Cat's Shack (Fidonet 1:109/401)
	Internet:  Ken.Knight@f421.n109.z1.fidonet.org    
	UUCP:      ...!uunet!blkcat!421!Ken.Knight

rcfische@polyslo.CalPoly.EDU (Raymond C. Fischer) (03/07/90)

In article <629.25F2006D@blkcat.fidonet.org> Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) writes:
>Can anyone tell me how to mix code so that it will be able to take best
>advantage of the math system available. That is, if an FPU (881/2) is
>available to use it; otherwise use SANE; or if the user wants to use
>SANE via the math chip? I know it is possible (there are benchmarks that
>let the user decide how to do math), but I can not figure out how to do
>it. I would be working in either Pascal or C (rather avoid Assembly) in
>the MPW environment. I have tried just having parts of code compiled for
>881 direct and other compiled normally, but you can not seem to mix
>them. THe linker did not like it. Worse, FPU code requires 68020 code
>and it does not seem possible to mix 68020 and 68000 code together. I am
>obviously missing something and it is probably simple. HELP! Thanks in
>advance...

'Tis simple.  Just compile two versions of the program.  If you REALLY
wanted to, you could test for the 68882 and branch to the appropriate
version of the routine, but this is generally nasty business.  Just
one of the problems is that 68882 reals are a different format (and 
different size) than SANE reals.
BTW, FPU code does NOT require 68020 code.  Two different beasts entirely.

Ray Fischer
rcfische@polyslo.calpoly.edu

stoms@castor.ncgia.ucsb.edu (David Stoms) (03/11/90)

In article <25f44316.711e@polyslo.CalPoly.EDU> rcfische@polyslo.CalPoly.EDU (Raymond C. Fischer) writes:
>
>In article <629.25F2006D@blkcat.fidonet.org> Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) writes:
>>Can anyone tell me how to mix code so that it will be able to take best
>>advantage of the math system available. That is, if an FPU (881/2) is
>>available to use it; otherwise use SANE; or if the user wants to use
>wanted to, you could test for the 68882 and branch to the appropriate
>version of the routine, but this is generally nasty business.  Just
>one of the problems is that 68882 reals are a different format (and 
>different size) than SANE reals.

Actually it isn't that bad. Your compilers can be set to use 80-bit or
96-bit extended numbers which are actually have identical precision.
To convert between the two you have to know the format. The format
works like this:

96-bit: 96- exponent -80- empty    -63- mantissa -0
80-bit:               80- exponent -63- mantissa -0

To convert between the two just move the exponent around. It doesn't
matter wants in the empty space of 96-bit reals. You can write a nice
macro to do this in C. These two work in ThC 4.0:

#define _96to80(ext);	((extended96*)&(ext))->zero = ((extended96*)&(ext))->exp;
#define _80to96(ext);	((extended96*)&(ext))->exp = ((extended96*)&(ext))->zero;

They should work no matter how big the compiler thinks the numbers are
but if you want to pass an 80-bit real to a function and your compiler
is set for 96-bit reals then you have to use a macro like this:

#define passext80(ext)	(*(extended*)&((extended96*)&(ext))->zero)

Another dangerous pitfall is converting an 80-bit real to a 96-bit
real without declaring your varible 96-bits. This can happen if your
compiler is set to 80-bit real and you declare a standard extended.

Disclamer: This doesn't nessesarily apply to compilers other than
Think C 4.0.