Repository navigation
MMI: use sa[3:0] for PSLLH/PSRLH/PSRAH shift amounts - #443
Open
dean-k-pearce wants to merge 1 commit into
Open
dean-k-pearce wants to merge 1 commit into
dean-k-pearce wants to merge 1 commit into
Conversation
The halfword shift-immediate ops passed the full 5-bit sa to _mm_slli/srli/srai_epi16. The EE only uses the low 4 bits for halfwords, while SSE zeroes the lanes (or sign fills for srai) for any count above 15, so sa 16-31 gave wrong results. Mask the count with 0xF for the three halfword forms; the word forms keep all five bits. Tests: run the emitted shift on the host for sa 0, 1, 15, 16, 17 and 31 on all three ops and compare with real PS2 results from ps2autotests tests/cpu/ee_simd/logic.expected (rows not in that file follow the same sa[3:0] rule, as in PCSX2 and DobieStation), and check that the word forms still emit sa 31 unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #434.
The halfword shift-immediate ops passed the full 5-bit
sato_mm_slli_epi16/_mm_srli_epi16/_mm_srai_epi16. The EE only uses the low 4 bits for halfwords. SSE zeroes the lanes (or sign fills forsrai) for any count above 15, so sa 16-31 gave wrong results.Change (
mmi_translator.cpp): the three halfword cases now emitsa & 0xF. PSLLW/PSRLW/PSRAW are unchanged because all 5 bits count there.Tests (
code_generator_tests.cpp, two new cases):MMI halfword shift immediates use sa[3:0]: translates PSLLH/PSRLH/PSRAH at sa 0, 1, 15, 16, 17 and 31 (plus 3 and 30 where the reference has them), runs the emitted SSE shift on the host and compares every word with the real PS2 result. 17 rows are taken as-is from ps2autoteststests/cpu/ee_simd/logic.expected, for examplepsllh -1, 16unchanged andpsllh -1, 31giving8000per halfword. The 7 rows markedderivedaren't in that file and follow the same sa[3:0] rule (PCSX2_PSLLHuses_Sa_ & 0xf, DobieStation uses(instruction >> 6) & 0xF).MMI word shift immediates keep all five sa bits: the word forms still emit sa 31 as is.One honest gap: none of the
psrahvectors inlogic.expectedcan tell the two rules apart (-1 and C_ONE give the same result masked or not), so the PSRAH rows that fail without the fix (kS16Minat sa 16 and 17) are derived from the PCSX2/DobieStation rule rather than taken from real-PS2 output. The PSRAH -1 rows at sa 16 and 31 are kept as controls.Without the fix the new halfword test fails at PSLLH sa 16/17/30/31, PSRLH sa 16/17/31 and PSRAH sa 16/17. PSRAH sa 31 passes either way, because a sign fill happens to equal a shift by 15.
Checked: Linux, GCC, Release. The full build passes, and
ps2x_testspasses all 448 (446 before, plus the 2 new). The gs_cache ctest suite passes all 45. I haven't built with Clang, MSVC or on ARM. The test picks its intrinsics header the same wayps2_runtime_macros.hdoes (intrin.h/sse2neon.h/immintrin.h).AI tools helped write this patch and its tests. I've reviewed the change and the test values myself.