PSLLH/PSRLH/PSRAH: shift amounts 16-31 should use sa[3:0] (SSE gives 0 / sign fill)

オープン 初心者向け
#434 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp
領域
backend

調査の方向性

mmi_translator.cpp の110~115行目では、3つのhalfwordシフトケースが生の sa をSSEに渡しています。それらのケースを読み、issueで引用されているEEの根拠と動作を比較してください。まず ps2autotests/tests/cpu/ee_simd/logic.expected を確認します。それらのケースではシフト量を下位4ビットにマスクし、次に sa 16 と31の再現カーネルがEEの動作と一致することを確認してください。

索引モデルが issue の本文から書いたものです。

説明

Hi! The halfword shift-immediate MMI ops pass the full 5-bit sa field to SSE. On the EE only the low 4 bits count for halfwords, so with sa 16-31 the results differ.

Where: mmi_translator.cpp lines 110-115 (at e5636981) emit _mm_slli_epi16 / _mm_srli_epi16 / _mm_srai_epi16 with the raw sa. SSE returns 0 (or a sign fill for srai) for any count above 15.

What the EE does:

op sa EE PS2Recomp
psllh / psrlh 16 value unchanged (shift by 0) 0 in every lane
psrah 16 value unchanged sign fill
psllh / psrlh 31 shift by 15 0 in every lane
psrah 31 shift by 15 sign fill (same result, by coincidence)

Evidence for the EE rule:

  1. Real PS2 output in ps2autotests tests/cpu/ee_simd/logic.expected: psllh -1, 16 comes back unchanged and psllh -1, 31 gives 8000 in every halfword. All 144 shift-immediate lines there fit sa[3:0] for the halfword forms.
  2. PCSX2 MMI.cpp _PSLLH: << (_Sa_ & 0xf).
  3. DobieStation emotion_mmi.cpp: shift = (instruction >> 6) & 0xF.

Repro: a one-instruction kernel (lq, psllh t0, a3, 16, sq) built with ps2dev EE gcc, run through PS2Recomp e5636981: every lane comes back 0, where the EE leaves the value unchanged. With sa 15 everything matches. Masking the count to sa & 15 in the three halfword cases fixes all of our sa 16/31 kernels (the word forms PSLLW/PSRLW/PSRAW are fine as they are; there all 5 bits count).

To be fair about impact: a C compiler shouldn't emit a halfword shift of 16 or more, so this most likely only matters for hand-written asm with an unusual count. Happy to open a small PR with the & 15 if that's useful.

AI tools helped with the testing and this write-up. I've reviewed it.

主要言語
C++
スター
3.3k
フォーク
149
平均マージ
8時間 46分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ran-j/PS2Recomp のほかの issue

ran-j/PS2Recomp の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。