24
\$\begingroup\$

It seems that the world has decided that std_logic (and std_logic_vector) are the default way of representing bits in VHDL. The alternative would be std_ulogic, which is not resolved.

This surprises me because usually, you're not describing a bus, so you do you don't want multiple drivers and you don't need to resolve a signal. The advantage of std_ulogic would be that the compiler warns you early on if you have multiple drivers.

Question: is this just a cultural / historical thing, or are there still technical reasons to use std_logic?

\$\endgroup\$
  • 3
    \$\begingroup\$ The "world" is wrong. Smart engineers use std_ulogic as because it has the correct semantics. \$\endgroup\$ – wjl Jul 29 '11 at 1:57
  • \$\begingroup\$ @wjl I'll interpret that as "it's a cultural/historical thing". Your answer below is much more helpful than the comment up here. \$\endgroup\$ – Philippe Jul 31 '11 at 18:00
  • \$\begingroup\$ I wrote the comment first, then thought it would be more appropriate to leave an answer with more specifics. Sorry, I guess it does sound a little flippant. But my comment is literal in that most people start out using std_logic because they learned it that way, then after a while they start to wonder about std_ulogic, they look up it, realize it's semantics, and then convert to it. =) \$\endgroup\$ – wjl Jul 31 '11 at 23:27
16
\$\begingroup\$

Std_logic is a subtype of std_ulogic and has exactly one extra property: it's resolved if there are multiple drivers.

Regardless of common practice, std_ulogic is the correct type to use for non-resolved signals that need 9-valued logic. (Often, using "bit" is even more correct -- for instance, on some FPGA architectures that do not have any such thing as an 'X' or a 'U').

Basically, the best thing to do is use the correct type for the job. Often bad practices get propagated by people just parroting the style that they see others use, do without understanding why.

\$\endgroup\$
  • 8
    \$\begingroup\$ The architecture may not have a 'U', but it's often useful to simulate as if it did as you can find incorrect initialisations. +1 for "the best thing to do is use the correct type for the job", but we tend to learn as we go along about what's "best" :) \$\endgroup\$ – Martin Thompson Jul 29 '11 at 12:28
8
\$\begingroup\$

My history is this:

I started off (in about 1999 IIRC) using std_ulogic* all the time - as it's the right thing to do, for just the reasons you describe.

Then I had to interface to a bunch of wizard generated vendor IP which all had std_logics all over the interface. Which meant conversions on the port-mappings (for the _vector elements), and I got lazy and moved over to using std_logic*.

However, I seem to make very few "double-driver" mistakes, so I haven't missed std_ulogic as much as I would've thought. And Modelsim's drivers command makes it very easy to find "who is driving what" when I do occasionally need to...

\$\endgroup\$
  • \$\begingroup\$ Yeah, IP cores (and especially stuff that is automatically translated from Verilog) tends to use std_logic. Your answer seems to suggest that the reason is mostly "cultural/historical". \$\endgroup\$ – Philippe Jul 28 '11 at 20:14
  • \$\begingroup\$ You never have to convert between std_logic and std_ulogic on ports. Did you mean you had to convert between std_logic_vector and std_ulogic_vector? \$\endgroup\$ – wjl Jul 29 '11 at 1:55
  • \$\begingroup\$ @wjl: sorry, yes that's what I meant. I'll update the post. \$\endgroup\$ – Martin Thompson Jul 29 '11 at 12:25
  • \$\begingroup\$ AFAIK, the std_logic and std_ulogic are assignment-compatible since they have the same base type. So, there should be no need for manual conversion. \$\endgroup\$ – Val Jun 5 '14 at 14:01
  • \$\begingroup\$ @Val: that's what wjl said (and I agree with) - but the *vector port parts still need conversions \$\endgroup\$ – Martin Thompson Jun 6 '14 at 7:15
4
\$\begingroup\$

IIRC the famed Reuse Methodology Manual recommended std_logic(_vector), so maybe methodology groups in companies etc. spread that further in the form of (mandatory) coding guides. Personally, +1 for using std_ulogic when possible.

\$\endgroup\$
2
\$\begingroup\$

I know its a horribly colored ppt slideshow, but it explains the difference pretty good:

http://web.archive.org/web/20151026150828/http://www.cs.auckland.ac.nz/~jmor159/reconfig/ppt/ResolutionFunctions.ppt

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.