You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[General]: The manual's for-loop rules give downto loops an empty variable type and zero iterations #102
The language manual (ISA_LRM, "For statements") says the loop variable "is
incremented each time round the loop if the to form is used or decremented each time
round the loop if the downto form is used". Two later paragraphs then state, for both
forms:
The variable can be thought of as if it was declared let i : {e1..e2} := … at the start
of the statement list.
If e1 > e2, the loop executes 0 times. If e1 == e2, the loop executes 1 time. The loop
executes Max(1 + e2 - e1, 0) times.
For for i := 31 downto 0, these give i : {31..0}, an empty set, and Max(1 + 0 - 31, 0) = 0 iterations. CRC32_Mod_2 (for i := 31 downto 0) and GF2_P8_Multiply (for i := 14 downto 8) need e1 - e2 + 1 iterations.
Proposed fix
Preserve the sentences about evaluating the bounds once and the loop variable's
immutability and scope (ISA_LRM). Let e1 and e2 denote the evaluated start
and end bounds. Replace only the explanation of the variable's type and the iteration
count with:
For `for i := e1 to e2`, the loop variable has type {e1..e2}
and the body executes Max(1 + e2 - e1, 0) times.
For `for i := e1 downto e2`, the loop variable has type {e2..e1}
and the body executes Max(1 + e1 - e2, 0) times.
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