summaryrefslogtreecommitdiffstats
path: root/baseline/source/ndes/ndes.c
diff options
context:
space:
mode:
Diffstat (limited to 'baseline/source/ndes/ndes.c')
-rw-r--r--baseline/source/ndes/ndes.c378
1 files changed, 378 insertions, 0 deletions
diff --git a/baseline/source/ndes/ndes.c b/baseline/source/ndes/ndes.c
new file mode 100644
index 0000000..e56906f
--- /dev/null
+++ b/baseline/source/ndes/ndes.c
@@ -0,0 +1,378 @@
1/*
2 This program is part of the TACLeBench benchmark suite.
3 Version V 1.x
4
5 Name: ndes
6
7 Author: unknown
8
9 Function: A lot of bit manipulation, shifts, array and matrix calculations.
10
11 Source:
12
13 Changes: no major functional changes
14
15 License: May be used, modified, and re-distributed freely.
16
17*/
18
19/* A read from this address will result in an known value of 1 */
20#include "../extra.h"
21#define KNOWN_VALUE 1
22#define NDES_WORSTCASE 1
23/*
24 Declaration of global variables
25*/
26
27typedef struct NDES_IMMENSE {
28 unsigned long l, r;
29} ndes_immense;
30typedef struct NDES_GREAT {
31 unsigned long l, c, r;
32} ndes_great;
33
34unsigned long ndes_bit[33];
35ndes_immense ndes_inp, ndes_key, ndes_out;
36int ndes_newkey, ndes_isw;
37
38static ndes_immense ndes_icd;
39static char ndes_ipc1[57];
40static char ndes_ipc2[49];
41
42
43#ifdef NDES_WORSTCASE
44int ndes_value = 1;
45#else
46int ndes_value = 0;
47#endif
48
49/* Forward funtion prototypes */
50
51void ndes_des( ndes_immense inp, ndes_immense key, int *newkey, int isw,
52 ndes_immense *out );
53void ndes_cyfun( unsigned long ir, ndes_great k, unsigned long *iout );
54unsigned long ndes_getbit( ndes_immense source, int bitno, int nbits );
55void ndes_ks( /*immense key, */int n, ndes_great *kn );
56void ndes_init( void );
57int ndes_return( void );
58void ndes_main( void );
59//int main( void );
60
61/*
62 Initialization
63*/
64void ndes_init()
65{
66 unsigned int i;
67 volatile char ndes_ipc1_tmp[57] = {
68 0, 57, 49, 41, 33, 25, 17, 9, 1, 58, 50,
69 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60,
70 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38,
71 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
72 };
73 volatile char ndes_ipc2_tmp[49] = {
74 0, 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21,
75 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31,
76 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34,
77 53, 46, 42, 50, 36, 29, 32
78 };
79 for ( i = 0; i < 57; i++ )
80 ndes_ipc1[i] = ndes_ipc1_tmp[i];
81 for ( i = 0; i < 49; i++ )
82 ndes_ipc2[i] = ndes_ipc2_tmp[i];
83
84 ndes_inp.l = KNOWN_VALUE * 35;
85 ndes_inp.r = KNOWN_VALUE * 26;
86 ndes_key.l = KNOWN_VALUE * 2;
87 ndes_key.r = KNOWN_VALUE * 16;
88
89 ndes_newkey = ndes_value;
90 ndes_isw = ndes_value;
91}
92/*
93 Arithmetic functions
94*/
95void ndes_des( ndes_immense inp, ndes_immense key, int *newkey, int isw,
96 ndes_immense *out )
97{
98 volatile char ip[65] = {
99 0, 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36,
100 28, 20, 12, 4, 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40,
101 32, 24, 16, 8, 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35,
102 27, 19, 11, 3, 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39,
103 31, 23, 15, 7
104 };
105
106 volatile char ipm[65] = {
107 0, 40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15,
108 55, 23, 63, 31, 38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13,
109 53, 21, 61, 29, 36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11,
110 51, 19, 59, 27, 34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9,
111 49, 17, 57, 25
112 };
113 static ndes_great kns[17];
114
115 #ifdef NDES_WORSTCASE
116 static int initflag = 1;
117 #else
118 static int initflag = 0;
119 #endif
120
121 int ii, i, j, k;
122 unsigned long ic, shifter;
123 ndes_immense itmp;
124 ndes_great pg;
125
126 if ( initflag ) {
127 initflag = 0;
128 ndes_bit[1] = shifter = 1L;
129
130 _Pragma( "loopbound min 31 max 31" )
131 for ( j = 2; j <= 32; j++ )
132 ndes_bit[j] = ( shifter <<= 1 );
133 }
134
135 if ( *newkey ) {
136 *newkey = 0;
137 ndes_icd.r = ndes_icd.l = 0L;
138
139 _Pragma( "loopbound min 28 max 28" )
140 for ( j = 28, k = 56; j >= 1; j--, k-- ) {
141 ndes_icd.r = ( ndes_icd.r << 1 ) | ndes_getbit( key, ndes_ipc1[j], 32 );
142 ndes_icd.l = ndes_icd.l << 1;
143 ndes_icd.l = ( ndes_icd.l ) | ndes_getbit( key, ndes_ipc1[k], 32 );
144 }
145
146 _Pragma( "loopbound min 16 max 16" )
147 for ( i = 1; i <= 16; i++ ) {
148 pg = kns[i];
149 ndes_ks( /* key,*/ i, &pg );
150 kns[i] = pg;
151 }
152 }
153
154 itmp.r = itmp.l = 0L;
155
156 _Pragma( "loopbound min 32 max 32" )
157 for ( j = 32, k = 64; j >= 1; j--, k-- ) {
158 itmp.r = itmp.r << 1;
159 itmp.r = ( itmp.r ) | ndes_getbit( inp, ip[j], 32 );
160 itmp.l = itmp.l << 1;
161 itmp.l = ( itmp.l ) | ndes_getbit( inp, ip[k], 32 );
162 }
163 _Pragma( "loopbound min 16 max 16" )
164 for ( i = 1; i <= 16; i++ ) {
165 ii = ( isw == 1 ? 17 - i : i );
166 ndes_cyfun( itmp.l, kns[ii], &ic );
167 ic ^= itmp.r;
168 itmp.r = itmp.l;
169 itmp.l = ic;
170 }
171
172 ic = itmp.r;
173 itmp.r = itmp.l;
174 itmp.l = ic;
175 ( *out ).r = ( *out ).l = 0L;
176
177 _Pragma( "loopbound min 32 max 32" )
178 for ( j = 32, k = 64; j >= 1; j--, k-- ) {
179 ( *out ).r = ( *out ).r << 1;
180 ( *out ).r = ( ( *out ).r ) | ndes_getbit( itmp, ipm[j], 32 );
181 ( *out ).l = ( *out ).l << 1;
182 ( *out ).l = ( ( *out ).l ) | ndes_getbit( itmp, ipm[k], 32 );
183 }
184}
185
186
187void ndes_cyfun( unsigned long ir, ndes_great k, unsigned long *iout )
188{
189 volatile long iet[49] = {0, 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9,
190 10, 11, 12, 13, 12, 13, 14, 15, 16, 17, 16, 17, 18, 19,
191 20, 21, 20, 21, 22, 23, 24, 25, 24, 25, 26, 27, 28, 29,
192 28, 29, 30, 31, 32, 1
193 };
194 volatile long ipp[33] = {0, 16, 7, 20, 21, 29, 12, 28, 17, 1, 15,
195 23, 26, 5, 18, 31, 10, 2, 8, 24, 14, 32, 27, 3, 9, 19, 13,
196 30, 6, 22, 11, 4, 25
197 };
198 volatile long is[16][4][9] = {{{ 0 , 14 , 15 , 10 , 7 , 2 , 12 , 4 , 13 },
199 { 0 , 0 , 3 , 13 , 13 , 14 , 10 , 13 , 1 },
200 { 0 , 4 , 0 , 13 , 10 , 4 , 9 , 1 , 7 },
201 { 0 , 15 , 13 , 1 , 3 , 11 , 4 , 6 , 2 }},
202 {{ 0 , 4 , 1 , 0 , 13 , 12 , 1 , 11 , 2 },
203 { 0 , 15 , 13 , 7 , 8 , 11 , 15 , 0 , 15 },
204 { 0 , 1 , 14 , 6 , 6 , 2 , 14 , 4 , 11 },
205 { 0 , 12 , 8 , 10 , 15 , 8 , 3 , 11 , 1 }},
206 {{ 0 , 13 , 8 , 9 , 14 , 4 , 10 , 2 , 8 },
207 { 0 , 7 , 4 , 0 , 11 , 2 , 4 , 11 , 13 },
208 { 0 , 14 , 7 , 4 , 9 , 1 , 15 , 11 , 4 },
209 { 0 , 8 , 10 , 13 , 0 , 12 , 2 , 13 , 14 }},
210 {{ 0 , 1 , 14 , 14 , 3 , 1 , 15 , 14 , 4 },
211 { 0 , 4 , 7 , 9 , 5 , 12 , 2 , 7 , 8 },
212 { 0 , 8 , 11 , 9 , 0 , 11 , 5 , 13 , 1 },
213 { 0 , 2 , 1 , 0 , 6 , 7 , 12 , 8 , 7 }},
214 {{ 0 , 2 , 6 , 6 , 0 , 7 , 9 , 15 , 6 },
215 { 0 , 14 , 15 , 3 , 6 , 4 , 7 , 4 , 10 },
216 { 0 , 13 , 10 , 8 , 12 , 10 , 2 , 12 , 9 },
217 { 0 , 4 , 3 , 6 , 10 , 1 , 9 , 1 , 4 }},
218 {{ 0 , 15 , 11 , 3 , 6 , 10 , 2 , 0 , 15 },
219 { 0 , 2 , 2 , 4 , 15 , 7 , 12 , 9 , 3 },
220 { 0 , 6 , 4 , 15 , 11 , 13 , 8 , 3 , 12 },
221 { 0 , 9 , 15 , 9 , 1 , 14 , 5 , 4 , 10 }},
222 {{ 0 , 11 , 3 , 15 , 9 , 11 , 6 , 8 , 11 },
223 { 0 , 13 , 8 , 6 , 0 , 13 , 9 , 1 , 7 },
224 { 0 , 2 , 13 , 3 , 7 , 7 , 12 , 7 , 14 },
225 { 0 , 1 , 4 , 8 , 13 , 2 , 15 , 10 , 8 }},
226 {{ 0 , 8 , 4 , 5 , 10 , 6 , 8 , 13 , 1 },
227 { 0 , 1 , 14 , 10 , 3 , 1 , 5 , 10 , 4 },
228 { 0 , 11 , 1 , 0 , 13 , 8 , 3 , 14 , 2 },
229 { 0 , 7 , 2 , 7 , 8 , 13 , 10 , 7 , 13 }},
230 {{ 0 , 3 , 9 , 1 , 1 , 8 , 0 , 3 , 10 },
231 { 0 , 10 , 12 , 2 , 4 , 5 , 6 , 14 , 12 },
232 { 0 , 15 , 5 , 11 , 15 , 15 , 7 , 10 , 0 },
233 { 0 , 5 , 11 , 4 , 9 , 6 , 11 , 9 , 15 }},
234 {{ 0 , 10 , 7 , 13 , 2 , 5 , 13 , 12 , 9 },
235 { 0 , 6 , 0 , 8 , 7 , 0 , 1 , 3 , 5 },
236 { 0 , 12 , 8 , 1 , 1 , 9 , 0 , 15 , 6 },
237 { 0 , 11 , 6 , 15 , 4 , 15 , 14 , 5 , 12 }},
238 {{ 0 , 6 , 2 , 12 , 8 , 3 , 3 , 9 , 3 },
239 { 0 , 12 , 1 , 5 , 2 , 15 , 13 , 5 , 6 },
240 { 0 , 9 , 12 , 2 , 3 , 12 , 4 , 6 , 10 },
241 { 0 , 3 , 7 , 14 , 5 , 0 , 1 , 0 , 9 }},
242 {{ 0 , 12 , 13 , 7 , 5 , 15 , 4 , 7 , 14 },
243 { 0 , 11 , 10 , 14 , 12 , 10 , 14 , 12 , 11 },
244 { 0 , 7 , 6 , 12 , 14 , 5 , 10 , 8 , 13 },
245 { 0 , 14 , 12 , 3 , 11 , 9 , 7 , 15 , 0 }},
246 {{ 0 , 5 , 12 , 11 , 11 , 13 , 14 , 5 , 5 },
247 { 0 , 9 , 6 , 12 , 1 , 3 , 0 , 2 , 0 },
248 { 0 , 3 , 9 , 5 , 5 , 6 , 1 , 0 , 15 },
249 { 0 , 10 , 0 , 11 , 12 , 10 , 6 , 14 , 3 }},
250 {{ 0 , 9 , 0 , 4 , 12 , 0 , 7 , 10 , 0 },
251 { 0 , 5 , 9 , 11 , 10 , 9 , 11 , 15 , 14 },
252 { 0 , 10 , 3 , 10 , 2 , 3 , 13 , 5 , 3 },
253 { 0 , 0 , 5 , 5 , 7 , 4 , 0 , 2 , 5 }},
254 {{ 0 , 0 , 5 , 2 , 4 , 14 , 5 , 6 , 12 },
255 { 0 , 3 , 11 , 15 , 14 , 8 , 3 , 8 , 9 },
256 { 0 , 5 , 2 , 14 , 8 , 0 , 11 , 9 , 5 },
257 { 0 , 6 , 14 , 2 , 2 , 5 , 8 , 3 , 6 }},
258 {{ 0 , 7 , 10 , 8 , 15 , 9 , 11 , 1 , 7 },
259 { 0 , 8 , 5 , 1 , 9 , 6 , 8 , 6 , 2 },
260 { 0 , 0 , 15 , 7 , 4 , 14 , 6 , 2 , 8 },
261 { 0 , 13 , 9 , 12 , 14 , 3 , 13 , 12 , 11 }}};
262
263 volatile char ibin[16] = {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15};
264 ndes_great ie;
265 unsigned long itmp, ietmp1, ietmp2;
266 char iec[9];
267 int irow, icol, iss, l, m;
268 int volatile j, jj;
269 unsigned long *p;
270
271 p = ndes_bit;
272 ie.r = ie.c = ie.l = 0;
273
274 _Pragma( "loopbound min 16 max 16" )
275 for ( j = 16, l = 32, m = 48; j >= 1; j--, l--, m-- ) {
276 ie.r = ( ie.r << 1 ) | ( p[iet[j]] & ir ? 1 : 0 );
277 ie.c = ( ie.c << 1 ) | ( p[iet[l]] & ir ? 1 : 0 );
278 ie.l = ( ie.l << 1 ) | ( p[iet[m]] & ir ? 1 : 0 );
279 }
280 ie.r ^= k.r;
281 ie.c ^= k.c;
282 ie.l ^= k.l;
283 ietmp1 = ( ( unsigned long ) ie.c << 16 ) + ( unsigned long ) ie.r;
284 ietmp2 = ( ( unsigned long ) ie.l << 8 ) + ( ( unsigned long ) ie.c >> 8 );
285
286 _Pragma( "loopbound min 4 max 4" )
287 for ( j = 1, m = 5; j <= 4; j++, m++ ) {
288 iec[j] = ietmp1 & 0x3fL;
289 iec[m] = ietmp2 & 0x3fL;
290 ietmp1 >>= 6;
291 ietmp2 >>= 6;
292 }
293
294 itmp = 0L;
295
296 _Pragma( "loopbound min 8 max 8" )
297 for ( jj = 8; jj >= 1; jj-- ) {
298 j = iec[jj];
299 irow = ( ( j & 0x1 ) << 1 ) + ( ( j & 0x20 ) >> 5 );
300 icol = ( ( j & 0x2 ) << 2 ) + ( j & 0x4 )
301 + ( ( j & 0x8 ) >> 2 ) + ( ( j & 0x10 ) >> 4 );
302 iss = is[icol][irow][jj];
303 itmp = ( itmp << 4 ) | ibin[iss];
304 }
305
306 *iout = 0L;
307 p = ndes_bit;
308
309 _Pragma( "loopbound min 32 max 32" )
310 for ( j = 32; j >= 1; j-- )
311 *iout = ( *iout << 1 );
312 *iout |= ( p[ipp[j]] & itmp ? 1 : 0 );
313}
314
315unsigned long ndes_getbit( ndes_immense source, int bitno, int nbits )
316{
317 if ( bitno <= nbits )
318 return ndes_bit[bitno] & source.r ? 1L : 0L;
319 else
320 return ndes_bit[bitno - nbits] & source.l ? 1L : 0L;
321}
322
323void ndes_ks( /*ndes_immense key, */int n, ndes_great *kn )
324{
325 int i, j, k, l;
326
327 if ( n == 1 || n == 2 || n == 9 || n == 16 ) {
328 ndes_icd.r = ( ndes_icd.r | ( ( ndes_icd.r & 1L ) << 28 ) ) >> 1;
329 ndes_icd.l = ( ndes_icd.l | ( ( ndes_icd.l & 1L ) << 28 ) ) >> 1;
330 } else {
331 _Pragma( "loopbound min 2 max 2" )
332 for ( i = 1; i <= 2; i++ ) {
333 ndes_icd.r = ( ndes_icd.r | ( ( ndes_icd.r & 1L ) << 28 ) ) >> 1;
334 ndes_icd.l = ( ndes_icd.l | ( ( ndes_icd.l & 1L ) << 28 ) ) >> 1;
335 }
336 }
337
338 ( *kn ).r = ( *kn ).c = ( *kn ).l = 0;
339
340 _Pragma( "loopbound min 16 max 16" )
341 for ( j = 16, k = 32, l = 48; j >= 1; j--, k--, l-- ) {
342 ( *kn ).r = ( *kn ).r << 1;
343 ( *kn ).r = ( ( *kn ).r ) | ( unsigned short )
344 ndes_getbit( ndes_icd, ndes_ipc2[j], 28 );
345 ( *kn ).c = ( *kn ).c << 1;
346 ( *kn ).c = ( ( *kn ).c ) | ( unsigned short )
347 ndes_getbit( ndes_icd, ndes_ipc2[k], 28 );
348 ( *kn ).l = ( *kn ).l << 1;
349 ( *kn ).l = ( ( *kn ).l ) | ( unsigned short )
350 ndes_getbit( ndes_icd, ndes_ipc2[l], 28 );
351 }
352}
353
354int ndes_return()
355{
356 return (ndes_icd.r+ndes_icd.l + (-8390656) ) != 0 ;
357}
358
359void _Pragma( "entrypoint" ) ndes_main()
360{
361 ndes_des( ndes_inp, ndes_key, &ndes_newkey, ndes_isw, &ndes_out );
362}
363
364/* main function */
365
366int main( int argc, char **argv )
367{
368 SET_UP
369 for(jobsComplete=-1; jobsComplete<maxJobs; jobsComplete++){
370 START_LOOP
371 ndes_init();
372 ndes_main();
373 STOP_LOOP
374 }
375 WRITE_TO_FILE
376
377 return ( ndes_return() );
378}