-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtblshft.c
157 lines (126 loc) · 3.85 KB
/
tblshft.c
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* This benchmark created on August 29, 2022.
*
* The table shift kernel appeared in MiBench Version 1.0,
* consumer/tiff-v3.5.4/libtiff/tif_pixarlog.c, LOC 565-576,
* with following explanation:
* > Since we lose info anyway on 16-bit data, we set up a 14-bit
* > table and shift 16-bit values down two bits on input.
* > saves a little table space.
*
* Web address: https://vhosts.eecs.umich.edu/mibench
*/
/* tblshft.c */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
/* Include polybench common header. */
#include <polybench.h>
/* Include benchmark-specific header. */
/* Default data type is double, default size is N=1024. */
#include <tblshft.h>
#define ONE 1250 /* token value of 1.0 exactly */
#define RATIO 1.004 /* nominal ratio for log part */
/* Array initialization. */
static
void init_array(int tsz,
DATA_TYPE POLYBENCH_1D(TLF,TSZ,tsz))
{
int i, j, nlin;
double b, c, linstep, v;
int TSIZE = tsz - 1;
j = 0;
c = log(RATIO);
nlin = 1. / c;
c = 1. / nlin;
b = exp(-c * ONE);
linstep = b * c * exp(1.);
for (i = 0; i < nlin; i++) {
v = i * linstep;
TLF[j++] = (DATA_TYPE) v;
}
for (i = nlin; i < TSIZE; i++)
TLF[j++] = b * exp(c * i);
TLF[TSIZE] = TLF[TSIZE - 1];
}
/* DCE code. Must scan the entire live-out data.
Can be used also to check the correctness of the output. */
static
void print_array(int f8sz, int f14sz,
DATA_TYPE POLYBENCH_1D(F8,F8SZ,f8sz),
DATA_TYPE POLYBENCH_1D(F14,F14SZ,f14sz))
{
int i, j;
POLYBENCH_DUMP_START;
POLYBENCH_DUMP_BEGIN("F8");
for (i = 0; i < f8sz; i++) {
fprintf (stderr, DATA_PRINTF_MODIFIER, F8[i]);
if (i % 20 == 0) fprintf (stderr, "\n");
}
POLYBENCH_DUMP_END("F8");
POLYBENCH_DUMP_BEGIN("F14");
for (j = 0; j < f14sz; j++) {
fprintf (stderr, DATA_PRINTF_MODIFIER, F14[j]);
if (j % 20 == 0) fprintf (stderr, "\n");
}
POLYBENCH_DUMP_END("F14");
POLYBENCH_DUMP_FINISH;
}
/* Main computational kernel. The whole function will be timed,
including the call and return. */
static
void kernel_tblshft(int f8sz, int f14sz, int tsz,
DATA_TYPE POLYBENCH_1D(F8,F8SZ,f8sz),
DATA_TYPE POLYBENCH_1D(F14,F14SZ,f14sz),
DATA_TYPE POLYBENCH_1D(TLF,TSZ,tsz))
{
int i, j;
DATA_TYPE F14SZM1 = (DATA_TYPE)(f14sz - 1);
DATA_TYPE F8SZM1 = (DATA_TYPE)(f8sz-1);
#pragma scop
j = 0;
#pragma omp parallel for private (i) firstprivate (f14sz,j,F14SZM1)
for (i = 0; i <= f14sz - 1; i += 1) {
while(((double )i) / F14SZM1 * (((double )i) / F14SZM1) > TLF[j] * TLF[j + 1])
j++;
F14[i] = ((double )j);
}
j = 0;
#pragma omp parallel for private (i) firstprivate (f8sz,j,F8SZM1)
for (i = 0; i <= f8sz - 1; i += 1) {
while(((double )i) / F8SZM1 * (((double )i) / F8SZM1) > TLF[j] * TLF[j + 1])
j++;
F8[i] = ((double )j);
}
#pragma endscop
}
int main(int argc, char** argv)
{
/* Retrieve problem size. */
int f8sz = F8SZ;
int f14sz = F14SZ;
int tsz = TSZ;
/* Variable declaration/allocation. */
POLYBENCH_1D_ARRAY_DECL(F8,DATA_TYPE,F8SZ,f8sz);
POLYBENCH_1D_ARRAY_DECL(F14,DATA_TYPE,F14SZ,f14sz);
POLYBENCH_1D_ARRAY_DECL(TLF,DATA_TYPE,TSZ,tsz);
/* Initialize array(s). */
init_array (tsz, POLYBENCH_ARRAY(TLF));
/* Start timer. */
polybench_start_instruments;
/* Run kernel. */
kernel_tblshft (f8sz, f14sz, tsz, POLYBENCH_ARRAY(F8), POLYBENCH_ARRAY(F14), POLYBENCH_ARRAY(TLF));
/* Stop and print timer. */
polybench_stop_instruments;
polybench_print_instruments;
/* Prevent dead-code elimination. All live-out data must be printed
by the function call in argument. */
polybench_prevent_dce(print_array(f8sz, f14sz, POLYBENCH_ARRAY(F8), POLYBENCH_ARRAY(F14)));
/* Be clean. */
POLYBENCH_FREE_ARRAY(TLF);
POLYBENCH_FREE_ARRAY(F14);
POLYBENCH_FREE_ARRAY(F8);
return 0;
}