From: Stephen W. <st...@ic...> - 2008-01-30 17:33:07
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Larry Doolittle wrote: > I detect sloppiness in the use of int vs. long. > > The offending NetNet was created by the buggy shift elaborator > with npins=0. A NetNet's msb_ is initialized to npins-1, where npins > is unsigned, and therefore npins-1 = 0xffffffff = 4294967295. msb_ is > declared long, so this result after cast is interpreted as 0x00000000ffffffff > (4294967295) on a 64-bit machine, but 0xffffffff (-1) on a 32-bit machine. > > Line 2151 of t-dll.cc is > obj->width_ = net->vector_width(); > where obj->width_ is declared unsigned (t-dll.h:576), > but net->vector_width() is unsigned long (netlist.h:504). > In the 64-bit case, the msb_ > lsb_ width calculation performed in > vector_width() (netlist.cc:632) is 4294967295-0+1=4294967296, > which yields 0 after the cast to unsigned. In the 32-bit case, > msb_ > lsb_ is false (-1 is not > 0), so the width calculation > (netlist.cc:634) is 0-(-1)+1=2, cast to unsigned is still 2. Looks like you nailed it. I've confirmed that the error does happen on the mac (32bit) and your patch does indeed fix it. And your analysis here explains the different behavior on a 64bit system. So I'm confident the problem at hand is understood and fixed. Great! > My new assert(npins>0) for NetNet will obviously help. I'm not sure > what other changes, if any, are called for. Of course there may be other int/long/signed/unsigned sloppynesses in there. The warnings used to be lingering reminders but we seem to be rid of those warnings so we'll just have to keep an eye out for them. It is tricky that indices are signed as entered in the source code (i.e. foo[4 : -1] but the widths of vectors are unsigned. It is also true that in the canonical form, the form that vvp works in as opposed to the index values passed to the user via vpi, they are unsigned and zero based. This was done to simplify the code generator (all vectors are zero-based with index-0 the LSB) but the signed indices are preserved for presentation via the VPI. The signed indices to canonical indices conversion is a place where the signed-unsigned- 32bit-64bit issues can get tangled, and that happens in the elaborator and also in the vvp VPI interface. Something to watch out for. - -- Steve Williams "The woods are lovely, dark and deep. steve at icarus.com But I have promises to keep, http://www.icarus.com and lines to code before I sleep, http://www.picturel.com And lines to code before I sleep." -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFHoLTXrPt1Sc2b3ikRAqLoAJ9TbfaMpy/GxzHfUs2YgCP1/7tPWgCg1xri j5oFs1bRLo8NKEK1b0gx9hM= =MlzI -----END PGP SIGNATURE----- |