• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/core/techModels/libHotSpot/util.h

00001 #ifndef __UTIL_H
00002 #define __UTIL_H
00003 
00004 #include <stdio.h>
00005 
00006 /* ----- SoM ----- */
00007 #ifndef MINMAX_H
00008 #define MINMAX_H
00009 
00010 #ifndef MAX
00011 #define MAX(x,y)                (((x)>(y))?(x):(y))
00012 #endif
00013 
00014 #ifndef MIN
00015 #define MIN(x,y)                (((x)<(y))?(x):(y))
00016 #endif
00017 
00018 #endif
00019 /* ----- EoM ----- */
00020 #define MAX3(a,b,c)             MAX(MAX(a,b),c)
00021 #define MIN3(a,b,c)             MIN(MIN(a,b),c)
00022 #define MID3(a,b,c)             ((MIN(a,b)<(c))?(MIN(MAX(a,b),c)):(MAX(MIN(a,b),c)))
00023 #define MAX4(a,b,c,d)   MAX(MAX(MAX(a,b),c),d)
00024 #define MIN4(a,b,c,d)   MIN(MIN(MIN(a,b),c),d)
00025 #define DELTA                   1.0e-6
00026 #define LARGENUM                1.0e100
00027 #define NULLFILE                "(null)"
00028 
00029 
00030 #define TRUE                    1
00031 #define FALSE                   0
00032 
00033 #define RAND_SEED               1500450271
00034 
00035 #define STR_SIZE                512
00036 #define LINE_SIZE               65536
00037 #define MAX_ENTRIES             512
00038 
00039 int eq(double x, double y);
00040 int le(double x, double y);
00041 int ge(double x, double y);
00042 
00043 #ifndef fatal
00044 void fatal (char *s);
00045 #endif 
00046 
00047 void warning (char *s);
00048 void swap_ival (int *a, int *b);
00049 void swap_dval (double *a, double *b);
00050 int tolerant_ceil(double val);
00051 int tolerant_floor(double val);
00052 
00053 /* vector routines      */
00054 double  *dvector(int n);
00055 void free_dvector(double *v);
00056 void dump_dvector(double *v, int n);
00057 void copy_dvector (double *dst, double *src, int n);
00058 void zero_dvector (double *v, int n);
00059 
00060 int *ivector(int n);
00061 void free_ivector(int *v);
00062 void dump_ivector(int *v, int n);
00063 void copy_ivector (int *dst, int *src, int n);
00064 void zero_ivector (int *v, int n);
00065 /* sum of the elements  */
00066 double sum_dvector (double *v, int n);
00067 
00068 /* matrix routines - Thanks to Greg Link
00069  * from Penn State University for the 
00070  * memory allocators/deallocators
00071  */
00072 double **dmatrix(int nr, int nc);
00073 void free_dmatrix(double **m);
00074 void dump_dmatrix(double **m, int nr, int nc);
00075 void copy_dmatrix(double **dst, double **src, int nr, int nc);
00076 void zero_dmatrix(double **m, int nr, int nc);
00077 void resize_dmatrix(double **m, int nr, int nc);
00078 /* mirror the lower triangle to make 'm' fully symmetric        */
00079 void mirror_dmatrix(double **m, int n);
00080 
00081 int **imatrix(int nr, int nc);
00082 void free_imatrix(int **m);
00083 void dump_imatrix(int **m, int nr, int nc);
00084 void copy_imatrix(int **dst, int **src, int nr, int nc);
00085 void resize_imatrix(int **m, int nr, int nc);
00086 
00087 /* routines for 3-d matrix with tail    */
00088 /* allocate 3-d matrix with 'nr' rows, 'nc' cols, 
00089  * 'nl' layers  and a tail of 'xtra' elements 
00090  */
00091 double ***dcuboid_tail(int nr, int nc, int nl, int xtra);
00092 /* destructor   */
00093 void free_dcuboid(double ***m);
00094 
00095 /* initialize random number generator   */
00096 void init_rand(void);
00097 /* random number within the range [0, max-1]    */
00098 int rand_upto(int max);
00099 /* random number in the range [0, 1)    */
00100 double rand_fraction(void);
00101 
00102 /* a table of name value pairs  */
00103 typedef struct str_pair_st
00104 {
00105         char name[STR_SIZE];
00106         char value[STR_SIZE];
00107 }str_pair;
00108 /* 
00109  * reads tab-separated name-value pairs from file into
00110  * a table of size max_entries and returns the number 
00111  * of entries read successfully
00112  */
00113 int read_str_pairs(str_pair *table, int max_entries, char *file);
00114 /* same as above but from command line instead of a file        */
00115 int parse_cmdline(str_pair *table, int max_entries, int argc, char **argv);
00116 /* append the table onto a file */
00117 void dump_str_pairs(str_pair *table, int size, char *file, char *prefix);
00118 /* table lookup for a name */
00119 int get_str_index(str_pair *table, int size, char *str);
00120 /* 
00121  * remove duplicate names in the table - the entries later 
00122  * in the table are discarded. returns the new size of the
00123  * table
00124  */
00125 int str_pairs_remove_duplicates(str_pair *table, int size);
00126 /* 
00127  * binary search a sorted double array 'arr' of size 'n'. if found,
00128  * the 'loc' pointer has the address of 'ele' and the return 
00129  * value is TRUE. otherwise, the return value is FALSE and 'loc' 
00130  * points to the 'should have been' location
00131  */
00132 int bsearch_double(double *arr, int n, double ele, double **loc);
00133 /* 
00134  * binary search and insert an element into a partially sorted
00135  * double array if not already present. returns FALSE if present
00136  */
00137 int bsearch_insert_double(double *arr, int n, double ele);
00138 
00139 /* 
00140  * population count of an 8-bit integer - using pointers from 
00141  * http://aggregate.org/MAGIC/
00142  */
00143 unsigned int ones8(register unsigned char n);
00144 /* 
00145  * find the number of non-empty, non-comment lines
00146  * in a file open for reading
00147  */
00148 int count_significant_lines(FILE *fp);
00149 #endif

Generated on Fri Oct 22 2010 11:02:14 for SST by  doxygen 1.7.1