SASC
DVBSoftCAM

logic.c File Reference

#include <stdio.h>

Go to the source code of this file.

Classes

struct  fun

Defines

#define noNEGATEDTOO
#define BINARY(b15, b14, b13, b12, b11, b10, b9, b8, b7, b6, b5, b4, b3, b2, b1, b0)
#define LEVEL_ALOT   1000000
#define OP_FALSE   0
#define OP_TRUE   1
#define OP_SRC   2
#define OP_AND   3
#define OP_OR   4
#define OP_XOR   5
#define SRC_A   10
#define SRC_B   20
#define SRC_C   30
#define SRC_D   40
#define SRC_AN   11
#define SRC_BN   21
#define SRC_CN   31
#define SRC_DN   41

Functions

void dump_element_prefix (int)
void dump_element_infix (int)
int main (void)

Variables

struct fun db [65536]
int n_fun

Define Documentation

#define BINARY (   b15,
  b14,
  b13,
  b12,
  b11,
  b10,
  b9,
  b8,
  b7,
  b6,
  b5,
  b4,
  b3,
  b2,
  b1,
  b0 
)
Value:
((b15)<<15)|((b14)<<14)|((b13)<<13)|((b12)<<12)| \
  ((b11)<<11)|((b10)<<10)|((b9) << 9)|((b8) << 8)| \
  ((b7) << 7)|((b6) << 6)|((b5) << 5)|((b4) << 4)| \
  ((b3) << 3)|((b2) << 2)|((b1) << 1)|((b0) << 0)

Definition at line 34 of file logic.c.

Referenced by main().

#define LEVEL_ALOT   1000000

Definition at line 50 of file logic.c.

Referenced by main().

#define noNEGATEDTOO

Definition at line 24 of file logic.c.

#define OP_AND   3

Definition at line 55 of file logic.c.

Referenced by main().

#define OP_FALSE   0

Definition at line 52 of file logic.c.

Referenced by main().

#define OP_OR   4

Definition at line 56 of file logic.c.

Referenced by main().

#define OP_SRC   2

Definition at line 54 of file logic.c.

Referenced by main().

#define OP_TRUE   1

Definition at line 53 of file logic.c.

Referenced by main().

#define OP_XOR   5

Definition at line 57 of file logic.c.

Referenced by main().

#define SRC_A   10

Definition at line 59 of file logic.c.

Referenced by main().

#define SRC_AN   11

Definition at line 63 of file logic.c.

Referenced by main().

#define SRC_B   20

Definition at line 60 of file logic.c.

Referenced by main().

#define SRC_BN   21

Definition at line 64 of file logic.c.

Referenced by main().

#define SRC_C   30

Definition at line 61 of file logic.c.

Referenced by main().

#define SRC_CN   31

Definition at line 65 of file logic.c.

Referenced by main().

#define SRC_D   40

Definition at line 62 of file logic.c.

Referenced by main().

#define SRC_DN   41

Definition at line 66 of file logic.c.

Referenced by main().


Function Documentation

void dump_element_infix ( int  e)
void dump_element_prefix ( int  e)
int main ( void  )

Definition at line 71 of file logic.c.

References BINARY, db, dump_element_infix(), dump_element_prefix(), i, j, fun::level, LEVEL_ALOT, n_fun, fun::op1, fun::op2, OP_AND, OP_FALSE, OP_OR, OP_SRC, OP_TRUE, fun::op_type, OP_XOR, SRC_A, SRC_AN, SRC_B, SRC_BN, SRC_C, SRC_CN, SRC_D, and SRC_DN.

              {
  int i,j;
  int l,p1,p2;
  int candidate;
  int max_p2_lev;
  
  for(i=0;i<65536;i++){
    db[i].level=LEVEL_ALOT;
  }
  n_fun=0;

  db[0].level=0;
  db[0].op_type=OP_FALSE;
  n_fun++;

  db[65535].level=0;
  db[65535].op_type=OP_TRUE;
  n_fun++;

  db[BINARY(0,0,0,0, 0,0,0,0,  1,1,1,1, 1,1,1,1)].level=0;
  db[BINARY(0,0,0,0, 0,0,0,0,  1,1,1,1, 1,1,1,1)].op_type=OP_SRC;
  db[BINARY(0,0,0,0, 0,0,0,0,  1,1,1,1, 1,1,1,1)].op1=SRC_A;
  n_fun++;

  db[BINARY(0,0,0,0, 1,1,1,1,  0,0,0,0, 1,1,1,1)].level=0;
  db[BINARY(0,0,0,0, 1,1,1,1,  0,0,0,0, 1,1,1,1)].op_type=OP_SRC;
  db[BINARY(0,0,0,0, 1,1,1,1,  0,0,0,0, 1,1,1,1)].op1=SRC_B;
  n_fun++;

  db[BINARY(0,0,1,1, 0,0,1,1,  0,0,1,1, 0,0,1,1)].level=0;
  db[BINARY(0,0,1,1, 0,0,1,1,  0,0,1,1, 0,0,1,1)].op_type=OP_SRC;
  db[BINARY(0,0,1,1, 0,0,1,1,  0,0,1,1, 0,0,1,1)].op1=SRC_C;
  n_fun++;

  db[BINARY(0,1,0,1, 0,1,0,1,  0,1,0,1, 0,1,0,1)].level=0;
  db[BINARY(0,1,0,1, 0,1,0,1,  0,1,0,1, 0,1,0,1)].op_type=OP_SRC;
  db[BINARY(0,1,0,1, 0,1,0,1,  0,1,0,1, 0,1,0,1)].op1=SRC_D;
  n_fun++;
#ifdef NEGATEDTOO
  db[BINARY(1,1,1,1, 1,1,1,1,  0,0,0,0, 0,0,0,0)].level=0;
  db[BINARY(1,1,1,1, 1,1,1,1,  0,0,0,0, 0,0,0,0)].op_type=OP_SRC;
  db[BINARY(1,1,1,1, 1,1,1,1,  0,0,0,0, 0,0,0,0)].op1=SRC_AN;
  n_fun++;

  db[BINARY(1,1,1,1, 0,0,0,0,  1,1,1,1, 0,0,0,0)].level=0;
  db[BINARY(1,1,1,1, 0,0,0,0,  1,1,1,1, 0,0,0,0)].op_type=OP_SRC;
  db[BINARY(1,1,1,1, 0,0,0,0,  1,1,1,1, 0,0,0,0)].op1=SRC_BN;
  n_fun++;

  db[BINARY(1,1,0,0, 1,1,0,0,  1,1,0,0, 1,1,0,0)].level=0;
  db[BINARY(1,1,0,0, 1,1,0,0,  1,1,0,0, 1,1,0,0)].op_type=OP_SRC;
  db[BINARY(1,1,0,0, 1,1,0,0,  1,1,0,0, 1,1,0,0)].op1=SRC_CN;
  n_fun++;

  db[BINARY(1,0,1,0, 1,0,1,0,  1,0,1,0, 1,0,1,0)].level=0;
  db[BINARY(1,0,1,0, 1,0,1,0,  1,0,1,0, 1,0,1,0)].op_type=OP_SRC;
  db[BINARY(1,0,1,0, 1,0,1,0,  1,0,1,0, 1,0,1,0)].op1=SRC_DN;
  n_fun++;
#endif

  for(l=0;l<100;l++){
    printf("calculating level %i\n",l);
    for(p1=1;p1<65536;p1++){
      if(db[p1].level==LEVEL_ALOT) continue;
      max_p2_lev=l-db[p1].level-1;
      for(p2=p1+1;p2<65536;p2++){
        if(db[p2].level>max_p2_lev) continue;

        candidate=p1&p2;
        if(db[candidate].level==LEVEL_ALOT){
          //found new
          db[candidate].level=db[p1].level+db[p2].level+1;
          db[candidate].op_type=OP_AND;
          db[candidate].op1=p1;
          db[candidate].op2=p2;
          n_fun++;
        }

        candidate=p1|p2;
        if(db[candidate].level==LEVEL_ALOT){
          //found new
          db[candidate].level=db[p1].level+db[p2].level+1;
          db[candidate].op_type=OP_OR;
          db[candidate].op1=p1;
          db[candidate].op2=p2;
          n_fun++;
        }

        candidate=p1^p2;
        if(db[candidate].level==LEVEL_ALOT){
          //found new
          db[candidate].level=db[p1].level+db[p2].level+1;
          db[candidate].op_type=OP_XOR;
          db[candidate].op1=p1;
          db[candidate].op2=p2;
          n_fun++;
        }

      }
    }
    printf("num fun=%i\n\n",n_fun);
    fflush(stdout);
    if(n_fun>=65536) break;
  }


  for(i=0;i<65536;i++){
    if(db[i].level==LEVEL_ALOT) continue;

    printf("PREFIX ");
    for(j=15;j>=0;j--){
      printf("%i",i&(1<<j)?1:0);
      if(j%4==0) printf(" ");
      if(j%8==0) printf(" ");
    }
    printf(" : lev %2i: ",db[i].level);
    dump_element_prefix(i);
    printf("\n");

    printf("INFIX  ");
    for(j=15;j>=0;j--){
      printf("%i",i&(1<<j)?1:0);
      if(j%4==0) printf(" ");
      if(j%8==0) printf(" ");
    }
    printf(" : lev %2i: ",db[i].level);
    dump_element_infix(i);
    printf("\n");
  }
  
  return 0;
}

Variable Documentation

struct fun db[65536]

Definition at line 47 of file logic.c.

int n_fun

Definition at line 48 of file logic.c.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines