Article View: comp.sys.amiga.tech
Article #7519Re: 68881/68882 programming
From: John Schultz
Date: Tue, 18 Dec 1990 00:52
Date: Tue, 18 Dec 1990 00:52
77 lines
2678 bytes
2678 bytes
In <6361@crash.cts.com> lkoop@pnet01.cts.com (Lamonte Koop) writes:
>Does anyone have some good examples of DIRECTLY accessing the 68881 or 68882
>math coprocessors from within a program? (without going through the math
>libraries). Specifically, I'm looking for assembly source examples if
>possible. I have a partially working code model, but would be interested to
>see other examples or hear other ideas about the subject as I have hit a few
>'interesting' effects.
>
Using the 881/882 is just as easy as the 030. Here's a simple example
that computes distance. Pick up "68030 Assembly Language Reference", by
Steve Williams [Addision Wesley]. It's got C and equivalent 882 asm examples
(in addition to 030 examples).
; This function works on long integers. It converts the longs to
; reals with the fmove.l instruction, sums the squares, then takes the
; sqrt, then fmove.l converts back to long. fmul could also be used
; but fsglmul is faster.
section distance,code
OPT p=68020/68881 ; Necessary for Adapt to use
; 020/030/881/882
xdef _distance
; extern long __asm distance64(register __d0 long x,
; register __d1 long y,
; register __d2 long z);
_distance:
fmove.l d0,fp0
fsglmul fp0,fp0
fmove.l d1,fp1
fsglmul fp1,fp1
fadd fp0,fp1
fmove.l d2,fp0
fsglmul fp0,fp0
fadd fp1,fp0
fsqrt fp0
fmove.l fp0,d0
rts
END
--------------------------------------------------------------
Here's the code and cycles:
PMA 68030+ Program Module Analyzer V17 ADAPT Release 1.00
Copyright ) 1990, HoweSoft, Inc. All Rights Reserved.
* Program_unit #0 name "<UNNAMED>".
* Hunk_Name #0 name "distance".
* Code_Hunk [PUBLIC] #0 Length = 44 bytes [11 longwords]
fmove.l D0,FP0 ; 60 CYCLES
fsglmul.x FP0,FP0 ; 59 CYCLES
fmove.l D1,FP1 ; 60 CYCLES
fsglmul.x FP1,FP1 ; 59 CYCLES
fadd.x FP0,FP1 ; 51 CYCLES
fmove.l D2,FP0 ; 60 CYCLES
fsglmul.x FP0,FP0 ; 59 CYCLES
fadd.x FP1,FP0 ; 51 CYCLES
fsqrt.x FP0 ; 107 CYCLES
fmove.l FP0,D0 ; 100 CYCLES
rts ; 16 CYCLES
DC.W 0
* 682 Total Cycles
* Hunk_Ext:
* Type = ext_def, Name = "_distance"
* Hunk_End.
Pretty fast, eh?
Have fun,
John
Technical Details
Message-ID:
<6378@crash.cts.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!nosc!crash!jcsReferences:
<6361@crash.cts.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!nosc!crash!jcs From: jcs@crash.cts.com (John Schultz) Newsgroups: comp.sys.amiga.tech Subject: Re: 68881/68882 programming Message-ID: <6378@crash.cts.com> Date: 18 Dec 90 00:52:46 GMT References: <6361@crash.cts.com> Organization: Crash TimeSharing, El Cajon, CA Lines: 77