@@ -4467,6 +4467,7 @@ RTLIL::SigSpec::SigSpec(const RTLIL::Const &value)
44674467
44684468	if  (GetSize (value) != 0 ) {
44694469		chunks_.emplace_back (value);
4470+ 		chunks_.back ().offset_in_sigspec  = 0 ;
44704471		width_ = chunks_.back ().width ;
44714472	} else  {
44724473		width_ = 0 ;
@@ -4481,6 +4482,7 @@ RTLIL::SigSpec::SigSpec(RTLIL::Const &&value)
44814482
44824483	if  (GetSize (value) != 0 ) {
44834484		chunks_.emplace_back (std::move (value));
4485+ 		chunks_.back ().offset_in_sigspec  = 0 ;
44844486		width_ = chunks_.back ().width ;
44854487	} else  {
44864488		width_ = 0 ;
@@ -4495,6 +4497,7 @@ RTLIL::SigSpec::SigSpec(const RTLIL::SigChunk &chunk)
44954497
44964498	if  (chunk.width  != 0 ) {
44974499		chunks_.emplace_back (chunk);
4500+ 		chunks_.back ().offset_in_sigspec  = 0 ;
44984501		width_ = chunks_.back ().width ;
44994502	} else  {
45004503		width_ = 0 ;
@@ -4509,6 +4512,7 @@ RTLIL::SigSpec::SigSpec(RTLIL::SigChunk &&chunk)
45094512
45104513	if  (chunk.width  != 0 ) {
45114514		chunks_.emplace_back (std::move (chunk));
4515+ 		chunks_.back ().offset_in_sigspec  = 0 ;
45124516		width_ = chunks_.back ().width ;
45134517	} else  {
45144518		width_ = 0 ;
@@ -4523,6 +4527,7 @@ RTLIL::SigSpec::SigSpec(RTLIL::Wire *wire)
45234527
45244528	if  (wire->width  != 0 ) {
45254529		chunks_.emplace_back (wire);
4530+ 		chunks_.back ().offset_in_sigspec  = 0 ;
45264531		width_ = chunks_.back ().width ;
45274532	} else  {
45284533		width_ = 0 ;
@@ -4537,6 +4542,7 @@ RTLIL::SigSpec::SigSpec(RTLIL::Wire *wire, int offset, int width)
45374542
45384543	if  (width != 0 ) {
45394544		chunks_.emplace_back (wire, offset, width);
4545+ 		chunks_.back ().offset_in_sigspec  = 0 ;
45404546		width_ = chunks_.back ().width ;
45414547	} else  {
45424548		width_ = 0 ;
@@ -4551,6 +4557,7 @@ RTLIL::SigSpec::SigSpec(const std::string &str)
45514557
45524558	if  (str.size () != 0 ) {
45534559		chunks_.emplace_back (str);
4560+ 		chunks_.back ().offset_in_sigspec  = 0 ;
45544561		width_ = chunks_.back ().width ;
45554562	} else  {
45564563		width_ = 0 ;
@@ -4563,8 +4570,10 @@ RTLIL::SigSpec::SigSpec(int val, int width)
45634570{
45644571	cover (" kernel.rtlil.sigspec.init.int" 
45654572
4566- 	if  (width != 0 )
4573+ 	if  (width != 0 ) { 
45674574		chunks_.emplace_back (val, width);
4575+ 		chunks_.back ().offset_in_sigspec  = 0 ;
4576+ 	}
45684577	width_ = width;
45694578	hash_ = 0 ;
45704579	check ();
@@ -4574,8 +4583,10 @@ RTLIL::SigSpec::SigSpec(RTLIL::State bit, int width)
45744583{
45754584	cover (" kernel.rtlil.sigspec.init.state" 
45764585
4577- 	if  (width != 0 )
4586+ 	if  (width != 0 ) { 
45784587		chunks_.emplace_back (bit, width);
4588+ 		chunks_.back ().offset_in_sigspec  = 0 ;
4589+ 	}
45794590	width_ = width;
45804591	hash_ = 0 ;
45814592	check ();
@@ -4586,11 +4597,15 @@ RTLIL::SigSpec::SigSpec(const RTLIL::SigBit &bit, int width)
45864597	cover (" kernel.rtlil.sigspec.init.bit" 
45874598
45884599	if  (width != 0 ) {
4589- 		if  (bit.wire  == NULL )
4600+ 		if  (bit.wire  == NULL ) { 
45904601			chunks_.emplace_back (bit.data , width);
4591- 		else 
4592- 			for  (int  i = 0 ; i < width; i++)
4602+ 			chunks_.back ().offset_in_sigspec  = 0 ;
4603+ 		} else  {
4604+ 			for  (int  i = 0 ; i < width; i++) {
45934605				chunks_.push_back (bit);
4606+ 				chunks_.back ().offset_in_sigspec  = i;
4607+ 			}
4608+ 		}
45944609	}
45954610	width_ = width;
45964611	hash_ = 0 ;
@@ -4667,7 +4682,8 @@ void RTLIL::SigSpec::pack() const
46674682	RTLIL::SigChunk *last = NULL ;
46684683	int  last_end_offset = 0 ;
46694684
4670- 	for  (auto  &bit : old_bits) {
4685+ 	for  (int  i = 0 ; i < GetSize (old_bits); ++i) {
4686+ 		const  RTLIL::SigBit &bit = old_bits[i];
46714687		if  (last && bit.wire  == last->wire ) {
46724688			if  (bit.wire  == NULL ) {
46734689				last->data .push_back (bit.data );
@@ -4680,6 +4696,7 @@ void RTLIL::SigSpec::pack() const
46804696			}
46814697		}
46824698		that->chunks_ .push_back (bit);
4699+ 		that->chunks_ .back ().offset_in_sigspec  = i;
46834700		last = &that->chunks_ .back ();
46844701		last_end_offset = bit.offset  + 1 ;
46854702	}
@@ -5074,6 +5091,7 @@ void RTLIL::SigSpec::remove_const()
50745091					new_chunks.back ().width  += chunk.width ;
50755092				} else  {
50765093					new_chunks.push_back (chunk);
5094+ 					new_chunks.back ().offset_in_sigspec  = width_;
50775095				}
50785096				width_ += chunk.width ;
50795097			}
@@ -5127,10 +5145,13 @@ RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const
51275145		extracted.width_  = length;
51285146
51295147		auto  it = chunks_.begin ();
5148+ 		int  offset_in_extracted = 0 ;
51305149		for  (; offset; offset -= it->width , it++) {
51315150			if  (offset < it->width ) {
51325151				int  chunk_length = min (it->width  - offset, length);
51335152				extracted.chunks_ .emplace_back (it->extract (offset, chunk_length));
5153+ 				extracted.chunks_ .back ().offset_in_sigspec  = 0 ;
5154+ 				offset_in_extracted = chunk_length;
51345155				length -= chunk_length;
51355156				it++;
51365157				break ;
@@ -5139,8 +5160,11 @@ RTLIL::SigSpec RTLIL::SigSpec::extract(int offset, int length) const
51395160		for  (; length; length -= it->width , it++) {
51405161			if  (length >= it->width ) {
51415162				extracted.chunks_ .emplace_back (*it);
5163+ 				extracted.chunks_ .back ().offset_in_sigspec  = offset_in_extracted;
5164+ 				offset_in_extracted += it->width ;
51425165			} else  {
51435166				extracted.chunks_ .emplace_back (it->extract (0 , length));
5167+ 				extracted.chunks_ .back ().offset_in_sigspec  = offset_in_extracted;
51445168				break ;
51455169			}
51465170		}
@@ -5168,7 +5192,8 @@ void RTLIL::SigSpec::append(const RTLIL::SigSpec &signal)
51685192		signal.pack ();
51695193	}
51705194
5171- 	if  (packed ())
5195+ 	if  (packed ()) {
5196+ 		int  offset_in_sigspec = width_;
51725197		for  (auto  &other_c : signal.chunks_ )
51735198		{
51745199			auto  &my_last_c = chunks_.back ();
@@ -5177,13 +5202,15 @@ void RTLIL::SigSpec::append(const RTLIL::SigSpec &signal)
51775202				auto  &other_data = other_c.data ;
51785203				this_data.insert (this_data.end (), other_data.begin (), other_data.end ());
51795204				my_last_c.width  += other_c.width ;
5180- 			} else 
5181- 			if  (my_last_c.wire  == other_c.wire  && my_last_c.offset  + my_last_c.width  == other_c.offset ) {
5205+ 			} else  if  (my_last_c.wire  == other_c.wire  && my_last_c.offset  + my_last_c.width  == other_c.offset ) {
51825206				my_last_c.width  += other_c.width ;
5183- 			} else 
5207+ 			} else  { 
51845208				chunks_.push_back (other_c);
5209+ 				chunks_.back ().offset_in_sigspec  = offset_in_sigspec;
5210+ 			}
5211+ 			offset_in_sigspec += other_c.width ;
51855212		}
5186- 	else 
5213+ 	}  else 
51875214		bits_.insert (bits_.end (), signal.bits_ .begin (), signal.bits_ .end ());
51885215
51895216	width_ += signal.width_ ;
@@ -5196,20 +5223,25 @@ void RTLIL::SigSpec::append(const RTLIL::SigBit &bit)
51965223	{
51975224		cover (" kernel.rtlil.sigspec.append_bit.packed" 
51985225
5199- 		if  (chunks_.size () == 0 )
5226+ 		if  (chunks_.size () == 0 ) { 
52005227			chunks_.push_back (bit);
5201- 		else 
5228+ 			chunks_.back ().offset_in_sigspec  = 0 ;
5229+ 		} else 
52025230			if  (bit.wire  == NULL )
52035231				if  (chunks_.back ().wire  == NULL ) {
52045232					chunks_.back ().data .push_back (bit.data );
52055233					chunks_.back ().width ++;
5206- 				} else 
5234+ 				} else  { 
52075235					chunks_.push_back (bit);
5236+ 					chunks_.back ().offset_in_sigspec  = width_;
5237+ 				}
52085238			else 
52095239				if  (chunks_.back ().wire  == bit.wire  && chunks_.back ().offset  + chunks_.back ().width  == bit.offset )
52105240					chunks_.back ().width ++;
5211- 				else 
5241+ 				else  { 
52125242					chunks_.push_back (bit);
5243+ 					chunks_.back ().offset_in_sigspec  = width_;
5244+ 				}
52135245	}
52145246	else 
52155247	{
@@ -5265,6 +5297,7 @@ void RTLIL::SigSpec::check(Module *mod) const
52655297		for  (size_t  i = 0 ; i < chunks_.size (); i++) {
52665298			const  RTLIL::SigChunk &chunk = chunks_[i];
52675299			log_assert (chunk.width  != 0 );
5300+ 			log_assert (chunk.offset_in_sigspec  == w);
52685301			if  (chunk.wire  == NULL ) {
52695302				if  (i > 0 )
52705303					log_assert (chunks_[i-1 ].wire  != NULL );
0 commit comments