Skip to content

[General]: The language manual does not define integer slices such as IDIV's quotient[7:0] #105

Open

Description

@shuklaayush

Problem

The language manual (ISA_LRM, "Indexing and bitslice expressions") defines slices
only for bitvector identifiers:

slice-expression = identifier '[' slice ']'

If an identifier B has type Bits(n), then B[…] is used to extract a slice from the
bitvector.

The manual itself slices an integer literal and a hexadecimal literal
(ISA_LRM, "Numeric literals"): "the best option is to use a bitslice as in
42[7:0]", and "the 15-bit constant 0x7fff[0 +: 15]".

The specification slices integer variables, including negative ones, and also expressions
that are not identifiers:

  • IDIV.xml lines 133–136: (AH, AL) := (remainder[7:0], quotient[7:0]); and the wider
    cases. quotient and remainder are Truncated_Divide and Truncated_Remainder of
    signed values, and both can be negative. For example, dividend -7 and divisor 3 give
    quotient -2 and remainder -1; the 8-bit case then slices both negative integers.
  • TZCNT.xml line 136: Count_Trailing_Zero_Bits(src)[0 +: operand_size], a slice of a
    function call.
  • FP87::Convert_From_Integer: let f80_bias := 0x3fff[0 +: 15]; and
    result.Exponent := f80_bias + (size-1)[0 +: 15];.

The manual therefore does not specify:

  • the bits of a negative integer, e.g. quotient[7:0] for quotient = -1;
  • the requirements of an integer slice, since an integer has no length n;
  • which expressions a slice may follow.

Proposed fix

  • Grammar: a slice may follow a postfix expression, including a function call, field
    selection, parenthesized expression, literal, or preceding slice.

  • Bits: for k >= 0, bit k of integer x is
    Std::Integer::Floor_Remainder(Std::Integer::Floor_Divide(x, 2**k), 2), the two's
    complement bit. For example, (-1)[7:0] == 0xFF.

  • Requirements for an integer x:

    x[i]       requires i >= 0
    x[i : j]   requires j >= 0 and i >= j-1
    x[i +: j]  requires i >= 0 and j >= 0
    x[i -: j]  requires i >= 0 and 0 <= j <= i+1
    x[i *: j]  requires i >= 0 and j > 0
    

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