diff options
Diffstat (limited to 'dis/Field/field.c')
-rw-r--r-- | dis/Field/field.c | 153 |
1 files changed, 153 insertions, 0 deletions
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 | } | ||