yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
demo_vec.cc File Reference
#include "ezminisat.h"
#include <assert.h>
+ Include dependency graph for demo_vec.cc:

Go to the source code of this file.

Macros

#define INIT_X   123456789
 
#define INIT_Y   362436069
 
#define INIT_Z   521288629
 
#define INIT_W   88675123
 

Functions

uint32_t xorshift128 ()
 
void xorshift128_sat (ezSAT &sat, std::vector< int > &x, std::vector< int > &y, std::vector< int > &z, std::vector< int > &w)
 
void find_xorshift128_init_state (uint32_t &x, uint32_t &y, uint32_t &z, uint32_t &w, uint32_t w1, uint32_t w2, uint32_t w3, uint32_t w4)
 
int main ()
 

Macro Definition Documentation

#define INIT_W   88675123

Definition at line 26 of file demo_vec.cc.

#define INIT_X   123456789

Definition at line 23 of file demo_vec.cc.

#define INIT_Y   362436069

Definition at line 24 of file demo_vec.cc.

#define INIT_Z   521288629

Definition at line 25 of file demo_vec.cc.

Function Documentation

void find_xorshift128_init_state ( uint32_t &  x,
uint32_t &  y,
uint32_t &  z,
uint32_t &  w,
uint32_t  w1,
uint32_t  w2,
uint32_t  w3,
uint32_t  w4 
)

Definition at line 46 of file demo_vec.cc.

47 {
48  ezMiniSAT sat;
49 
50  std::vector<int> vx = sat.vec_var("x", 32);
51  std::vector<int> vy = sat.vec_var("y", 32);
52  std::vector<int> vz = sat.vec_var("z", 32);
53  std::vector<int> vw = sat.vec_var("w", 32);
54 
55  xorshift128_sat(sat, vx, vy, vz, vw);
56  sat.vec_set_unsigned(vw, w1);
57 
58  xorshift128_sat(sat, vx, vy, vz, vw);
59  sat.vec_set_unsigned(vw, w2);
60 
61  xorshift128_sat(sat, vx, vy, vz, vw);
62  sat.vec_set_unsigned(vw, w3);
63 
64  xorshift128_sat(sat, vx, vy, vz, vw);
65  sat.vec_set_unsigned(vw, w4);
66 
67  std::vector<int> modelExpressions;
68  std::vector<bool> modelValues;
69 
70  sat.vec_append(modelExpressions, sat.vec_var("x", 32));
71  sat.vec_append(modelExpressions, sat.vec_var("y", 32));
72  sat.vec_append(modelExpressions, sat.vec_var("z", 32));
73  sat.vec_append(modelExpressions, sat.vec_var("w", 32));
74 
75  // sat.printDIMACS(stdout);
76 
77  if (!sat.solve(modelExpressions, modelValues)) {
78  fprintf(stderr, "SAT solver failed to find a model!\n");
79  abort();
80  }
81 
82  x = sat.vec_model_get_unsigned(modelExpressions, modelValues, sat.vec_var("x", 32));
83  y = sat.vec_model_get_unsigned(modelExpressions, modelValues, sat.vec_var("y", 32));
84  z = sat.vec_model_get_unsigned(modelExpressions, modelValues, sat.vec_var("z", 32));
85  w = sat.vec_model_get_unsigned(modelExpressions, modelValues, sat.vec_var("w", 32));
86 }
void xorshift128_sat(ezSAT &sat, std::vector< int > &x, std::vector< int > &y, std::vector< int > &z, std::vector< int > &w)
Definition: demo_vec.cc:39
std::vector< int > vec_var(int numBits)
Definition: ezsat.cc:673
void vec_set_unsigned(const std::vector< int > &vec1, uint64_t value)
Definition: ezsat.cc:1167
uint64_t vec_model_get_unsigned(const std::vector< int > &modelExpressions, const std::vector< bool > &modelValues, const std::vector< int > &vec1) const
Definition: ezsat.cc:1126
bool solve(const std::vector< int > &modelExpressions, std::vector< bool > &modelValues, const std::vector< int > &assumptions)
Definition: ezsat.h:122
void vec_append(std::vector< int > &vec, const std::vector< int > &vec1) const
Definition: ezsat.cc:1083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int main ( )

Definition at line 88 of file demo_vec.cc.

89 {
90  uint32_t w1 = xorshift128();
91  uint32_t w2 = xorshift128();
92  uint32_t w3 = xorshift128();
93  uint32_t w4 = xorshift128();
94  uint32_t x, y, z, w;
95 
96  printf("\n");
97 
98  find_xorshift128_init_state(x, y, z, w, w1, w2, w3, w4);
99 
100  printf("x = %9u (%s)\n", (unsigned int)x, x == INIT_X ? "ok" : "ERROR");
101  printf("y = %9u (%s)\n", (unsigned int)y, y == INIT_Y ? "ok" : "ERROR");
102  printf("z = %9u (%s)\n", (unsigned int)z, z == INIT_Z ? "ok" : "ERROR");
103  printf("w = %9u (%s)\n", (unsigned int)w, w == INIT_W ? "ok" : "ERROR");
104 
105  if (x != INIT_X || y != INIT_Y || z != INIT_Z || w != INIT_W)
106  abort();
107 
108  printf("\n");
109 
110  return 0;
111 }
void find_xorshift128_init_state(uint32_t &x, uint32_t &y, uint32_t &z, uint32_t &w, uint32_t w1, uint32_t w2, uint32_t w3, uint32_t w4)
Definition: demo_vec.cc:46
#define INIT_Z
Definition: demo_vec.cc:25
#define INIT_Y
Definition: demo_vec.cc:24
#define INIT_X
Definition: demo_vec.cc:23
#define INIT_W
Definition: demo_vec.cc:26
uint32_t xorshift128()
Definition: demo_vec.cc:28

+ Here is the call graph for this function:

uint32_t xorshift128 ( )

Definition at line 28 of file demo_vec.cc.

28  {
29  static uint32_t x = INIT_X;
30  static uint32_t y = INIT_Y;
31  static uint32_t z = INIT_Z;
32  static uint32_t w = INIT_W;
33  uint32_t t = x ^ (x << 11);
34  x = y; y = z; z = w;
35  w ^= (w >> 19) ^ t ^ (t >> 8);
36  return w;
37 }
#define INIT_Z
Definition: demo_vec.cc:25
#define INIT_Y
Definition: demo_vec.cc:24
#define INIT_X
Definition: demo_vec.cc:23
#define INIT_W
Definition: demo_vec.cc:26

+ Here is the caller graph for this function:

void xorshift128_sat ( ezSAT sat,
std::vector< int > &  x,
std::vector< int > &  y,
std::vector< int > &  z,
std::vector< int > &  w 
)

Definition at line 39 of file demo_vec.cc.

40 {
41  std::vector<int> t = sat.vec_xor(x, sat.vec_shl(x, 11));
42  x = y; y = z; z = w;
43  w = sat.vec_xor(sat.vec_xor(w, sat.vec_shr(w, 19)), sat.vec_xor(t, sat.vec_shr(t, 8)));
44 }
std::vector< int > vec_shl(const std::vector< int > &vec1, int shift, bool signExtend=false)
Definition: ezsat.cc:964
std::vector< int > vec_shr(const std::vector< int > &vec1, int shift, bool signExtend=false)
Definition: ezsat.h:266
std::vector< int > vec_xor(const std::vector< int > &vec1, const std::vector< int > &vec2)
Definition: ezsat.cc:727

+ Here is the call graph for this function:

+ Here is the caller graph for this function: