abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kitPerm.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "kit.h"

Go to the source code of this file.

Macros

#define inline   __inline
 
#define NFUNCS   (1<<20)
 

Typedefs

typedef unsigned __int64 word
 DECLARATIONS ///. More...
 
typedef unsigned short shot
 
typedef unsigned char byte
 

Functions

void Kit_PermCreateS ()
 FUNCTION DEFINITIONS ///. More...
 
void Kit_PermCreateP ()
 
static void Kit_PermCycleOne (shot *s, byte *b, int v)
 
static void Kit_PermCycleMany (shot *s, byte *b, int V, int v)
 
void Kit_PermCompute (word *o, word *i, int V)
 
void Kit_PermComputeNaive (word *F, int nVars)
 
word M (word f1, word f2, int n)
 
word Tf (word f, int n)
 
void Kit_PermComputeTest ()
 
void Kit_PermComputeTest_ ()
 

Variables

static shot S [256]
 
static byte P [256]
 

Macro Definition Documentation

#define inline   __inline

CFile****************************************************************

FileName [kitPerm.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Computation kit.]

Synopsis [Procedures for permuting truth tables.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - Oct 26, 2011.]

Revision [

Id:
kitPerm.c,v 1.00 2011/11/26 00:00:00 alanmi Exp

]

Definition at line 28 of file kitPerm.c.

#define NFUNCS   (1<<20)

Definition at line 265 of file kitPerm.c.

Typedef Documentation

typedef unsigned char byte

Definition at line 38 of file kitPerm.c.

typedef unsigned short shot

Definition at line 37 of file kitPerm.c.

typedef unsigned __int64 word

DECLARATIONS ///.

Definition at line 36 of file kitPerm.c.

Function Documentation

void Kit_PermCompute ( word o,
word i,
int  V 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 199 of file kitPerm.c.

200 {
201  word * t;
202  int v, n = (1 << (V-3));
203  assert( V >= 6 && V <= 16 );
204  for ( v = 0; v < n; v++ )
205  ((byte *)i)[v] = P[((byte *)i)[v]];
206  for ( v = 3; v < V; v++ )
207  {
208  Kit_PermCycleMany( (shot *)o, (byte *)i, V, v );
209  t = i; i = o; o = t;
210  }
211  if ( V & 1 )
212  {
213  n = (1 << (V-6));
214  for ( v = 0; v < n; v++ )
215  o[v] = i[v];
216  }
217 }
static byte P[256]
Definition: kitPerm.c:76
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
unsigned short shot
Definition: kitPerm.c:37
unsigned char byte
Definition: kitPerm.c:38
static void Kit_PermCycleMany(shot *s, byte *b, int V, int v)
Definition: kitPerm.c:180
#define assert(ex)
Definition: util_old.h:213
void Kit_PermComputeNaive ( word F,
int  nVars 
)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 230 of file kitPerm.c.

231 {
232  extern void If_CluReverseOrder( word * pF, int nVars, int * V2P, int * P2V, int iVarStart );
233  int i, V2P[16], P2V[16];
234  for ( i = 0; i < nVars; i++ )
235  V2P[i] = P2V[i] = i;
236  If_CluReverseOrder( F, nVars, V2P, P2V, 0 );
237 }
void If_CluReverseOrder(word *pTruth, int nVars, int *V2P, int *P2V, int iVarStart)
Definition: ifDec16.c:800
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
void Kit_PermComputeTest ( )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 278 of file kitPerm.c.

279 {
280  word * T = (word *)malloc( 8 * NFUNCS );
281  word i, o, w = 0;
282  int k, b;
283  abctime clk;
284 
285  srand( 0 );
286 
287  clk = Abc_Clock();
288  for ( k = 0; k < NFUNCS; k++ )
289  for ( b = 0; b < 8; b++ )
290  ((byte *)(T + k))[b] = (byte)(rand() & 0xFF);
291  ABC_PRT( "Assign", Abc_Clock() - clk );
292 
293 // T[0] = 0xacaccacaaccaacca;
294 // Kit_DsdPrintFromTruth( T, 6 );
295 
296  // perform measurements
297  clk = Abc_Clock();
298  for ( k = 0; k < NFUNCS; k++ )
299  {
300  i = T[k];
301 // Kit_PermComputeNaive( &i, 6 );
302  Tf( i, 6 );
303  }
304  ABC_PRT( "Perm1 ", Abc_Clock() - clk );
305 
306  // perform measurements
307  clk = Abc_Clock();
308  for ( k = 0; k < NFUNCS; k++ )
309  {
310  i = T[k];
311  Kit_PermCompute( &o, &i, 6 );
312 
313 // w = T[k];
314 // Kit_PermComputeNaive( &w, 6 );
315 // assert( w == o );
316  }
317  ABC_PRT( "Perm2 ", Abc_Clock() - clk );
318 
319  assert( w == 0 );
320  free( T );
321 }
char * malloc()
VOID_HACK free()
static abctime Abc_Clock()
Definition: abc_global.h:279
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
word Tf(word f, int n)
Definition: kitPerm.c:250
#define NFUNCS
Definition: kitPerm.c:265
#define ABC_PRT(a, t)
Definition: abc_global.h:220
unsigned char byte
Definition: kitPerm.c:38
#define assert(ex)
Definition: util_old.h:213
ABC_INT64_T abctime
Definition: abc_global.h:278
void Kit_PermCompute(word *o, word *i, int V)
Definition: kitPerm.c:199
void Kit_PermComputeTest_ ( )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso [] `

Definition at line 334 of file kitPerm.c.

335 {
336  word t, s;
337  t = 0xacaccacaaccaacca;
338 // Kit_DsdPrintFromTruth( &t, 6 ); printf( "\n" );
339  s = Tf( t, 6 );
340 // Kit_PermComputeNaive( &t, 6 );
341 // Kit_DsdPrintFromTruth( &s, 6 ); printf( "\n" );
342 }
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
word Tf(word f, int n)
Definition: kitPerm.c:250
void Kit_PermCreateP ( )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 135 of file kitPerm.c.

136 {
137  int i, s1, s2, r;
138  for ( i = 0; i < 256; i++ )
139  {
140  if ( i % 16 == 0 )
141  printf( "\n" );
142  s1 = i & 0x0A;
143  s2 = i & 0x50;
144  r = i ^ s1 ^ s2 ^ (s1 << 3) ^ (s2 >> 3);
145  assert( r < 256 );
146  printf( "0x%02x, ", r );
147  }
148 }
static char s1[largest_string]
Definition: set.c:514
#define assert(ex)
Definition: util_old.h:213
void Kit_PermCreateS ( )

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 111 of file kitPerm.c.

112 {
113  int i, n, r;
114  for ( i = 0; i < 256; i++ )
115  {
116  if ( i % 8 == 0 )
117  printf( "\n" );
118  for ( r = n = 0; n < 8; n++ )
119  r |= ((i & (1 << n)) << n);
120  printf( "0x%04x, ", r );
121  }
122 }
static void Kit_PermCycleMany ( shot s,
byte b,
int  V,
int  v 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 180 of file kitPerm.c.

181 {
182  int i, n = (1 << (V - 1 - v)), m = (1 << (v-2));
183  assert( v > 2 && v < V );
184  for ( i = 0; i < n; i++, s += (m >> 1), b += m )
185  Kit_PermCycleOne( s, b, v );
186 }
static void Kit_PermCycleOne(shot *s, byte *b, int v)
Definition: kitPerm.c:161
#define assert(ex)
Definition: util_old.h:213
static void Kit_PermCycleOne ( shot s,
byte b,
int  v 
)
inlinestatic

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 161 of file kitPerm.c.

162 {
163  int i, n = (1 << (v-3));
164  assert( v > 2 && v < 16 );
165  for ( i = 0; i < n; i++ )
166  s[i] = S[b[i]] | (S[b[i+n]] << 1);
167 }
#define assert(ex)
Definition: util_old.h:213
static shot S[256]
Definition: kitPerm.c:40
word M ( word  f1,
word  f2,
int  n 
)

Definition at line 240 of file kitPerm.c.

241 {
242  word temp = 0;
243  word a = 1;
244  int i;
245  for( i = 0; i < n; i++)
246  temp = temp + (((f1>>i)&a) << (2*i) ) + (((f2>>i)&a) << (2*i+1));
247  return temp;
248 }
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
word Tf ( word  f,
int  n 
)

Definition at line 250 of file kitPerm.c.

251 {
252  if(n==1)
253  return f;
254  else
255  {
256 // int x = (int)pow(2,n-1);
257  int x;
258  x = (1 << (n-1));
259  return ( M (Tf( (f << x) >> x, n-1), Tf( (f >> x), n-1), x) ); //def. of M just below the function
260  }
261 }
word M(word f1, word f2, int n)
Definition: kitPerm.c:240
word Tf(word f, int n)
Definition: kitPerm.c:250

Variable Documentation

byte P[256]
static
Initial value:
=
{
0x00, 0x01, 0x10, 0x11, 0x04, 0x05, 0x14, 0x15, 0x40, 0x41, 0x50, 0x51, 0x44, 0x45, 0x54, 0x55,
0x02, 0x03, 0x12, 0x13, 0x06, 0x07, 0x16, 0x17, 0x42, 0x43, 0x52, 0x53, 0x46, 0x47, 0x56, 0x57,
0x20, 0x21, 0x30, 0x31, 0x24, 0x25, 0x34, 0x35, 0x60, 0x61, 0x70, 0x71, 0x64, 0x65, 0x74, 0x75,
0x22, 0x23, 0x32, 0x33, 0x26, 0x27, 0x36, 0x37, 0x62, 0x63, 0x72, 0x73, 0x66, 0x67, 0x76, 0x77,
0x08, 0x09, 0x18, 0x19, 0x0c, 0x0d, 0x1c, 0x1d, 0x48, 0x49, 0x58, 0x59, 0x4c, 0x4d, 0x5c, 0x5d,
0x0a, 0x0b, 0x1a, 0x1b, 0x0e, 0x0f, 0x1e, 0x1f, 0x4a, 0x4b, 0x5a, 0x5b, 0x4e, 0x4f, 0x5e, 0x5f,
0x28, 0x29, 0x38, 0x39, 0x2c, 0x2d, 0x3c, 0x3d, 0x68, 0x69, 0x78, 0x79, 0x6c, 0x6d, 0x7c, 0x7d,
0x2a, 0x2b, 0x3a, 0x3b, 0x2e, 0x2f, 0x3e, 0x3f, 0x6a, 0x6b, 0x7a, 0x7b, 0x6e, 0x6f, 0x7e, 0x7f,
0x80, 0x81, 0x90, 0x91, 0x84, 0x85, 0x94, 0x95, 0xc0, 0xc1, 0xd0, 0xd1, 0xc4, 0xc5, 0xd4, 0xd5,
0x82, 0x83, 0x92, 0x93, 0x86, 0x87, 0x96, 0x97, 0xc2, 0xc3, 0xd2, 0xd3,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