1e61e483ac3ec11e52479c12ba8e5039d3f193b7
[openafs.git] / src / des / make_p.c
1 /*
2  * Copyright 1985, 1988 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information, please
5  * see the file <mit-cpyright.h>.
6  *
7  * This routine generates the P permutation code for the DES.
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <mit-cpyright.h>
15 #include <stdio.h>
16 #include <des.h>
17 #include "des_internal.h"
18 #include "tables.h"
19 #include "des_prototypes.h"
20
21 void
22 gen(FILE * stream)
23 {
24     /* P permutes 32 bit input R1 into 32 bit output R2 */
25
26     /* clear the output */
27     fprintf(stream, "    L2 = 0;\n");
28 #ifndef BIG
29     fprintf(stream, "    R2 = 0;\n");
30     fprintf(stream, "/* P operations */\n/* from right to right */\n");
31     /* first list mapping from left to left */
32     for (i = 0; i <= 31; i++)
33         if (P[i] < 32)
34             fprintf(stream, "    if (R1 & (1<<%d)) R2 |= 1<<%d;\n", P[i], i);
35 #else /* BIG */
36     /* flip p into p_temp */
37     fprintf(stream, "    P_temp = R1;\n");
38     fprintf(stream, "    P_temp_p = (unsigned char *) &P_temp;\n");
39
40 #ifdef AFS_DARWIN80_ENV
41     fprintf(stream, "#if defined(__i386__) || defined(__amd64__)\n");
42     fprintf(stream, "    R2 = P_prime[0][*P_temp_p++];\n");
43     fprintf(stream, "    R2 |= P_prime[1][*P_temp_p++];\n");
44     fprintf(stream, "    R2 |= P_prime[2][*P_temp_p++];\n");
45     fprintf(stream, "    R2 |= P_prime[3][*P_temp_p];\n");
46     fprintf(stream, "#elif defined(__ppc__) || defined(__ppc64__)\n");
47     fprintf(stream, "    R2 = P_prime[3][*P_temp_p++];\n");
48     fprintf(stream, "    R2 |= P_prime[2][*P_temp_p++];\n");
49     fprintf(stream, "    R2 |= P_prime[1][*P_temp_p++];\n");
50     fprintf(stream, "    R2 |= P_prime[0][*P_temp_p];\n");
51     fprintf(stream, "#else\n#error Unsupported architecture\n#endif\n");
52 #else /* !AFS_DARWIN80_ENV */
53 #ifdef  LSBFIRST
54     fprintf(stream, "    R2 = P_prime[0][*P_temp_p++];\n");
55     fprintf(stream, "    R2 |= P_prime[1][*P_temp_p++];\n");
56     fprintf(stream, "    R2 |= P_prime[2][*P_temp_p++];\n");
57     fprintf(stream, "    R2 |= P_prime[3][*P_temp_p];\n");
58 #else /* MSBFIRST */
59     fprintf(stream, "    R2 = P_prime[3][*P_temp_p++];\n");
60     fprintf(stream, "    R2 |= P_prime[2][*P_temp_p++];\n");
61     fprintf(stream, "    R2 |= P_prime[1][*P_temp_p++];\n");
62     fprintf(stream, "    R2 |= P_prime[0][*P_temp_p];\n");
63 #endif /* MSBFIRST */
64 #endif /* !AFS_DARWIN80_ENV */
65 #endif /* BIG */
66 }