Skip to content

[General]: Count_Set_Bits and Extend read an undeclared variable x #98

Open

Description

@shuklaayush

Problem

Two standard-library definitions name their bitvector argument a but read an
undeclared variable x.

Std::Bits::Count_Set_Bits:

function Std::Bits::Count_Set_Bits(implicit size : {0..}, a : Bits(size)) -> {0..size}
begin
    var result : {0..size} := 0;
    for i := 0 to size-1 do
        if x[i] == 0b1 then
            result := result + 1;
        end
    end
    return result;
end

Std::Bits::Extend:

function Std::Bits::Extend(implicit source_size : {0..}, a : Bits(source_size), target_size : {..}, is_unsigned : Boolean) -> Bits(target_size)
begin
    return if is_unsigned then Zero_Extend(x, target_size) else Sign_Extend(x, target_size);
end

Neither body type-checks as published. Both functions are used: POPCNT calls
Count_Set_Bits (POPCNT.xml line 138), and Dot_Product calls Extend.

Proposed fix

-        if x[i] == 0b1 then
+        if a[i] == 0b1 then
-    return if is_unsigned then Zero_Extend(x, target_size) else Sign_Extend(x, target_size);
+    return if is_unsigned then Zero_Extend(a, target_size) else Sign_Extend(a, target_size);

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