Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in vector single-width averaging add and subtract instructions: wrong results #228

Open
SoufSilence opened this issue May 16, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@SoufSilence
Copy link

In vector single-width averaging add and subtract instructions, it seems that the code of vaadd, vasubu, and vasub give wrong results.

For vaadd:

VAADD, VAADDU: if (FixPtSupport == FixedPointEnable) unique case (vew_i)
EW8: for (int b = 0; b < 8; b++) begin
automatic logic [ 8:0] sum = opa.w8 [b] + opb.w8 [b];
unique case (vxrm)
2'b00: r = sum[0];
2'b01: r = &sum[1:0];
2'b10: r = 1'b0;
2'b11: r = !sum[1] & (sum[0]!=0);
endcase
res.w8[b] = (op_i == VAADDU) ? sum[8:1] + r : {sum[7], sum[7:1]} + r;
end

I think code {sum[7], sum[7:1]} + r will not give correct results.
For example, if opa.w8 and opb.w8 equals to 0x80, the results is 0. However, I believe the real result should be 0x80.

For vasub and vasubu:

VASUB, VASUBU: if (FixPtSupport == FixedPointEnable) unique case (vew_i)
EW8: for (int b = 0; b < 8; b++) begin
automatic logic [ 8:0] sub = opb.w8 [b] - opa.w8 [b];
unique case (vxrm)
2'b00: r = sub[0];
2'b01: r = &sub[1:0];
2'b10: r = 1'b0;
2'b11: r = !sub[1] & (sub[0]!=0);
endcase
res.w8[b] = (op_i == VSSUBU) ? (sub[7:0] >> 1) + r : $signed(sub[7:0]) >>> 1 + r;
end

I believe that right shift sub[7:0] by 1 bit won't give correct results.

Of course, maybe my understanding is not correct, if so, I hope you can point out my problem, thanks a lot!

@mp-17
Copy link
Collaborator

mp-17 commented Sep 6, 2023

Hello @SoufSilence,

Sorry for the late reply; I was busy with other projects! :-)
I will get back to this asap, thanks for reporting!

Best,
Matteo

@mp-17 mp-17 added the bug Something isn't working label Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants