File indexing completed on 2025-05-11 08:24:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include "dhry.h"
0019
0020 #include <inttypes.h>
0021 #include <stdlib.h>
0022 #include <string.h>
0023
0024
0025
0026 Rec_Pointer Ptr_Glob,
0027 Next_Ptr_Glob;
0028 int Int_Glob;
0029 Boolean Bool_Glob;
0030 char Ch_1_Glob,
0031 Ch_2_Glob;
0032 int Arr_1_Glob [50];
0033 int Arr_2_Glob [50] [50];
0034
0035 #ifndef REG
0036 Boolean Reg = false;
0037 #define REG
0038
0039
0040 #else
0041 Boolean Reg = true;
0042 #endif
0043
0044
0045
0046 #ifdef TIMES
0047 struct tms time_info;
0048 extern int times ();
0049
0050 #define Too_Small_Time 120
0051
0052 #endif
0053 #ifdef TIME
0054 #include <sys/time.h>
0055
0056 #define time(x) Time()
0057 static double Time(void)
0058 {
0059 struct timeval tv;
0060
0061 gettimeofday(&tv, NULL);
0062 return (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
0063 }
0064 #define Too_Small_Time 2
0065
0066 #endif
0067
0068 double Begin_Time,
0069 End_Time,
0070 User_Time;
0071 double Microseconds,
0072 Dhrystones_Per_Second;
0073
0074
0075
0076
0077 int main (int argc, char **argv)
0078
0079
0080
0081
0082 {
0083 One_Fifty Int_1_Loc;
0084 REG One_Fifty Int_2_Loc;
0085 One_Fifty Int_3_Loc;
0086 REG char Ch_Index;
0087 Enumeration Enum_Loc;
0088 Str_30 Str_1_Loc;
0089 Str_30 Str_2_Loc;
0090 REG int Run_Index;
0091 REG int Number_Of_Runs;
0092
0093
0094
0095 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
0096 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
0097
0098 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
0099 Ptr_Glob->Discr = Ident_1;
0100 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
0101 Ptr_Glob->variant.var_1.Int_Comp = 40;
0102 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
0103 "DHRYSTONE PROGRAM, SOME STRING");
0104 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
0105
0106 Arr_2_Glob [8][7] = 10;
0107
0108
0109
0110
0111
0112 printf ("\n");
0113 printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
0114 printf ("\n");
0115 if (Reg)
0116 {
0117 printf ("Program compiled with 'register' attribute\n");
0118 printf ("\n");
0119 }
0120 else
0121 {
0122 printf ("Program compiled without 'register' attribute\n");
0123 printf ("\n");
0124 }
0125
0126 Number_Of_Runs = atoi(argv[1]);
0127 if (Number_Of_Runs < 1) {
0128 return 1;
0129 }
0130
0131 execution_start:
0132 printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
0133
0134 #ifdef __rtems__
0135
0136 Int_1_Loc = 0;
0137 Int_2_Loc = 0;
0138 #endif
0139
0140
0141
0142
0143
0144 #ifdef TIMES
0145 times (&time_info);
0146 Begin_Time = (long) time_info.tms_utime;
0147 #endif
0148 #ifdef TIME
0149 Begin_Time = time ( (long *) 0);
0150 #endif
0151
0152 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
0153 {
0154
0155 Proc_5();
0156 Proc_4();
0157
0158 Int_1_Loc = 2;
0159 Int_2_Loc = 3;
0160 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
0161 Enum_Loc = Ident_2;
0162 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
0163
0164 while (Int_1_Loc < Int_2_Loc)
0165 {
0166 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
0167
0168 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
0169
0170 Int_1_Loc += 1;
0171 }
0172
0173 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
0174
0175 Proc_1 (Ptr_Glob);
0176 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
0177
0178 {
0179 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
0180
0181 {
0182 Proc_6 (Ident_1, &Enum_Loc);
0183 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
0184 Int_2_Loc = Run_Index;
0185 Int_Glob = Run_Index;
0186 }
0187 }
0188
0189 Int_2_Loc = Int_2_Loc * Int_1_Loc;
0190 Int_1_Loc = Int_2_Loc / Int_3_Loc;
0191 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
0192
0193 Proc_2 (&Int_1_Loc);
0194
0195
0196 }
0197
0198
0199
0200
0201
0202 #ifdef TIMES
0203 times (&time_info);
0204 End_Time = (long) time_info.tms_utime;
0205 #endif
0206 #ifdef TIME
0207 End_Time = time ( (long *) 0);
0208 #endif
0209
0210 printf ("Execution ends\n");
0211 printf ("\n");
0212 printf ("Final values of the variables used in the benchmark:\n");
0213 printf ("\n");
0214 printf ("Int_Glob: %d\n", Int_Glob);
0215 printf (" should be: %d\n", 5);
0216 printf ("Bool_Glob: %d\n", Bool_Glob);
0217 printf (" should be: %d\n", 1);
0218 printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
0219 printf (" should be: %c\n", 'A');
0220 printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
0221 printf (" should be: %c\n", 'B');
0222 printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
0223 printf (" should be: %d\n", 7);
0224 printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
0225 printf (" should be: Number_Of_Runs + 10\n");
0226 printf ("Ptr_Glob->\n");
0227 printf (" Ptr_Comp: %" PRIdPTR "\n", (intptr_t) Ptr_Glob->Ptr_Comp);
0228 printf (" should be: (implementation-dependent)\n");
0229 printf (" Discr: %d\n", Ptr_Glob->Discr);
0230 printf (" should be: %d\n", 0);
0231 printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
0232 printf (" should be: %d\n", 2);
0233 printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
0234 printf (" should be: %d\n", 17);
0235 printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
0236 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
0237 printf ("Next_Ptr_Glob->\n");
0238 printf (" Ptr_Comp: %" PRIdPTR "\n", (intptr_t) Next_Ptr_Glob->Ptr_Comp);
0239 printf (" should be: (implementation-dependent), same as above\n");
0240 printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
0241 printf (" should be: %d\n", 0);
0242 printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
0243 printf (" should be: %d\n", 1);
0244 printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
0245 printf (" should be: %d\n", 18);
0246 printf (" Str_Comp: %s\n",
0247 Next_Ptr_Glob->variant.var_1.Str_Comp);
0248 printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
0249 printf ("Int_1_Loc: %d\n", Int_1_Loc);
0250 printf (" should be: %d\n", 5);
0251 printf ("Int_2_Loc: %d\n", Int_2_Loc);
0252 printf (" should be: %d\n", 13);
0253 printf ("Int_3_Loc: %d\n", Int_3_Loc);
0254 printf (" should be: %d\n", 7);
0255 printf ("Enum_Loc: %d\n", Enum_Loc);
0256 printf (" should be: %d\n", 1);
0257 printf ("Str_1_Loc: %s\n", Str_1_Loc);
0258 printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
0259 printf ("Str_2_Loc: %s\n", Str_2_Loc);
0260 printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
0261 printf ("\n");
0262
0263 User_Time = End_Time - Begin_Time;
0264
0265 if (User_Time < Too_Small_Time)
0266 {
0267 printf ("Measured time too small to obtain meaningful results\n");
0268 printf ("Please increase number of runs\n");
0269 printf ("\n");
0270 Number_Of_Runs *= 2;
0271 goto execution_start;
0272 }
0273 else
0274 {
0275 #ifdef TIME
0276 Microseconds = User_Time * Mic_secs_Per_Second / Number_Of_Runs;
0277 Dhrystones_Per_Second = Number_Of_Runs / User_Time;
0278 #else
0279 Microseconds = (float) User_Time * Mic_secs_Per_Second
0280 / ((float) HZ * ((float) Number_Of_Runs));
0281 Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
0282 / (float) User_Time;
0283 #endif
0284 printf ("Microseconds for one run through Dhrystone: ");
0285 printf ("%6.1f \n", Microseconds);
0286 printf ("Dhrystones per Second: ");
0287 printf ("%6.1f \n", Dhrystones_Per_Second);
0288 printf ("DMIPS: ");
0289 printf ("%5.2f \n", Dhrystones_Per_Second / 1757.0);
0290 printf ("\n");
0291 }
0292
0293 return 0;
0294 }
0295
0296
0297 void Proc_1 (Ptr_Val_Par)
0298
0299
0300 REG Rec_Pointer Ptr_Val_Par;
0301
0302 {
0303 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
0304
0305
0306
0307
0308 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
0309 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
0310 Next_Record->variant.var_1.Int_Comp
0311 = Ptr_Val_Par->variant.var_1.Int_Comp;
0312 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
0313 Proc_3 (&Next_Record->Ptr_Comp);
0314
0315
0316 if (Next_Record->Discr == Ident_1)
0317
0318 {
0319 Next_Record->variant.var_1.Int_Comp = 6;
0320 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
0321 &Next_Record->variant.var_1.Enum_Comp);
0322 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
0323 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
0324 &Next_Record->variant.var_1.Int_Comp);
0325 }
0326 else
0327 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
0328 }
0329
0330
0331 void Proc_2 (Int_Par_Ref)
0332
0333
0334
0335
0336 One_Fifty *Int_Par_Ref;
0337 {
0338 One_Fifty Int_Loc;
0339 Enumeration Enum_Loc;
0340
0341 Int_Loc = *Int_Par_Ref + 10;
0342 do
0343 if (Ch_1_Glob == 'A')
0344
0345 {
0346 Int_Loc -= 1;
0347 *Int_Par_Ref = Int_Loc - Int_Glob;
0348 Enum_Loc = Ident_1;
0349 }
0350 while (Enum_Loc != Ident_1);
0351 }
0352
0353
0354 void Proc_3 (Ptr_Ref_Par)
0355
0356
0357
0358
0359 Rec_Pointer *Ptr_Ref_Par;
0360
0361 {
0362 if (Ptr_Glob != Null)
0363
0364 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
0365 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
0366 }
0367
0368
0369 void Proc_4 (void)
0370
0371
0372 {
0373 Boolean Bool_Loc;
0374
0375 Bool_Loc = Ch_1_Glob == 'A';
0376 Bool_Glob = Bool_Loc | Bool_Glob;
0377 Ch_2_Glob = 'B';
0378 }
0379
0380
0381 void Proc_5 (void)
0382
0383
0384 {
0385 Ch_1_Glob = 'A';
0386 Bool_Glob = false;
0387 }
0388
0389
0390
0391
0392 #ifdef NOSTRUCTASSIGN
0393 memcpy (d, s, l)
0394 register char *d;
0395 register char *s;
0396 register int l;
0397 {
0398 while (l--) *d++ = *s++;
0399 }
0400 #endif
0401
0402