Closed kg closed 1 year ago
Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics See info in area-owners.md if you want to be subscribed.
Author: | kg |
---|---|
Assignees: | - |
Labels: | `documentation`, `area-System.Runtime.Intrinsics`, `increase-code-coverage` |
Milestone: | - |
Tests exist, they are generated from templates and cover testing correctness: https://raw.githubusercontent.com/dotnet/runtime/main/src/tests/Common/GenerateHWIntrinsicTests
The conversion from long->double->long
matches the general case of ConvertToDouble(VectorXXX<Int64>)
and ConvertToInt64(VectorXXX<double>)
which likewise has coverage and testing.
In general, NaN->integer
is considered implementation defined behavior and the exact result is non-deterministic, even for scalar results.
Sqrt
for integers is really a case that likely shouldn't have been exposed/supported. It should have instead been like Ceiling/Floor
where it only exists for floating-point values. However, that's not how the original Vector<T>
APIs were designed in 2014 and so the handling was brought forward for consistency.
Do the HW intrinsic tests get run for targets without HW vector intrinsics?
Yes. Arm32 and Unix x86 have no support.
Mono (and therefore WASM) are still onboarding SIMD support.
We also stress test all levels of HWIntrinsics disabled (that is we individually test disabling each available ISA in the hierarchy, including disabling HWIntrinsics entirely). Such disablement is available to consumers as well via the DOTNET_Enable*=0
environment variables (where *
is the name of the ISA, for example DOTNET_EnableSSE3=0
disables SSE3 and later ISAs that derive from SSE3.
This is extremely valuable context for digging into the possible failures I'm looking at, thank you!
@kg does this need to stay open given the above or is there still a concern on your end about missing coverage for some scenario?
This issue has been marked needs-author-action
and may be missing some important information.
I'm still uncertain whether we actually have test coverage that would catch the issue I ran into, but we won't be able to find out any time soon since the related stuff (SIMD intrinsics in the interpreter + jiterpreter) hasn't landed yet. I'm ok with closing it and then reopening later if it turns out we do need more tests.
Will close this for the time being. Feel free to re-open if we do have edge cases that need additional coverage.
The
Sqrt
API forVectorNNN<T>
does not specify its behavior for unusual inputs, and it also doesn't appear to have tests in the System.Runtime.Intrinsics test suite. It's not clear to me what should happen if (for example) you attempt to callVector128<Int64>.Sqrt(Vector128<Int64>.AllBitsSet)
, as the benchmarks do. Based on reading theScalar
implementation, we appear to cast the T to Double before passing it toMath.Sqrt
, then cast it back to T. So the behavior I would expect is:For each input,
-1
) to Double, yielding a Double with the value-1.0
-1.0
toSystem.Math.Sqrt
, yielding a Double with aNaN
valueAccording to the official docs
VectorNNN<T>.Sqrt
does not throw any exceptions other thanNotSupportedException
(we also don't specifyMath.Sqrt(double)
as throwing any exceptions, but that's reasonable unlike a possible integerSqrt
- something we don't offer - which might have to throw).So to summarize some issues I see:
Sqrt
does when passed integer values that have no square root, at least not one that can be represented in an integerVectorNNN<T>.Sqrt
and might be missing it for other key methodsSqrt
and may be missing it for other methods (there is already an issue about the relevant benchmarks in the performance repo)For most parts of the vector API you can just presume it will do what the scalar version would do, but there's no scalar equivalent here. Even reading the implementation merely tells me what it probably does, it doesn't tell me what it's meant to do.
Do we have a general documentation page for vectors that specifies how integer vectors behave? I wasn't able to find an overview like this, but I admit I didn't search for too long (since I only visited the docs when trying to puzzle this out).