Roman Popov Posted March 19, 2016 Report Share Posted March 19, 2016 A follow-up question for http://forums.accellera.org/topic/5443-vector-declaration/ Why square brakets are not overloaded for sc_signal class? In case underling datatype allows bit-level access, it seems it would be handy to allow it for signals? Looks like there is no technical limitation to do this, here is an example: #include <systemc.h> template< class T, sc_writer_policy POL = SC_DEFAULT_WRITER_POLICY > struct my_sc_signal : public sc_signal<T, POL> { typedef my_sc_signal<T,POL> this_type; typedef sc_signal<T, POL> base_type; explicit my_sc_signal( const char* name_) : base_type( name_ ){} struct signal_writer_helper { signal_writer_helper (this_type &s, size_t i) : sig(s), id(i) {} template <typename AT> void operator = ( const AT& val_ ) { bool value_changed = !( sig.m_cur_val[id] == val_ ); sig.m_new_val[id] = val_; if( value_changed ) sig.request_update(); } this_type &sig; size_t id; }; signal_writer_helper operator [](size_t i) { return signal_writer_helper(*this, i); } }; SC_MODULE(test) { static const int BUS_WIDTH = 10; my_sc_signal<sc_uint<BUS_WIDTH> > test_sig{"test_sig"}; SC_CTOR(test) { SC_THREAD(master_thread); SC_METHOD(slave_method); sensitive << test_sig; } void master_thread() { for (int i = 0; i < BUS_WIDTH; ++i) { test_sig[i] = 1; wait(1, SC_NS); } for (int i = 0; i < BUS_WIDTH; ++i) { test_sig[i] = 1; wait(1, SC_NS); } sc_stop(); } void slave_method() { cout << "New signal value is: " << test_sig.read() << endl; } }; int sc_main(int argc, char *argv[]) { test test_inst("test_inst"); sc_start(); return 0; } Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted March 23, 2016 Author Report Share Posted March 23, 2016 There is an ASSIGN implementation proposal in: http://nascug.org/events/17th/black_cpp11_2_27_2012.pdf So with bit level access to sc_signals I can imagine something like: ASSIGN( addr_sig, a_sel_sig = addr_sig[0] ); ASSIGN( addr_sig, b_sel_sig = addr_sig[1] ); ASSIGN( addr_sig, c_sel_sig = addr_sig[2] ); or even ASSIGN( addr_sig[0], a_sel_sig = addr_sig[0] ); ASSIGN( addr_sig[1], b_sel_sig = addr_sig[1] ); ASSIGN( addr_sig[2], c_sel_sig = addr_sig[2] ); if sc_signal[] returns something with event capabilities Highly desired for Synthesizable SystemC. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.