| Summary: | [Patch] SSE2-based converter makes junk result of S32 -> Float | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Vitaly Novichkov <admin> |
| Component: | audio | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | major | ||
| Priority: | P2 | CC: | sezeroz |
| Version: | HG 2.1 | ||
| Hardware: | x86_64 | ||
| OS: | All | ||
| Attachments: | Patch which fixes correctess of SSE2 S32 to F32 sound conversion | ||
|
Description
Vitaly Novichkov
2018-07-01 16:17:18 UTC
Okay, I did the analysis of input data and I began to log source and final results of SDL_Convert_S32_to_F32_SSE2's function, and what I have next: SRC: 1053578242 RES: 1.970398 Then, I did a manual calculation of the value: (1053578242>>8) * 0.00000011920930376163766 and I got next result: 0.490610658 So, it's a pobably was used some incorrect SSE2 call which was produced the incorrect result in final. Okay, as I never expired in SSEx, I looked for the documentation that describes SSE2 calls. I have found next: "Intrinsic", | "Operation" | "Shift Type" | "Corresponding Instruction" _mm_srli_epi32 | "Shift right"| "Logical" | "PSRLD" <-- Was used in a code _mm_srai_epi32 | "Shift right"| "Arithmetic" | "PSRAD" I did replaced `_mm_srli_epi32` with `_mm_srai_epi32` in the 536'th line of SDL_audiotypecvt.c and everything became fine! Gotta go make the patch for this... Created attachment 3267 [details]
Patch which fixes correctess of SSE2 S32 to F32 sound conversion
P.S. For a future, make the unit test that generates random data for each test. Copy generated buffer into second copy. Convert the first copy with the scalar converter which gives 100% correct result. Then, convert the second copy of original with SSE2 (or also with ARM NEON on a different unit test). After this run, compare both results, and if it's a difference between of them, fail the test. This patch is now https://hg.libsdl.org/SDL/rev/523e803a0192, thanks! --ryan. Thanks! :3 Anyway, please take my tip to make the unit test to verify the correctness of optimized resamplers to avoid bugs like this in future. Otherwise, I'll create it by myself, maybe I'll catch some another bug in a place I wasn't touched yet... |