Skip to content

Conversation

@tedinski
Copy link
Contributor

Description of changes:

  1. Add CBMC's vector_exprt to our gotoc representation.
  2. Add support for the simd_shuffle instrinsics.
  3. Add a test of the above.

Resolved issues:

Resolves #309

Call-outs:

  1. TODO: I need to create some new issues about future follow-ups (e.g. getting CBMC to expose shuffle_vector_exprt for us?) and possibly link to them from the code.
  2. I still have a TODO in the code about the type of the array index expressions we generate. Currently, I use a signed index. Unsigned causes CBMC to object:
--- begin invariant violation report ---
Invariant check failed
File: ../src/solvers/flattening/boolbv_mult.cpp:73 function: convert_mult
Condition: it->type() == expr.type()
Reason: multiplication operands should have same type as expression

I'm going to investigate this before merging. It's possible I should be picking the type in some other way, but this is difficult to diagnose because it seems to be internal to CBMC's transformations (e.g. I think we put "array index" in the symbol table, but them CBMC is transforming that into "pointer + index*size" internally, and that's where the "mult" is coming from. A guess, for now. Perplexing because it would seem to imply that the "sizeof" a type has signed type internally?)

Testing:

  • How is this change tested? Added tests.

  • 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.

Copy link
Contributor

@avanhatt avanhatt Aug 13, 2021

Choose a reason for hiding this comment

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

Could this be integrated into the match below instead of its own code block?

i if i.strip_prefix("simd_shuffle") => ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently this is an "if let guard" and is marked as experimental currently: https://github.com/rust-lang/rfcs/blob/master/text/2294-if-let-guard.md

I'm going to leave it as-is for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not have it at the end of the match with an starts_with guard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to extract the suffix still. This is what's done in the LLVM code as well.

I don't think including it in the match would be any better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still, you can match the prefix, then extract the suffix before calling the codegen function.

@tedinski tedinski marked this pull request as ready for review August 13, 2021 22:55
Copy link
Contributor

@avanhatt avanhatt left a comment

Choose a reason for hiding this comment

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

LGTM, with one testing suggestion

Comment on lines 10 to 13
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move simd_shuffle testing into its own file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I don't anymore, will fix...

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not have it at the end of the match with an starts_with guard?

@tedinski
Copy link
Contributor Author

I think this has addressed everything except the nits about the match vs preceding if. I think there isn't any obviously better choice (except "if let guards", which isn't stable yet), and this style is what appears in some of the llvm codegen crate. IMO, let's just go with it.

}

pub fn vector_expr(typ: Type, elems: Vec<Expr>) -> Self {
if let Type::Vector { size, typ: value_typ } = typ.clone() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the clone needed here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The use of value_typ later is a partial move out of the value.


// An unsigned type here causes an invariant violation in CBMC.
// Issue: https://github.com/diffblue/cbmc/issues/6298
let st_rep = Type::ssize_t();
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be clearer to just use Type::ssize_t() wherever this is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had that thought too, but I felt like keeping it since it created a place for the comment about the CBMC issue.

@adpaco-aws adpaco-aws merged commit 122281b into model-checking:main-154-2021-08-06 Aug 17, 2021
adpaco-aws added a commit that referenced this pull request Aug 17, 2021
* introduce simd_shuffle intrinsic

* add links to cbmc issues in simd_shuffle comments

* add assert for arguments length to simd instrinsic functions

* typo fix

Co-authored-by: Adrian Palacios <[email protected]>

* separate simd_shuffle test from other tests

Co-authored-by: Adrian Palacios <[email protected]>
Co-authored-by: Daniel Schwartz-Narbonne <[email protected]>
adpaco-aws added a commit that referenced this pull request Aug 24, 2021
* introduce simd_shuffle intrinsic

* add links to cbmc issues in simd_shuffle comments

* add assert for arguments length to simd instrinsic functions

* typo fix

Co-authored-by: Adrian Palacios <[email protected]>

* separate simd_shuffle test from other tests

Co-authored-by: Adrian Palacios <[email protected]>
Co-authored-by: Daniel Schwartz-Narbonne <[email protected]>
tedinski added a commit to tedinski/rmc that referenced this pull request Apr 26, 2022
* introduce simd_shuffle intrinsic

* add links to cbmc issues in simd_shuffle comments

* add assert for arguments length to simd instrinsic functions

* typo fix

Co-authored-by: Adrian Palacios <[email protected]>

* separate simd_shuffle test from other tests

Co-authored-by: Adrian Palacios <[email protected]>
Co-authored-by: Daniel Schwartz-Narbonne <[email protected]>
tedinski added a commit that referenced this pull request Apr 27, 2022
* introduce simd_shuffle intrinsic

* add links to cbmc issues in simd_shuffle comments

* add assert for arguments length to simd instrinsic functions

* typo fix

Co-authored-by: Adrian Palacios <[email protected]>

* separate simd_shuffle test from other tests

Co-authored-by: Adrian Palacios <[email protected]>
Co-authored-by: Daniel Schwartz-Narbonne <[email protected]>
@tedinski tedinski deleted the simd-shuffle branch July 8, 2022 22:32
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.

Codegen failure: Unsupported intrinisic simd_shuffle8

4 participants