darwin-x86-and-leopard-20060309
[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 RCSID
15     ("$Header$");
16
17 #include <mit-cpyright.h>
18 #include <stdio.h>
19 #include <des.h>
20 #include "des_internal.h"
21 #include "des_prototypes.h"
22
23 #define WANT_FP_TABLE
24 #include "tables.h"
25
26 void
27 gen(FILE * stream)
28 {
29     register int i;
30 #ifdef AFS_DARWIN80_ENV
31     int j;
32
33 #define swap_long_bytes_bit_number _darwin_swap_long_bytes_bit_number
34 #endif /* AFS_DARWIN80_ENV */
35
36     /* clear the output */
37     fprintf(stream, "    L2 = 0; R2 = 0;\n");
38
39     /*
40      *  NOTE: As part of the final permutation, we also have to adjust
41      *  for host bit order via "swap_bit_pos_0()".  Since L2,R2 are
42      *  the output from this, we adjust the bit positions written into
43      *  L2,R2.
44      */
45
46 #define SWAP(i,j) \
47     swap_long_bytes_bit_number(swap_bit_pos_0_to_ansi((unsigned)i)-j)
48
49 #ifdef AFS_DARWIN80_ENV
50   for(j = 0;; j++) {
51     fprintf(stream, _darwin_whichstr[j]);
52     if (j == 2)
53         break;
54 #endif /* AFS_DARWIN80_ENV */
55     /* first setup FP */
56     fprintf(stream, "/* FP operations */\n/* first left to left */\n");
57
58     /* first list mapping from left to left */
59     for (i = 0; i <= 31; i++)
60         if (FP[i] < 32)
61             test_set(stream, "L1", FP[i], "L2", SWAP(i, 0));
62
63     /* now mapping from right to left */
64     fprintf(stream, "\n\n/* now from right to left */\n");
65     for (i = 0; i <= 31; i++)
66         if (FP[i] >= 32)
67             test_set(stream, "R1", FP[i] - 32, "L2", SWAP(i, 0));
68
69     fprintf(stream, "\n/* now from left to right */\n");
70
71     /*  list mapping from left to right */
72     for (i = 32; i <= 63; i++)
73         if (FP[i] < 32)
74             test_set(stream, "L1", FP[i], "R2", SWAP(i, 32));
75
76     /* now mapping from right to right */
77     fprintf(stream, "\n/* last from right to right */\n");
78     for (i = 32; i <= 63; i++)
79         if (FP[i] >= 32)
80             test_set(stream, "R1", FP[i] - 32, "R2", SWAP(i, 32));
81 #ifdef AFS_DARWIN80_ENV
82     _darwin_which = !_darwin_which;
83   }
84 #endif /* AFS_DARWIN80_ENV */
85 }