Skip to content

Undefined order of always block execution #110

@PhilippvK

Description

@PhilippvK

According to the spec, always blocks run in parallel to the behavior of the instruction. This leads to undefined behavior when modifying the same variables in the architectural state, as also pointed out in #103 (Which was related to dependencies between an always block and instruction behavior). This issue, on the other hand, is regarding the handling of multiple always blocks which depend on each other.

A real-world example is the following:

  1. Always Block 1: implicit_pc_increment implemented in RISCVBase (i.e. PC = PC + 4;)
  2. Always Block 2: hwlp_0 implemented inXHwlp extends RISCVBase (i.e. if (PC == hwlp_end) { PC = hwlp_start; })
  3. Optional: Some Jump/Branch instruction (i.e. PC = target_addr;)

Let's assume that previous changes to the PC are not visible to the following behavior blocks (see #103). Otherwise, we do not have a way to dismiss the implicit_pc_increment before/after a jump/branch instruction.

There are 3!=3*2*1=6 possible execution orders for the situation above and only one of them yields the correct behavior:

  • 1. -> 2. -> 3.

How we deal with this is currently tool-specific. M2-ISA-R would currently generate 2. -> 1. -> 3. due to the traversal order of the hierarchy. Reversing the order of always block would be required for the specific example above but might not be a generic solution. Should the spec define a defined order of execution or should we offer a way to customize the order (if required) by the user?

@eyck @AtomCrafty @wysiwyng

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions