Repository navigation
Fix vector float-to-int and signed integer conversions - #16
Merged
Merged
Conversation
OpConvertFToS produced a signed convert_intN value for an unsigned uintN result. Scalars convert implicitly, but OpenCL C has no implicit conversion between vector types, so reinterpret the result with as_type as other signed operations do. The NaN guard of saturating conversions spliced isnan(x) in as the condition of a select, which for a vector is a mask as wide as x's elements rather than the result's, and selected an untyped 0 that outranks narrow element types. Bring the mask to the result's width through relational_mask and a new expression-level select_mask, factored out of select_condition, and select the result type's null constant. Fixes #10.
OpSConvert and OpSatConvertUToS convert to the signed spelling of their result type, but the result is declared with the unsigned spelling. That converts implicitly for scalars but is an error for vectors, so reinterpret the result with as_type like OpConvertFToS.
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.
Saturating
OpConvertFToS/OpConvertFToUon vectors emitted C that clang rejects. There were three separate problems:isnan(x)directly as the select condition. For a vector, that mask is as wide asx's elements, not the result's (long4vsint4fordouble4→uint4). It now goes throughrelational_maskand a new expression-levelselect_mask, which is factored out ofselect_condition.0, which outranks narrow element types (short4). It now selects the result type's null constant.OpConvertFToSassigned a signedconvert_intNresult to the unsigneduintNresult. Scalars convert implicitly, but OpenCL C has no implicit conversion between vector types, so even non-saturating vector conversions failed. The result is now reinterpreted withas_type, as other signed operations already do.The second commit fixes the same signedness bug in
OpSConvertandOpSatConvertUToS(ulong4 = convert_long4(...),ushort4 = convert_short4_sat(...)).The emitted expressions give the expected results (NaN → 0, saturation at the type limits, rounding toward zero) on Intel OpenCL, PoCL and NVIDIA.
Fixes #10.