OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [examples/] [dhrystone21/] [src/] [dhry/] [dhry_1.c] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
/*
2
 ****************************************************************************
3
 *
4
 *                   "DHRYSTONE" Benchmark Program
5
 *                   -----------------------------
6
 *
7
 *  Version:    C, Version 2.1
8
 *
9
 *  File:       dhry_1.c (part 2 of 3)
10
 *
11
 *  Date:       May 25, 1988
12
 *
13
 *  Author:     Reinhold P. Weicker
14
 *
15
 ****************************************************************************
16
 */
17
 
18
#include "dhry.h"
19
#if defined(CONFIG_RISCV64) || defined(CONFIG_LEON3)
20
#include <inttypes.h>
21
#include <stdarg.h>
22
#include <string.h>
23
char _Next_Glob [sizeof (Rec_Type)];
24
char _Glob[sizeof (Rec_Type)];
25
 
26
extern int printf_uart(const char *_format, ... );
27
 
28
#pragma GCC diagnostic push
29
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
30
#pragma GCC diagnostic ignored "-Wimplicit-int"
31
#pragma GCC diagnostic ignored "-Wreturn-type"
32
#pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
33
#endif
34
 
35
/* Global Variables: */
36
 
37
Rec_Pointer     Ptr_Glob,
38
                Next_Ptr_Glob;
39
int             Int_Glob;
40
Boolean         Bool_Glob;
41
char            Ch_1_Glob,
42
                Ch_2_Glob;
43
int             Arr_1_Glob [50];
44
int             Arr_2_Glob [50] [50];
45
 
46
//extern char     *malloc ();
47
Enumeration     Func_1 ();
48
  /* forward declaration necessary since Enumeration may not simply be int */
49
 
50
#ifndef REG
51
        Boolean Reg = false;
52
#define REG
53
        /* REG becomes defined as empty */
54
        /* i.e. no register variables   */
55
#else
56
        Boolean Reg = true;
57
#endif
58
 
59
/* variables for time measurement: */
60
 
61
#ifdef CONFIG_LEON3
62
uint64_t k_cycle_get_64() {
63
    // 0x8000030C was added to into grlib gptimer in 2017 Jan 28.
64
    uint32 *p_gpTimer = (uint32 *)0x80000300;
65
    return (uint64_t)p_gpTimer[3];
66
}
67
#endif
68
 
69
#ifdef CONFIG_RISCV64
70
uint64_t k_cycle_get_64() {
71
    uint64_t *p_highcnt = (uint64_t *)0x80005000;
72
    return p_highcnt[0];
73
}
74
#endif
75
 
76
#ifdef TIMES
77
#if defined(CONFIG_RISCV64) || defined(CONFIG_LEON3)
78
#define HZ 60000000  // 60 MHz
79
int clock() {
80
    return (int)k_cycle_get_64();
81
}
82
#define Too_Small_Time (2)
83
 
84
#else
85
struct tms      time_info;
86
extern clock_t times_ (struct tms *t);
87
/* see library function "times" */
88
#define Too_Small_Time (2*HZ)
89
#endif
90
                /* Measurements should last at least about 2 seconds */
91
#endif
92
#ifdef TIME
93
extern long     time();
94
                /* see library function "time"  */
95
#define Too_Small_Time 2
96
                /* Measurements should last at least 2 seconds */
97
#endif
98
#ifdef MSC_CLOCK
99
extern clock_t  clock();
100
#define Too_Small_Time (2*HZ)
101
#endif
102
 
103
long            Begin_Time,
104
                End_Time,
105
                User_Time;
106
#if defined(CONFIG_RISCV64) || defined (CONFIG_LEON3)
107
uint64_t        Microseconds,
108
                Dhrystones_Per_Second;
109
#else
110
float           Microseconds,
111
                Dhrystones_Per_Second;
112
#endif
113
 
114
/* end of variables for time measurement */
115
 
116
#if defined(CONFIG_RISCV64) || defined (CONFIG_LEON3)
117
int shell_cmd_soc_dhry(int argc, char *argv[])
118
#else
119
main ()
120
#endif
121
/*****/
122
 
123
  /* main program, corresponds to procedures        */
124
  /* Main and Proc_0 in the Ada version             */
125
{
126
        One_Fifty       Int_1_Loc;
127
  REG   One_Fifty       Int_2_Loc;
128
        One_Fifty       Int_3_Loc;
129
  REG   char            Ch_Index;
130
        Enumeration     Enum_Loc;
131
        Str_30          Str_1_Loc;
132
        Str_30          Str_2_Loc;
133
  REG   int             Run_Index;
134
  REG   int             Number_Of_Runs;
135
 
136
  /* Initializations */
137
 
138
#if defined(CONFIG_RISCV64) || defined (CONFIG_LEON3)
139
  Next_Ptr_Glob = (Rec_Pointer) &_Next_Glob;
140
  Ptr_Glob = (Rec_Pointer) &_Glob ;
141
#else
142
  Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
143
  Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
144
#endif
145
 
146
  Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
147
  Ptr_Glob->Discr                       = Ident_1;
148
  Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
149
  Ptr_Glob->variant.var_1.Int_Comp      = 40;
150
  strcpy (Ptr_Glob->variant.var_1.Str_Comp,
151
          "DHRYSTONE PROGRAM, SOME STRING");
152
  strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
153
 
154
  Arr_2_Glob [8][7] = 10;
155
        /* Was missing in published program. Without this statement,    */
156
        /* Arr_2_Glob [8][7] would have an undefined value.             */
157
        /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
158
        /* overflow may occur for this array element.                   */
159
 
160
  printf_uart ("\n");
161
  printf_uart ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
162
  printf_uart ("\n");
163
  if (Reg)
164
  {
165
    printf_uart ("Program compiled with 'register' attribute\n");
166
    printf_uart ("\n");
167
  }
168
  else
169
  {
170
    printf_uart ("Program compiled without 'register' attribute\n");
171
    printf_uart ("\n");
172
  }
173
#if defined(CONFIG_RISCV64) || defined (CONFIG_LEON3)
174
  Number_Of_Runs = 16*1024;
175
#else
176
  printf_uart ("Please give the number of runs through the benchmark: ");
177
  {
178
    int n;
179
    scanf ("%d", &n);
180
    Number_Of_Runs = n;
181
  }
182
  printf_uart ("\n");
183
#endif
184
 
185
  printf_uart ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
186
 
187
  /***************/
188
  /* Start timer */
189
  /***************/
190
 
191
#ifdef TIMES
192
#if defined(CONFIG_RISCV64) || defined (CONFIG_LEON3)
193
  Begin_Time = (long) clock();
194
#else
195
  times (&time_info);
196
  Begin_Time = (long) time_info.tms_utime;
197
#endif
198
#endif
199
#ifdef TIME
200
  Begin_Time = time ( (long *) 0);
201
#endif
202
#ifdef MSC_CLOCK
203
  Begin_Time = clock();
204
#endif
205
 
206
  for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
207
  {
208
 
209
    Proc_5();
210
    Proc_4();
211
      /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
212
    Int_1_Loc = 2;
213
    Int_2_Loc = 3;
214
    strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
215
    Enum_Loc = Ident_2;
216
    Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
217
      /* Bool_Glob == 1 */
218
    while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
219
    {
220
      Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
221
        /* Int_3_Loc == 7 */
222
      Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
223
        /* Int_3_Loc == 7 */
224
      Int_1_Loc += 1;
225
    } /* while */
226
      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
227
    Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
228
      /* Int_Glob == 5 */
229
    Proc_1 (Ptr_Glob);
230
    for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
231
                             /* loop body executed twice */
232
    {
233
      if (Enum_Loc == Func_1 (Ch_Index, 'C'))
234
          /* then, not executed */
235
        {
236
        Proc_6 (Ident_1, &Enum_Loc);
237
        strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
238
        Int_2_Loc = Run_Index;
239
        Int_Glob = Run_Index;
240
        }
241
    }
242
      /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
243
    Int_2_Loc = Int_2_Loc * Int_1_Loc;
244
    Int_1_Loc = Int_2_Loc / Int_3_Loc;
245
    Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
246
      /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
247
    Proc_2 (&Int_1_Loc);
248
      /* Int_1_Loc == 5 */
249
 
250
  } /* loop "for Run_Index" */
251
 
252
  /**************/
253
  /* Stop timer */
254
  /**************/
255
 
256
#ifdef TIMES
257
#if defined(CONFIG_RISCV64) || defined (CONFIG_LEON3)
258
  End_Time = (long) clock();
259
#else
260
  times_ (&time_info);
261
  End_Time = (long) time_info.tms_utime;
262
#endif
263
#endif
264
#ifdef TIME
265
  End_Time = time ( (long *) 0);
266
#endif
267
#ifdef MSC_CLOCK
268
  End_Time = clock();
269
#endif
270
 
271
  printf_uart ("Execution ends\n");
272
  printf_uart ("\n");
273
  printf_uart ("Final values of the variables used in the benchmark:\n");
274
  printf_uart ("\n");
275
  printf_uart ("Int_Glob:            %d\n", Int_Glob);
276
  printf_uart ("        should be:   %d\n", 5);
277
  printf_uart ("Bool_Glob:           %d\n", Bool_Glob);
278
  printf_uart ("        should be:   %d\n", 1);
279
  printf_uart ("Ch_1_Glob:           %c\n", Ch_1_Glob);
280
  printf_uart ("        should be:   %c\n", 'A');
281
  printf_uart ("Ch_2_Glob:           %c\n", Ch_2_Glob);
282
  printf_uart ("        should be:   %c\n", 'B');
283
  printf_uart ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
284
  printf_uart ("        should be:   %d\n", 7);
285
  printf_uart ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
286
  printf_uart ("        should be:   Number_Of_Runs + 10\n");
287
  printf_uart ("Ptr_Glob->\n");
288
  printf_uart ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
289
  printf_uart ("        should be:   (implementation-dependent)\n");
290
  printf_uart ("  Discr:             %d\n", Ptr_Glob->Discr);
291
  printf_uart ("        should be:   %d\n", 0);
292
  printf_uart ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
293
  printf_uart ("        should be:   %d\n", 2);
294
  printf_uart ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
295
  printf_uart ("        should be:   %d\n", 17);
296
  printf_uart ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
297
  printf_uart ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
298
  printf_uart ("Next_Ptr_Glob->\n");
299
  printf_uart ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
300
  printf_uart ("        should be:   (implementation-dependent), same as above\n");
301
  printf_uart ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
302
  printf_uart ("        should be:   %d\n", 0);
303
  printf_uart ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
304
  printf_uart ("        should be:   %d\n", 1);
305
  printf_uart ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
306
  printf_uart ("        should be:   %d\n", 18);
307
  printf_uart ("  Str_Comp:          %s\n",
308
                                Next_Ptr_Glob->variant.var_1.Str_Comp);
309
  printf_uart ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
310
  printf_uart ("Int_1_Loc:           %d\n", Int_1_Loc);
311
  printf_uart ("        should be:   %d\n", 5);
312
  printf_uart ("Int_2_Loc:           %d\n", Int_2_Loc);
313
  printf_uart ("        should be:   %d\n", 13);
314
  printf_uart ("Int_3_Loc:           %d\n", Int_3_Loc);
315
  printf_uart ("        should be:   %d\n", 7);
316
  printf_uart ("Enum_Loc:            %d\n", Enum_Loc);
317
  printf_uart ("        should be:   %d\n", 1);
318
  printf_uart ("Str_1_Loc:           %s\n", Str_1_Loc);
319
  printf_uart ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
320
  printf_uart ("Str_2_Loc:           %s\n", Str_2_Loc);
321
  printf_uart ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n");
322
  printf_uart ("\n");
323
 
324
  User_Time = End_Time - Begin_Time;
325
 
326
  if (User_Time < Too_Small_Time)
327
  {
328
    printf_uart ("Measured time too small to obtain meaningful results\n");
329
    printf_uart ("Please increase number of runs\n");
330
    printf_uart ("\n");
331
  }
332
  else
333
  {
334
 
335
#ifdef TIME
336
    Microseconds = (float) User_Time * Mic_secs_Per_Second
337
                        / (float) Number_Of_Runs;
338
    Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
339
#elif defined(CONFIG_RISCV64) || defined (CONFIG_LEON3)
340
#else
341
    Microseconds = (float) User_Time * Mic_secs_Per_Second
342
                        / ((float) HZ * ((float) Number_Of_Runs));
343
    Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
344
                        / (float) User_Time;
345
#endif
346
    printf_uart ("Microseconds for one run through Dhrystone: ");
347
#if defined(CONFIG_RISCV64) || defined (CONFIG_LEON3)
348
    int64_t div1 = (int64_t)HZ*(int64_t)Number_Of_Runs;
349
    Microseconds = 10ll * (int64_t)User_Time * Mic_secs_Per_Second;
350
    printf_uart ("%6d.%01d \n", (int)(Microseconds/(10*div1)), (int)(Microseconds%10));
351
#else
352
    printf_uart ("%6.1f \n", Microseconds);
353
#endif
354
    printf_uart ("Dhrystones per Second:                      ");
355
#if defined(CONFIG_RISCV64) || defined (CONFIG_LEON3)
356
    Dhrystones_Per_Second = 10ll * ((int64_t)HZ * (int64_t) Number_Of_Runs);
357
    div1 = (int64_t)User_Time;
358
    printf_uart ("%6d.%01d \n", (int)(Dhrystones_Per_Second/(10*div1)), (int)(Dhrystones_Per_Second%10));
359
#else
360
    printf_uart ("%6.1f \n", Dhrystones_Per_Second);
361
#endif
362
    printf_uart ("\n");
363
 
364
  }
365
 
366
  return 0;
367
}
368
 
369
 
370
Proc_1 (Ptr_Val_Par)
371
/******************/
372
 
373
REG Rec_Pointer Ptr_Val_Par;
374
    /* executed once */
375
{
376
  REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
377
                                        /* == Ptr_Glob_Next */
378
  /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
379
  /* corresponds to "rename" in Ada, "with" in Pascal           */
380
 
381
  structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
382
  Ptr_Val_Par->variant.var_1.Int_Comp = 5;
383
  Next_Record->variant.var_1.Int_Comp
384
        = Ptr_Val_Par->variant.var_1.Int_Comp;
385
  Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
386
  Proc_3 (&Next_Record->Ptr_Comp);
387
    /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
388
                        == Ptr_Glob->Ptr_Comp */
389
  if (Next_Record->Discr == Ident_1)
390
    /* then, executed */
391
  {
392
    Next_Record->variant.var_1.Int_Comp = 6;
393
    Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
394
           &Next_Record->variant.var_1.Enum_Comp);
395
    Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
396
    Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
397
           &Next_Record->variant.var_1.Int_Comp);
398
  }
399
  else /* not executed */
400
    structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
401
} /* Proc_1 */
402
 
403
 
404
Proc_2 (Int_Par_Ref)
405
/******************/
406
    /* executed once */
407
    /* *Int_Par_Ref == 1, becomes 4 */
408
 
409
One_Fifty   *Int_Par_Ref;
410
{
411
  One_Fifty  Int_Loc;
412
  Enumeration   Enum_Loc;
413
 
414
  Int_Loc = *Int_Par_Ref + 10;
415
  do /* executed once */
416
    if (Ch_1_Glob == 'A')
417
      /* then, executed */
418
    {
419
      Int_Loc -= 1;
420
      *Int_Par_Ref = Int_Loc - Int_Glob;
421
      Enum_Loc = Ident_1;
422
    } /* if */
423
  while (Enum_Loc != Ident_1); /* true */
424
} /* Proc_2 */
425
 
426
 
427
Proc_3 (Ptr_Ref_Par)
428
/******************/
429
    /* executed once */
430
    /* Ptr_Ref_Par becomes Ptr_Glob */
431
 
432
Rec_Pointer *Ptr_Ref_Par;
433
 
434
{
435
  if (Ptr_Glob != Null)
436
    /* then, executed */
437
    *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
438
  Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
439
} /* Proc_3 */
440
 
441
 
442
Proc_4 () /* without parameters */
443
/*******/
444
    /* executed once */
445
{
446
  Boolean Bool_Loc;
447
 
448
  Bool_Loc = Ch_1_Glob == 'A';
449
  Bool_Glob = Bool_Loc | Bool_Glob;
450
  Ch_2_Glob = 'B';
451
} /* Proc_4 */
452
 
453
 
454
Proc_5 () /* without parameters */
455
/*******/
456
    /* executed once */
457
{
458
  Ch_1_Glob = 'A';
459
  Bool_Glob = false;
460
} /* Proc_5 */
461
 
462
 
463
        /* Procedure for the assignment of structures,          */
464
        /* if the C compiler doesn't support this feature       */
465
#ifdef  NOSTRUCTASSIGN
466
memcpy (d, s, l)
467
register char   *d;
468
register char   *s;
469
register int    l;
470
{
471
        while (l--) *d++ = *s++;
472
}
473
#endif
474
 
475
#if defined(CONFIG_RISCV64) || defined (CONFIG_LEON3)
476
#pragma GCC diagnostic pop
477
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.