00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "espresso.h"
00011
00012 static pcube Gcube;
00013 static pset Gminterm;
00014
00015 pset minterms(T)
00016 pcover T;
00017 {
00018 int size, var;
00019 register pcube last;
00020
00021 size = 1;
00022 for(var = 0; var < cube.num_vars; var++)
00023 size *= cube.part_size[var];
00024 Gminterm = set_new(size);
00025
00026 foreach_set(T, last, Gcube)
00027 explode(cube.num_vars-1, 0);
00028
00029 return Gminterm;
00030 }
00031
00032
00033 void explode(var, z)
00034 int var, z;
00035 {
00036 int i, last = cube.last_part[var];
00037 for(i=cube.first_part[var], z *= cube.part_size[var]; i<=last; i++, z++)
00038 if (is_in_set(Gcube, i))
00039 if (var == 0)
00040 set_insert(Gminterm, z);
00041 else
00042 explode(var-1, z);
00043 }
00044
00045
00046 static int mapindex[16][16] = {
00047 0, 1, 3, 2, 16, 17, 19, 18, 80, 81, 83, 82, 64, 65, 67, 66,
00048 4, 5, 7, 6, 20, 21, 23, 22, 84, 85, 87, 86, 68, 69, 71, 70,
00049 12, 13, 15, 14, 28, 29, 31, 30, 92, 93, 95, 94, 76, 77, 79, 78,
00050 8, 9, 11, 10, 24, 25, 27, 26, 88, 89, 91, 90, 72, 73, 75, 74,
00051
00052 32, 33, 35, 34, 48, 49, 51, 50, 112,113,115,114, 96, 97, 99, 98,
00053 36, 37, 39, 38, 52, 53, 55, 54, 116,117,119,118, 100,101,103,102,
00054 44, 45, 47, 46, 60, 61, 63, 62, 124,125,127,126, 108,109,111,110,
00055 40, 41, 43, 42, 56, 57, 59, 58, 120,121,123,122, 104,105,107,106,
00056
00057
00058 160,161,163,162, 176,177,179,178, 240,241,243,242, 224,225,227,226,
00059 164,165,167,166, 180,181,183,182, 244,245,247,246, 228,229,231,230,
00060 172,173,175,174, 188,189,191,190, 252,253,255,254, 236,237,239,238,
00061 168,169,171,170, 184,185,187,186, 248,249,251,250, 232,233,235,234,
00062
00063 128,129,131,130, 144,145,147,146, 208,209,211,210, 192,193,195,194,
00064 132,133,135,134, 148,149,151,150, 212,213,215,214, 196,197,199,198,
00065 140,141,143,142, 156,157,159,158, 220,221,223,222, 204,205,207,206,
00066 136,137,139,138, 152,153,155,154, 216,217,219,218, 200,201,203,202
00067 };
00068
00069 #define POWER2(n) (1 << n)
00070 void map(T)
00071 pcover T;
00072 {
00073 int j, k, l, other_input_offset, output_offset, outnum, ind;
00074 int largest_input_ind, numout;
00075 char c;
00076 pset m;
00077 bool some_output;
00078
00079 m = minterms(T);
00080 largest_input_ind = POWER2(cube.num_binary_vars);
00081 numout = cube.part_size[cube.num_vars-1];
00082
00083 for(outnum = 0; outnum < numout; outnum++) {
00084 output_offset = outnum * largest_input_ind;
00085 printf("\n\nOutput space # %d\n", outnum);
00086 for(l = 0; l <= MAX(cube.num_binary_vars - 8, 0); l++) {
00087 other_input_offset = l * 256;
00088 for(k = 0; k < 16; k++) {
00089 some_output = FALSE;
00090 for(j = 0; j < 16; j++) {
00091 ind = mapindex[k][j] + other_input_offset;
00092 if (ind < largest_input_ind) {
00093 c = is_in_set(m, ind+output_offset) ? '1' : '.';
00094 putchar(c);
00095 some_output = TRUE;
00096 }
00097 if ((j+1)%4 == 0)
00098 putchar(' ');
00099 if ((j+1)%8 == 0)
00100 printf(" ");
00101 }
00102 if (some_output)
00103 putchar('\n');
00104 if ((k+1)%4 == 0) {
00105 if (k != 15 && mapindex[k+1][0] >= largest_input_ind)
00106 break;
00107 putchar('\n');
00108 }
00109 if ((k+1)%8 == 0)
00110 putchar('\n');
00111 }
00112 }
00113 }
00114 set_free(m);
00115 }