home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmlsrc23.zoo / pmlsrc / cadd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  3.5 KB  |  163 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20.  
  21. /*
  22.  *  FUNCTION
  23.  *
  24.  *    cadd   double precision complex addition
  25.  *
  26.  *  KEY WORDS
  27.  *
  28.  *    cadd
  29.  *    complex functions
  30.  *    machine independent routines
  31.  *    math libraries
  32.  *
  33.  *  DESCRIPTION
  34.  *
  35.  *    Computes double precision complex result of addition of
  36.  *    first double precision complex argument with second double
  37.  *    precision complex argument.
  38.  *
  39.  *    Note that the complex addition function is
  40.  *    so simple that it would not normally be called as a function
  41.  *    but simply done "inline".  It is supplied mostly for
  42.  *    completeness.
  43.  *
  44.  *  USAGE
  45.  *
  46.  *    COMPLEX cadd (z1, z2)
  47.  *    COMPLEX z1;
  48.  *    COMPLEX z2;
  49.  *
  50.  *  PROGRAMMER
  51.  *
  52.  *    Fred Fish
  53.  *    Tempe, Az 85281
  54.  *    (602) 966-8871
  55.  *
  56.  *  INTERNALS
  57.  *
  58.  *    Computes cadd(z1,z2) from:
  59.  *
  60.  *        1.    Let z1 = a + j b
  61.  *            Let z2 = c + j d
  62.  *
  63.  *        2.    Then cadd(z1,z2) = (a + c) + j (b + d)
  64.  *
  65.  */
  66.  
  67. #if !defined (__M68881__) && !defined (sfp004)
  68.  
  69. #include <stdio.h>
  70. #include <math.h>
  71. #include "pml.h"
  72.  
  73. COMPLEX cadd (z1, z2)
  74. COMPLEX z1;
  75. COMPLEX z2;
  76. {
  77.     z1.real += z2.real;
  78.     z1.imag += z2.imag;
  79.     return (z1);
  80. }
  81. #endif !defined (__M68881__) && !defined (sfp004)
  82.  
  83. #ifdef    __M68881__
  84. __asm("
  85. .text
  86. _funcname:
  87.     .ascii    \"cadd\\0\"
  88. .even
  89. .globl    _cadd
  90. _cadd:
  91.     fmoved    sp@(4),fp0
  92.     faddd    sp@(20),fp0
  93.     fmoved    sp@(12),fp1
  94.     faddd    sp@(28),fp1
  95.     movel    a1,d0        | pointer to result
  96.     fmoved    fp0,a1@        | return z.real
  97.     fmoved    fp1,a1@(8)    | return z.imag
  98. ");    /* end asm    */
  99. #endif    __M68881__
  100.  
  101. #ifdef    sfp004
  102. __asm("
  103.  
  104. comm =     -6
  105. resp =    -16
  106. zahl =      0
  107.  
  108. .text
  109. _funcname:
  110.     .ascii    \"cadd\\0\"
  111. .text
  112. .even
  113. .globl    _cadd
  114. _cadd:
  115.     lea    0xfffa50,a0
  116.     movew    #0x5400,a0@(comm)    | z1.real -> fp0
  117.     .long    0x0c688900, 0xfff067f8
  118.     movel    a7@(4),a0@        | load arg_hi
  119.     movel    a7@(8),a0@        | load arg_low
  120.  
  121.     movew    #0x5422,a0@(comm)    | fp0 += z2.real
  122.     .long    0x0c688900, 0xfff067f8
  123.     movel    a7@(20),a0@        | load arg_hi
  124.     movel    a7@(24),a0@        | load arg_low
  125.  
  126.     movew    #0x5480,a0@(comm)    | z1.imag -> fp1
  127.     .long    0x0c688900, 0xfff067f8
  128.     movel    a7@(12),a0@        | load arg_hi
  129.     movel    a7@(16),a0@        | load arg_low
  130.  
  131.     movew    #0x54a2,a0@(comm)    | fp1 += z2.imag
  132.     movel    a1,d0            | pointer to result
  133.     .long    0x0c688900, 0xfff067f8
  134.     movel    a7@(28),a0@        | load arg_hi
  135.     movel    a7@(32),a0@        | load arg_low
  136.  
  137. |    movew    #%0111 0101 0000 0000,a0@(comm)    | fetch fp0
  138.     movew    #0x7400,a0@(comm)        | 
  139.     .long    0x0c688900, 0xfff067f8
  140.     movel    a0@(zahl),a1@
  141.     movel    a0@(zahl),a1@(4)
  142.  
  143. |    movew    #%0111 0100 1000 0000,a0@(comm)    | fetch fp1
  144.     movew    #0x7480,a0@(comm)        |
  145.     .long    0x0c688900, 0xfff067f8
  146.     movel    a0@(zahl),a1@(8)
  147.     movel    a0@(zahl),a1@(12)
  148. ");    /* end asm    */
  149. #endif    sfp004
  150.  
  151. #if defined (__M68881__) || defined (sfp004)
  152. # ifdef ERROR_CHECK    /* no error checking for now    */
  153. __asm("
  154.     pea    _funcname
  155.     jmp    c_err_check    
  156. ");    /* end asm    */
  157. # else  ERROR_CHECK
  158.  
  159. __asm("rts");
  160.  
  161. # endif ERROR_CHECK
  162. #endif defined (__M68881__) || defined (sfp004)
  163.