[comp.sys.amiga.tech] 68881/68882 programming

lkoop@pnet01.cts.com (Lamonte Koop) (12/17/90)

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.
 

                             LaMonte Koop
 Internet: lkoop@pnet01.cts.com         ARPA: crash!pnet01!lkoop@nosc.mil
           UUCP: {hplabs!hp-sdd ucsd nosc}!crash!pnet01!lkoop
  A scientist is one who finds interest in the kinetic energy of Jell-O
   moving at ridiculous velocities...an engineer is one who can find a
               real-life application for such silliness.

jcs@crash.cts.com (John Schultz) (12/18/90)

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