home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / mesch12a.zip / machine.c < prev    next >
C/C++ Source or Header  |  1994-01-25  |  4KB  |  147 lines

  1.  
  2. /**************************************************************************
  3. **
  4. ** Copyright (C) 1993 David E. Stewart & Zbigniew Leyk, all rights reserved.
  5. **
  6. **                 Meschach Library
  7. ** 
  8. ** This Meschach Library is provided "as is" without any express 
  9. ** or implied warranty of any kind with respect to this software. 
  10. ** In particular the authors shall not be liable for any direct, 
  11. ** indirect, special, incidental or consequential damages arising 
  12. ** in any way from use of the software.
  13. ** 
  14. ** Everyone is granted permission to copy, modify and redistribute this
  15. ** Meschach Library, provided:
  16. **  1.  All copies contain this copyright notice.
  17. **  2.  All modified copies shall carry a notice stating who
  18. **      made the last modification and the date of such modification.
  19. **  3.  No charge is made for this software or works derived from it.  
  20. **      This clause shall not be construed as constraining other software
  21. **      distributed on the same medium as this software, nor is a
  22. **      distribution fee considered a charge.
  23. **
  24. ***************************************************************************/
  25.  
  26. /*
  27.   This file contains basic routines which are used by the functions
  28.   in meschach.a etc.
  29.   These are the routines that should be modified in order to take
  30.   full advantage of specialised architectures (pipelining, vector
  31.   processors etc).
  32.   */
  33.  
  34. static    char    *rcsid = "$Id: machine.c,v 1.4 1994/01/13 05:28:56 des Exp $";
  35.  
  36. #include    "machine.h"
  37.  
  38. /* __ip__ -- inner product */
  39. double    __ip__(dp1,dp2,len)
  40. register Real    *dp1, *dp2;
  41. int    len;
  42. {
  43. #ifdef VUNROLL
  44.     register int    len4;
  45.     register Real    sum1, sum2, sum3;
  46. #endif
  47.     register int    i;
  48.     register Real     sum;
  49.  
  50.     sum = 0.0;
  51. #ifdef VUNROLL
  52.     sum1 = sum2 = sum3 = 0.0;
  53.     
  54.     len4 = len / 4;
  55.     len  = len % 4;
  56.     
  57.     for ( i = 0; i < len4; i++ )
  58.     {
  59.     sum  += dp1[4*i]*dp2[4*i];
  60.     sum1 += dp1[4*i+1]*dp2[4*i+1];
  61.     sum2 += dp1[4*i+2]*dp2[4*i+2];
  62.     sum3 += dp1[4*i+3]*dp2[4*i+3];
  63.     }
  64.     sum  += sum1 + sum2 + sum3;
  65.     dp1 += 4*len4;    dp2 += 4*len4;
  66. #endif
  67.     
  68.     for ( i = 0; i < len; i++ )
  69.     sum  += dp1[i]*dp2[i];
  70.     
  71.     return sum;
  72. }
  73.  
  74. /* __mltadd__ -- scalar multiply and add c.f. v_mltadd() */
  75. void    __mltadd__(dp1,dp2,s,len)
  76. register Real    *dp1, *dp2;
  77. register double s;
  78. register int    len;
  79. {
  80.     register int    i;
  81. #ifdef VUNROLL
  82.     register int        len4;
  83.     
  84.     len4 = len / 4;
  85.     len  = len % 4;
  86.     for ( i = 0; i < len4; i++ )
  87.     {
  88.     dp1[4*i]   += s*dp2[4*i];
  89.     dp1[4*i+1] += s*dp2[4*i+1];
  90.     dp1[4*i+2] += s*dp2[4*i+2];
  91.     dp1[4*i+3] += s*dp2[4*i+3];
  92.     }
  93.     dp1 += 4*len4;    dp2 += 4*len4;
  94. #endif
  95.     
  96.     for ( i = 0; i < len; i++ )
  97.     dp1[i] += s*dp2[i];
  98. }
  99.  
  100. /* __smlt__ scalar multiply array c.f. sv_mlt() */
  101. void    __smlt__(dp,s,out,len)
  102. register Real    *dp, *out;
  103. register double s;
  104. register int    len;
  105. {
  106.     register int    i;
  107.     for ( i = 0; i < len; i++ )
  108.     out[i] = s*dp[i];
  109. }
  110.  
  111. /* __add__ -- add arrays c.f. v_add() */
  112. void    __add__(dp1,dp2,out,len)
  113. register Real    *dp1, *dp2, *out;
  114. register int    len;
  115. {
  116.     register int    i;
  117.     for ( i = 0; i < len; i++ )
  118.     out[i] = dp1[i] + dp2[i];
  119. }
  120.  
  121. /* __sub__ -- subtract arrays c.f. v_sub() */
  122. void    __sub__(dp1,dp2,out,len)
  123. register Real    *dp1, *dp2, *out;
  124. register int    len;
  125. {
  126.     register int    i;
  127.     for ( i = 0; i < len; i++ )
  128.     out[i] = dp1[i] - dp2[i];
  129. }
  130.  
  131. /* __zero__ -- zeros an array of floating point numbers */
  132. void    __zero__(dp,len)
  133. register Real    *dp;
  134. register int    len;
  135. {
  136. #ifdef CHAR0ISDBL0
  137.     /* if a floating point zero is equivalent to a string of nulls */
  138.     MEM_ZERO((char *)dp,len*sizeof(Real));
  139. #else
  140.     /* else, need to zero the array entry by entry */
  141.     int    i;
  142.     for ( i = 0; i < len; i++ )
  143.     dp[i] = 0.0;
  144. #endif
  145. }
  146.  
  147.