pymtl / pymtl3

Pymtl 3 (Mamba), an open-source Python-based hardware generation, simulation, and verification framework
BSD 3-Clause "New" or "Revised" License
388 stars 46 forks source link

Assuming other is not Bits? #191

Closed JimJJewett closed 4 years ago

JimJJewett commented 4 years ago

https://github.com/pymtl/pymtl3/blob/a97f2a5a7d8d960907c8f7b4a9476632d0fc4707/pymtl3/datatypes/PythonBits.py#L218

Usually, it would use add on the left operand instead, but not always. For example, if self is actually an instance of a subclass of Bits, but other is an instance of regular old Bits. The subclass might have some extra state to take care of, so its radd is called instead of the parent's add. (Recent optimizations may have changed this for cases when the subclass does not actually redefine radd.)

jsn1993 commented 4 years ago

Oh I think recently we already support Bits arithmetics with regular integer, so this TODO item can probably be removed. Are you referring to this?

JimJJewett commented 4 years ago

It sounded like you wanted to micro-optimize it by assuming it was NOT a Bits. (For example, just going straight to the int logic.) Since it still could be bit-like ... I think the right solution is to just remove the TODO line, and maybe add a comment if you think you'll be tempted again later.

jsn1993 commented 4 years ago

It sounded like you wanted to micro-optimize it by assuming it was NOT a Bits

We are trying to enforce a stronger restriction of arithmetics. If an operation is between Bits and non-Bits, we want to infer the non-Bits object as the same Bits type as the Bits object. If an operation is between two Bits objects, we want them to have the same bitwidth. I will remove the TODO.