Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-06 - 43,50363/inepta.mac
There are no other files named inepta.mac in the archive.
         TITLE   SQRT  --QUICK SQUARE ROOT
;CALL:   MOVE    16,X
;        JSP     15,SQRT
         TWOSEG                    ;COMPUTE THE SQUARE ROOT OF THE SINGLE
         ENTRY   SQRT              ;PRECISION NUMBER IN AC16.
         RELOC   0
SAVE:    BLOCK   3
         RELOC   400000
SQRT:    JUMPE   16,SQRETN         ;WATCH OUT FOR THE ROOT OF ZERO.
         MOVEM   0,SAVE            ;SAVE THE CALLER'S ACCUMULATORS.
         MOVEM   1,SAVE+1
         MOVEM   2,SAVE+2
         MOVMS   1,16              ;FORCE POSITIVE ARGUMENT.
         ASH     16,-1             ;COMPUTE A FIRST GUESS:
         TLO     16,777            ;    CONSTRUCT A NUMBER WITH
         FSC     16,^D64           ;    1/2 THE EXPONENT (EXCESS 128).
         MOVEI   2,4               ;    THE "TLO" FORCES NORMALIZATION.
H:       MOVE    0,1               ;    THE "FSC" CORRECTS FOR SHIFTING THE 128.
         FDVR    0,16
         FADR    16,0              ;USE HERON'S METHOD:
         FSC     16,-1             ;    X(N+1)=(ARG/X(N)+X)/2.
         SOJG    2,H               ;THE FIFTH VALUE SHOULD BE ACCURATE
         MOVSI   2,SAVE            ;TO THE LIMIT OF SINGLE PRECISION.
         BLT     2,2               ;RESTORE THE CALLER'S ACCUMULATORS.
SQRETN:  JRSTF   (15)              ;RETURN TO THE CALLER.
         PRGEND
         TITLE   RANDOM--A PSEUDO RANDOM NUMBER GENERATOR
;TO INITIALIZE, JSP 15,RANDIT.
;TO GET A RANDOM NUMBER (35 BIT FRACTION IN AC15), JSP 15,RANDOM.
;TO GET THE FLOATING POINT VERSION IN AC16, JSP 15,RANFLO.
         TWOSEG
         ENTRY   RANDOM,RANDIT,RANFLO

         RELOC   0
RNDNUM:  BLOCK   1

         RELOC   400000

RANDIT:  MOVEM   15,RNDNUM         ;INITIALIZE THE RANDOM NUMBER GENERATOR:
         MSTIME  15,               ;PROCURE A REASONABLY LARGE INTEGER
         ASH     15,6
         ADDI    15,1(15)          ;AND MAKE IT ODD.
         EXCH    15,RNDNUM         ;THIS IS THE GENERATORS STARTING POINT.
         JRSTF   (15)              ;RETURN TO THE CALLER.

RANDOM:  EXCH    15,RNDNUM         ;SAVE RETURN ADDRESS AND ACCESS LAST NUMBER.
         MUL     15,FIVE15         ;MULTIPLY BY 5 TO THE 15TH POWER.
         EXCH    16,RNDNUM         ;TAKE RESULT MOD 2 TO THE 35TH POWER AND
         MOVE    15,RNDNUM         ;INTERPRET AS FRACTION WITH POINT AT LEFT.
         JRSTF   (16)              ;RETURN TO THE CALLER.

RANFLO:  EXCH    15,RNDNUM         ;SAVE RETURN ADDRESS AND ACCESS LAST NUMBER.
         MUL     15,FIVE15         ;MULTIPLY BY 5 TO THE 15TH POWER.
         MOVE    15,RNDNUM         ;RECALL THE RETURN ADDRESS.
         MOVEM   16,RNDNUM         ;TAKE RESULT MOD 2 TO THE 35TH POWER.
         LSH     16,-10            ;INTERPRETING THIS AS A 35 BIT FRACTION,
         FSC     16,200            ;CONVERT IT TO FLOATING POINT.
         JRSTF   (15)              ;RETURN TO CALLER.

F5==5*5*5*5*5
FIVE15:  F5*F5*F5
         PRGEND
         TITLE   SINCOS--QUICK SINE AND COSINE
                                   ;SINE & COSINE OF AN ANGLE
         TWOSEG                    ;WITH MAX ABS ERROR ABOUT 0.0002.
         ENTRY   SIN,COS,DSIN,DCOS ;SIN & COS ARE FOR ANGLES IN RADIANS.
         RELOC   0                 ;DSIN & DCOS ARE FOR ANGLES IN DEGREES.
SAVE:    BLOCK   2
         RELOC   400000
DSIN:    FSBRI   16,(90.0)
DCOS:    FDVR    16,DPERAD
COS:     FADR    16,PIOVR2
SIN:     MOVEM   0,SAVE            ;SAVE CALLER'S ACCUMULATORS.
         MOVEM   1,SAVE+1
         MOVSI   0,(1.0)           ;SET INITIAL SIGN CORRECTION.
         SKIPGE  16                ;UPDATE THE SIGN CORRECTION IF
         MOVN    0,0               ;NEGATING THE ANGLE.
         MOVMS   1,16              ;ENSURE A POSITIVE ANGLE.
                                   ;ADJUST ANGLE TO WITHIN
                                   ;RANGE -PI/2 TO +PI/2 BY ADDING
         FDVR    16,PI             ;A MULTIPLE OF PI.
         FIXR    16,16
                                   ;UPDATE SIGN CORRECTION IF ODD MULT OF PI.
         TRNE    16,1              ;(WILL MULTIPLY BY 1.0 OR -1.0)
         MOVN    0,0
         FLTR    16,16
         FMPR    16,PI
         FSBR    1,16
         FMPRM   1,0
         FMPR    1,1               ;COMPUTE SINE OF ANGLE WITH
         MOVE    16,A4             ;THE FORMULA:
         FMPR    16,1              ;    SINE(X)=(1+X**2*(A2+X**2*A4))*X
         FADR    16,A2             ;WHERE A2 AND A4 ARE THE NIFTY CONTANTS BELOW.
         FMPR    16,1              ;MULTIPLY BY EITHER ANGLE OR -ANGLE TO
         FADRI   16,(1.0)          ;COMPLETE THE COMPUTATION AND CORRECT
         FMPR    16,0              ;FOR THE ABOVE SUBTRACTION OF N*PI.
         MOVE    0,SAVE
         MOVE    1,SAVE+1
         JRSTF   (15)
PIOVR2:  1.57079633
PI:      3.14159265
A2:      -0.16605
A4:       0.00761
DPERAD:  57.2957795


         PRGEND
         TITLE   ARCTAN--QUICK ARCTANGENT
;TO COMPUTE ARCTANGENT OF SINGLE PRECISION FLOATING POINT IN AC16,
;CALL:   JSP     15,ARCTAN
;        (RETURNS FLOATING POINT ANGLE BETWEEN 0 AND PI IN AC16)
         TWOSEG
         ENTRY   ARCTAN
         RELOC   0                 ;COMPUTES ARCTAN OF SINGLE PRECISION
SAVE:    BLOCK   1                 ;NUMBER IN AC16.  THE RESULT IS ACCURATE TO
         RELOC   400000            ;0.005 RADIAN (OR 0.3 DEGREES).
ARCTAN:  MOVEM   1,SAVE
         MOVE    1,16
         CAMG    16,LARGE          ;TRAP FLOATING POINT OVERFLOWS AND
         CAMGE   16,LARGEN         ;UNDERFLOWS BEFORE THEY OCCUR.
         JRST    LRGFDG
         CAML    16,SMALL
         JRST    MAGOK
         CAMLE   16,SMALLN
         JRST    MAGCHK
MAGOK:   FMPR    1,1
         CAML    1,ONE             ;IF TANGENT>1,COMPUTE THE ARCCOTANGENT.
         JRST    COTAN
         FMPR    1,C               ;USE FORMULA:
         FADRI   1,(1.0)           ;  ATAN(X)=X/(1+0.28*X**2).
         FDVR    16,1
MAGCHK:  JUMPGE  16,RETURN
         FADR    16,PI
RETURN:  MOVE    1,SAVE
         JRSTF   (15)
COTAN:   FADR    1,C
LRGFIX:  FDVR    16,1              ;USE FORMULA:
         FSBR    16,PIOVR2         ;  ATAN(X)=PI/2-X/(X**2+0.28).
         MOVN    16,16
         JRST    RETURN
LRGFDG:  MOVE    16,ONE
         JRST    LRGFIX
C:       0.28
PI:      3.14159265
PIOVR2:  1.57079633
ONE:     1.0
LARGE:   1.0E10
SMALL:   1.0E-10
SMALLN:  -1.0E-10
LARGEN:  -1.0E10

         PRGEND
         TITLE   FLOFDG--ROUTINE TO TRAP & FUDGE FLOATING POINT OVERFLOWS
;TO INITIALIZE, CALL FLOFDG:
;        JSP     R,FLOFDG
;        (RETURN)

         TWOSEG
         ENTRY   FLOFDG
         EXTERN  .JBCNI,.JBTPC,.JBAPR
DEBUG==0
OPDEF    PORTAL[JRST 1,]           ;ENTER CONCEALED MODE

DMPDEV==SIXBIT/USR1/               ;DUMP FILE DEVICE,
DMPFIL==SIXBIT/MGNOPS/             ;DUMP FILE NAME,
DMPEXT==SIXBIT/DMP/                ;DUMP FILE EXTENSION,
DMPPPN==777777,,777777             ;DUMP FILE PPN.

;ACCUMULATOR ASSIGNMENTS
A==1
B==2
R==15

         RELOC   0
SAVEA:   BLOCK   1                 ;SAVE AREA FOR ACCUMULATOR A
SAVEB:   BLOCK   1                 ;SAVE AREA FOR ACCUMULATOR B
INSTRC:  BLOCK   1                 ;A COPY OF THE OFFENDING INSTRUCTION
MEMARG:  BLOCK   1                 ;ADDRESS OF ITS MEMORY ARGUMENT
ACCARG:  BLOCK   1                 ;ADDRESS OF ITS ACCUMULATOR ARGUMENT
ALTVAL:  BLOCK   1                 ;THE FUDGED RESULT
XINS1:   BLOCK   1                 ;SCREWBALL INSTRUCTIONS FOR ACCESSING
XINS2:   BLOCK   1                 ;THE OFFENDER'S ARGUMENTS.
XINS3=INSTRC                       ;(HORSESHOE NAILS ARE EXPENSIVE)
TRPCNT:  BLOCK   1                 ;COUNT OF FLOATING OVERFLOWS OCCURED.


         RELOC   400000
FLOFDG:  MOVEM   A,SAVEA
         CLEARM  TRPCNT            ;INITIALIZE THE TRAP COUNT.
         MOVEI   A,OVRFLO          ;SET ADDRESS OF TRAP ROUTINE.
         MOVEM   A,.JBAPR
         MOVEI   A,1B18+110        ;SET REPETATIVE OVERFLOW TRAP.
IFN DEBUG,<ORI A,3B23>               ;TRAP ON BAD MEM REFS.
         APRENB  A,
         MOVE    A,SAVEA
         TLZ     R,(1B11)          ;CLEAR FLOATING UNDERFLOW FLAG.
         JRSTF   (R)               ;RETURN TO CALLER.


;TRAPS HERE IF FLOATING OVERFLOW OCCURS.
OVRFLO:  PORTAL  .+1               ;JUST IN CASE.
         MOVEM   A,SAVEA
          MOVE   A,.JBCNI          ;GET CAUSE OF TRAP.
         CAIN    A,10              ;IGNORE FIXED POINT OVERFLOWS.
         JRST    GOBACK
IFN DEBUG,<TRNE  A,3B23              ;DUMP ON BAD MEM REFS.
           JRST  LOWSEG>
         HRRZ    A,.JBTPC          ;GET THE OFFENDING INSTRUCTION.
         MOVE    A,-1(A)
         MOVEM   A,INSTRC
         CAML    A,LOWLIM          ;MAKE SURE IT IS ONE OF
         CAMLE   A,HIGLIM          ;FAD,FADR,FSB,FSBR,FMP,FMPR,FDV,FDVR.
OVRHLT:  HALT    .
         AOS     TRPCNT            ;RECORD THIS OVERFLOW.
         MOVE    A,SAVEA           ;GET THE MEMORY ARGUMENT ADDRESS.
         MOVEI   A,@INSTRC
         CAIN    A,A               ;IF IT IS A, REDIRECT IT TO SAVEA.
         MOVEI   A,SAVEA
         MOVEM   A,MEMARG
         LDB     A,POINT1          ;GET THE ACCUMULATOR ARGUMENT ADDRESS.
         CAIN    A,A               ;IF IT IS A, REDIRECT IT TO SAVEA.
         MOVEI   A,SAVEA
         MOVEM   A,ACCARG
         LDB     A,POINT2          ;GET THE FLOATING UNDERFLOW FLAG.
         MOVE    A,VALUES(A)       ;GET THE ALTERNATE MAGNITUDE.
         MOVEM   A,ALTVAL
         MOVSI   A,(1B11)          ;CLEAR THE FLOATING UNDERFLOW FLAG.
         ANDCAM  A,.JBTPC

;CHOOSE THE INSTRUCTIONS FOR ACCESSING THE OFFENDER'S ARGUMENTS:
         LDB     A,POINT3          ;GET THE OFFENDER'S MODE.
         SUBI    A,4               ;WE FIX ONLY THE ROUNDING INSTRUCTIONS.
         JUMPL   A,OVRHLT
         MOVEM   B,SAVEB
         MOVEI   B,GETINS(A)       ;GET THE INSTRUCTION TO FETCH OLD RESULT.
         MOVEM   B,XINS1
         MOVEI   B,SAVIN1(A)       ;GET THE INSTRUCTION TO RESTORE THE AC ARG.
         MOVEM   B,XINS2
         MOVEI   B,SAVIN2(A)       ;GET THE INSTRUCTION TO RESTORE THE MEM ARG.
         MOVEM   B,XINS3
         MOVE    B,SAVEB

         XCT     @XINS1            ;GET THE OLD RESULT.
         SKIPGE  A
         MOVNS   ALTVAL            ;MAKE NEW VALUE HAVE SAME SIGN AS OLD.
         MOVE    A,ALTVAL
         XCT     @XINS2            ;RESET THE ACUMULATOR ARGUMENT.
         XCT     @XINS3            ;RESET THE MEMORY ARGUMENT.
GOBACK:  MOVE    A,SAVEA
         JRSTF   @.JBTPC           ;RESUME THE INTERRUPTED PROGRAM.

LOWLIM:  FAD
HIGLIM:  FDVRB   17,@-1(17)
POINT1:  POINT   4,INSTRC,12       ;EXTRACTS ACCUMULATOR FROM INTRUCTION.
POINT2:  POINT   1,.JBTPC,11       ;EXTRACTS FLOATING UNDERFLOW FLAG.
POINT3:  POINT   3,INSTRC,8        ;EXTRACTS INSTRUCTION MODE BITS.
VALUES:  1.0E38  ;A VERY BIG NUMBER
         1.0E-38 ;A VERY SMALL NUMBER

GETINS:  MOVE    A,@ACCARG
         MOVE    A,@ACCARG
         MOVE    A,@MEMARG
         MOVE    A,@ACCARG

SAVIN1:  MOVEM   A,@ACCARG
         MOVEM   A,@ACCARG
         JFCL
         MOVEM   A,@ACCARG

SAVIN2:  JFCL
         JFCL
         MOVEM   A,@MEMARG
         MOVEM   A,@MEMARG

IFN DEBUG,<      ;DUMP CORE TO A LIKELY FILE:
LOWSEG:  MOVE    A,DCW1            ;PUT THIS INTO LOWSEG JUST IN CASE.
         BLT     A,SAVEB+5
         MOVE    A,DCW2
         DAEMON  A,
         HALT
         HALT
DCW1:    XWD     DCARGS,SAVEB
DCW2:    XWD     6,SAVEB
DCARGS:  EXP     1,DMPDEV,DMPFIL,DMPEXT,0,DMPPPN>

         END