Skip to content

[General]: The language manual does not define Bits–Integer arithmetic or the width of Bits * Bits #108

Open

Description

@shuklaayush

Problem

The arithmetic table in the language manual (ISA_LRM, "Arithmetic operators")
lists x + y, x - y and x * y for "Integer, Bits". It gives no operand signatures or
result types. The specification relies on two cases it does not define.

  1. A Bits operand with an Integer operand. The callee lists name
    Std::Bits::Add_int (about 1,800 times), Std::Bits::Subtract_int and
    Std::Bits::Multiply_int; none has a page. Examples:

    • Mem_Fetch: Create_Logical_Address(code_segment, rip + i, 8) with
      rip : Bits(64) and the integer loop variable i.
    • INCSSPD-INCSSPQ.xml line 139: SSP := SSP + range * size_in_bytes; with
      range : Bits(64) (Zero_Extend(src[7:0], 64)) and the integer
      size_in_bytes := operand_size / 8.
  2. Same-width multiplication. PMULLW.xml lines 198–199:

    let r := op1 * op2;
    result[i *: element_size] := r;
    

    with op1, op2 : Bits(element_size). The slice assignment requires r to have type
    Bits(element_size). PMULLW additionally requires its value to contain the low
    element_size product bits: it
    "stores the low 16 bits of each intermediate 32-bit result in the destination operand"
    (Intel SDM, 325462-093, Vol. 2B, PMULLW, PDF page 1680).
    PMULLD-PMULLQ.xml line 191 is the same.

Proposed fix

Add to the arithmetic operators section:

  • For x : Bits(n) and y : Integer, x + y, x - y and x * y return Bits(n) whose
    unsigned values are Floor_Remainder(Unsigned(x) + y, 2**n),
    Floor_Remainder(Unsigned(x) - y, 2**n) and Floor_Remainder(Unsigned(x) * y, 2**n).
  • For x, y : Bits(n), x * y returns Bits(n) containing the low n bits of the
    product.

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