Search code examples
pythonyieldmyhdl

Difference between yield statement in python and MyHDL


I am currently learning MyHDL for my summer project. I have a problem grasping the functioning of yield statement in it. Though its true that the MyHDL is based upon python, it uses its yield statement in a specialized way. the link for the same is : http://www.myhdl.org/doc/current/manual/reference.html#myhdl.always

it states: MyHDL generators are standard Python generators with specialized yield statements. In hardware description languages, the equivalent statements are called sensitivity lists. The general format of yield statements in in MyHDL generators is: yield clause [, clause ...] When a generator executes a yield statement, its execution is suspended at that point. At the same time, each clause is a trigger object which defines the condition upon which the generator should be resumed. However, per invocation of a yield statement, the generator resumes exactly once, regardless of the number of clauses. This happens on the first trigger that occurs.

I am not able to comprehend it. Could someone please explain it in simple words? or perhaps redirect me to another source?

I'll be grateful if you could help. Thanks!

Regards


Solution

  • First and foremost: remember that the MyHDL implementation is strictly pure Python. In that sense there is no "difference" between a yield statement in MyHDL and in Python.

    MyHDL really is a way to use Python as a HDL. Partially, this is done by implementing some hardware design specific objects in a pure Python package called myhdl. For example, there is a myhdl.Simulation object that runs generators in a way suited for hardware simulation.

    The other part is simply interpreting certain Python features in a hardware specific way. For example, a hardware module is modeled as a Python function that returns generators. Another example is that the "yield" statement is interpreted as a "wait" functionality.