1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include "nmglobal.h"
#include "nbench1.h"
#include "emfloat.h"
/*****************************
** FLOATING-POINT EMULATION **
*****************************/
/**************
** DoEmFloat **
***************
** Perform the floating-point emulation routines portion of the
** CPU benchmark. Returns the operations per second.
*/
void
DoEmFloat(void)
{
/* Error context string pointer */
const char *errorcontext = "CPU:Floating Emulation";
/* Local structure */
EmFloatStruct *locemfloatstruct = &global_emfloatstruct;
InternalFPF *abase = NULL; /* Base of A array */
InternalFPF *bbase = NULL; /* Base of B array */
InternalFPF *cbase = NULL; /* Base of C array */
unsigned long accumtime; /* Accumulated time in ticks */
double iterations; /* # of iterations */
unsigned long tickcount; /* # of ticks */
unsigned long loops; /* # of loops */
abase = malloc(locemfloatstruct->arraysize * sizeof(InternalFPF));
if (!abase) {
printf("ERROR CONDITION\nContext: %s\n", errorcontext);
exit(1);
}
bbase = malloc(locemfloatstruct->arraysize * sizeof(InternalFPF));
if (!bbase) {
printf("ERROR CONDITION\nContext: %s\n", errorcontext);
free(abase);
exit(1);
}
cbase = malloc(locemfloatstruct->arraysize * sizeof(InternalFPF));
if (!cbase) {
printf("ERROR CONDITION\nContext: %s\n", errorcontext);
free(abase);
free(bbase);
exit(1);
}
SetupCPUEmFloatArrays(abase, bbase, cbase, locemfloatstruct->arraysize); /* FIXME: ugly */
/* See if we need to do self-adjusting code.*/
if (locemfloatstruct->adjust == 0) {
locemfloatstruct->loops = 0;
/*
** Do an iteration of the tests. If the elapsed time is
** less than minimum, increase the loop count and try
** again.
*/
for (loops = 1; loops < CPUEMFLOATLOOPMAX; loops += loops) {
tickcount = DoEmFloatIteration(abase, bbase, cbase, /* FIXME: ugly */
locemfloatstruct->arraysize, loops);
if (tickcount > global_min_ticks) {
locemfloatstruct->loops = loops;
break;
}
}
}
/*
** Verify that selft adjustment code worked.
*/
if (locemfloatstruct->loops == 0) {
puts("CPU:EMFPU -- CMPUEMFLOATLOOPMAX limit hit");
free(abase);
free(bbase);
free(cbase);
exit(1);
}
/*
** All's well if we get here. Repeatedly perform floating
** tests until the accumulated time is greater than the
** # of seconds requested.
** Each iteration performs arraysize * 3 operations.
*/
accumtime = 0L;
iterations = 0.0;
do {
accumtime += DoEmFloatIteration(abase, bbase, cbase, /* FIXME: ugly */
locemfloatstruct->arraysize, locemfloatstruct->loops);
iterations += 1.0;
} while (TicksToSecs(accumtime) < locemfloatstruct->request_secs);
/*
** Clean up, calculate results, and go home.
** Also, indicate that adjustment is done.
*/
free(abase);
free(bbase);
free(cbase);
locemfloatstruct->emflops = (iterations * (double)locemfloatstruct->loops)
/ (double)TicksToFracSecs(accumtime);
if (locemfloatstruct->adjust == 0) {
locemfloatstruct->adjust = 1;
}
}
|