diff options
Diffstat (limited to 'dis/original/Field/field.c')
| -rw-r--r-- | dis/original/Field/field.c | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/dis/original/Field/field.c b/dis/original/Field/field.c new file mode 100644 index 0000000..7d26d37 --- /dev/null +++ b/dis/original/Field/field.c | |||
| @@ -0,0 +1,148 @@ | |||
| 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 | |||
| 22 | |||
| 23 | #define MIN_FIELD_SIZE 16 | ||
| 24 | #define MAX_FIELD_SIZE 16777216 | ||
| 25 | #define MIN_SEED -2147483647 | ||
| 26 | #define MAX_SEED -1 | ||
| 27 | #define MIN_MOD_OFFSET 0 | ||
| 28 | #define MAX_MOD_OFFSET 65535 | ||
| 29 | #define MIN_TOKENS 1 | ||
| 30 | #define MAX_TOKENS 256 | ||
| 31 | #define MIN_TOKEN_LENGTH 1 | ||
| 32 | #define MAX_TOKEN_LENGTH 8 | ||
| 33 | #define MIN_TOKEN_VALUE 0 | ||
| 34 | #define MAX_TOKEN_VALUE 255 | ||
| 35 | #define MAX_SUBFIELDS 256 | ||
| 36 | |||
| 37 | /* | ||
| 38 | * main() | ||
| 39 | */ | ||
| 40 | |||
| 41 | int main(){ | ||
| 42 | |||
| 43 | unsigned char *field; | ||
| 44 | unsigned int f; | ||
| 45 | int seed; | ||
| 46 | int mod_offset; | ||
| 47 | unsigned int n; | ||
| 48 | |||
| 49 | time_t startTime; | ||
| 50 | |||
| 51 | struct tokenS{ | ||
| 52 | unsigned char delimiter[MAX_TOKEN_LENGTH]; | ||
| 53 | unsigned char length; | ||
| 54 | struct statisticS{ | ||
| 55 | unsigned int count; | ||
| 56 | unsigned char min; | ||
| 57 | unsigned char sum; | ||
| 58 | }stat[MAX_SUBFIELDS]; | ||
| 59 | unsigned char subfields; | ||
| 60 | }token[MAX_TOKENS]; | ||
| 61 | |||
| 62 | unsigned int l; | ||
| 63 | |||
| 64 | fscanf(stdin, "%d %d %d %d", &f, &seed, &mod_offset, &n); | ||
| 65 | |||
| 66 | assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); | ||
| 67 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); | ||
| 68 | assert((mod_offset >= MIN_MOD_OFFSET) && (mod_offset <= MAX_MOD_OFFSET)); | ||
| 69 | assert((n >= MIN_TOKENS) && (n <= MAX_TOKENS)); | ||
| 70 | for (l=0; l<n; l++){ | ||
| 71 | int x; | ||
| 72 | int index; | ||
| 73 | index = 0; | ||
| 74 | fscanf(stdin,"%x", &x); | ||
| 75 | while(x!=0){ | ||
| 76 | assert((x >= MIN_TOKEN_VALUE) && (x <= MAX_TOKEN_VALUE)); | ||
| 77 | token[l].delimiter[index] = (unsigned char )x; | ||
| 78 | index++; | ||
| 79 | fscanf(stdin,"%x", &x); | ||
| 80 | } | ||
| 81 | assert((index >= MIN_TOKEN_LENGTH) && (index <= MAX_TOKEN_LENGTH)); | ||
| 82 | token[l].length = index; | ||
| 83 | } | ||
| 84 | |||
| 85 | if ((field = (unsigned char*)malloc(f*sizeof(unsigned char))) == NULL) | ||
| 86 | return (-1); | ||
| 87 | |||
| 88 | randInit(seed); | ||
| 89 | for (l =0; l<f; l++){ | ||
| 90 | field[l] = randInt(MIN_TOKEN_VALUE, MAX_TOKEN_VALUE); | ||
| 91 | } | ||
| 92 | |||
| 93 | startTime = time(NULL); | ||
| 94 | |||
| 95 | for (l =0; l<n; l++){ | ||
| 96 | unsigned int index; | ||
| 97 | |||
| 98 | token[l].subfields = 0; | ||
| 99 | token[l].stat[0].count = 0; | ||
| 100 | token[l].stat[0].sum = 0; | ||
| 101 | token[l].stat[0].min = MAX_TOKEN_VALUE; | ||
| 102 | |||
| 103 | index = 0; | ||
| 104 | while ((index < f) && (token[l].subfields < MAX_SUBFIELDS)){ | ||
| 105 | unsigned char offset; | ||
| 106 | offset = 0; | ||
| 107 | while ((field[index+offset] == token[l].delimiter[offset]) && | ||
| 108 | (offset < token[l].length)){ | ||
| 109 | offset++; | ||
| 110 | } | ||
| 111 | |||
| 112 | if (offset == token[l].length){ | ||
| 113 | for (offset=0; offset<token[l].length; offset++){ | ||
| 114 | field[index+offset] = (field[index+offset] + | ||
| 115 | field[(index+offset+mod_offset) % f]) | ||
| 116 | %(MAX_TOKEN_VALUE+1); | ||
| 117 | } | ||
| 118 | index += token[l].length-1; | ||
| 119 | token[l].subfields++; | ||
| 120 | token[l].stat[token[l].subfields].count = 0; | ||
| 121 | token[l].stat[token[l].subfields].sum = 0; | ||
| 122 | token[l].stat[token[l].subfields].min = MAX_TOKEN_VALUE; | ||
| 123 | } | ||
| 124 | |||
| 125 | else{ | ||
| 126 | token[l].stat[token[l].subfields].count++; | ||
| 127 | token[l].stat[token[l].subfields].sum += field[index]; | ||
| 128 | if (token[l].stat[token[l].subfields].min > field[index]) | ||
| 129 | token[l].stat[token[l].subfields].min = field[index]; | ||
| 130 | } | ||
| 131 | index++; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | startTime = time(NULL) - startTime; | ||
| 136 | |||
| 137 | for (l = 0; l< n; l++){ | ||
| 138 | unsigned int ll; | ||
| 139 | fprintf(stdout, "%d subfields for token %d \n", token[l].subfields, l); | ||
| 140 | for ( ll =0; ll<token[l].subfields; ll++) | ||
| 141 | fprintf(stdout, "subfields %d:\tcount = %d\tmin= %x\tsum= %x\n", | ||
| 142 | ll, token[l].stat[ll].count, | ||
| 143 | token[l].stat[ll].min, token[l].stat[ll].sum); | ||
| 144 | } | ||
| 145 | fprintf(stdout, "total time = %d seconds.\n", (int)startTime); | ||
| 146 | free(field); | ||
| 147 | return(0); | ||
| 148 | } | ||
