diff options
author | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-16 16:55:14 -0400 |
---|---|---|
committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-16 16:55:14 -0400 |
commit | 6ea9939e0610a809f6f47d13ec68df00d1ca0afc (patch) | |
tree | fe4a2eee3ddcf77e2367309dcd75a232b76dcd62 /dis/Field | |
parent | e9285d0cdea756a2830f0ace378e4197b36869aa (diff) |
Move the DIS benchmarks up a directory and update hardcoded paths
Note that this repo does not attempt to keep a copy of the original
DIS benchmark distributions. UNC real-time has another repo for that.
Diffstat (limited to 'dis/Field')
-rw-r--r-- | dis/Field/DISstressmarkRNG.h | 190 | ||||
-rw-r--r-- | dis/Field/field.c | 153 |
2 files changed, 343 insertions, 0 deletions
diff --git a/dis/Field/DISstressmarkRNG.h b/dis/Field/DISstressmarkRNG.h new file mode 100644 index 0000000..4aa2620 --- /dev/null +++ b/dis/Field/DISstressmarkRNG.h | |||
@@ -0,0 +1,190 @@ | |||
1 | #include <math.h> | ||
2 | |||
3 | #define IA 16807 | ||
4 | #define IM 2147483647 | ||
5 | #define AM (1.0/IM) | ||
6 | #define IQ 127773 | ||
7 | #define IR 2836 | ||
8 | #define NTAB 32 | ||
9 | #define NDIV (1+(IM-1)/NTAB) | ||
10 | #define EPS 1.2e-7 | ||
11 | #define RNMX (1.0-EPS) | ||
12 | |||
13 | static long iy=0; | ||
14 | static long iv[NTAB]; | ||
15 | static long iseed; | ||
16 | |||
17 | int ABS(int x){ | ||
18 | if (x>= 0) return x; | ||
19 | else | ||
20 | return (-x); | ||
21 | } | ||
22 | |||
23 | int sign(int x){ | ||
24 | if (x >= 0) return 1; | ||
25 | else | ||
26 | return (-1); | ||
27 | } | ||
28 | |||
29 | int MAX(int x, int y){ | ||
30 | if (x>= y) return x; | ||
31 | else | ||
32 | return y; | ||
33 | } | ||
34 | |||
35 | int MIN(int x, int y){ | ||
36 | if (x<= y) return x; | ||
37 | else | ||
38 | return y; | ||
39 | } | ||
40 | |||
41 | void randInit(long idum) | ||
42 | { | ||
43 | long j; | ||
44 | long k; | ||
45 | |||
46 | assert (idum <= 0); | ||
47 | assert (iy == 0); | ||
48 | |||
49 | iseed = idum; | ||
50 | if (-(iseed)<1){ | ||
51 | iseed = 1; | ||
52 | } | ||
53 | else { | ||
54 | iseed = -(iseed); | ||
55 | } | ||
56 | for (j=NTAB+7; j>=0; j--){ | ||
57 | k = (iseed)/IQ; | ||
58 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
59 | if (iseed < 0){ | ||
60 | iseed += IM; | ||
61 | } | ||
62 | if (j < NTAB){ | ||
63 | iv[j] = iseed; | ||
64 | } | ||
65 | } | ||
66 | iy = iv[0]; | ||
67 | } | ||
68 | |||
69 | float randNum() | ||
70 | { | ||
71 | long j; | ||
72 | long k; | ||
73 | float temp; | ||
74 | |||
75 | assert (iy != 0); | ||
76 | |||
77 | k = (iseed)/IQ; | ||
78 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
79 | |||
80 | if (iseed < 0){ | ||
81 | iseed += IM; | ||
82 | } | ||
83 | j = iy/NDIV; | ||
84 | iy = iv[j]; | ||
85 | iv[j] = iseed; | ||
86 | |||
87 | temp = AM * iy; | ||
88 | |||
89 | if (temp > RNMX){ | ||
90 | return RNMX; | ||
91 | } | ||
92 | else { | ||
93 | return temp; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | |||
98 | float randomFloat(float lowest_float, float highest_float) | ||
99 | { | ||
100 | float value; | ||
101 | float range; | ||
102 | |||
103 | assert (lowest_float < highest_float); | ||
104 | |||
105 | range = highest_float - lowest_float; | ||
106 | value = randNum()*(highest_float - lowest_float) + lowest_float; | ||
107 | assert(value >= lowest_float); | ||
108 | assert(value <= highest_float); | ||
109 | |||
110 | return value; | ||
111 | |||
112 | } | ||
113 | |||
114 | float randomNonZeroFloat(float lowest_float, float highest_float, float epsilon) | ||
115 | { | ||
116 | |||
117 | double range; | ||
118 | float value; | ||
119 | |||
120 | |||
121 | assert (lowest_float < 0); | ||
122 | assert (highest_float > 0); | ||
123 | assert (epsilon > 0); | ||
124 | assert ((epsilon < -lowest_float) && (epsilon < highest_float)); | ||
125 | |||
126 | range = highest_float - lowest_float; | ||
127 | value = (randNum() * range)+lowest_float; | ||
128 | |||
129 | if (ABS(value) < epsilon) | ||
130 | { | ||
131 | if (value > 0) value = value + epsilon; | ||
132 | else if (value < 0) value = value - epsilon; | ||
133 | |||
134 | } | ||
135 | |||
136 | assert (value >= lowest_float); | ||
137 | assert (value <= highest_float); | ||
138 | |||
139 | return value; | ||
140 | } | ||
141 | |||
142 | unsigned int randomUInt(int lowest_uint, int highest_uint) | ||
143 | { | ||
144 | float range; | ||
145 | unsigned int value; | ||
146 | float temp; | ||
147 | |||
148 | range =(float)(highest_uint - lowest_uint + 1); | ||
149 | temp = randNum(); | ||
150 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
151 | |||
152 | assert (value >= lowest_uint); | ||
153 | assert (value <= highest_uint); | ||
154 | |||
155 | return value; | ||
156 | } | ||
157 | |||
158 | unsigned int randomNonZeroUInt(int lowest_uint, int highest_uint) | ||
159 | { | ||
160 | float range; | ||
161 | unsigned int value; | ||
162 | float temp; | ||
163 | |||
164 | range =(float)(highest_uint - lowest_uint + 1); | ||
165 | value = 0; | ||
166 | while(value == 0){ | ||
167 | temp = randNum(); | ||
168 | |||
169 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
170 | } | ||
171 | |||
172 | assert (value >= lowest_uint); | ||
173 | assert (value <= highest_uint); | ||
174 | |||
175 | return value; | ||
176 | } | ||
177 | |||
178 | int randInt(int lowest_uint, int highest_uint) | ||
179 | { | ||
180 | float range; | ||
181 | int value; | ||
182 | |||
183 | range = highest_uint - lowest_uint + 1; | ||
184 | value = (int)(floor(randNum() * range) + lowest_uint); | ||
185 | |||
186 | assert (value >= lowest_uint); | ||
187 | assert (value <= highest_uint); | ||
188 | |||
189 | return value; | ||
190 | } | ||
diff --git a/dis/Field/field.c b/dis/Field/field.c new file mode 100644 index 0000000..8565e8c --- /dev/null +++ b/dis/Field/field.c | |||
@@ -0,0 +1,153 @@ | |||
1 | /* | ||
2 | * Sample code for the DIS Field Stressmark | ||
3 | * | ||
4 | * This source code is the completely correct source code based on | ||
5 | * the example codes provided by Atlantic Aerospace Division, Titan | ||
6 | * Systems Corporation, 2000. | ||
7 | * | ||
8 | * If you just compile and generate the executables from this source | ||
9 | * code, this code would be enough. However, if you wish to get a complete | ||
10 | * understanding of this stressmark, it is strongly suggested that you | ||
11 | * read the Benchmark Analysis and Specifications Document Version 1.0 | ||
12 | * before going on since the detailed comments are given in this documents. | ||
13 | * the comments are not repeated here. | ||
14 | */ | ||
15 | |||
16 | #include <stdio.h> | ||
17 | #include <time.h> | ||
18 | #include <assert.h> | ||
19 | #include <stdlib.h> | ||
20 | #include "DISstressmarkRNG.h" | ||
21 | #include "extra.h" | ||
22 | |||
23 | |||
24 | #define MIN_FIELD_SIZE 16 | ||
25 | #define MAX_FIELD_SIZE (16777216*4) // This has been quadrupled from original | ||
26 | #define MIN_SEED -2147483647 | ||
27 | #define MAX_SEED -1 | ||
28 | #define MIN_MOD_OFFSET 0 | ||
29 | #define MAX_MOD_OFFSET 65535 | ||
30 | #define MIN_TOKENS 1 | ||
31 | #define MAX_TOKENS 256 | ||
32 | #define MIN_TOKEN_LENGTH 1 | ||
33 | #define MAX_TOKEN_LENGTH 8 | ||
34 | #define MIN_TOKEN_VALUE 0 | ||
35 | #define MAX_TOKEN_VALUE 255 | ||
36 | #define MAX_SUBFIELDS 256 | ||
37 | |||
38 | /* | ||
39 | * main() | ||
40 | */ | ||
41 | |||
42 | int main(int argc, char** argv){ | ||
43 | SET_UP | ||
44 | unsigned char *field; | ||
45 | unsigned int f; | ||
46 | int seed; | ||
47 | int mod_offset; | ||
48 | unsigned int n; | ||
49 | |||
50 | time_t startTime; | ||
51 | |||
52 | struct tokenS{ | ||
53 | unsigned char delimiter[MAX_TOKEN_LENGTH]; | ||
54 | unsigned char length; | ||
55 | struct statisticS{ | ||
56 | unsigned int count; | ||
57 | unsigned char min; | ||
58 | unsigned char sum; | ||
59 | }stat[MAX_SUBFIELDS]; | ||
60 | unsigned char subfields; | ||
61 | }token[MAX_TOKENS]; | ||
62 | |||
63 | unsigned int l; | ||
64 | |||
65 | assert(fscanf(stdin, "%d %d %d %d", &f, &seed, &mod_offset, &n) == 4); | ||
66 | |||
67 | assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); | ||
68 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); | ||
69 | assert((mod_offset >= MIN_MOD_OFFSET) && (mod_offset <= MAX_MOD_OFFSET)); | ||
70 | assert((n >= MIN_TOKENS) && (n <= MAX_TOKENS)); | ||
71 | for (l=0; l<n; l++){ | ||
72 | int x; | ||
73 | int index; | ||
74 | index = 0; | ||
75 | assert(fscanf(stdin,"%x", &x) == 1); | ||
76 | while(x!=0){ | ||
77 | assert((x >= MIN_TOKEN_VALUE) && (x <= MAX_TOKEN_VALUE)); | ||
78 | token[l].delimiter[index] = (unsigned char )x; | ||
79 | index++; | ||
80 | assert(fscanf(stdin,"%x", &x) == 1); | ||
81 | } | ||
82 | assert((index >= MIN_TOKEN_LENGTH) && (index <= MAX_TOKEN_LENGTH)); | ||
83 | token[l].length = index; | ||
84 | } | ||
85 | |||
86 | if ((field = (unsigned char*)malloc(f*sizeof(unsigned char))) == NULL) | ||
87 | return (-1); | ||
88 | |||
89 | randInit(seed); | ||
90 | for (l =0; l<f; l++){ | ||
91 | field[l] = randInt(MIN_TOKEN_VALUE, MAX_TOKEN_VALUE); | ||
92 | } | ||
93 | |||
94 | startTime = time(NULL); | ||
95 | |||
96 | for (l =0; l<n; l++){ | ||
97 | START_LOOP | ||
98 | unsigned int index; | ||
99 | |||
100 | token[l].subfields = 0; | ||
101 | token[l].stat[0].count = 0; | ||
102 | token[l].stat[0].sum = 0; | ||
103 | token[l].stat[0].min = MAX_TOKEN_VALUE; | ||
104 | |||
105 | index = 0; | ||
106 | while ((index < f) && (token[l].subfields < MAX_SUBFIELDS)){ | ||
107 | unsigned char offset; | ||
108 | offset = 0; | ||
109 | while ((field[index+offset] == token[l].delimiter[offset]) && | ||
110 | (offset < token[l].length)){ | ||
111 | offset++; | ||
112 | } | ||
113 | |||
114 | if (offset == token[l].length){ | ||
115 | for (offset=0; offset<token[l].length; offset++){ | ||
116 | field[index+offset] = (field[index+offset] + | ||
117 | field[(index+offset+mod_offset) % f]) | ||
118 | %(MAX_TOKEN_VALUE+1); | ||
119 | } | ||
120 | index += token[l].length-1; | ||
121 | token[l].subfields++; | ||
122 | token[l].stat[token[l].subfields].count = 0; | ||
123 | token[l].stat[token[l].subfields].sum = 0; | ||
124 | token[l].stat[token[l].subfields].min = MAX_TOKEN_VALUE; | ||
125 | } | ||
126 | |||
127 | else{ | ||
128 | token[l].stat[token[l].subfields].count++; | ||
129 | token[l].stat[token[l].subfields].sum += field[index]; | ||
130 | if (token[l].stat[token[l].subfields].min > field[index]) | ||
131 | token[l].stat[token[l].subfields].min = field[index]; | ||
132 | } | ||
133 | index++; | ||
134 | } | ||
135 | token[l].subfields++; | ||
136 | STOP_LOOP | ||
137 | } | ||
138 | |||
139 | startTime = time(NULL) - startTime; | ||
140 | |||
141 | for (l = 0; l< n; l++){ | ||
142 | unsigned int ll; | ||
143 | fprintf(stdout, "%d subfields for token %d \n", token[l].subfields, l); | ||
144 | for ( ll =0; ll<token[l].subfields; ll++) | ||
145 | fprintf(stdout, "subfields %d:\tcount = %d\tmin= %x\tsum= %x\n", | ||
146 | ll, token[l].stat[ll].count, | ||
147 | token[l].stat[ll].min, token[l].stat[ll].sum); | ||
148 | } | ||
149 | fprintf(stdout, "total time = %d seconds.\n", (int)startTime); | ||
150 | free(field); | ||
151 | WRITE_TO_FILE | ||
152 | return(0); | ||
153 | } | ||