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

Added tests for signed comparisons, mod, div and sign extension #1768

Open
wants to merge 4 commits into
base: arith-dev
Choose a base branch
from

Conversation

lorenzogentile404
Copy link
Collaborator

No description provided.

@lorenzogentile404 lorenzogentile404 linked an issue Feb 3, 2025 that may be closed by this pull request
8 tasks
Copy link

sonarqubecloud bot commented Feb 3, 2025

for (OpCode opCode : List.of(OpCode.SLT, OpCode.SGT, OpCode.SMOD, OpCode.SDIV)) {
for (String a : VALUES) {
for (String b : VALUES) {
arguments.add(Arguments.of(opCode, a, b));
Copy link
Collaborator

@OlivierBBB OlivierBBB Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the signed case we should test more signed cases, we should explore more large or negative integers, e.g. by having as a set from which to choose

MIN_NEG = 0x80 00 .. 00
NEG_ONE = 0xff ff .. ff
ZERO    = 0x00 00 .. 00
ONE     = 0x00 00 .. 01
MAX_POS = 0x7f ff .. ff
RAN_POS_k // k = 1..10, ten or so BigIntegers, all positive, constructed from as many random 32 byte strings, by AND'ing with MAX_POS
RAN_NEG_k // k = 1..10, ten or so BigIntegers, all negative, constructed from as many random 32 byte strings, by OR'ing with MIN_NEG

And test all combinations of these.

arguments.add(Arguments.of(b, b.length() / 2 - 1));
// In this other case we assume there is always 00 as a prefix
if (nTrailingBytes != 31) {
arguments.add(Arguments.of(b, b.length() / 2));
Copy link
Collaborator

@OlivierBBB OlivierBBB Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good source of inputs would be e.g.

pos = 0, 1, 2, ..., 31, 32, 0xff,
      256^16 - 1, 256^16, 256^16 + 1,
      256^32 - 1

And

value = 0x 11 11 .. 11 [B] ff ff .. ff

Where [B] is a byte from among e.g. { 0x00, 0x56, 0x7f, 0x80, 0xc2, 0xff } and occupies the position i-th byte, i = 0, 1, 2, ..., 31.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which would amount to 38 * 6 * 32 = 7 296 test cases, which is ok and which we will run on a weekly basis.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lorenzogentile404 SIGNEXTEND takes two arguments, one being the integer you want to sign extend, one being the position of the byte containing the sign bit.

Copy link
Collaborator

@OlivierBBB OlivierBBB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More test vectors would make sense. We want to be exhaustive as much as possible like in the EXP case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extensive testing for signed operations
2 participants