Skip to content

[General]: The manual forbids slice-by-slice initialization that the style guide recommends #103

Open

Description

@shuklaayush

Problem

The language manual requires every variable to be initialized before it is read
(ISA_LRM, "All variables must be initialized before use"), and it describes a
slice assignment as a read of the whole variable (ISA_LRM, "Assignments"):

RIP[0] := 0b0;   Set the bottom bit of a variable RIP to zero. Note that this reads
                 the current value of RIP, clears the bottom bit, and writes the value
                 back to RIP.

Under these two rules, assigning a slice of a variable that has not been initialized is
an error.

The published style guide says the opposite. It defines the error per bit
("It is an .isa language error to read a variable (or field or array element or
bitslice) if it has not been initialized"), recommends against "a spurious
initializer", and gives this as the preferred style:

var x : Bits(32);
if ... then
    x := Foo32(32);
else
    x[31:16] := Bar16();
    x[15:0] := Zeros();
end

The sources follow the style guide:

  • AESDEC.xml lines 193–195: var result : Bits(register_size); then
    result[i *: 128] := AESDEC_128(…) in a loop.
  • ENQCMD.xml lines 94–95: var src : Bits(512); then
    src[0 *: 128] := Logical_Mem_Read?(…).
  • Mem_Fetch: var value : Bits(size); then value[i *: 8] := Physical_Mem_Fetch(physical);
    in a loop.

Proposed fix

In the manual, define initialization per bit, as the style guide does. For example, add
to "All variables must be initialized before use":

Assigning a slice of a local bitvector variable writes and initializes the selected bits
without reading the remaining bits. The remaining bits retain their values and
initialization state. Reading a bit requires that bit to have been initialized.

and qualify the RIP[0] description to apply to an initialized variable.

AI disclosure

Assisted-by: Claude

Claude assisted with source analysis, the proposed correction and drafting this report.
Reviewed with assistance from Codex.

Pinned source: definitions.xml.gz at revision 35eface1b7ee003a1cda95005ec5fd83de658a64.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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