CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
vppc_sim_lib.h
Go to the documentation of this file.
1 #ifndef _VPPC_SIM_LIB_H_FILE_
2 #define _VPPC_SIM_LIB_H_FILE_
3 #include <iostream>
4 #include <sstream>
5 #include <fstream>
6 #include <iomanip>
7 #include <cstdarg>
8 #include <map>
9 #include <vector>
10 #include <exception>
11 #include <stdexcept> // out_of_range exception
12 #include <time.h>
13 
14 using namespace std;
15 
16 #define ull unsigned int
17 #define dull unsigned long long
18 #define sull 32 // size of unsigned __int32
19 #define sdull 64 // size of double variable
20 #define mull (0xffffffffUL) // max value
21 #define mdull (0xffffffffffffffffULL)
22 #define max_depth 32
23 #define max_temp_sig 64 // has to be power of 2
24 #define temp_i_mask (max_temp_sig - 1) // temp signal index mask
25 #define max_bits 1024
26 #define const__p const_s_p
27 
28 #define Stime clock()
29 #define repeat(a) for (int __rep_counter__ = 0; __rep_counter__ < a; __rep_counter__++)
30 #define Swrite(cl, ...) Sfwrite(stdout_sig, cl, ##__VA_ARGS__)
31 #define Sdisplay(cl, ...) Sfwrite(stdout_sig, (string)cl + "\n", ##__VA_ARGS__)
32 #define Sfdisplay(fd,cl, ...) Sfwrite(fd, (string)cl + "\n", ##__VA_ARGS__)
33 
34 void sim_lib_init();
35 
37 {
38 public:
39  signal_storage(){cell = NULL; dim_h = dim_l = 0;};
40  ull *r, *rc; // storage for current and registered values, needs to be reserved
41  // initialization before each sim iteration
42  void init();
43  void bw(size_t ih, size_t il);
44  void add_dim(size_t h, size_t l);
45  void build();
47 
48  bool change; // change in value flag
49  bool assigned; // flag showing that it was assigned
50  bool edge; // posedge/negedge flag, set only for clock by test fixture. change & edge = posedge, change & !edge = negedge
51  size_t btw, wn, byten; // bit width, word count, byte count
52  size_t alwaysn;
53  signal_storage* cell; // array of signals
54  size_t dim_h, dim_l; // array dimensions
55 };
56 
57 class signal_
58 {
59 public:
60  signal_(){st = NULL; cell = NULL; dim_h = dim_l = 0;};
61  // signal_ bitwidth declaration
62  void bw(size_t h, size_t l);
63  void set_storage(signal_storage* st);
64  ull get_ull(size_t bnum);
65  void set_ull(size_t bnum, size_t bcnt, ull val);
66  ull* getval();
67  void attach(signal_& src);
68  void add_dim(size_t h, size_t l);
69  void build();
70 
71  signal_& operator[](ull i); // single bit selection
72  signal_& operator()(ull hn, ull ln); // bit portion selection
73  signal_& bp(ull sn, ull lng); // +: bit portion selection
74  signal_& bm(ull sn, ull lng); // -: bit portion selection
75  signal_& operator=(signal_& oth); // assignment
76  signal_& operator=(ull n); // assignment
77  ull operator!();
78 
81  ull operator++ (int){return *this = *this + 1;};
82  ull operator-- (int){return *this = *this - 1;};
83 
85  ull operator% (signal_& arg);
90 
91  signal_& operator+= (signal_& arg){return *this = *this + arg;};
92  signal_& operator-= (signal_& arg){return *this = *this - arg;};
93  signal_& operator/= (signal_& arg){return *this = *this / arg;};
94  signal_& operator%= (signal_& arg){return *this = *this % arg;};
95 
98 
102 
103  signal_& operator|= (signal_& arg){return *this = *this | arg;};
104  signal_& operator&= (signal_& arg){return *this = *this & arg;};
105  signal_& operator^= (signal_& arg){return *this = *this ^ arg;};
106 
107  signal_& operator~ ();
108 
109  signal_& operator, (signal_& arg);
110 
111  operator ull(); // conversion operator
112 
113  friend ull uor (signal_&);
114  friend ull uxor (signal_&);
115  friend ull uand (signal_&);
116  friend ull uor (ull);
117  friend ull uxor (ull);
118  friend ull uand (ull);
119  friend ull const_(size_t sz, ull val); // for constants fitting into one ull
120  friend signal_& const_s(size_t sz, dull val); // for constants fitting into one ull
121  friend signal_& const_l(size_t sz, size_t count, ... ); // for longer constants
122  friend signal_& const_s_p(size_t sz, dull val); // for permanent constants fitting into one ull
123  friend signal_& const_l_p(size_t sz, size_t count, ... ); // for longer permanent constants
124  friend bool posedge (signal_&);
125  friend bool negedge (signal_&);
126  friend void clk_drive(signal_& clk, ull v);
127 
128  signal_storage* st; // pointer to signal value storage
129  ull *r, *rc; // copies of pointers from st. For temp signals, rc == rt;
130  ull *rt; // storage for temp signal only
131  size_t dh, dl; // high and low bit numbers as declared
132  size_t sh, sl; // high and low bits that should be applied to storage
133  // number of always block where it was assigned
134  // this number is individual for each reference because portions of the original
135  // storage may be assigned in different ABs
136  signal_ *ca1, *ca2; // concatenated signals
137  size_t alwaysn;
138  signal_* cell; // array of signals if this is lowest level
139  size_t dim_h, dim_l; // array dimensions
140 };
141 
142 
143 ull const_(size_t sz, ull val); // for constants fitting into one ull
144 signal_& const_s(size_t sz, dull val); // for constants fitting into one ull
145 signal_& const_l(size_t sz, size_t count, ... ); // for longer constants
146 signal_& const_s_p(size_t sz, dull val); // for permanent constants fitting into one ull
147 signal_& const_l_p(size_t sz, size_t count, ... ); // for longer permanent constants
148 signal_& const_l(size_t sz, size_t count, ... ); // for longer constants
149 void Sfwrite(signal_& fd, string format, ... );
150 int Ssscanf (signal_& line, string format, ... );
151 void Sreadmemh(string fname, signal_& dest, size_t adr = 0);
152 signal_ Sfopen(string fname, string mode = "w");
153 void Sfclose (signal_& fd);
154 int Sfgets (signal_& line, signal_& fd);
155 int Sfeof(signal_& fd);
156 void beginalways();
157 void endalways();
158 
159 
160 #endif
161 
162 
unsigned int * rc
Definition: vppc_sim_lib.h:129
signal_ Sfopen(string fname, string mode="w")
int i
Definition: DBlmapReader.cc:9
mathSSE::Vec4< double > operator|(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:122
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
int Sfeof(signal_ &fd)
MatrixMeschach operator+(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
signal_ & const_s(size_t sz, unsigned long long val)
mathSSE::Vec4< double > operator&(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:119
bool operator>(l1t::Jet &a, l1t::Jet &b)
int init
Definition: HydjetWrapper.h:67
MatrixMeschach operator-(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
Basic3DVector & operator-=(const Basic3DVector< U > &p)
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
#define NULL
Definition: scimark2.h:8
#define dull
Definition: vppc_sim_lib.h:17
int Sfgets(signal_ &line, signal_ &fd)
unsigned int * rt
Definition: vppc_sim_lib.h:130
A arg
Definition: Factorize.h:36
signal_storage * st
Definition: vppc_sim_lib.h:128
Basic3DVector< long double > operator/(const Basic3DVector< long double > &v, S s)
bool operator<=(View< T > const &, View< T > const &)
Definition: View.h:371
#define ull
Definition: vppc_sim_lib.h:16
signal_ & const_l(size_t sz, size_t count,...)
bool operator>=(View< T > const &, View< T > const &)
Definition: View.h:383
void beginalways()
int Ssscanf(signal_ &line, string format,...)
bool operator<(const FedChannelConnection &, const FedChannelConnection &)
size_t sl
Definition: vppc_sim_lib.h:132
void Sreadmemh(string fname, signal_ &dest, size_t adr=0)
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
unsigned int const_(size_t sz, unsigned int val)
T operator[](int i) const
tuple fd
Definition: ztee.py:136
signal_ * cell
Definition: vppc_sim_lib.h:138
size_t dl
Definition: vppc_sim_lib.h:131
size_t dim_l
Definition: vppc_sim_lib.h:139
signal_ & const_s_p(size_t sz, unsigned long long val)
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
signal_ * ca2
Definition: vppc_sim_lib.h:136
void Sfclose(signal_ &fd)
void Sfwrite(signal_ &fd, string format,...)
string fname
main script
signal_ & const_l_p(size_t sz, size_t count,...)
void endalways()
signal_storage * cell
Definition: vppc_sim_lib.h:53
mathSSE::Vec4< double > operator^(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
Definition: AVXVec.h:125
void sim_lib_init()
size_t alwaysn
Definition: vppc_sim_lib.h:137
Basic3DVector & operator+=(const Basic3DVector< U > &p)
tuple dh
Definition: cuy.py:353