/dgc-0.98/cube/dcube.c
# · C · 5900 lines · 4299 code · 777 blank · 824 comment · 1768 complexity · 3ee80781952e9c843ac71d24272cd8a3 MD5 · raw file
Large files are truncated click here to view the full file
- /*
-
- dynamic cube
-
- Copyright (C) 2001 Oliver Kraus (olikraus@yahoo.com)
- This file is part of DGC.
- DGC is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- DGC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with DGC; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- /*! \defgroup dclist Sum of Product Management */
- #include <stdarg.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
- #include "b_io.h"
- #include "b_ff.h"
- #include "dcube.h"
- #include "mcov.h"
- #include "mwc.h"
- #include "matrix.h"
- /*-- dcInSetAll -------------------------------------------------------------*/
- void dcInSetAll(pinfo *pi, dcube *c, c_int v)
- {
- int i;
- for( i = 0; i < pi->in_words; i++ )
- c->in[i] = v;
- }
- /*-- dcCopy -----------------------------------------------------------------*/
- void dcCopy(pinfo *pi, dcube *dest, dcube *src)
- {
- int i;
-
- for( i = 0; i < pi->in_out_words_min; i++ )
- {
- dest->in[i] = src->in[i];
- dest->out[i] = src->out[i];
- }
- for( i = pi->in_out_words_min; i < pi->in_words; i++ )
- dest->in[i] = src->in[i];
- for( i = pi->in_out_words_min; i < pi->out_words; i++ )
- dest->out[i] = src->out[i];
- dest->n = src->n;
- }
- /*-- dcCopyOut --------------------------------------------------------------*/
- void dcCopyOut(pinfo *pi, dcube *dest, dcube *src)
- {
- int i;
- for( i = 0; i < pi->out_words; i++ )
- dest->out[i] = src->out[i];
- }
- /*-- dcCopyIn ---------------------------------------------------------------*/
- void dcCopyIn(pinfo *pi, dcube *dest, dcube *src)
- {
- int i;
- for( i = 0; i < pi->in_words; i++ )
- dest->in[i] = src->in[i];
- }
- /*-- dcCopyInToIn -----------------------------------------------------------*/
- void dcCopyInToIn(pinfo *pi_dest, dcube *dest, int dest_offset, pinfo *pi_src, dcube *src)
- {
- int i;
- int s;
- for( i = 0; i < pi_src->in_cnt; i++ )
- {
- s = dcGetIn(src, i);
- dcSetIn(dest, i+dest_offset, s);
- }
- }
- /*-- dcCopyInToInRange ------------------------------------------------------*/
- void dcCopyInToInRange(pinfo *pi_dest, dcube *dest, int dest_offset,
- pinfo *pi_src, dcube *src, int src_offset, int src_cnt)
- {
- int i;
- int s;
- assert(src_offset+src_cnt <= pi_src->in_cnt);
- for( i = src_offset; i < src_offset+src_cnt; i++ )
- {
- s = dcGetIn(src, i);
- dcSetIn(dest, i+dest_offset-src_offset, s);
- }
- }
- /*-- dcCopyOutToIn ----------------------------------------------------------*/
- void dcCopyOutToIn(pinfo *pi_dest, dcube *dest, int dest_offset, pinfo *pi_src, dcube *src)
- {
- int i;
- int s;
- for( i = 0; i < pi_src->out_cnt; i++ )
- {
- s = dcGetOut(src, i) + 1;
- dcSetIn(dest, i+dest_offset, s);
- }
- }
- /*-- dcCopyOutToInRange -----------------------------------------------------*/
- void dcCopyOutToInRange(pinfo *pi_dest, dcube *dest, int dest_offset,
- pinfo *pi_src, dcube *src, int src_offset, int src_cnt)
- {
- int i;
- int s;
- assert(src_offset+src_cnt <= pi_src->in_cnt);
- for( i = src_offset; i < src_offset+src_cnt; i++ )
- {
- s = dcGetOut(src, i) + 1;
- dcSetIn(dest, i+dest_offset-src_offset, s);
- }
- }
- /*-- dcCopyInToOut ----------------------------------------------------------*/
- void dcCopyInToOut(pinfo *pi_dest, dcube *dest, int dest_offset, pinfo *pi_src, dcube *src)
- {
- int i;
- int s;
- for( i = 0; i < pi_src->in_cnt; i++ )
- {
- s = dcGetIn(src, i) - 1;
- dcSetOut(dest, i+dest_offset, s);
- }
- }
- /*-- dcCopyInToOutRange -----------------------------------------------------*/
- void dcCopyInToOutRange(pinfo *pi_dest, dcube *dest, int dest_offset,
- pinfo *pi_src, dcube *src, int src_offset, int src_cnt)
- {
- int i;
- int s;
- assert(src_offset+src_cnt <= pi_src->in_cnt);
- for( i = src_offset; i < src_offset+src_cnt; i++ )
- {
- s = dcGetIn(src, i) - 1;
- dcSetOut(dest, i+dest_offset-src_offset, s);
- }
- }
- /*-- dcCopyOutToOut ---------------------------------------------------------*/
- void dcCopyOutToOut(pinfo *pi_dest, dcube *dest, int dest_offset,
- pinfo *pi_src, dcube *src)
- {
- int i, cnt;
- int s;
- cnt = pi_src->out_cnt;
- if ( cnt > pi_dest->out_cnt-dest_offset )
- cnt = pi_dest->out_cnt-dest_offset;
- for( i = 0; i < cnt; i++ )
- {
- s = dcGetOut(src, i);
- dcSetOut(dest, i+dest_offset, s);
- }
- }
- /*-- dcCopyOutToOutRange ----------------------------------------------------*/
- void dcCopyOutToOutRange(pinfo *pi_dest, dcube *dest, int dest_offset,
- pinfo *pi_src, dcube *src, int src_offset, int src_cnt)
- {
- int i;
- int s;
- assert(src_offset+src_cnt <= pi_src->out_cnt);
- assert(dest_offset+src_cnt < pi_dest->out_cnt);
- for( i = src_offset; i < src_offset+src_cnt; i++ )
- {
- s = dcGetOut(src, i);
- dcSetOut(dest, i+dest_offset-src_offset, s);
- }
- }
- /*-- dcOutSetAll ------------------------------------------------------------*/
- void dcOutSetAll(pinfo *pi, dcube *c, c_int v)
- {
- int i;
- for( i = 0; i < pi->out_words; i++ )
- c->out[i] = v;
- }
- /*-- dcAllClear -------------------------------------------------------------*/
- void dcAllClear(pinfo *pi, dcube *c)
- {
- dcInSetAll(pi, c, 0);
- dcOutSetAll(pi, c, 0);
- }
- /*-- dcSetTautology ---------------------------------------------------------*/
- void dcSetTautology(pinfo *pi, dcube *c)
- {
- dcInSetAll(pi, c, CUBE_IN_MASK_DC);
- dcOutSetAll(pi, c, CUBE_OUT_MASK);
- if ( pi->out_words > 0 )
- c->out[pi->out_words-1] = pi->out_last_mask;
- }
- /*-- dcSetOutTautology ------------------------------------------------------*/
- void dcSetOutTautology(pinfo *pi, dcube *c)
- {
- dcOutSetAll(pi, c, CUBE_OUT_MASK);
- if ( pi->out_words > 0 )
- c->out[pi->out_words-1] = pi->out_last_mask;
- }
- /*-- dcInitMem --------------------------------------------------------------*/
- int dcInitMem(pinfo *pi, dcube *c)
- {
- c->in = NULL;
- c->out = NULL;
- return dcAdjustByPinfo(pi, c);
- }
- /*-- dcInit -----------------------------------------------------------------*/
- int dcInit(pinfo *pi, dcube *c)
- {
- c->in = NULL;
- c->out = NULL;
- if ( dcAdjustByPinfo(pi, c) == 0 )
- return 0;
- dcInSetAll(pi, c, CUBE_IN_MASK_DC);
- dcOutSetAll(pi, c, 0);
- c->n = 0;
- return 1;
- }
- /*-- dcInitVA --------------------------------------------------------------*/
- int dcInitVA(pinfo *pi, int n, ...)
- {
- va_list va;
- int i;
- va_start(va, n);
- for( i = 0; i < n; i++ )
- if ( dcInit(pi, va_arg(va, dcube *)) == 0 )
- break;
- va_end(va);
- if ( i < n )
- {
- va_start(va, n);
- while( i-- >= 0 )
- dcDestroy(va_arg(va, dcube *));
- va_end(va);
- return 0;
- }
- return 1;
- }
- /*-- dcDestroy --------------------------------------------------------------*/
- void dcDestroy(dcube *c)
- {
- if ( c->in != NULL )
- free(c->in);
- if ( c->out != NULL )
- free(c->out);
-
- c->in = NULL;
- c->out = NULL;
- }
- /*-- dcDestroyVA ------------------------------------------------------------*/
- void dcDestroyVA(int n, ...)
- {
- va_list va;
- int i;
- va_start(va, n);
- for( i = 0; i < n; i++ )
- dcDestroy(va_arg(va, dcube *));
- va_end(va);
- }
- /*-- dcAdjust ---------------------------------------------------------------*/
- int dcAdjust(dcube *c, int in_words, int out_words)
- {
- void *ptr;
- if ( in_words == 0 )
- {
- if ( c->in != NULL )
- free(c->in);
- c->in = NULL;
- }
- else
- {
- if ( c->in == NULL )
- ptr = malloc(sizeof(c_int)*in_words);
- else
- ptr = realloc(c->in, sizeof(c_int)*in_words);
- if ( ptr == NULL )
- return 0;
- c->in = (c_int *)ptr;
- }
- if ( out_words == 0 )
- {
- if ( c->out != NULL )
- free(c->out);
- c->out = NULL;
- }
- else
- {
- if ( c->out == NULL )
- ptr = malloc(sizeof(c_int)*out_words);
- else
- ptr = realloc(c->out, sizeof(c_int)*out_words);
- if ( ptr == NULL )
- return 0;
- c->out = (c_int *)ptr;
- }
-
- return 1;
- }
- /*-- dcAdjustByPinfo --------------------------------------------------------*/
- int dcAdjustByPinfo(pinfo *pi, dcube *c)
- {
- return dcAdjust(c, pi->in_words, pi->out_words);
- }
- /*-- dcAdjustByPinfoVA ------------------------------------------------------*/
- int dcAdjustByPinfoVA(pinfo *pi, int n, ...)
- {
- va_list va;
- int i;
- va_start(va, n);
- for( i = 0; i < n; i++ )
- if ( dcAdjustByPinfo(pi, va_arg(va, dcube *)) == 0 )
- {
- va_end(va);
- return 0;
- }
- va_end(va);
- return 1;
- }
- /*-- dcSetIn ----------------------------------------------------------------*/
- void dcSetIn(dcube *c, int pos, int code)
- {
- c->in[pos/CUBE_SIGNALS_PER_IN_WORD] &= ~(3<<((pos&(CUBE_SIGNALS_PER_IN_WORD-1))*2));
- c->in[pos/CUBE_SIGNALS_PER_IN_WORD] |= code<<((pos&(CUBE_SIGNALS_PER_IN_WORD-1))*2);
- }
- /*-- dcGetIn ----------------------------------------------------------------*/
- int dcGetIn(dcube *c, int pos)
- {
- return (c->in[pos/CUBE_SIGNALS_PER_IN_WORD] >>
- ((pos&(CUBE_SIGNALS_PER_IN_WORD-1))*2)) & 3;
- }
- /*-- dcSetOut ---------------------------------------------------------------*/
- void dcSetOut(dcube *c, int pos, int code)
- {
- c->out[pos/CUBE_SIGNALS_PER_OUT_WORD] &= ~(1<<(pos&(CUBE_SIGNALS_PER_OUT_WORD-1)));
- c->out[pos/CUBE_SIGNALS_PER_OUT_WORD] |= (code<<(pos&(CUBE_SIGNALS_PER_OUT_WORD-1)));
- }
- /*-- dcGetOut ----------------------------------------------------------------*/
- int dcGetOut(dcube *c, int pos)
- {
- return (c->out[pos/CUBE_SIGNALS_PER_OUT_WORD] >>
- (pos&(CUBE_SIGNALS_PER_OUT_WORD-1))) & 1;
- }
- /*-- dcSetByStr -------------------------------------------------------------*/
- int dcSetByStr(pinfo *pi, dcube *c, char *str)
- {
- size_t i = 0;
-
- if ( dcAdjustByPinfo(pi, c) == 0 )
- return 0;
- dcInSetAll(pi, c, CUBE_IN_MASK_DC);
- dcOutSetAll(pi, c, 0);
-
- while( i < pi->in_cnt )
- switch(*str++)
- {
- case '0': dcSetIn(c, i++, 1); break;
- case '1': dcSetIn(c, i++, 2); break;
- case '-': dcSetIn(c, i++, 3); break;
- case '\0': return 0;
- }
- i = 0;
- while( i < pi->out_cnt )
- switch(*str++)
- {
- case '0': dcSetOut(c, i++, 0); break;
- case '1': dcSetOut(c, i++, 1); break;
- case '\0': return 0;
- }
- return 1;
- }
- /*-- dcSetInByStr -----------------------------------------------------------*/
- int dcSetInByStr(pinfo *pi, dcube *c, char *str)
- {
- size_t i = 0;
-
- if ( dcAdjustByPinfo(pi, c) == 0 )
- return 0;
- dcInSetAll(pi, c, CUBE_IN_MASK_DC);
-
- i = 0;
- while( i < pi->in_cnt )
- switch(*str++)
- {
- case '0': dcSetIn(c, i++, 1); break;
- case '1': dcSetIn(c, i++, 2); break;
- case '-': dcSetIn(c, i++, 3); break;
- case '\0': return 0;
- }
- return 1;
- }
- /*-- dcSetOutByStr ----------------------------------------------------------*/
- int dcSetOutByStr(pinfo *pi, dcube *c, char *str)
- {
- size_t i = 0;
-
- if ( dcAdjustByPinfo(pi, c) == 0 )
- return 0;
- dcInSetAll(pi, c, 0);
-
- i = 0;
- while( i < pi->out_cnt )
- switch(*str++)
- {
- case '0': dcSetOut(c, i++, 0); break;
- case '1': dcSetOut(c, i++, 1); break;
- case '\0': return 0;
- }
- return 1;
- }
- /*-- dcSetAllByStr ----------------------------------------------------------*/
- /* dcSetAllByStr ... dcSetAllByStrPtr */
- char *dcSetAllByStr(pinfo *pi, int in_cnt, int out_cnt, dcube *c_on, dcube *c_dc, char *str)
- {
- size_t i = 0;
-
- if ( dcAdjustByPinfo(pi, c_on) == 0 )
- return NULL;
- if ( dcAdjustByPinfo(pi, c_dc) == 0 )
- return NULL;
- dcInSetAll(pi, c_on, CUBE_IN_MASK_DC);
- dcOutSetAll(pi, c_on, 0);
- dcInSetAll(pi, c_dc, CUBE_IN_MASK_DC);
- dcOutSetAll(pi, c_dc, 0);
-
- while( i < in_cnt )
- {
- switch(*str++)
- {
- case '0': dcSetIn(c_on, i, 1); dcSetIn(c_dc, i, 1); i++; break;
- case '1': dcSetIn(c_on, i, 2); dcSetIn(c_dc, i, 2); i++; break;
- case '-': dcSetIn(c_on, i, 3); dcSetIn(c_dc, i, 3); i++; break;
- case '\0': return 0;
- }
- }
- i = 0;
- while( i < out_cnt )
- {
- switch(*str)
- {
- case '0': dcSetOut(c_on, i, 0); dcSetOut(c_dc, i, 0); i++; break;
- case '1': dcSetOut(c_on, i, 1); dcSetOut(c_dc, i, 0); i++; break;
- case '2': dcSetOut(c_on, i, 0); dcSetOut(c_dc, i, 1); i++; break;
- case '-': dcSetOut(c_on, i, 0); dcSetOut(c_dc, i, 1); i++; break;
- case '\0': return 0;
- default:
- if ( *str >= 'a' && *str <= 'z' )
- return 0;
- if ( *str >= 'A' && *str <= 'Z' )
- return 0;
- if ( *str == '_' )
- return 0;
-
- }
- str++;
- }
- return str;
- }
- /*-- dcToStr ----------------------------------------------------------------*/
- char *dcToStr(pinfo *pi, dcube *c, char *sep, char *post)
- {
- static char s[1024*8];
- int i, l;
- for( i = 0; i < pi->in_cnt; i++ )
- s[i] = "x01-"[dcGetIn(c, i)];
- strcpy(s+pi->in_cnt, sep);
- l = pi->in_cnt+strlen(sep);
- for( i = 0; i < pi->out_cnt; i++ )
- s[i+l] = "01"[dcGetOut(c, i)];
- strcpy(s+l+pi->out_cnt, post);
- return s;
- }
- char *dcToStr2(pinfo *pi, dcube *c, char *sep, char *post)
- {
- static char s[1024*8];
- int i, l;
- for( i = 0; i < pi->in_cnt; i++ )
- s[i] = "x01-"[dcGetIn(c, i)];
- strcpy(s+pi->in_cnt, sep);
- l = pi->in_cnt+strlen(sep);
- for( i = 0; i < pi->out_cnt; i++ )
- s[i+l] = "01"[dcGetOut(c, i)];
- strcpy(s+l+pi->out_cnt, post);
- return s;
- }
- char *dcToStr3(pinfo *pi, dcube *c, char *sep, char *post)
- {
- static char s[1024*8];
- int i, l;
- for( i = 0; i < pi->in_cnt; i++ )
- s[i] = "x01-"[dcGetIn(c, i)];
- strcpy(s+pi->in_cnt, sep);
- l = pi->in_cnt+strlen(sep);
- for( i = 0; i < pi->out_cnt; i++ )
- s[i+l] = "01"[dcGetOut(c, i)];
- strcpy(s+l+pi->out_cnt, post);
- return s;
- }
- /*-- dcOutToStr -------------------------------------------------------------*/
- char *dcOutToStr(pinfo *pi, dcube *c, char *post)
- {
- static char s[1024*16];
- int i;
- for( i = 0; i < pi->out_cnt; i++ )
- s[i] = "01"[dcGetOut(c, i)];
- strcpy(s+pi->out_cnt, post);
- return s;
- }
- /*-- dcInToStr --------------------------------------------------------------*/
- char *dcInToStr(pinfo *pi, dcube *c, char *post)
- {
- static char s[1024*16];
- int i, l;
- for( i = 0; i < pi->in_cnt; i++ )
- s[i] = "x01-"[dcGetIn(c, i)];
- strcpy(s+pi->in_cnt, post);
- return s;
- }
- /*-- dcInc ------------------------------------------------------------------*/
- /* assume that there are no don't cares */
- /* interpret the cube as a binary number and add 1 */
- /* returns 0 if there was a overflow */
- int dcInc(pinfo *pi, dcube *c)
- {
- int i = 0;
- for(;;)
- {
- if ( dcGetIn(c, i) == 1 )
- {
- dcSetIn(c, i, 2);
- break;
- }
- else
- {
- dcSetIn(c, i, 1);
- i++;
- }
- if ( i >= pi->in_cnt )
- return 0;
- }
- return 1;
- }
- /*-- dcIncOut ---------------------------------------------------------------*/
- /* assume that there are no don't cares */
- /* interpret the cube as a binary number and add 1 */
- /* returns 0 if there was a overflow */
- int dcIncOut(pinfo *pi, dcube *c)
- {
- int i = 0;
- for(;;)
- {
- if ( dcGetOut(c, i) == 0 )
- {
- dcSetOut(c, i, 1);
- break;
- }
- else
- {
- dcSetOut(c, i, 0);
- i++;
- }
- if ( i >= pi->out_cnt )
- return 0;
- }
- return 1;
- }
- /*-- dcIsEqualIn ------------------------------------------------------------*/
- int dcIsEqualIn(pinfo *pi, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- if ( a->in[i] != b->in[i] )
- return 0;
- return 1;
- }
- /*-- dcIsEqualOut -----------------------------------------------------------*/
- int dcIsEqualOut(pinfo *pi, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->out_words; i++ )
- if ( a->out[i] != b->out[i] )
- return 0;
- return 1;
- }
- /*-- dcIsEqualOutCnt --------------------------------------------------------*/
- int dcIsEqualOutCnt(dcube *a, dcube *b, int off, int cnt)
- {
- register int i;
- for( i = off; i < off+cnt; i++ )
- if ( dcGetOut(a, i) != dcGetOut(b, i) )
- return 0;
- return 1;
- }
- /*-- dcIsEqualOutRange ------------------------------------------------------*/
- int dcIsEqualOutRange(dcube *a, int off_a, dcube *b, int off_b, int cnt)
- {
- register int i;
- for( i = 0; i < cnt; i++ )
- if ( dcGetOut(a, i+off_a) != dcGetOut(b, i+off_b) )
- return 0;
- return 1;
- }
- /*-- dcIsEqual --------------------------------------------------------------*/
- int dcIsEqual(pinfo *pi, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- if ( a->in[i] != b->in[i] )
- return 0;
- for( i = 0; i < pi->out_words; i++ )
- if ( a->out[i] != b->out[i] )
- return 0;
- return 1;
- }
- /*-- dcIntersection ---------------------------------------------------------*/
- int dcIntersectionOld(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- register int i;
- if ( dcDeltaOut(pi, a, b) > 0 )
- return 0;
- if ( dcIsDeltaInNoneZero(pi, a, b) > 0 )
- return 0;
- for( i = 0; i < pi->in_words; i++ )
- r->in[i] = a->in[i] & b->in[i];
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = a->out[i] & b->out[i];
- return 1;
- }
- int dcIntersection(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- register int i;
- register c_int c;
- for( i = 0; i < pi->in_words; i++ )
- {
- c = a->in[i] & b->in[i]; /* Problem: Wie oft kommt 00 vor? */
- r->in[i] = c;
- c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
- c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- if ( c > 0 )
- return 0;
- }
- if ( pi->out_cnt == 0 )
- return 1;
- c = 0;
- for( i = 0; i < pi->out_words; i++ )
- {
- r->out[i] = a->out[i] & b->out[i];
- c |= r->out[i];
- }
- if ( c == 0 )
- return 0;
-
- return 1;
- }
- /*-- dcIsInSubSet -----------------------------------------------------------*/
- /* Ist der Eingangs-Teil von b Teilmenge vom Eingangs-Teil von a? */
- /* Ja: Rueckgabe ist 1, nein: Rueckgabe ist 0 */
- int dcIsInSubSet(pinfo *pi, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- if ( (a->in[i] & b->in[i]) != b->in[i] )
- return 0;
- return 1;
- }
- /*-- dcIsOutSubSet ----------------------------------------------------------*/
- /* Ist der Eingangs-Teil von b Teilmenge vom Eingangs-Teil von a? */
- /* Ja: Rueckgabe ist 1, nein: Rueckgabe ist 0 */
- int dcIsOutSubSet(pinfo *pi, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->out_words; i++ )
- if ( (a->out[i] & b->out[i]) != b->out[i] )
- return 0;
- return 1;
- }
- /*-- dcIsSubSet -------------------------------------------------------------*/
- /* Ist b Teilmenge von a? */
- /* Ja: Rueckgabe ist 1, nein: Rueckgabe ist 0 */
- int dcIsSubSetReadable(pinfo *pi, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- if ( (a->in[i] & b->in[i]) != b->in[i] )
- return 0;
- for( i = 0; i < pi->out_words; i++ )
- if ( (a->out[i] & b->out[i]) != b->out[i] )
- return 0;
- return 1;
- }
- int dcIsSubSet(pinfo *pi, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->in_out_words_min; i++ )
- {
- if ( (~a->in[i] & b->in[i]) != 0 )
- return 0;
- if ( (~a->out[i] & b->out[i]) != 0 )
- return 0;
- }
- for( i = pi->in_out_words_min; i < pi->in_words; i++ )
- if ( (~a->in[i] & b->in[i]) != 0 )
- return 0;
- for( i = pi->in_out_words_min; i < pi->out_words; i++ )
- if ( (~a->out[i] & b->out[i]) != 0 )
- return 0;
- return 1;
- }
- int dcIsSubSet4(pinfo *pi, dcube *a1, dcube *a2, dcube *a3, dcube *a4, dcube *b)
- {
- register int i;
- register c_int r1, r2, r3, r4;
- r1 = 0;
- r2 = 0;
- r3 = 0;
- r4 = 0;
- for( i = 0; i < pi->in_words; i++ )
- {
- r1 |= (~a1->in[i] & b->in[i]);
- r2 |= (~a2->in[i] & b->in[i]);
- r3 |= (~a3->in[i] & b->in[i]);
- r4 |= (~a4->in[i] & b->in[i]);
- if ( r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 )
- return 0;
- }
- for( i = 0; i < pi->out_words; i++ )
- {
- r1 |= (~a1->out[i] & b->out[i]);
- r2 |= (~a2->out[i] & b->out[i]);
- r3 |= (~a3->out[i] & b->out[i]);
- r4 |= (~a4->out[i] & b->out[i]);
- if ( r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 )
- return 0;
- }
- return 1;
- }
- int dcIsSubSet6n(pinfo *pi, dcube *a, dcube *b1, dcube *b2, dcube *b3, dcube *b4, dcube *b5, dcube *b6)
- {
- register int i;
- register c_int r1, r2, r3, r4, r5, r6;
- register c_int aw;
- r1 = 0;
- r2 = 0;
- r3 = 0;
- r4 = 0;
- r5 = 0;
- r6 = 0;
- for( i = 0; i < pi->in_words; i++ )
- {
- aw = ~a->in[i];
- r1 |= (aw & b1->in[i]);
- r2 |= (aw & b2->in[i]);
- r3 |= (aw & b3->in[i]);
- r4 |= (aw & b4->in[i]);
- r5 |= (aw & b5->in[i]);
- r6 |= (aw & b6->in[i]);
- if ( r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 && r5 != 0 && r6 != 0 )
- return 0;
- }
- for( i = 0; i < pi->out_words; i++ )
- {
- aw = ~a->out[i];
- r1 |= (aw & b1->out[i]);
- r2 |= (aw & b2->out[i]);
- r3 |= (aw & b3->out[i]);
- r4 |= (aw & b4->out[i]);
- r5 |= (aw & b5->out[i]);
- r6 |= (aw & b6->out[i]);
- if ( r1 != 0 && r2 != 0 && r3 != 0 && r4 != 0 && r5 != 0 && r6 != 0 )
- return 0;
- }
- return 1;
- }
- /*-- dcInDCCnt --------------------------------------------------------------*/
- int dcInDCCnt(pinfo *pi, dcube *cube)
- {
- register c_int c;
- register int bc = 0;
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- {
- c = cube->in[i]; /* Problem: Wie oft kommt 11 vor? */
- c = ~c; /* Problem: Wie oft kommt 00 vor? */
- c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
- c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- bc += bitcount(c);
- }
- if ( ((pi->in_cnt)&(CUBE_SIGNALS_PER_IN_WORD-1)) != 0 )
- bc -= CUBE_SIGNALS_PER_IN_WORD-((pi->in_cnt)&(CUBE_SIGNALS_PER_IN_WORD-1));
- return bc;
- }
- /*-- dcInDCMask--------------------------------------------------------------*/
- void dcInDCMask(pinfo *pi, dcube *cube)
- {
- register c_int c;
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- {
- c = cube->in[i]; /* Problem: Wie oft kommt 11 vor? */
- c &= c>>1; /* Reduktion: Wie oft kommt x1 vor? */
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- c |= c<<1;
- cube->in[i] = c;
- }
- }
- /*-- dcInZeroCnt ------------------------------------------------------------*/
- int dcInZeroCnt(pinfo *pi, dcube *cube)
- {
- register c_int c;
- register int bc = 0;
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- {
- c = cube->in[i]; /* Problem: Wie oft kommt 11 vor? */
- c = ~c; /* Problem: Wie oft kommt 00 vor? */
- c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
- c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- c |= c<<1;
- c = cube->in[i] & ~c;
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- bc += bitcount(c);
- }
- return bc;
- }
- /*-- dcInOneCnt -------------------------------------------------------------*/
- int dcInOneCnt(pinfo *pi, dcube *cube)
- {
- register c_int c;
- register int bc = 0;
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- {
- c = cube->in[i]; /* Problem: Wie oft kommt 11 vor? */
- c = ~c; /* Problem: Wie oft kommt 00 vor? */
- c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
- c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- c |= c<<1;
- c = cube->in[i] & ~c;
- c = c>>1;
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- bc += bitcount(c);
- }
- return bc;
- }
- /*-- dcDeltaIn --------------------------------------------------------------*/
- int dcDeltaIn(pinfo *pi, dcube *a, dcube *b)
- {
- register c_int c;
- register int bc = 0;
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- {
- c = a->in[i] & b->in[i]; /* Problem: Wie oft kommt 00 vor? */
- c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
- c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- bc += bitcount(c);
- }
- return bc;
- }
- /*-- dcOutCnt ---------------------------------------------------------------*/
- int dcOutCnt(pinfo *pi, dcube *c)
- {
- register int i;
- register int bc = 0;
- for( i = 0; i < pi->out_words; i++ )
- bc += bitcount(c->out[i]);
- return bc;
- }
- /*-- dcInvIn ----------------------------------------------------------------*/
- int dcInvIn(pinfo *pi, dcube *cube)
- {
- register c_int c;
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- {
- c = cube->in[i]; /* Problem: Wie oft kommt 11 vor? */
- c &= c>>1; /* Reduktion: Wie oft kommt x1 vor? */
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- c |= c<<1; /* neue maske: 11 */
- cube->in[i] = ((~cube->in[i]) | c); /* 01 -> 10, 10 -> 01, 11 -> 11 */
- }
- return 0;
- }
- /*-- dcInvOut ---------------------------------------------------------------*/
- void dcInvOut(pinfo *pi, dcube *c)
- {
- register int i;
- for( i = 0; i < pi->out_words; i++ )
- c->out[i] = ~c->out[i];
- if ( pi->out_words > 0 )
- c->out[pi->out_words-1] &= pi->out_last_mask;
- }
- /*-- dcDeltaOut -------------------------------------------------------------*/
- int dcDeltaOut(pinfo *pi, dcube *a, dcube *b)
- {
- register int i;
- if ( pi->out_cnt == 0 )
- return 0;
- for( i = 0; i < pi->out_words; i++ )
- if ( (a->out[i] & b->out[i]) != 0 )
- return 0;
- return 1;
- }
- /*-- dcDelta ----------------------------------------------------------------*/
- int dcDelta(pinfo *pi, dcube *a, dcube *b)
- {
- return dcDeltaIn(pi, a, b) + dcDeltaOut(pi, a, b);
- }
- /*-- dcIsOutIllegal ---------------------------------------------------------*/
- int dcIsOutIllegal(pinfo *pi, dcube *c)
- {
- register int i;
- if ( pi->out_words == 0 )
- return 0;
- for( i = 0; i < pi->out_words; i++ )
- {
- if ( c->out[i] != 0 )
- break;
- }
- if ( i >= pi->out_words )
- return 1;
- return 0;
- }
- /*-- dcIsDeltaInNoneZero ----------------------------------------------------*/
- int dcIsDeltaInNoneZero(pinfo *pi, dcube *a, dcube *b)
- {
- register c_int c;
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- {
- c = a->in[i] & b->in[i]; /* Problem: Wie oft kommt 00 vor? */
- c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
- c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- if ( c > 0 )
- return 1;
- }
- return 0;
- }
- /*-- dcIsInIllegal ----------------------------------------------------------*/
- int dcIsInIllegal(pinfo *pi, dcube *cube)
- {
- register c_int c;
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- {
- c = cube->in[i]; /* Problem: Wie oft kommt 00 vor? */
- c |= c>>1; /* Reduktion: Wie oft kommt x0 vor? */
- c = ~c; /* Invertierung: Wie oft kommt x1 vor? */
- c &= CUBE_IN_MASK_ZERO; /* Maskierung: Wie oft kommt 01 vor? */
- if ( c > 0 )
- return 1;
- }
- return 0;
- }
- /*-- dcIsDeltaNoneZero ------------------------------------------------------*/
- int dcIsDeltaNoneZero(pinfo *pi, dcube *a, dcube *b)
- {
- if ( dcDeltaOut(pi, a, b) > 0 )
- return 1;
- return dcIsDeltaInNoneZero(pi, a, b);
- }
- /*-- dcIsIllegal ------------------------------------------------------------*/
- int dcIsIllegal(pinfo *pi, dcube *c)
- {
- if ( dcIsInIllegal(pi, c) != 0 )
- return 1;
- if ( dcIsOutIllegal(pi, c) != 0 )
- return 1;
- return 0;
- }
- /*-- dcCofactor -------------------------------------------------------------*/
- /* Berechnet den Kofaktor von a bezueglich b. */
- /* Das Ergebnis wird in r abgelegt. */
- /* Der Reuckgabewert ist 0, wenn kein Ergebnis */
- /* berechnet wurde. */
- static void dc_cofactor(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- r->in[i] = a->in[i] | ~b->in[i];
- if ( pi->out_words > 0 )
- {
- for( i = 0; i < pi->out_words-1; i++ )
- r->out[i] = a->out[i] | (~b->out[i]);
- r->out[i] = a->out[i] | ((~b->out[i]) & pi->out_last_mask);
- }
- r->n = a->n; /* notwendig fuer den irredundant algorithmus */
- }
- int dcCofactor(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- if ( dcIsDeltaNoneZero(pi, a, b) != 0 )
- return 0;
- dc_cofactor(pi, r, a, b);
- return 1;
- }
- /* cofactoren, die teilmenge des cofactors sind */
- int dcSubCofactor(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- if ( dcIsSubSet(pi, b, a) == 0 )
- return 0;
- dc_cofactor(pi, r, a, b);
- return 1;
- }
- /* cofactoren, die reduziert werden muessen */
- int dcRedCofactor(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- if ( dcIsSubSet(pi, b, a) != 0 )
- return 0;
- return dcCofactor(pi, r, a, b);
- }
- /*-- dcConsensus ------------------------------------------------------------*/
- int dcConsensus(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- int i;
- int d_in = dcDeltaIn(pi, a, b);
- int d_out = dcDeltaOut(pi, a, b);
- if ( d_in == 0 )
- {
- for( i = 0; i < pi->in_words; i++ )
- r->in[i] = a->in[i] & b->in[i];
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = a->out[i] | b->out[i];
- }
- else if ( d_in == 1 && d_out == 0 )
- {
- c_int c;
- c_int m;
-
- for( i = 0; i < pi->in_words; i++ )
- {
- c = a->in[i] & b->in[i];
- m = (~((c)|(c>>1))) & CUBE_IN_MASK_ZERO;
- r->in[i] = c | m | (m<<1);
- }
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = a->out[i] & b->out[i];
- }
- else
- {
- return 0;
- }
- return 1;
- }
- /*-- dcSharpIn --------------------------------------------------------------*/
- int dcSharpIn(pinfo *pi, dcube *r, dcube *a, dcube *b, int k)
- {
- register int i;
- dcAllClear(pi, &(pi->tmp[5]));
- dcSetIn(&(pi->tmp[5]), k, 3);
-
- for( i = 0; i < pi->in_words; i++ )
- {
- if ( pi->tmp[5].in[i] != 0 )
- {
- if ( ((a->in[i] & ~b->in[i]) & pi->tmp[5].in[i]) == 0 )
- return 0;
- r->in[i] = (a->in[i] & ~b->in[i]) & pi->tmp[5].in[i];
- r->in[i] |= a->in[i] & ~pi->tmp[5].in[i];
- }
- else
- {
- r->in[i] = a->in[i];
- }
- }
-
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = a->out[i];
-
- return 1;
- }
- /*-- dcSharpOut -------------------------------------------------------------*/
- int dcSharpOut(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- int i;
- for( i = 0; i < pi->out_words; i++ )
- if ( (a->out[i] & ~b->out[i]) != 0 )
- break;
- if ( i >= pi->out_words )
- return 0;
- for( i = 0; i < pi->in_words; i++ )
- r->in[i] = a->in[i];
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = a->out[i] & ~b->out[i];
- return 1;
- }
- /*-- dcD1SharpIn ------------------------------------------------------------*/
- int dcD1SharpIn(pinfo *pi, dcube *r, dcube *a, dcube *b, int k)
- {
- register int i;
- dcAllClear(pi, &(pi->tmp[5]));
- dcSetIn(&(pi->tmp[5]), k, 3);
-
- for( i = 0; i < pi->in_words; i++ )
- {
- if ( pi->tmp[5].in[i] != 0 )
- {
- if ( ((a->in[i] & ~b->in[i]) & pi->tmp[5].in[i]) == 0 )
- return 0;
- r->in[i] = (a->in[i] & ~b->in[i]) & pi->tmp[5].in[i];
- r->in[i] |= b->in[i] & ~pi->tmp[5].in[i];
- }
- else
- {
- r->in[i] = b->in[i];
- }
- }
-
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = b->out[i];
-
- return 1;
- }
- /*-- dcD1SharpOut -----------------------------------------------------------*/
- int dcD1SharpOut(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- int i;
- for( i = 0; i < pi->out_words; i++ )
- if ( (a->out[i] & ~b->out[i]) != 0 )
- break;
- if ( i >= pi->out_words )
- return 0;
- for( i = 0; i < pi->in_words; i++ )
- r->in[i] = b->in[i];
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = a->out[i] & ~b->out[i];
- return 1;
- }
- /*-- dcGetCofactorForSplit --------------------------------------------------*/
- int dcGetBinateInVarCofactor(pinfo *pi, dcube *r, dcube *rinv, dclist cl, dcube *cof)
- {
- int i;
- for( i = 0; i < pi->in_cnt; i++ )
- {
- if ( dclIsBinateInVar(cl, i) != 0 )
- {
- dcCopy(pi, r, cof);
- dcCopy(pi, rinv, cof);
- dcInSetAll(pi, r, CUBE_IN_MASK_DC);
- dcInSetAll(pi, rinv, CUBE_IN_MASK_DC);
- dcSetIn(r, i, 2);
- dcSetIn(rinv, i, 1);
- return 1;
- }
- }
- return 0;
- }
- int dcGetNoneDCInVarCofactor(pinfo *pi, dcube *r, dcube *rinv, dclist cl, dcube *cof)
- {
- int i;
- for( i = 0; i < pi->in_cnt; i++ )
- {
- if ( dclIsDCInVar(pi, cl, i) == 0 )
- {
- dcCopy(pi, r, cof);
- dcCopy(pi, rinv, cof);
- dcInSetAll(pi, r, CUBE_IN_MASK_DC);
- dcInSetAll(pi, rinv, CUBE_IN_MASK_DC);
- dcSetIn(r, i, 2);
- dcSetIn(rinv, i, 1);
- return 1;
- }
- }
- return 0;
- }
- int dcGetOutVarCofactor(pinfo *pi, dcube *r, dcube *rinv, dclist cl, dcube *cof)
- {
- int i, j;
- int aktive_bit_cnt;
- aktive_bit_cnt = 0;
- for( i = 0; i < pi->out_cnt; i++ )
- if ( dcGetOut(cof, i) != 0 )
- aktive_bit_cnt++;
-
- if ( aktive_bit_cnt <= 1 )
- return 0;
- dcInSetAll(pi, r, CUBE_IN_MASK_DC);
- dcOutSetAll(pi, r, 0);
- dcInSetAll(pi, rinv, CUBE_IN_MASK_DC);
- dcOutSetAll(pi, rinv, 0);
-
- j = 0;
- for( i = 0; i < pi->out_cnt; i++ )
- if ( dcGetOut(cof, i) != 0 )
- {
- if ( j < aktive_bit_cnt/2 )
- dcSetOut(r, i, 1);
- else
- dcSetOut(rinv, i, 1);
- j++;
- }
- return 1;
- }
- int dcGetCofactorForSplit(pinfo *pi, dcube *l, dcube *r, dclist cl, dcube *cof)
- {
- /*
- if ( dcGetBinateInVarCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- if ( dcGetOutVarCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- return 0;
- */
- /*
- if ( pinfoGetInVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- if ( pinfoGetOutVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- */
-
- return pinfoGetDCubeCofactorForSplitting(pi, l, r, cl, cof);
- }
- int dcGetNoneDCCofactorForSplit(pinfo *pi, dcube *l, dcube *r, dclist cl, dcube *cof)
- {
- /*
- if ( pinfoGetOutVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- */
- /*
- if ( pinfoGetInVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- if ( dcGetNoneDCInVarCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- if ( pinfoGetOutVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- */
- /*
- if ( pinfoGetDCubeCofactorForSplitting(pi, l, r, cl, cof) != 0 )
- return 1;
- */
- /* reihenfolge wichtig??? zuerst eingangs variablen */
- if ( pinfoGetInVarDCubeCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- if ( dcGetOutVarCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- if ( dcGetNoneDCInVarCofactor(pi, l, r, cl, cof) != 0 )
- return 1;
- /* jetzt die ausgangsvariablen */
- /* die pinfo out var function zerstoert das ergebnis hmmmm??? */
- return 0;
- }
- /*-- dcIsInTautology --------------------------------------------------------*/
- int dcIsInTautology(pinfo *pi, dcube *c)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- if ( c->in[i] != CUBE_IN_MASK_DC )
- return 0;
- return 1;
- }
- /*-- dcIsTautology ----------------------------------------------------------*/
- int dcIsTautology(pinfo *pi, dcube *c)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- if ( c->in[i] != CUBE_IN_MASK_DC )
- return 0;
- if ( pi->out_words > 0 )
- {
- for( i = 0; i < pi->out_words-1; i++ )
- {
- if ( c->out[i] != CUBE_OUT_MASK )
- return 0;
- }
- if ( (c->out[i]&pi->out_last_mask) != pi->out_last_mask )
- return 0;
- }
- return 1;
- }
- /*-- dcNot ------------------------------------------------------------------*/
- void dcNot(pinfo *pi, dcube *c)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- c->in[i] = ~c->in[i];
- for( i = 0; i < pi->out_words; i++ )
- c->out[i] = ~c->out[i];
- if ( pi->out_words > 0 )
- c->out[pi->out_words-1] &= pi->out_last_mask;
- }
- /*-- dcOrIn -----------------------------------------------------------------*/
- void dcOrIn(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- r->in[i] = a->in[i] | b->in[i];
- }
- /*-- dcOrOut ----------------------------------------------------------------*/
- void dcOrOut(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = a->out[i] | b->out[i];
- }
- /*-- dcOr -------------------------------------------------------------------*/
- void dcOr(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- r->in[i] = a->in[i] | b->in[i];
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = a->out[i] | b->out[i];
- }
- /*-- dcAnd ------------------------------------------------------------------*/
- void dcAnd(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- r->in[i] = a->in[i] & b->in[i];
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = a->out[i] & b->out[i];
- }
- /*-- dcAndIn ----------------------------------------------------------------*/
- void dcAndIn(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->in_words; i++ )
- r->in[i] = a->in[i] & b->in[i];
- }
- /*-- dcNotAndOut -----------------------------------------------------------*/
- void dcNotAndOut(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = (~a->out[i]) & b->out[i];
- }
- /*-- dcXorOut -----------------------------------------------------------*/
- void dcXorOut(pinfo *pi, dcube *r, dcube *a, dcube *b)
- {
- register int i;
- for( i = 0; i < pi->out_words; i++ )
- r->out[i] = a->out[i] ^ b->out[i];
- }
- /*-- dcGetLiteralCnt --------------------------------------------------------*/
- int dcGetLiteralCnt(pinfo *pi, dcube *c)
- {
- return pi->in_cnt - dcInDCCnt(pi, c) + dcOutCnt(pi, c);
- }
- /*-- dcGetDichotomyWeight ---------------------------------------------------*/
- int dcGetDichotomyWeight(pinfo *pi, dcube *c)
- {
- int z = dcInZeroCnt(pi, c);
- int o = dcInOneCnt(pi, c);
- int w;
-
- w = z-o;
- if ( w < 0 )
- w = -w;
-
- w = pi->in_cnt - w + 1;
- return w;
- }
- /*-- dcExpand1 --------------------------------------------------------------*/
- /* Spezial Expand algorithmus fuer das URP Complement */
- static void dcExpand1(pinfo *pi, dcube *c, dclist cl_off)
- {
- dcube *b = &(pi->tmp[7]);
- int delta_in;
- int delta_out;
- int i, cnt = dclCnt(cl_off);
- dcSetTautology(pi, b);
- dcInSetAll(pi, b, 0);
- dcOutSetAll(pi, b, 0);
- for( i = 0; i < cnt; i++ )
- {
- delta_in = dcDeltaIn(pi, c, dclGet(cl_off, i));
- delta_out = dcDeltaOut(pi, c, dclGet(cl_off, i));
- if ( delta_in + delta_out == 1 )
- dcOr(pi, b, b, dclGet(cl_off, i));
- }
- dcNot(pi, b);
- dcOr(pi, c, c, b);
- }
- /*-- dcWriteBin -------------------------------------------------------------*/
- int dcWriteBin(pinfo *pi, dcube *c, FILE *fp)
- {
- int i, j;
- dcube *a = &(pi->tmp[7]);
- c_int w;
- if ( pi->in_words != 0 )
- {
- for( i = 0; i < pi->in_words; i++ )
- {
- w = c->in[i];
- for( j = 0; j < sizeof(c_int); j++ )
- {
- ((unsigned char *)a->in)[i*sizeof(c_int)+j] = (unsigned char)(w&255);
- w>>=8;
- }
- }
- if ( b_io_Write(fp, pi->in_words*sizeof(c_int), (unsigned char *)a->in) == 0 )
- return 0;
- }
- if ( pi->out_words != 0 )
- {
- for( i = 0; i < pi->out_words; i++ )
- {
- w = c->out[i];
- for( j = 0; j < sizeof(c_int); j++ )
- {
- ((unsigned char *)a->out)[i*sizeof(c_int)+j] = (unsigned char)(w&255);
- w>>=8;
- }
- }
- if ( b_io_Write(fp, pi->out_words*sizeof(c_int), (unsigned char *)a->out) == 0 )
- return 0;
- }
- if ( b_io_WriteInt(fp, c->n) == 0 )
- return 0;
- return 1;
- }
- /*-- dcReadBin --------------------------------------------------------------*/
- int dcReadBin(pinfo *pi, dcube *c, FILE *fp)
- {
- int i, j;
- dcube *a = &(pi->tmp[7]);
- c_int w;
- if ( pi->in_words != 0 )
- {
- if ( b_io_Read(fp, pi->in_words*sizeof(c_int), (unsigned char *)a->in) == 0 )
- return 0;
- for( i = 0; i < pi->in_words; i++ )
- {
- w = 0;
- for( j = 0; j < sizeof(c_int); j++ )
- {
- w<<=8;
- w |= (c_int)((unsigned char *)a->in)[i*sizeof(c_int)+sizeof(c_int)-1-j];
- }
- c->in[i] = w;
- }
- }
- if ( pi->out_words != 0 )
- {
- if ( b_io_Read(fp, pi->out_words*sizeof(c_int), (unsigned char *)a->out) == 0 )
- return 0;
- for( i = 0; i < pi->out_words; i++ )
- {
- w = 0;
- for( j = 0; j < sizeof(c_int); j++ )
- {
- w<<=8;
- w |= (c_int)((unsigned char *)a->out)[i*sizeof(c_int)+sizeof(c_int)-1-j];
- }
- c->out[i] = w;
- }
- }
- if ( b_io_ReadInt(fp, &(c->n)) == 0 )
- return 0;
- return 1;
- }
- /*===========================================================================*/
- /*-- dclInit ----------------------------------------------------------------*/
- int dclInit(dclist *cl)
- {
- *cl = (dclist)malloc(sizeof(struct _dclist_struct));
- if ( *cl == NULL )
- return 0;
- (*cl)->list = NULL;
- (*cl)->max = 0;
- (*cl)->cnt = 0;
- (*cl)->flag_list = NULL;
- return 1;
- }
- /*-- dclInitCached ----------------------------------------------------------*/
- int dclInitCached(pinfo *pi, dclist *cl)
- {
- if ( pi->cache_cnt == 0 )
- return dclInit(cl);
- pi->cache_cnt--;
- *cl = pi->cache_cl[pi->cache_cnt];
- return 1;
- }
- /*-- dclInitVA --------------------------------------------------------------*/
- int dclInitVA(int n, ...)
- {
- va_list va;
- int i;
- va_start(va, n);
- for( i = 0; i < n; i++ )
- if ( dclInit(va_arg(va, dclist *)) == 0 )
- break;
- va_end(va);
- if ( i < n )
- {
- va_start(va, n);
- while( i-- >= 0 )
- dclDestroy(*va_arg(va, dclist *));
- va_end(va);
- return 0;
- }
- return 1;
- }
- /*-- dclInitCachedVA --------------------------------------------------------*/
- int dclInitCachedVA(pinfo *pi, int n, ...)
- {
- va_list va;
- int i;
- va_start(va, n);
- for( i = 0; i < n; i++ )
- if ( dclInitCached(pi, va_arg(va, dclist *)) == 0 )
- break;
- va_end(va);
- if ( i < n )
- {
- va_start(va, n);
- while( i-- >= 0 )
- dclDestroyCached(pi, *va_arg(va, dclist *));
- va_end(va);
- return 0;
- }
- return 1;
- }
- /*-- dclDestroy -------------------------------------------------------------*/
- static void dcl_destroy(dclist cl)
- {
- int i;
- for( i = 0; i < cl->max; i++ )
- dcDestroy(cl->list+i);
- if ( cl->list != NULL )
- free(cl->list);
- if ( cl->flag_list != NULL )
- free(cl->flag_list);
- cl->flag_list = NULL;
- cl->list = NULL;
- cl->max = 0;
- cl->cnt = 0;
- }
- void dclDestroy(dclist cl)
- {
- dcl_destroy(cl);
- free(cl);
- }
- /*-- dclDestroyCached -------------------------------------------------------*/
- void dclDestroyCached(pinfo *pi, dclist cl)
- {
- if ( pi->cache_cnt >= PINFO_CACHE_CL )
- dclDestroy(cl);
- else
- {
- dclClear(cl);
- pi->cache_cl[pi->cache_cnt++] = cl;
- }
- }
- /*-- dclDestroyVA -----------------------------------------------------------*/
- void dclDestroyVA(int n, ...)
- {
- va_list va;
- int i;
- va_start(va, n);
- for( i = 0; i < n; i++ )
- dclDestroy(va_arg(va, dclist));
- va_end(va);
- }
- /*-- dclDestroyCachedVA -----------------------------------------------------*/
- void dclDestroyCachedVA(pinfo *pi, int n, ...)
- {
- va_list va;
- int i;
- va_start(va, n);
- for( i = 0; i < n; i++ )
- dclDestroyCached(pi, va_arg(va, dclist));
- va_end(va);
- }
- /*-- dclExpandFlagListTo ----------------------------------------------------*/
- int dclExpandFlagListTo(dclist cl, int max)
- {
- void *ptr;
- /* allocate at least one byte */
- if ( max <= 0 )
- max = 1;
- if ( cl->flag_list != NULL )
- {
- if ( max == 0 )
- {
- /* 14 jan 2002: assigning a NULL pointer seems to be an error... */
- /*
- free(cl->flag_list);
- cl->flag_list = NULL;
- return 1;
- */
- /* instead, allocate at least one byte */
- max = 1;
- }
- ptr = realloc(cl->flag_list, max);
- }
- else
- {
- ptr = malloc(max);
- }
- if ( ptr == NULL )
- return 0;
- cl->flag_list = (char *)ptr;
- return 1;
- }
- /*-- dclExpandTo ------------------------------------------------------------*/
- int dclExpandTo(pinfo *pi, dclist cl, int max)
- {
- void *ptr;
- max = (max+31)&~31;
- if ( max <= cl->max )
- return 1;
- if ( cl->list == NULL )
- ptr = malloc(max*sizeof(dcube));
- else
- ptr = realloc(cl->list, max*sizeof(dcube));
- if ( ptr == NULL )
- return 0;
- cl->list = (dcube *)ptr;
-
- if ( cl->flag_list != NULL )
- if ( dclExpandFlagListTo(cl, max) == 0 )
- return 0;
- while(cl->max < max)
- {
- if ( dcInitMem(pi, cl->list+cl->max) == 0 )
- return 0;
- if ( cl->flag_list != NULL )
- cl->flag_list[cl->max] = 0;
- cl->max++;
- }
- return 1;
- }
- /*-- dclAddEmpty ------------------------------------------------------------*/
- /* returns position or -1 */
- int dclAddEmpty(pinfo *pi, dclist cl)
- {
- if ( dclCnt(cl) >= cl->max )
- if ( dclExpandTo(pi, cl, dclCnt(cl)+1) == 0 )
- return -1;
- dcInSetAll(pi, cl->list+cl->cnt, CUBE_IN_MASK_DC);
- dcOutSetAll(pi, cl->list+cl->cnt, 0);
- if ( cl->flag_list != NULL )
- cl->flag_list[cl->cnt] = 0;
- cl->cnt++;
- return cl->cnt-1;
- }
- dcube *dclAddEmptyCube(pinfo *pi, dclist cl)
- {
- int pos;
- pos = dclAddEmpty(pi, cl);
- if ( pos < 0 )
- return NULL;
- return dclGet(cl, pos);
- }
- /*-- dclAdd -----------------------------------------------------------------*/
- /* returns position or -1 */
- int dclAdd(pinfo *pi, dclist cl, dcube *c)
- {
- if ( dclCnt(cl) >= cl->max )
- {
- /* there is an interessting possible bug here */
- /* if c is an element of cl, c might become invalid */
- /* if cl->list is expanded and moved to another */
- /* location in the memory, c becomes invalid */
- if ( c >= cl->list && c < cl->list+cl->max )
- {
- dcCopy(pi, pi->tmp+12, c);
- c = pi->tmp+12;
- }
- if ( dclExpandTo(pi, cl, dclCnt(cl)+1) == 0 )
- return -1;
- assert(cl->max > cl->cnt);
- }
- {
- register dcube *d;
- int i;
- d = cl->list+cl->cnt;
- for( i = 0; i < pi->in_out_words_min; i++ )
- {
- d->in[i] = c->in[i];
- d->out[i] = c->out[i];
- }
- for( i = pi->in_out_words_min; i < pi->in_words; i++ )
- d->in[i] = c->in[i];
- for( i = pi->in_out_words_min; i < pi->out_words; i++ )
- d->out[i] = c->out[i];
- d->n = c->n;
- }
- /* dcCopy(pi, cl->list+cl->cnt, c); */
-
-
- if ( cl->flag_list != NULL )
- cl->flag_list[cl->cnt] = 0;
- cl->cnt++;
- return cl->cnt-1;
- }
- /*-- dclAddUnique -----------------------------------------------------------*/
- /* returns position or -1 */
- int dclAddUnique(pinfo *pi, dclist cl, dcube *c)
- {
- int i, cnt = dclCnt(cl);
- for( i = 0; i < cnt; i++ )
- if ( dcIsEqual(pi, dclGet(cl, i), c) != 0 )
- return i;
- return dclAdd(pi, cl, c);
- }
- /*-- dclJoin ----------------------------------------------------------------*/
- int dclJoin(pinfo *pi, dclist dest, dclist src)
- {
- int i, cnt = dclCnt(src);
- if ( dclExpandTo(pi, dest, dclCnt(dest)+dclCnt(src)) == 0 )
- return 0;
- for( i = 0; i < cnt; i++ )
- if ( dclAdd(pi, dest, dclGet(src, i)) < 0 )
- return 0;
- return 1;
- }
- /*-- dclCopy ----------------------------------------------------------------*/
- int dclCopy(pinfo *pi, dclist dest, dclist src)
- {
- dclClear(dest);
- return dclJoin(pi, dest, src);
- }
- /*-- dclClearFlags ----------------------------------------------------------*/
- int dclClearFlags(dclist cl)
- {
- if ( dclExpandFlagListTo(cl, cl->max) == 0 )
- return 0;
- if ( cl->max == 0 )
- return 1;
- memset(cl->flag_list, 0, cl->max);
- return 1;
- }
- /*-- dclSetFlag -------------------------------------------------------------*/
- /*
- void dclSetFlag(dclist cl, int pos)
- {
- cl->flag_list[pos] = 1;
- }
- */
- /*-- dclIsFlag --------------------------------------------------------------*/
- /*
- int dclIsFlag(dclist cl, int pos)
- {
- return (int)cl->flag_list[pos];
- }
- */
- /*-- dclDeleteCubesWithFlag -------------------------------------------------*/
- void dclDeleteCubesWithFlag(pinfo *pi, dclist cl)
- {
- int src, dest;
-
- src = 0;
- dest = 0;
- while( src < cl->cnt )
- {
- if ( cl->flag_list[src] != 0 )
- {
- src++;
- }
- else
- {
- if ( src != dest )
- {
- dcCopy(pi, cl->list+dest, cl->list+src);
- cl->flag_list[dest] = cl->flag_list[src];
- }
- dest++;
- src++;
- }
- }
- memset(cl->flag_list, 0, cl->cnt);
- cl->cnt = dest;
- }
- /*-- dclCopyCubesWithFlag ----------------------------------------------------*/
- int dclCopyCubesWithFlag(pinfo *pi, dclist dest, dclist src)
- {
- int i, cnt = dclCnt(src);
-
- dclClear(dest);
- for( i = 0; i < cnt; i++ )
- if ( dclIsFlag(src, i) != 0 )
- if ( dclAdd(pi, dest, dclGet(src, i)) < 0 )
- return 0;
- return 1;
- }
- /*-- dclDeleteCube ----------------------------------------------------------*/
- void dclDeleteCube(pinfo *pi, dclist cl, int pos)
- {
- if ( cl->cnt == 0 )
- return;
- if ( pos >= cl->cnt )
- return;
- pos++;
- while( pos < cl->cnt )
- {
- dcCopy(pi, cl->list+pos-1, cl->list+pos);
- pos++;
- }
- /* dcDestroy(cl->list+cl->cnt-1); */
- cl->cnt--;
- }
- /*-- dclDeleteByCube --------------------------------------------------------*/
- int dclDeleteByCube(pinfo *pi, dclist cl, dcube *c)
- {
- int i, cnt = dclCnt(cl);
- if ( dclClearFlags(cl) == 0 )
- return 0;
- for( i = 0; i < cnt; i++ )
- {
- if ( dcIsEqual(pi, c, dclGet(cl, i)) != 0 )
- dclSetFlag(cl, i);
- }
- dclDeleteCubesWithFlag(pi, cl);
- return 1;
- }
- /*-- dclDeleteByCubeList ----------------------------------------------------*/
- int…