Skip to content

Add support for SIMD vector comparison intrinsics - #1853

Merged
adpaco merged 28 commits into
model-checking:mainfrom
adpaco:simd-cmp-support
Nov 16, 2022
Merged

adpaco merged 28 commits into
model-checking:mainfrom
adpaco:simd-cmp-support

Conversation

@adpaco

@adpaco adpaco commented Nov 4, 2022 •

Copy link
Copy Markdown
Contributor

Description of changes:

  1. Declares Vector* expressions which generate vector-* ireps, as regular operators (e.g., == or <=) aren't picked up by CBMC. This also makes our own type-checking code cleaner.
  2. Re-enables SIMD intrinsics.
  3. Performs type-checking for cases where the Rust front-end doesn't check.
  4. Adds some utilities functions for vector types.
  5. Moves the SIMD tests folder to Intrinsics.
  6. Splits our test case into unsigned integers, signed integers, and floats.

Resolved issues:

Towards #1148

Call-outs:

Testing:

  • How is this change tested? Existing regression + more cases.

  • Is this a refactor change? No.

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@adpaco
adpaco requested a review from a team as a code owner November 4, 2022 22:35
@adpaco adpaco self-assigned this Nov 8, 2022

@celinval celinval left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you please make sure the fixme tests have an explanation on why they are failing and an issue associated with it?

}

impl PartialEq for VectorData {
/// Rust allows conversions between SIMD vector types with the same size. By

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a bit curious about this one. Do you have any reference? What kind of conversions are we talking about? I can see conversions between signed and unsigned, but does it allow conversions between float and integer types? Does it allow conversions between types with different sizes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry about the confusion, I shouldn't have used "conversions" here nor in the tests. Conversions as such (i.e., with as) don't seem to be allowed for SIMD types.

Unfortunately, there isn't a lot of documentation on this topic. The most complete I've found, at least for this particular SIMD work (the first one, I think) is this RFC, which I've been linking almost everywhere in this PR. But even things like type-checking are loosely defined there, and most of what I've learn has been through trial and error.

@@ -0,0 +1,2 @@
Kani unexpectedly panicked during compilation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this expected? Can we make this a user friendly error?

@adpaco adpaco Nov 10, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The problem here is that we have to do the type-checking... Compiling this with rustc would cause an error, but doing so with Kani didn't. I've added cases for this in vector_cmp and a couple of test cases. But in there I don't have anything to exit gracefully as we do in other cases (e.g., the session object). I agree with you this should just be a compiler error, but in general this is what we do when type-checking (assertions).

@celinval celinval left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for all the explanations. I added a few comments based on my understanding. Please let me know if that makes sense.

@adpaco

adpaco commented Nov 11, 2022

Copy link
Copy Markdown
Contributor Author

Ready for review again!

Typecheck errors are now triggered in codegen_intrinsic_simd_cmp and they are very similar to the ones produced by rustc. I've also included the (redundant) typechecks in a new associated function typecheck_vector_cmp_expr.

I've also undone the VectorData wrapper change. It isn't needed anymore because we're passing down the place type as the return type, which we use to generate the vector comparison expression. Previously, I wasn't doing this so I need to bypass the typecheck for assign statements somehow.

I've also moved/edited/added some comments.

@celinval celinval left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Adrian! I only have one ask, can you please make the errors relative to the Rust types instead of the goto ones?

Everything else is nit, and I'm OK with keeping as they are if you prefer.

/// 2. An integer base type (or just "boolean"-y, as mentioned in
/// <https://github.com/rust-lang/rfcs/blob/master/text/1199-simd-infrastructure.md#comparisons>).
/// The signedness doesn't matter, as the result for each element is
/// either "all ones" (false) or "all zeros" (true).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is that backwards?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, nice catch!

@adpaco

adpaco commented Nov 16, 2022

Copy link
Copy Markdown
Contributor Author

BTW this is ready for review again, all comments above have been addressed.

@adpaco
adpaco merged commit 3c7e3fc into model-checking:main Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants