home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / microcode / array.h < prev    next >
C/C++ Source or Header  |  1999-01-02  |  4KB  |  139 lines

  1. /* -*-C-*-
  2.  
  3. $Id: array.h,v 9.36 1999/01/02 06:11:34 cph Exp $
  4.  
  5. Copyright (c) 1987-1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #ifndef REAL_IS_DEFINED_DOUBLE
  23. #define REAL_IS_DEFINED_DOUBLE 0
  24. #endif
  25.  
  26. #if (REAL_IS_DEFINED_DOUBLE == 0)
  27. #define REAL float
  28. #else
  29. #define REAL double
  30. #endif
  31.  
  32. #define arg_real(arg_number) ((REAL) (arg_real_number (arg_number)))
  33. #define REAL_SIZE (BYTES_TO_WORDS (sizeof (REAL)))
  34.  
  35. #define FLOAT_SIZE (BYTES_TO_WORDS (sizeof (float)))
  36. #define DOUBLE_SIZE (BYTES_TO_WORDS (sizeof (double)))
  37.  
  38. #if (REAL_IS_DEFINED_DOUBLE == 0)
  39.  
  40. /* Scheme_Arrays are implemented as NON_MARKED_VECTOR. */
  41.  
  42. #define ARRAY_P NON_MARKED_VECTOR_P
  43. #define ARRAY_LENGTH(array) ((long) (FAST_MEMORY_REF ((array), 1)))
  44. #define ARRAY_CONTENTS(array) ((REAL *) (MEMORY_LOC (array, 2)))
  45.  
  46. #else /* (REAL_IS_DEFINED_DOUBLE != 0) */
  47.  
  48. /* Scheme_Arrays are implemented as flonum vectors.
  49.    This is required to get alignment to work right on RISC machines. */
  50.  
  51. #define ARRAY_P FLONUM_P
  52. #define ARRAY_LENGTH(array) ((VECTOR_LENGTH (array)) / DOUBLE_SIZE)
  53. #define ARRAY_CONTENTS(array) ((REAL *) (MEMORY_LOC (array, 1)))
  54.  
  55. #endif /* (REAL_IS_DEFINED_DOUBLE != 0) */
  56.  
  57. extern SCHEME_OBJECT allocate_array ();
  58.  
  59. extern void C_Array_Find_Min_Max ();
  60. extern void C_Array_Complex_Multiply_Into_First_One ();
  61.  
  62. extern void C_Array_Make_Histogram ();
  63. /* REAL * Array;
  64.    REAL * Histogram;
  65.    long Length;
  66.    long npoints; */
  67.  
  68. extern void Find_Offset_Scale_For_Linear_Map();
  69. /* REAL Min;
  70.    REAL Max;
  71.    REAL New_Min;
  72.    REAL New_Max;
  73.    REAL * Offset;
  74.    REAL * Scale; */
  75.  
  76. /* The following macros implement commonly used array procs. */
  77.  
  78. /* In the following macros we assign the arguments to local variables
  79.    so as to do any computation (referencing, etc.) only once outside the loop.
  80.    Otherwise it would be done again and again inside the loop.
  81.    The names, like "MCRINDX", have been chosen to avoid shadowing the
  82.    variables that are substituted in.  WARNING: Do not use any names
  83.    starting with the prefix "mcr", when calling these macros */
  84.  
  85. #define C_Array_Scale(array, scale, n)                    \
  86. {                                    \
  87.   fast REAL * mcr_scan = (array);                    \
  88.   fast REAL * mcr_end = (mcr_scan + (n));                \
  89.   fast REAL mcrd0 = (scale);                        \
  90.   while (mcr_scan < mcr_end)                        \
  91.     (*mcr_scan++) *= mcrd0;                        \
  92. }
  93.  
  94. #define Array_Scale(array, scale)                    \
  95. {                                    \
  96.   C_Array_Scale                                \
  97.     ((ARRAY_CONTENTS (array)),                        \
  98.      (scale),                                \
  99.      (ARRAY_LENGTH (array)));                        \
  100. }
  101.  
  102. #define C_Array_Copy(from, to, n)                    \
  103. {                                    \
  104.   fast REAL * mcr_scan_source = (from);                    \
  105.   fast REAL * mcr_end_source = (mcr_scan_source + (n));            \
  106.   fast REAL * mcr_scan_target = (to);                    \
  107.   while (mcr_scan_source < mcr_end_source)                \
  108.     (*mcr_scan_target++) = (*mcr_scan_source++);            \
  109. }
  110.  
  111. #define Array_Copy(from, to)                        \
  112. {                                    \
  113.   C_Array_Copy                                \
  114.     ((ARRAY_CONTENTS (from)),                        \
  115.      (ARRAY_CONTENTS (to)),                        \
  116.      (ARRAY_LENGTH (from)));                        \
  117. }
  118.  
  119. #define C_Array_Add_Into_Second_One(from, to, n)            \
  120. {                                    \
  121.   fast REAL * mcr_scan_source = (from);                    \
  122.   fast REAL * mcr_end_source = (mcr_scan_source + (n));            \
  123.   fast REAL * mcr_scan_target = (to);                    \
  124.   while (mcr_scan_source < mcr_end_source)                \
  125.     (*mcr_scan_target++) += (*mcr_scan_source++);            \
  126. }
  127.  
  128. #define Array_Add_Into_Second_One(from,to)                \
  129. {                                    \
  130.   C_Array_Add_Into_Second_One                        \
  131.     ((ARRAY_CONTENTS (from)),                        \
  132.      (ARRAY_CONTENTS (to)),                        \
  133.      (ARRAY_LENGTH (from)));                        \
  134. }
  135.  
  136. #define mabs(x) (((x) < 0) ? (- (x)) : (x))
  137. #define max(x,y) (((x) < (y)) ? (y) : (x))
  138. #define min(x,y) (((x) < (y)) ? (x) : (y))
  139.