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

x86: fix semantics of VPERMD, VPMADDWD, & VPMADDUBSW #442

Merged
merged 3 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@
([PR #422](https://github.com/jasmin-lang/jasmin/pull/422);
fixes [#421](https://github.com/jasmin-lang/jasmin/issues/421)).

- Fix semantics of the `VPERMD`, `VPMADDWD`, and `VPMADDUBSW` instructions
([PR #442](https://github.com/jasmin-lang/jasmin/pull/442)).

## Other changes

- Explicit if-then-else in flag combinations is no longer supported
Expand Down
16 changes: 8 additions & 8 deletions proofs/lang/word.v
Original file line number Diff line number Diff line change
Expand Up @@ -1499,8 +1499,8 @@ Definition wpermd1 (v: seq u32) (idx: u32) :=
let off := wunsigned idx mod 8 in
(v`_(Z.to_nat off))%R.

Definition wpermd sz (w1 idx: word sz) : word sz :=
let v := split_vec U32 w1 in
Definition wpermd sz (idx w: word sz) : word sz :=
let v := split_vec U32 w in
let i := split_vec U32 idx in
make_vec sz (map (wpermd1 v) i).

Expand Down Expand Up @@ -1551,15 +1551,15 @@ Fixpoint add_pairs (m: seq Z) : seq Z :=
else [::].

Definition wpmaddubsw sz (v1 v2: word sz) : word sz :=
let w1 := map wunsigned (split_vec VE8 v1) in
let w2 := map wsigned (split_vec VE8 v2) in
let result := [seq wrepr_saturated_signed sz z | z <- add_pairs (map2 *%R w1 w2) ] in
let w1 := map wunsigned (split_vec U8 v1) in
let w2 := map wsigned (split_vec U8 v2) in
let result := [seq wrepr_saturated_signed U16 z | z <- add_pairs (map2 *%R w1 w2) ] in
make_vec sz result.

Definition wpmaddwd sz (v1 v2: word sz) : word sz :=
let w1 := map wsigned (split_vec VE16 v1) in
let w2 := map wsigned (split_vec VE16 v2) in
let result := [seq wrepr sz z | z <- add_pairs (map2 *%R w1 w2) ] in
let w1 := map wsigned (split_vec U16 v1) in
let w2 := map wsigned (split_vec U16 v2) in
let result := [seq wrepr U32 z | z <- add_pairs (map2 *%R w1 w2) ] in
make_vec sz result.

(* Test case from the documentation: VPMADDWD wraps when all inputs are min-signed *)
Expand Down