b91ed8746d7bf78bd942239f22524192177b9002
[openafs.git] / src / des / make_fp.c
1 /*
2  * Copyright 1988 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information,
5  * please see the file <mit-cpyright.h>.
6  *
7  * This file contains a generation routine for source code
8  * implementing the final permutation of the DES.
9  */
10
11 #include <afsconfig.h>
12 #include <afs/param.h>
13
14
15 #include "mit-cpyright.h"
16 #include <stdio.h>
17 #include "des.h"
18 #include "des_internal.h"
19 #include "des_prototypes.h"
20
21 #define WANT_FP_TABLE
22 #include "tables.h"
23
24 void
25 gen(FILE * stream)
26 {
27     int i;
28 #ifdef AFS_DARWIN80_ENV
29     int j;
30
31 #define swap_long_bytes_bit_number _darwin_swap_long_bytes_bit_number
32 #endif /* AFS_DARWIN80_ENV */
33
34     /* clear the output */
35     fprintf(stream, "    L2 = 0; R2 = 0;\n");
36
37     /*
38      *  NOTE: As part of the final permutation, we also have to adjust
39      *  for host bit order via "swap_bit_pos_0()".  Since L2,R2 are
40      *  the output from this, we adjust the bit positions written into
41      *  L2,R2.
42      */
43
44 #define SWAP(i,j) \
45     swap_long_bytes_bit_number(swap_bit_pos_0_to_ansi((unsigned)i)-j)
46
47 #ifdef AFS_DARWIN80_ENV
48   for(j = 0;; j++) {
49     fprintf(stream, "%s", _darwin_whichstr[j]);
50     if (j == 2)
51         break;
52 #endif /* AFS_DARWIN80_ENV */
53     /* first setup FP */
54     fprintf(stream, "/* FP operations */\n/* first left to left */\n");
55
56     /* first list mapping from left to left */
57     for (i = 0; i <= 31; i++)
58         if (FP[i] < 32)
59             test_set(stream, "L1", FP[i], "L2", SWAP(i, 0));
60
61     /* now mapping from right to left */
62     fprintf(stream, "\n\n/* now from right to left */\n");
63     for (i = 0; i <= 31; i++)
64         if (FP[i] >= 32)
65             test_set(stream, "R1", FP[i] - 32, "L2", SWAP(i, 0));
66
67     fprintf(stream, "\n/* now from left to right */\n");
68
69     /*  list mapping from left to right */
70     for (i = 32; i <= 63; i++)
71         if (FP[i] < 32)
72             test_set(stream, "L1", FP[i], "R2", SWAP(i, 32));
73
74     /* now mapping from right to right */
75     fprintf(stream, "\n/* last from right to right */\n");
76     for (i = 32; i <= 63; i++)
77         if (FP[i] >= 32)
78             test_set(stream, "R1", FP[i] - 32, "R2", SWAP(i, 32));
79 #ifdef AFS_DARWIN80_ENV
80     _darwin_which = !_darwin_which;
81   }
82 #endif /* AFS_DARWIN80_ENV */
83 }