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 
15 #define ull unsigned int
16 #define dull unsigned long long
17 #define sull 32 // size of unsigned __int32
18 #define sdull 64 // size of double variable
19 #define mull (0xffffffffUL) // max value
20 #define mdull (0xffffffffffffffffULL)
21 #define max_depth 32
22 #define max_temp_sig 64 // has to be power of 2
23 #define temp_i_mask (max_temp_sig - 1) // temp signal index mask
24 #define max_bits 1024
25 #define const__p const_s_p
26 
27 #define Stime clock()
28 #define repeat(a) for (int __rep_counter__ = 0; __rep_counter__ < a; __rep_counter__++)
29 #define Swrite(cl, ...) Sfwrite(stdout_sig, cl, ##__VA_ARGS__)
30 #define Sdisplay(cl, ...) Sfwrite(stdout_sig, (std::string)cl + "\n", ##__VA_ARGS__)
31 #define Sfdisplay(fd,cl, ...) Sfwrite(fd, (std::string)cl + "\n", ##__VA_ARGS__)
32 
33 void sim_lib_init();
34 
36 {
37 public:
39  ull *r, *rc; // storage for current and registered values, needs to be reserved
40  // initialization before each sim iteration
41  void init();
42  void bw(size_t ih, size_t il);
43  void add_dim(size_t h, size_t l);
44  void build();
46 
47  bool change; // change in value flag
48  bool assigned; // flag showing that it was assigned
49  bool edge; // posedge/negedge flag, set only for clock by test fixture. change & edge = posedge, change & !edge = negedge
50  size_t btw, wn, byten; // bit width, word count, byte count
51  size_t alwaysn;
52  signal_storage* cell; // array of signals
53  size_t dim_h, dim_l; // array dimensions
54 };
55 
56 class signal_
57 {
58 public:
59  signal_(){st = NULL; cell = NULL; dim_h = dim_l = 0;};
60  // signal_ bitwidth declaration
61  void bw(size_t h, size_t l);
63  ull get_ull(size_t bnum);
64  void set_ull(size_t bnum, size_t bcnt, ull val);
65  ull* getval();
66  void attach(signal_& src);
67  void add_dim(size_t h, size_t l);
68  void build();
69 
70  signal_& operator[](ull i); // single bit selection
71  signal_& operator()(ull hn, ull ln); // bit portion selection
72  signal_& bp(ull sn, ull lng); // +: bit portion selection
73  signal_& bm(ull sn, ull lng); // -: bit portion selection
74  signal_& operator=(signal_& oth); // assignment
75  signal_& operator=(ull n); // assignment
76  ull operator!();
77 
80  ull operator++ (int){return *this = *this + 1;};
81  ull operator-- (int){return *this = *this - 1;};
82 
89 
90  signal_& operator+= (signal_& arg){return *this = *this + arg;};
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 
97 
101 
102  signal_& operator|= (signal_& arg){return *this = *this | arg;};
103  signal_& operator&= (signal_& arg){return *this = *this & arg;};
104  signal_& operator^= (signal_& arg){return *this = *this ^ arg;};
105 
106  signal_& operator~ ();
107 
109 
110  operator ull(); // conversion operator
111 
112  friend ull uor (signal_&);
113  friend ull uxor (signal_&);
114  friend ull uand (signal_&);
115  friend ull uor (ull);
116  friend ull uxor (ull);
117  friend ull uand (ull);
118  friend ull const_(size_t sz, ull val); // for constants fitting into one ull
119  friend signal_& const_s(size_t sz, dull val); // for constants fitting into one ull
120  friend signal_& const_l(size_t sz, size_t count, ... ); // for longer constants
121  friend signal_& const_s_p(size_t sz, dull val); // for permanent constants fitting into one ull
122  friend signal_& const_l_p(size_t sz, size_t count, ... ); // for longer permanent constants
123  friend bool posedge (signal_&);
124  friend bool negedge (signal_&);
125  friend void clk_drive(signal_& clk, ull v);
126 
127  signal_storage* st; // pointer to signal value storage
128  ull *r, *rc; // copies of pointers from st. For temp signals, rc == rt;
129  ull *rt; // storage for temp signal only
130  size_t dh, dl; // high and low bit numbers as declared
131  size_t sh, sl; // high and low bits that should be applied to storage
132  // number of always block where it was assigned
133  // this number is individual for each reference because portions of the original
134  // storage may be assigned in different ABs
135  signal_ *ca1, *ca2; // concatenated signals
136  size_t alwaysn;
137  signal_* cell; // array of signals if this is lowest level
138  size_t dim_h, dim_l; // array dimensions
139 };
140 
141 
142 ull const_(size_t sz, ull val); // for constants fitting into one ull
143 signal_& const_s(size_t sz, dull val); // for constants fitting into one ull
144 signal_& const_l(size_t sz, size_t count, ... ); // for longer constants
145 signal_& const_s_p(size_t sz, dull val); // for permanent constants fitting into one ull
146 signal_& const_l_p(size_t sz, size_t count, ... ); // for longer permanent constants
147 signal_& const_l(size_t sz, size_t count, ... ); // for longer constants
148 void Sfwrite(signal_& fd, std::string format, ... );
149 int Ssscanf (signal_& line, std::string format, ... );
150 void Sreadmemh(std::string fname, signal_& dest, size_t adr = 0);
152 void Sfclose (signal_& fd);
153 int Sfgets (signal_& line, signal_& fd);
154 int Sfeof(signal_& fd);
155 void beginalways();
156 void endalways();
157 
158 
159 #endif
160 
161 
unsigned int * rc
Definition: vppc_sim_lib.h:128
size_t dh
Definition: vppc_sim_lib.h:130
int i
Definition: DBlmapReader.cc:9
friend void clk_drive(signal_ &clk, unsigned int v)
void Sfwrite(signal_ &fd, std::string format,...)
signal_ & operator[](unsigned int i)
signal_ & operator,(signal_ &arg)
signal_ & operator|(signal_ &arg)
void attach(signal_ &src)
signal_ Sfopen(std::string fname, std::string mode="w")
signal_ & operator%=(signal_ &arg)
Definition: vppc_sim_lib.h:93
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
int Sfeof(signal_ &fd)
signal_ & operator()(unsigned int hn, unsigned int ln)
signal_ & operator+=(signal_ &arg)
Definition: vppc_sim_lib.h:90
unsigned int operator-(signal_ &arg)
void add_dim(size_t h, size_t l)
unsigned int * r
Definition: vppc_sim_lib.h:38
signal_ & const_s(size_t sz, unsigned long long val)
signal_ & operator-=(signal_ &arg)
Definition: vppc_sim_lib.h:91
friend unsigned int uand(signal_ &)
int Ssscanf(signal_ &line, std::string format,...)
void bw(size_t ih, size_t il)
#define NULL
Definition: scimark2.h:8
#define dull
Definition: vppc_sim_lib.h:16
int Sfgets(signal_ &line, signal_ &fd)
unsigned int operator--(int)
Definition: vppc_sim_lib.h:81
unsigned int * rt
Definition: vppc_sim_lib.h:129
void set_ull(size_t bnum, size_t bcnt, unsigned int val)
A arg
Definition: Factorize.h:36
signal_ & operator&(signal_ &arg)
signal_storage * st
Definition: vppc_sim_lib.h:127
signal_ & operator~()
unsigned int * getval()
void add_dim(size_t h, size_t l)
#define ull
Definition: vppc_sim_lib.h:15
unsigned int get_ull(size_t bnum)
signal_ & const_l(size_t sz, size_t count,...)
unsigned int operator++(int)
Definition: vppc_sim_lib.h:80
size_t sh
Definition: vppc_sim_lib.h:131
void beginalways()
signal_ & bm(unsigned int sn, unsigned int lng)
friend unsigned int uor(signal_ &)
size_t sl
Definition: vppc_sim_lib.h:131
signal_ & operator^=(signal_ &arg)
Definition: vppc_sim_lib.h:104
signal_ & operator/=(signal_ &arg)
Definition: vppc_sim_lib.h:92
friend signal_ & const_l(size_t sz, size_t count,...)
signal_ & operator=(signal_ &oth)
friend signal_ & const_s(size_t sz, unsigned long long val)
unsigned int const_(size_t sz, unsigned int val)
friend unsigned int uxor(signal_ &)
signal_storage & operator[](unsigned int i)
tuple fd
Definition: ztee.py:136
size_t dim_h
Definition: vppc_sim_lib.h:138
unsigned int operator%(signal_ &arg)
signal_ * cell
Definition: vppc_sim_lib.h:137
size_t dl
Definition: vppc_sim_lib.h:130
void Sreadmemh(std::string fname, signal_ &dest, size_t adr=0)
unsigned int operator<=(signal_ &arg)
friend bool posedge(signal_ &)
signal_ & operator|=(signal_ &arg)
Definition: vppc_sim_lib.h:102
size_t dim_l
Definition: vppc_sim_lib.h:138
signal_ & const_s_p(size_t sz, unsigned long long val)
unsigned int * rc
Definition: vppc_sim_lib.h:38
signal_ * ca2
Definition: vppc_sim_lib.h:135
unsigned int operator==(signal_ &arg)
unsigned int operator/(signal_ &arg)
friend signal_ & const_s_p(size_t sz, unsigned long long val)
friend unsigned int const_(size_t sz, unsigned int val)
unsigned int operator+(signal_ &arg)
void Sfclose(signal_ &fd)
string fname
main script
unsigned int operator>(signal_ &arg)
signal_ * ca1
Definition: vppc_sim_lib.h:135
unsigned int operator>=(signal_ &arg)
signal_ & const_l_p(size_t sz, size_t count,...)
void endalways()
friend signal_ & const_l_p(size_t sz, size_t count,...)
signal_ & operator^(signal_ &arg)
void bw(size_t h, size_t l)
signal_storage * cell
Definition: vppc_sim_lib.h:52
friend bool negedge(signal_ &)
unsigned int operator!=(signal_ &arg)
unsigned int operator!()
void sim_lib_init()
void set_storage(signal_storage *st)
unsigned int * r
Definition: vppc_sim_lib.h:128
unsigned int operator<(signal_ &arg)
size_t alwaysn
Definition: vppc_sim_lib.h:136
void build()
signal_ & bp(unsigned int sn, unsigned int lng)
signal_ & operator&=(signal_ &arg)
Definition: vppc_sim_lib.h:103