Skip to content

Fix operand order in v128_select_ssss#1834

Open
shumbo wants to merge 1 commit intowasmi-labs:mainfrom
shumbo:fix/v128-select-operand-swap
Open

Fix operand order in v128_select_ssss#1834
shumbo wants to merge 1 commit intowasmi-labs:mainfrom
shumbo:fix/v128-select-operand-swap

Conversation

@shumbo
Copy link
Copy Markdown

@shumbo shumbo commented Apr 2, 2026

This PR fixes a miscompilation in SIMD v128.select.

v128_select_ssss is executed with operands in the order (result, condition, true_val, false_val), but the translator currently emits (result, condition, false_val, true_val) when lowering v128.select. This causes the instruction to select the opposite branch.

Other select variants, including u32_select_* and u64_select_*, already use the correct operand order, so the issue is specific to the v128 lowering path.

Regression test:

(module
  (func (export "v128_select") (param i32) (result v128)
    (select (result v128)
      (v128.const i64x2 0x1111111111111111 0x2222222222222222)
      (v128.const i64x2 0x3333333333333333 0x4444444444444444)
      (local.get 0)
    )
  )
)
(assert_return (invoke "v128_select" (i32.const 1)) (v128.const i64x2 0x1111111111111111 0x2222222222222222))
(assert_return (invoke "v128_select" (i32.const 0)) (v128.const i64x2 0x3333333333333333 0x4444444444444444))
$ git rev-parse HEAD
9f6ff82fc11baea9a3c1232e13f2304fdc49d432
$ cargo run --bin wasmi --features simd -- wast test.wast
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/wasmi wast test.wast`
Error: failed directive on test.wast:10:1

Caused by:
    0: evaluation mismatch of `v128` values
    1: expected = [1229782938247303441, 2459565876494606882], actual = [3689348814741910323, 4919131752989213764]

The test passes with this patch.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 11, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.37%. Comparing base (9f6ff82) to head (00f8dc9).

Files with missing lines Patch % Lines
crates/wasmi/src/engine/translator/func/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1834   +/-   ##
=======================================
  Coverage   73.37%   73.37%           
=======================================
  Files         175      175           
  Lines       14274    14274           
=======================================
  Hits        10473    10473           
  Misses       3801     3801           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Robbepop
Copy link
Copy Markdown
Member

@shumbo thank you a lot for the bug fix and especially for the additional regression test!

@Robbepop
Copy link
Copy Markdown
Member

The audit CI job is failing for reasons not associated to this PR's changes.

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.

2 participants