home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / ScreenSavers / BackSpaceViews / MandelView.BackModule / ms_real.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  3.3 KB  |  108 lines

  1. /* ms_real.c - machine-dependent real number manipulation */
  2.  
  3. /*  
  4.     This file is part of MandelSpawn, a network Mandelbrot program.
  5.  
  6.     Copyright (C) 1990-1993 Andreas Gustafsson
  7.  
  8.     MandelSpawn is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License, version 1,
  10.     as published by the Free Software Foundation.
  11.  
  12.     MandelSpawn is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License,
  18.     version 1, along with this program; if not, write to the Free 
  19.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #ifdef REAL_FIXED
  23. #ifdef lint /* lint doesn't like asm's; fake it */
  24. static inline unsigned long fracmult(x,y) unsigned long x,y;
  25. { return(x*y);
  26. }
  27. static inline unsigned long fracmult2(x,y) unsigned long x,y;
  28. { return(2*x*y);
  29. }
  30. #else
  31.  
  32. #ifdef mc68000
  33. static inline unsigned long fracmult(x,y) unsigned long x,y;
  34. { unsigned long high;
  35.   asm("mulsl %3,%1,%0" : "=d" (x), "=d" (high): "0" (x), "d" (y));
  36.   return((high<<LEFTBITS) | (x>>RIGHTBITS));
  37. }
  38.  
  39. static inline unsigned long fracmult2(x,y) unsigned long x,y;
  40. { unsigned long high;
  41.   asm("mulsl %3,%1,%0" : "=d" (x), "=d" (high): "0" (x), "d" (y));
  42.   return((high<<(LEFTBITS+1)) | (x>>(RIGHTBITS-1)));
  43. }
  44. #endif /* mc68000 */
  45.  
  46. #ifdef vax  /* VAX code due to Jussi Maki, thanks */
  47. typedef struct 
  48. { unsigned int i0;
  49.   unsigned int i1;
  50. } int64;
  51.  
  52. static inline unsigned long fracmult(x,y) unsigned long x,y;
  53. { int64 r;
  54.   asm("emul %1,%2,$0,%0" : "=g" (r) : "g" (x), "g" (y));
  55.   return((r.i1<<LEFTBITS) | (r.i0>>RIGHTBITS));
  56. }
  57.  
  58. static inline unsigned long fracmult2(x,y) unsigned long x,y;
  59. { int64 r;
  60.   asm("emul %1,%2,$0,%0" : "=g" (r) : "g" (x), "g" (y));
  61.   return((r.i1<<LEFTBITS+1) | (r.i0>>RIGHTBITS-1));
  62. }
  63. #endif /* vax */
  64.  
  65. #ifdef i386
  66. /* i386 assembly syntax tested with Mach/i386 */
  67. static inline long fracmult(x,y) long x,y;
  68. { long high;
  69.   asm("imull %3" : "=a" (x), "=d" (high) : "0" (x), "rm" (y));
  70.   asm("shrdl %4,%1,%2" : "=a" (x), "=d" (high) : "0" (x), "1" (high),
  71.         "i" (RIGHTBITS));
  72.   return(x);
  73. }
  74.  
  75. static inline long fracmult2(x,y) long x,y;
  76. { long high;
  77.   asm("imull %3" : "=a" (x), "=d" (high) : "0" (x), "rm" (y));
  78.   asm("shrdl %4,%1,%2" : "=a" (x), "=d" (high) : "0" (x), "1" (high),
  79.         "i" (RIGHTBITS-1));
  80.   return(x);
  81. }
  82. #endif /* i386 */
  83.  
  84. #ifdef mips
  85. /*
  86.   This is slower than it needs to be because mflo/mfhi are accessed 
  87.   immediately after the multiply; if GCC would know about mflo/mfhi,
  88.   the code could be optimized to avoid at least part of the interlocks. 
  89. */
  90. static inline long fracmult(x,y) register long x,y;
  91. { register long high;
  92.   register unsigned long low;
  93.   asm("mult %2,%3; mflo %0; mfhi %1" : "=r" (low), "=r" (high) :
  94.       "r" (x), "r" (y));
  95.   return((high<<LEFTBITS) | (low>>RIGHTBITS));
  96. }
  97.  
  98. static inline long fracmult2(x,y) register long x,y;
  99. { register long high;
  100.   register unsigned long low;
  101.   asm("mult %2,%3; mflo %0; mfhi %1" : "=r" (low), "=r" (high) :
  102.       "r" (x), "r" (y));
  103.   return((high<<LEFTBITS+1) | (low>>RIGHTBITS-1));
  104. }
  105. #endif /* not mips */
  106. #endif /* not lint */
  107. #endif /* REAL_FIXED */
  108.