******************************** ``b_asic.comparison_operations`` ******************************** Comparisons and logical types ============================= Signals have one of three logical types: ``SignalType.ALGORITHM``, ``SignalType.BOOLEAN``, or ``SignalType.INTEGER``. These identify independent data paths; the algorithm's numeric representation is still selected separately using ``DataType``. Untyped graphs continue to default to algorithm data. ``LessThan``, ``LessThanOrEqual``, ``GreaterThan``, ``GreaterThanOrEqual``, ``Equal``, and ``NotEqual`` return boolean values. Their signals use boolean storage by default, or integer storage when required by a connected operation; false is zero and true is one. ``Comparison`` accepts the predicate as its first argument, either a ``ComparisonType`` enum member or one of ``"<"``, ``"<="``, ``">"``, ``">="``, ``"=="``, and ``"!="``. Equality supports complex values; ordered comparisons require real values. These operations do not overload Python object equality or ordering. ``Select(condition, in0, in1)`` accepts boolean or integer conditions and returns ``in0`` when its condition is nonzero, otherwise ``in1``. Both data branches execute under the static schedule. The data inputs must have the same logical type, which is also the output type. For example, this graph selects positive input samples and counts them:: from b_asic import ( Addition, Constant, Delay, GreaterThan, Input, Output, Select, SFG, SignalType, ) source = Input(signal_type=SignalType.ALGORITHM) positive = GreaterThan(source, Constant(0)) state = Delay(initial_value=0) count = Addition(state, positive) state <<= count selected = Select(positive, source, Constant(0)) graph = SFG([source], [Output(selected), Output(count)]) assert graph.output(0).signal_type is SignalType.ALGORITHM assert graph.output(1).signal_type is SignalType.INTEGER graph.validate_signal_types() For a complete example with a schedule, shared processing elements, separate typed memories, and interconnect multiplexers, see :doc:`../examples/architecture/comparison_select_architecture`. Interfaces, constants, delays, and selectors propagate constraints in both directions, including through feedback and nested graphs. Addition, subtraction, negation, and constant multiplication accept algorithm or integer data. Comparison results can feed integer arithmetic directly, including when the same result also controls a selector. A boolean source may feed an integer input without changing its stored type; the interconnect zero-extends it. Python integer constants remain algorithm data unless constrained by their connections or an explicit ``signal_type`` argument. Boolean constants and reset values must be zero or one; integer constants and reset values must be integral. Read ``port.signal_type`` or ``signal.signal_type`` for the resolved type, and ``operation.port_types`` for the input/output signatures. On homogeneous operations, ``operation.signal_type`` is an optional explicit constraint; it is ``None`` when inferred. SFG construction and ``validate_signal_types()`` reject incompatible connections. Type queries recompute constraints after graph edits. Resource assignment separates memories and processing elements by logical type/signature, even for nonoverlapping accesses. Consequently, architecture interconnect multiplexers connect compatible data paths. Integer width in the VHDL implementation is independent of the logical signal type. Native simulation retains its existing complex-double storage; counts should remain below ``2**52``. Simulation with a global quantizing ``DataType`` has not been extended to mixed types. VHDL generation supports integer ``Addition``, ``Subtraction``, and ``AddSub`` using ``VhdlPrinter(data_type, integer_bits=32, integer_signed=True)``. The integer width includes the sign bit when signed and is shared by every integer PE, memory, and interface, independently of the algorithm representation. Boolean ports, pipeline registers, and storage use ``std_logic`` and are zero-extended at integer input multiplexers. Integer arithmetic uses modulo ``2**integer_bits`` arithmetic independently of the algorithm's overflow and quantization policies. Set ``integer_signed=False`` for unsigned integers. Register splits and control pipelines follow the existing arithmetic structure. Comparisons select their VHDL printer by input format and always return ``std_logic``. The generic ``Comparison`` and all six named comparisons support real fixed-point and integer operands. A shared PE generates only its scheduled predicates. Ordered predicates share one widened subtraction and, when needed, a zero check; equality-only PEs share one equality check and optional inversion. Fixed-point and integer comparisons can share that PE by sign/zero-extending their raw operands at its multiplexers. Both operands of each comparison retain the same binary point. ``Select`` selects its printer by the data inputs and handles its boolean condition separately. .. automodule:: b_asic.comparison_operations :members: :undoc-members: :show-inheritance: