simuhw.alu package

Module contents

class simuhw.alu.GenericArithmeticLogicUnit(ops: Iterable[Operator])

Bases: Device

A generic arithmetic logic unit.

This device can integrate any operator devices.

__init__(ops: Iterable[Operator]) None

Creates a generic arithmetic logic unit.

Parameters:

ops – The operator devices to be integrated.

find_op_indices(cond: tuple[type[Operator], int, int]) list[int]

Returns the indices of the integrated operator devices that match the specified condition.

Each index can be used to create a word for the operator device selection port (port_op).

Parameters:

cond – The condition to be matched with the integrated operator devices. The first tuple element is the type of the operator device, the second tuple element is the bit width of the input port or ports, and the third tuple element is the bit width of the output port.

Returns:

The indices of the integrated operator devices that match the specified condition.

property ops: tuple[Operator, ...]

The integrated operator devices.

property port_ci: InputPort

The carry input port.

The width is 1 bit.

property port_co: OutputPort

The carry output port.

The width is 1 bit.

property port_e: OutputPort

The output port to emit overflow exception of integer multiplication and division.

The width is 1 bit.

property port_fe_i: InputPort

The input port to set the floating-point exception flags.

property port_fe_o: OutputPort

The output port to get the floating-point exception flags.

property port_fr: InputPort

The input port to set the rounding mode.

property port_ft: InputPort

The input port to set the tininess detection mode.

property port_o: OutputPort

The output port.

property port_op: InputPort

The operator device selection port.

property port_s: InputPort

The SIMD word width selection port.

property ports_i: tuple[InputPort, ...]

The input ports.

reset() None

Resets the states.

property width_fe: int

The bit width of the input and output ports to set and get floating-point exception flags.

The value is 0 unless simuhw.fp submodule is available.

property width_fr: int

The bit width of the input port to set rounding mode.

The value is 0 unless simuhw.fp submodule is available.

property width_ft: int

The bit width of the input port to set tininess detection mode.

The value is 0 unless simuhw.fp submodule is available.

property width_i: int

The bit width of the input ports.

property width_o: int

The bit width of the output port.

property width_op: int

The bit width of the operator device selection port.

property width_s: int

The bit width of the SIMD word width selection port.

work(time: float | None) tuple[list[InputPort], float | None]

Makes the device work.

Parameters:

time – The current time in seconds. None when starting to make the device work.

Returns:

A tuple of the list of the input ports that are to be watched receive a signal, and the next resuming time in seconds. The next resuming time can be None if resumable anytime.

class simuhw.alu.FullArithmeticLogicUnit(dsize: int | Iterable[int], *, use_int: bool = True, use_fp: bool = False, use_fp_riscv: bool = False, add_ops: Iterable[Operator] = [])

Bases: GenericArithmeticLogicUnit

A full arithmetic logic unit.

This device integrates all operator devices supported by SimuHW.

__init__(dsize: int | Iterable[int], *, use_int: bool = True, use_fp: bool = False, use_fp_riscv: bool = False, add_ops: Iterable[Operator] = []) None

Creates a full arithmetic logic unit.

Parameters:
  • dsize – The word width or widths in bits.

  • use_int – If it is True, all integer operator devices other than architecture-specific ones are integrated. Every multiple-input bitwise logic gate such as ANDGate has two inputs. The LookupTable device is not integrated unless specifying it in add_ops argument.

  • use_fp – If it is True, all floating-point operator devices other than architecture-specific ones are integrated. The integration can be done only if an appropriate version of softfloatpy module is found.

  • use_fp_riscv

    If it is True, all floating-point operator devices specific to RISC-V are integrated. The integration can be done only if an appropriate version of softfloatpy module is found.

  • add_ops – The additional operator devices.

Raises:

RuntimeError

If no appropriate version of softfloatpy module is found.

property dsize: tuple[int, ...]

The word widths in bits.

class simuhw.alu.SIMD_FullArithmeticLogicUnit(width: int, dsize: int | Iterable[int], *, with_non_simd: bool = True, use_int: bool = True, use_fp: bool = False, use_fp_riscv: bool = False, add_ops: Iterable[Operator] = [])

Bases: GenericArithmeticLogicUnit

A SIMD full arithmetic logic unit.

This device integrates all non-SIMD and SIMD operator devices supported by SimuHW.

__init__(width: int, dsize: int | Iterable[int], *, with_non_simd: bool = True, use_int: bool = True, use_fp: bool = False, use_fp_riscv: bool = False, add_ops: Iterable[Operator] = []) None

Creates a SIMD full arithmetic logic unit.

Parameters:
  • width – The total width of words in bits.

  • dsize – The selectable word width or widths in bits.

  • with_non_simd – If it is True, non-SIMD operator devices are also integrated.

  • use_int – If it is True, all integer operator devices other than architecture-specific ones are integrated. Every multiple-input bitwise logic gate such as ANDGate has two inputs. The LookupTable device is not integrated unless specifying it in add_ops argument.

  • use_fp

    If it is True, all floating-point operator devices other than architecture-specific ones are integrated. The integration can be done only if an appropriate version of softfloatpy module is found.

  • use_fp_riscv

    If it is True, all floating-point operator devices specific to RISC-V are integrated. The integration can be done only if an appropriate version of softfloatpy module is found.

  • add_ops – The additional operator devices.

Raises:
  • ValueError – If width is not divisible by any of dsize.

  • RuntimeError

    If no appropriate version of softfloatpy module is found.

property dsize: tuple[int, ...]

The word widths in bits.

property width: int

The total width of words in bits.