Fix invalid shift warning in vsli_n implementation. #1253
Merged
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: #1231
Per the ARMv8 manual, the valid range of shifts for the vector SLI operations is "0 to the element width in bits minus 1." The existing SIMDe implementation creates an invalid shift in the case of 0, as the shifts are (element width - n) - so, for a 0-bit shift on a 64-bit value, the shift is 64. This is undefined per the C spec, and leads to compiler warnings on build. Examples of the error:
This fix changes the sli_n shift operations to work properly for the valid range of values, shifting ((element width - 1) - n), with a modified constant value to generate the same results (7f... instead of ff...).
For all valid n values of (0 to width - 1), this now generates a valid, C-spec-compliant shift value, and eliminates the warning about undefined behavior.
While the existing tests all pass with the change, a number of the tests have been modified (and have new constant values generated) to properly exercise and demonstrate the "n == 0" shift case correctness. These test vectors were generated on an ARMv9 system (Google Compute Engine C4A system), and pass on x86 hardware as well.